Hi, welcom to this forum.
You have some troubles in createDialog method, but I can not tell what is wrong.
I can add the tab control on the dialog instantiated by css.awt.DialogProvider service even in Java. When I hack your code to use DialogProvider service to generate the dialog, the code worked well. I used the way to create dialog by instantiating css.awt.UnoControlDialogModel and UnoControlDialog services but I met some problems with that and I switched to use the DialogProvider. I have empty.xdl file that contains only dialog itself in some extension package and I use it as base dialog to construct something on it.
You are creating the page from the multiservice factory of the dialog model but use the following way to create new page:
Code: Select all
XComponentContext xContext = xScriptContext.getComponentContext();
XDialog xDialog = createDialog(xContext, "vnd.sun.star.script:Standard.Dialog1?location=application");
if (xDialog == null) return;
XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, xDialog).getModel();
XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDialogModel);
try {
XNameContainer xNameContainer = UnoRuntime.queryInterface(XNameContainer.class, xDialogModel);
Object tabPagesModel = xMsf.createInstance("com.sun.star.awt.tab.UnoControlTabPageContainerModel");
xNameContainer.insertByName("tab", tabPagesModel);
XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, tabPagesModel);
xPropSet.setPropertyValue("Width", 100);
xPropSet.setPropertyValue("Height", 100);
XTabPageContainerModel xTabPagesModel = UnoRuntime.queryInterface(XTabPageContainerModel.class, tabPagesModel);
XTabPageModel xTabPageModel1 = xTabPagesModel.createTabPage((short) 1);
xTabPageModel1.setTitle("Page 1");
xTabPagesModel.insertByIndex(0, xTabPageModel1);
XTabPageModel xTabPageModel2 = xTabPagesModel.createTabPage((short) 2);
xTabPageModel2.setTitle("Page 2");
xTabPagesModel.insertByIndex(1, xTabPageModel2);
com.sun.star.awt.tab.XTabPageContainerModel interface provides createTabPage method to instantiate new page. This is the newer way than the way you are using.
Even you can make the tab control on the dialog, the tab page is not shown on LibreOffice 4.0 - 4.3 (I do not know about later version). It seems this is the bug but I have never seen the issue about it. It works well on Apache OpenOffice 3.4 -.
If you want to use tab control on LO, there is another implementation as com.sun.star.awt.UnoMultiPageModel service. I have used it on MRI extension.
I tried to write an example in Java but LO 4.3.4.1 failed to find Java macro on my environment to test myself. I wrote the following example in BeanShell, the code is not so different from the code written in Java.
Code: Select all
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.beans.NamedValue;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XControlContainer;
import com.sun.star.awt.XSimpleTabController;
import com.sun.star.awt.XDialog;
import com.sun.star.awt.XDialogProvider;
import com.sun.star.awt.tab.XTabPageContainerModel;
import com.sun.star.awt.tab.XTabPageModel;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameContainer;
import com.sun.star.document.XDocumentInsertable;
import com.sun.star.frame.XController;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
XComponentContext xContext = XSCRIPTCONTEXT.getComponentContext();
XMultiComponentFactory xMcf = xContext.getServiceManager();
Object oDialogProvider = xMcf.createInstanceWithContext("com.sun.star.awt.DialogProvider", xContext);
XDialogProvider xDialogProvider = UnoRuntime.queryInterface(XDialogProvider.class, oDialogProvider);
XDialog xDialog = xDialogProvider.createDialog("vnd.sun.star.script:Standard.Dialog1?location=application");
XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, xDialog).getModel();
XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDialogModel);
XNameContainer xNameContainer = UnoRuntime.queryInterface(XNameContainer.class, xDialogModel);
// On LibreOffice 4.0 - 4.3, css.awt.tab.UnoControlTabPageContainerModel service does not work well.
isAOO = true;
String tabServiceName = isAOO ? "com.sun.star.awt.tab.UnoControlTabPageContainerModel" : "com.sun.star.awt.UnoMultiPageModel";
String sTabControlName = "tab";
Object tabPagesModel = xMsf.createInstance(tabServiceName);
xNameContainer.insertByName(sTabControlName, tabPagesModel);
XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, tabPagesModel);
xPropSet.setPropertyValue("Width", 100);
xPropSet.setPropertyValue("Height", 100);
if (isAOO) {
// AOO 3.4 -
XTabPageContainerModel xTabPagesModel = UnoRuntime.queryInterface(XTabPageContainerModel.class, tabPagesModel);
// Create new tab page through XTabPageContainerModel interface
XTabPageModel xTabPageModel1 = xTabPagesModel.createTabPage((short) 1);
xTabPageModel1.setTitle("Page 1");
xTabPagesModel.insertByIndex(0, xTabPageModel1);
XTabPageModel xTabPageModel2 = xTabPagesModel.createTabPage((short) 2);
xTabPageModel2.setTitle("Page 2");
xTabPagesModel.insertByIndex(1, xTabPageModel2);
} else {
// LO 4 -
XControlContainer xControlContaienr = UnoRuntime.queryInterface(XControlContainer.class, xDialog);
XControl xTabPagesControl = xControlContaienr.getControl(sTabControlName);
XSimpleTabController xTabController = UnoRuntime.queryInterface(XSimpleTabController.class, xTabPagesControl);
XNameContainer xTabPageNameContainer = UnoRuntime.queryInterface(XNameContainer.class, tabPagesModel);
// New page created through multi service factory of the dialog
Object pageModel1 = xMsf.createInstance("com.sun.star.awt.UnoPageModel");
xTabPageNameContainer.insertByName("page_1", pageModel1);
NamedValue v = new NamedValue("Title", "Page 1");
xTabController.setTabProps(1, new NamedValue[]{v});
Object pageModel2 = xMsf.createInstance("com.sun.star.awt.UnoPageModel");
xTabPageNameContainer.insertByName("page_2", pageModel2);
NamedValue v = new NamedValue("Title", "Page 2");
xTabController.setTabProps(2, new NamedValue[]{v});
}
xDialog.execute();
return 0;
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04