这是indexloc提供的服务,不要输入任何密码
Skip to content
Jochen Staerk edited this page Dec 21, 2015 · 1 revision

Source: http://ubion.ion.ag/mainForumFolder/noa_forum/0092/

as demonstrated by Astor, one can add a toolbar button to openoffice e.g. via

private void addToolbarButton() throws java.lang.Exception {
// use the toolbar
final String resourceURL = "private:resource/toolbar/ToolBar_1";
final String sUnoUrl = ".uno:CommandLineToolbar";
final String sService = "ToolBar.testtoolsc";
final String sToolbarUIName = "ToolBar_1";
XFrame xFrame = officeFrame.getXFrame();
Object ooToolbar = officeApplication.getServiceProvider().createService(
"com.sun.star.frame.ToolBarControllerFactory";);
XUIControllerRegistration oo = (XUIControllerRegistration) UnoRuntime.queryInterface(
XUIControllerRegistration.class, ooToolbar);
if (oo.hasController(sUnoUrl, "";)) {
oo.deregisterController(sUnoUrl, "";);
} else {
oo.registerController(sUnoUrl, "", sService);
}
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFrame);
XLayoutManager oLM = (XLayoutManager) UnoRuntime.queryInterface(XLayoutManager.class, xPropSet
.getPropertyValue("LayoutManager";));
if (oLM.getElement(resourceURL) != null) {
oLM.destroyElement(resourceURL);
}
oLM.createElement(resourceURL);
XUIElement toolbarUIElement = oLM.getElement(resourceURL);
XUIElementSettings toolbarUIElementSettings = (XUIElementSettings) UnoRuntime.queryInterface(
XUIElementSettings.class, toolbarUIElement);
XIndexAccess toolbarIndexAccess = toolbarUIElementSettings.getSettings(true);
XPropertySet toolbarUIElementSettingsPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
toolbarIndexAccess);
toolbarUIElementSettingsPropertySet.setPropertyValue("UIName", sToolbarUIName);
PropertyValue aToolbarItem = new PropertyValue[2];
aToolbarItem[0] = new PropertyValue();
aToolbarItem[0].Name = "CommandURL";
aToolbarItem[0].Value = sUnoUrl;
aToolbarItem[1] = new PropertyValue();
aToolbarItem[1].Name = "Label";
aToolbarItem[1].Value = "Platzhalter";
XIndexContainer toolbarIndexContainer = (XIndexContainer) UnoRuntime.queryInterface(XIndexContainer.class,
toolbarIndexAccess);
toolbarIndexContainer.insertByIndex(0, aToolbarItem);
toolbarUIElementSettings.setSettings(toolbarIndexAccess);
oLM.showElement(resourceURL);
}
Clone this wiki locally