Hi together once again,
at the moment I try to disable a command, but transient. I found an
example in the Dev-Guide. In this example I find two methods - one for
disabling the commands and the other for enabling them again.
I would like to make the disabling transient. Up to now I learned from
Carsten, that I have to change a PropertyValue:
xPropertySet.setPropertyValue("Persistent", new Boolean(false));
I tried to apply it to several Objects, but it does not work out.
Can you tell me wether it is possible to make these changes transient?
The code is below.
Greetings, Tobias
-----%<-----
/**
* Disable all commands defined in the aCommandURLTestSet array
*/
private static void disableCommands() {
// Set the root path for our configuration access
com.sun.star.beans.PropertyValue[] lParams = new
com.sun.star.beans.PropertyValue[1];
lParams[0] = new com.sun.star.beans.PropertyValue();
lParams[0].Name = new String("nodepath");
lParams[0].Value =
"/org.openoffice.Office.Commands/Execute/Disabled";
try {
// Create configuration update access to have write access to
// the configuration
Object xAccess = xConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess",
lParams);
com.sun.star.lang.XSingleServiceFactory xSetElementFactory =
(com.sun.star.lang.XSingleServiceFactory) UnoRuntime
.queryInterface(
com.sun.star.lang.XSingleServiceFactory.class,
xAccess);
com.sun.star.container.XNameContainer xNameContainer =
(com.sun.star.container.XNameContainer) UnoRuntime
.queryInterface(
com.sun.star.container.XNameContainer.class,
xAccess);
if (xSetElementFactory != null && xNameContainer != null) {
Object[] aArgs = new Object[0];
for (int i = 0; i < aCommandURLTestSet.length; i++) {
// Create the nodes with the
// XSingleServiceFactory of the configuration
Object xNewElement = xSetElementFactory
.createInstanceWithArguments(aArgs);
if (xNewElement != null) {
// We have a new node. To set the properties of
// the node we need the XPropertySet interface.
com.sun.star.beans.XPropertySet xPropertySet =
(com.sun.star.beans.XPropertySet) UnoRuntime
.queryInterface(
com.sun.star.beans.XPropertySet.class,
xNewElement);
if (xPropertySet != null) {
// Create a unique node name.
String aCmdNodeName = new
String("Command-");
aCmdNodeName += i;
// Insert the node into the Disabled set
xPropertySet.setPropertyValue("Command",
aCommandURLTestSet[i]);
xPropertySet.setPropertyValue("Persistent",
new Boolean(false));
xNameContainer.insertByName(aCmdNodeName,
xNewElement);
}
}
}
// Commit our changes
com.sun.star.util.XChangesBatch xFlush =
(com.sun.star.util.XChangesBatch) UnoRuntime
queryInterface(
com.sun.star.util.XChangesBatch.class,
xAccess);
xFlush.commitChanges();
}
} catch (com.sun.star.uno.Exception e) {
System.out.println("Exception detected!");
System.out.println(e);
}
}
-----%<-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]