OO-Snippets: Remove textfield

Commons

Keywordsuser, defined, TextField, remove, com.sun.star.text.XTextFieldsSupplier, com.sun.star.text.FieldMaster.User
LanguageJava
ApplicationWriter
AuthorsRodrigo Nunes (initial)
Tom Schindl
Supported Versions
Supported OS
Question How can I remove a user defined textfield so that it does show up in the list of fields anymore?

Given that the text field was created this way:

XDependentTextField myField = (XDependentTextField)
	UnoRuntime.queryInterface(XDependentTextField.class, 
		xTextDocumentFactory.createInstance("com.sun.star.text.TextField.User"));
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextDocumentFactory.createInstance("com.sun.star.text.FieldMaster.User"));
xPropertySet.setPropertyValue("Name", "myField");
xPropertySet.setPropertyValue("Value", new Integer(1));
myField.attachTextFieldMaster(xPropertySet);
Answer

Code-Snippet-Listing (snippet-source)

XTextFieldsSupplier xTFS = (XTextFieldsSupplier)
		UnoRuntime.queryInterface(XTextFieldsSupplier.class, yourTextDocument);
if (xTFS != null) 
{
	XNameAccess xEA = xTFS.getTextFieldMasters();
	if (xEA.hasByName(yourFieldName)) 
	{
		try 
		{
			Object xTFL = xEA.getByName(yourFieldName);
			XComponent xC = (XComponent)UnoRuntime.queryInterface(XComponent.class, xTFL);
			xC.dispose();
		} 
		catch (java.lang.Exception ex) 
		{
			ex.printStackTrace();
		}
	}
}

Changelog

DateUserModification
2004-06-22tomsontomModified to match codesnippet.dtd v2.0
0000-00-00rodInitial version

and