 | OO-Snippets: Remove textfieldCommons| Keywords | user, defined, TextField, remove, com.sun.star.text.XTextFieldsSupplier, com.sun.star.text.FieldMaster.User |
|---|
| Language | Java |
|---|
| Application | Writer |
|---|
| Authors | Rodrigo 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 | |
|---|
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| Date | User | Modification |
|---|
| 2004-06-22 | tomsontom | Modified to match codesnippet.dtd v2.0 | | 0000-00-00 | rod | Initial version |
|