diff options
Diffstat (limited to 'wizards/com/sun/star/wizards/form')
-rw-r--r-- | wizards/com/sun/star/wizards/form/CallFormWizard.java | 170 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/DataEntrySetter.java | 147 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/FieldLinker.java | 308 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/Finalizer.java | 133 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/FormConfiguration.java | 246 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/FormControlArranger.java | 675 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/FormDocument.java | 554 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/FormWizard.java | 464 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/MANIFEST.MF | 2 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/StyleApplier.java | 444 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/UIControlArranger.java | 295 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/form/form.component | 26 |
12 files changed, 3464 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/form/CallFormWizard.java b/wizards/com/sun/star/wizards/form/CallFormWizard.java new file mode 100644 index 000000000..297ce5775 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/CallFormWizard.java @@ -0,0 +1,170 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.uno.Type; +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.common.PropertyNames; + +/** This class capsulates the class, that implements the minimal component, a + * factory for creating the service (<CODE>__getServiceFactory</CODE>). + */ +public class CallFormWizard +{ + + /** Gives a factory for creating the service. + * This method is called by the <code>JavaLoader</code> + * <p> + * @return Returns a <code>XSingleServiceFactory</code> for creating the component. + * @see com.sun.star.comp.loader.JavaLoader + * @param stringImplementationName The implementation name of the component. + * @param xMSF The service manager, who gives access to every known service. + * @param xregistrykey Makes structural information (except regarding tree structures) of a single + * registry key accessible. + */ + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory(String stringImplementationName, com.sun.star.lang.XMultiServiceFactory xMSF, com.sun.star.registry.XRegistryKey xregistrykey) + { + com.sun.star.lang.XSingleServiceFactory xsingleservicefactory = null; + if (stringImplementationName.equals(FormWizardImplementation.class.getName())) + { + xsingleservicefactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory(FormWizardImplementation.class, FormWizardImplementation.__serviceName, xMSF, xregistrykey); + } + return xsingleservicefactory; + } + + /** This class implements the component. At least the interfaces XServiceInfo, + * XTypeProvider, and XInitialization should be provided by the service. + */ + public static class FormWizardImplementation extends com.sun.star.lib.uno.helper.PropertySet implements com.sun.star.lang.XInitialization, com.sun.star.lang.XServiceInfo, com.sun.star.task.XJobExecutor + { + private PropertyValue[] m_wizardContext; + + /** The constructor of the inner class has a XMultiServiceFactory parameter. + * @param xmultiservicefactoryInitialization A special service factory + * could be introduced while initializing. + */ + public FormWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization) + { + super(); + m_serviceFactory = xmultiservicefactoryInitialization; + } + + public void trigger(String sEvent) + { + try + { + if (sEvent.equals(PropertyNames.START)) + { + FormWizard CurFormWizard = new FormWizard( m_serviceFactory, m_wizardContext ); + CurFormWizard.start(); + } + } + catch (Exception exception) + { + System.err.println(exception); + } + System.gc(); + } + /** The service name, that must be used to get an instance of this service. + */ + private static final String __serviceName = "com.sun.star.wizards.form.CallFormWizard"; + /** The service manager, that gives access to all registered services. + */ + private final com.sun.star.lang.XMultiServiceFactory m_serviceFactory; + + /** This method is a member of the interface for initializing an object + * directly after its creation. + * @param object This array of arbitrary objects will be passed to the + * component after its creation. + * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be + * passed to the caller. + */ + public void initialize(Object[] object) throws com.sun.star.uno.Exception + { + m_wizardContext = Properties.convertToPropertyValueArray(object); + } + + /** This method returns an array of all supported service names. + * @return Array of supported service names. + */ + public java.lang.String[] getSupportedServiceNames() + { + String[] stringSupportedServiceNames = new String[] { __serviceName }; + + return stringSupportedServiceNames; + } + + /** This method returns true, if the given service will be + * supported by the component. + * @param stringService Service name. + * @return True, if the given service name will be supported. + */ + public boolean supportsService(String stringService) + { + boolean booleanSupportsService = false; + + if (stringService.equals(__serviceName)) + { + booleanSupportsService = true; + } + return booleanSupportsService; + } + + @Override + public byte[] getImplementationId() + { + return new byte[0]; + } + + /** Return the class name of the component. + * @return Class name of the component. + */ + public java.lang.String getImplementationName() + { + return FormWizardImplementation.class.getName(); + } + + /** Provides a sequence of all types (usually interface types) + * provided by the object. + * @return Sequence of all types (usually interface types) provided by the + * service. + */ + @Override + public Type[] getTypes() + { + Type[] typeReturn = + { + }; + + try + { + typeReturn = new Type[] + { + new Type(com.sun.star.task.XJobExecutor.class), new Type(com.sun.star.lang.XTypeProvider.class), new Type(com.sun.star.lang.XServiceInfo.class), new Type(com.sun.star.beans.XPropertySet.class), new Type(com.sun.star.beans.XFastPropertySet.class), new Type(com.sun.star.beans.XMultiPropertySet.class), new Type(com.sun.star.lang.XInitialization.class) + }; + } + catch (Exception exception) + { + System.err.println(exception); + } + + return typeReturn; + } + } +} diff --git a/wizards/com/sun/star/wizards/form/DataEntrySetter.java b/wizards/com/sun/star/wizards/form/DataEntrySetter.java new file mode 100644 index 000000000..4b4a3e0cf --- /dev/null +++ b/wizards/com/sun/star/wizards/form/DataEntrySetter.java @@ -0,0 +1,147 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.XCheckBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.beans.PropertyValue; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.WizardDialog; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +public class DataEntrySetter +{ + + private final XRadioButton optDisplayAllData; + private final XCheckBox chknomodification; + private final XCheckBox chknodeletion; + private final XCheckBox chknoaddition; + + public DataEntrySetter(WizardDialog CurUnoDialog) + { + short curtabindex = (short) (FormWizard.SODATA_PAGE * 100); + Integer IDataStep = Integer.valueOf(FormWizard.SODATA_PAGE); + String sNewDataOnly = CurUnoDialog.m_oResource.getResText("RID_FORM_44"); + String sDisplayAllData = CurUnoDialog.m_oResource.getResText("RID_FORM_46"); + String sNoModification = CurUnoDialog.m_oResource.getResText("RID_FORM_47"); // AllowUpdates + String sNoDeletion = CurUnoDialog.m_oResource.getResText("RID_FORM_48"); // AllowDeletes + String sNoAddition = CurUnoDialog.m_oResource.getResText("RID_FORM_49"); // AllowInserts + String sdontdisplayExistingData = CurUnoDialog.m_oResource.getResText("RID_FORM_45"); + + CurUnoDialog.insertRadioButton("optNewDataOnly", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + toggleCheckBoxes(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTNEWDATAONLY", sNewDataOnly, 98, 25, IDataStep, Short.valueOf(curtabindex++), 195 + }); + + optDisplayAllData = CurUnoDialog.insertRadioButton("optDisplayAllData", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + toggleCheckBoxes(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTDISPLAYALLDATA", sDisplayAllData, 98, 50, Short.valueOf((short) 1), IDataStep, Short.valueOf(curtabindex++), 197 + }); + chknomodification = CurUnoDialog.insertCheckBox("chknomodification", null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_CHKNOMODIFICATION", sNoModification, 108, 62, Short.valueOf((short) 0), IDataStep, Short.valueOf(curtabindex++), 189 + }); + chknodeletion = CurUnoDialog.insertCheckBox("chknodeletion", null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_CHKNODELETION", sNoDeletion, 108, 74, Short.valueOf((short) 0), IDataStep, Short.valueOf(curtabindex++), 189 + }); + chknoaddition = CurUnoDialog.insertCheckBox("chknoaddition", null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_CHKNOADDITION", sNoAddition, 108, 86, Short.valueOf((short) 0), IDataStep, Short.valueOf(curtabindex++), 191 + }); + CurUnoDialog.insertLabel("lbldontdisplayExistingData", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, sdontdisplayExistingData, 108, 33, IDataStep, Short.valueOf(curtabindex++), 134 + }); + } + + public PropertyValue[] getFormProperties() + { + PropertyValue[] retProperties; + if (optDisplayAllData.getState()) + { + retProperties = new PropertyValue[3]; + boolean bAllowUpdates = (((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(chknomodification), PropertyNames.PROPERTY_STATE)).shortValue()) != 1; + boolean bAllowDeletes = (((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(chknodeletion), PropertyNames.PROPERTY_STATE)).shortValue()) != 1; + boolean bAllowInserts = (((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(chknoaddition), PropertyNames.PROPERTY_STATE)).shortValue()) != 1; + retProperties[0] = Properties.createProperty("AllowUpdates", Boolean.valueOf(bAllowUpdates)); + retProperties[1] = Properties.createProperty("AllowDeletes", Boolean.valueOf(bAllowDeletes)); + retProperties[2] = Properties.createProperty("AllowInserts", Boolean.valueOf(bAllowInserts)); + } + else + { + retProperties = new PropertyValue[1]; + retProperties[0] = Properties.createProperty("IgnoreResult", Boolean.TRUE); + } + return retProperties; + + } + + private void toggleCheckBoxes() + { + boolean bdisplayalldata = optDisplayAllData.getState(); + Helper.setUnoPropertyValue(UnoDialog.getModel(chknomodification), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdisplayalldata)); + Helper.setUnoPropertyValue(UnoDialog.getModel(chknodeletion), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdisplayalldata)); + Helper.setUnoPropertyValue(UnoDialog.getModel(chknoaddition), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdisplayalldata)); + } +} diff --git a/wizards/com/sun/star/wizards/form/FieldLinker.java b/wizards/com/sun/star/wizards/form/FieldLinker.java new file mode 100644 index 000000000..74dc5707e --- /dev/null +++ b/wizards/com/sun/star/wizards/form/FieldLinker.java @@ -0,0 +1,308 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.VclWindowPeerAttribute; +import com.sun.star.awt.XFixedText; +import com.sun.star.awt.XListBox; +import com.sun.star.uno.Exception; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.HelpIds; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.db.RelationController; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.WizardDialog; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.DBLimitedFieldSelection; +import com.sun.star.wizards.common.PropertyNames; + +public class FieldLinker extends DBLimitedFieldSelection +{ + + private XFixedText[] lblSlaveFields; + private XFixedText[] lblMasterFields; + private XListBox[] lstSlaveFields; + private XListBox[] lstMasterFields; + private int[] SOLINKLST = null; + private String[] sSlaveListHeader; + private String[] sMasterListHeader; //CurUnoDialog.m_oResource.getResText("RID_FORM_40"); + + public FieldLinker(WizardDialog _CurUnoDialog, int iStep, int iCompPosY, int _firsthelpid) + { + super(_CurUnoDialog, iStep, iCompPosY, _firsthelpid); + } + + @Override + protected void insertControlGroup(int i) + { + try + { + if (i == 0) + { + lblSlaveFields = new XFixedText[rowcount]; + lblMasterFields = new XFixedText[rowcount]; + lstSlaveFields = new XListBox[rowcount]; + lstMasterFields = new XListBox[rowcount]; + int SOFIRSTLINKLST = 0; + int SOSECLINKLST = 1; + int SOTHIRDLINKLST = 2; + int SOFOURTHLINKLST = 3; + sSlaveListHeader = new String[4]; //new String[rowcount];PropertyNames.EMPTY_STRING; //CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 40); + sSlaveListHeader[0] = CurUnoDialog.m_oResource.getResText("RID_FORM_20"); + sSlaveListHeader[1] = CurUnoDialog.m_oResource.getResText("RID_FORM_21"); + sSlaveListHeader[2] = CurUnoDialog.m_oResource.getResText("RID_FORM_22"); + sSlaveListHeader[3] = CurUnoDialog.m_oResource.getResText("RID_FORM_23"); + sMasterListHeader = new String[4]; // new String[rowcount];PropertyNames.EMPTY_STRING; //CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 40); + sMasterListHeader[0] = CurUnoDialog.m_oResource.getResText("RID_FORM_24"); + sMasterListHeader[1] = CurUnoDialog.m_oResource.getResText("RID_FORM_25"); + sMasterListHeader[2] = CurUnoDialog.m_oResource.getResText("RID_FORM_26"); + sMasterListHeader[3] = CurUnoDialog.m_oResource.getResText("RID_FORM_27"); + SOLINKLST = new int[] + { + SOFIRSTLINKLST, SOSECLINKLST, SOTHIRDLINKLST, SOFOURTHLINKLST + }; + } + String sSlaveHidString = HelpIds.getHelpIdString(FirstHelpIndex + (i * 2)); + String sMasterHidString = HelpIds.getHelpIdString(FirstHelpIndex + (i * 2) + 1); + boolean bDoEnable = (i < 2); + lblSlaveFields[i] = CurUnoDialog.insertLabel("lblSlaveFieldLink" + Integer.toString(i + 1), + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.valueOf(bDoEnable), 8, sSlaveListHeader[i], 97, Integer.valueOf(iCurPosY), IStep, Short.valueOf(curtabindex++), 97 + }); + lstSlaveFields[i] = CurUnoDialog.insertListBox("lstSlaveFieldLink" + (i + 1), SOLINKLST[i], null, new ItemListenerImpl(), + new String[] + { + "Dropdown", + PropertyNames.PROPERTY_ENABLED, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + "LineCount", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, + Boolean.valueOf(bDoEnable), + UIConsts.INTEGER_12, + sSlaveHidString, + Short.valueOf(UnoDialog.getListBoxLineCount()), + 97, + Integer.valueOf(iCurPosY + 10), + IStep, + Short.valueOf(curtabindex++), + 97 + }); + + lblMasterFields[i] = CurUnoDialog.insertLabel("lblMasterFieldLink" + Integer.toString(i + 1), + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.valueOf(bDoEnable), 8, sMasterListHeader[i], 206, Integer.valueOf(iCurPosY), IStep, Short.valueOf(curtabindex++), 97 + }); + + lstMasterFields[i] = CurUnoDialog.insertListBox("lstMasterFieldLink" + Integer.toString(i + 1), SOLINKLST[i], null, new ItemListenerImpl(), + new String[] + { + "Dropdown", + PropertyNames.PROPERTY_ENABLED, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + "LineCount", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, + Boolean.valueOf(bDoEnable), + UIConsts.INTEGER_12, + sMasterHidString, + Short.valueOf(UnoDialog.getListBoxLineCount()), + 206, + Integer.valueOf(iCurPosY + 10), + IStep, + Short.valueOf(curtabindex++), + 97 + }); + iCurPosY = iCurPosY + 38; + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + @Override + protected void enableNextControlRow(int curindex) + { + boolean bSlaveField = lstSlaveFields[curindex].getSelectedItemPos() > 0; + boolean bMasterField = lstMasterFields[curindex].getSelectedItemPos() > 0; + boolean bDoEnable = (bSlaveField && bMasterField); + if (!bDoEnable) + { + moveupSelectedItems(curindex, bDoEnable); + } + else + { + toggleControlRow(curindex + 1, true); + } + } + + @Override + protected int getMaxSelIndex() + { + int MaxSelIndex = -1; + for (int i = 0; i < rowcount; i++) + { + if ((lstSlaveFields[i].getSelectedItemPos() > 0) && (lstMasterFields[i].getSelectedItemPos() > 0)) + { + MaxSelIndex += 1; + } + } + return MaxSelIndex; + } + + @Override + protected void toggleControlRow(int i, boolean bDoEnable) + { + if (i < rowcount) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(lblSlaveFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(lblMasterFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + if (!bDoEnable) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[i]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[i]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); + } + } + } + + @Override + protected void updateFromNextControlRow(int curindex) + { + short iNextMasterItemPos = lstMasterFields[curindex + 1].getSelectedItemPos(); + short iNextSlaveItemPos = lstSlaveFields[curindex + 1].getSelectedItemPos(); + + if ((iNextMasterItemPos != 0) && (iNextSlaveItemPos != 0)) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[curindex]), PropertyNames.SELECTED_ITEMS, new short[] {iNextMasterItemPos }); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[curindex]), PropertyNames.SELECTED_ITEMS, new short[] {iNextSlaveItemPos}); + + Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[curindex + 1]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[curindex + 1]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); + toggleControlRow(curindex, true); + } + } + + public void initialize(String[] _AllMasterFieldNames, String[] _AllSlaveFieldNames, String[][] _LinkFieldNames) + { + int SOMASTERINDEX = 1; + String[] MasterLinkNames = JavaTools.ArrayOutOfMultiDimArray(_LinkFieldNames, SOMASTERINDEX); + int SOSLAVEINDEX = 0; + String[] SlaveLinkNames = JavaTools.ArrayOutOfMultiDimArray(_LinkFieldNames, SOSLAVEINDEX); + String[] ViewMasterFieldNames = addNoneFieldItemToList(_AllMasterFieldNames); // add '-undefined-' + String[] ViewSlaveFieldNames = addNoneFieldItemToList(_AllSlaveFieldNames); + for (int i = 0; i < rowcount; i++) + { + super.initializeListBox(lstMasterFields[i], ViewMasterFieldNames, MasterLinkNames, i); + super.initializeListBox(lstSlaveFields[i], ViewSlaveFieldNames, SlaveLinkNames, i); + if (_LinkFieldNames != null) + { + toggleControlRow(i, (i <= _LinkFieldNames.length)); + } + else + { + toggleControlRow(i, i == 0); + } + } + } + + public String[][] getLinkFieldNames(RelationController _oRelationController, String _sReferencedTableName) + { + return _oRelationController.getImportedKeyColumns(_sReferencedTableName); + } + + /** + * @return the LinkFieldnames of the joins. When no LinkFieldNames were selected the returned Array is empty. + * When Joins were assigned duplicate a null value is returned + * + */ + public String[][] getLinkFieldNames() + { + int nSelectedIndex = getMaxSelIndex(); + String[][] LinkFieldNames = new String[2][nSelectedIndex + 1]; + for (int i = 0; i <= nSelectedIndex; i++) + { + LinkFieldNames[0][i] = lstSlaveFields[i].getSelectedItem(); + LinkFieldNames[1][i] = lstMasterFields[i].getSelectedItem(); + } + int iduplicate = JavaTools.getDuplicateFieldIndex(LinkFieldNames); + if (iduplicate != -1) + { + String sLinkFieldsAreDuplicate = CurUnoDialog.m_oResource.getResText("RID_FORM_19"); + String sLocLinkFieldsAreDuplicate = JavaTools.replaceSubString(sLinkFieldsAreDuplicate, LinkFieldNames[0][iduplicate], "<FIELDNAME1>"); + sLocLinkFieldsAreDuplicate = JavaTools.replaceSubString(sLocLinkFieldsAreDuplicate, LinkFieldNames[1][iduplicate], "<FIELDNAME2>"); + CurUnoDialog.setCurrentStep(FormWizard.SOFIELDLINKER_PAGE); + CurUnoDialog.enableNavigationButtons(true, true, true); + CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, sLocLinkFieldsAreDuplicate); + CurUnoDialog.setFocus("lstSlaveFieldLink" + (iduplicate + 1)); + return null; + } + return LinkFieldNames; + + } + + public void enable(boolean _bdoenable) + { + CurUnoDialog.setStepEnabled(IStep.intValue(), _bdoenable); + } + + private class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + public void itemStateChanged(ItemEvent EventObject) + { + if (EventObject == null) { + return; + } + int ikey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); + enableNextControlRow(ikey); + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } +} diff --git a/wizards/com/sun/star/wizards/form/Finalizer.java b/wizards/com/sun/star/wizards/form/Finalizer.java new file mode 100644 index 000000000..1fa97b0ac --- /dev/null +++ b/wizards/com/sun/star/wizards/form/Finalizer.java @@ -0,0 +1,133 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.XRadioButton; +import com.sun.star.awt.XTextComponent; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.ui.*; +import com.sun.star.wizards.ui.event.XTextListenerAdapter; + +/** + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class Finalizer +{ + + private WizardDialog CurUnoDialog; + private XRadioButton optModifyForm; + private XTextComponent txtFormName; + private FormDocument oFormDocument; + + public Finalizer(WizardDialog _CurUnoDialog) + { + this.CurUnoDialog = _CurUnoDialog; + short curtabindex = (short) (FormWizard.SOSTORE_PAGE * 100); + + String slblFormName = CurUnoDialog.m_oResource.getResText("RID_FORM_50"); + String slblProceed = CurUnoDialog.m_oResource.getResText("RID_FORM_51"); + String sWorkWithForm = CurUnoDialog.m_oResource.getResText("RID_FORM_52"); + String sModifyForm = CurUnoDialog.m_oResource.getResText("RID_FORM_53"); + CurUnoDialog.insertLabel("lblFormName", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], slblFormName, 97, 25, UIConsts.INTEGERS[8], Short.valueOf(curtabindex++), 111 + }); + txtFormName = CurUnoDialog.insertTextField("txtFormName", new XTextListenerAdapter() { + @Override + public void textChanged(TextEvent event) { + toggleFinishButton(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Text", PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGER_12, "HID:WIZARDS_HID_DLGFORM_TXTPATH", 97, 35, UIConsts.INTEGERS[8], Short.valueOf((short) 82), PropertyNames.EMPTY_STRING, 185 + }); + CurUnoDialog.insertLabel("lblProceed", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], slblProceed, 97, 62, UIConsts.INTEGERS[8], Short.valueOf(curtabindex++), 185 + }); + CurUnoDialog.insertRadioButton("optWorkWithForm", null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTWORKWITHFORM", sWorkWithForm, 101, 77, Short.valueOf((short) 1), UIConsts.INTEGERS[8], Short.valueOf(curtabindex++), 107 + }); + optModifyForm = CurUnoDialog.insertRadioButton("optModifyForm", null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTMODIFYFORM", sModifyForm, 101, 89, UIConsts.INTEGERS[8], Short.valueOf(curtabindex++), 107 + }); + } + + public void initialize(String _formname, FormDocument _oFormDocument) + { + if (oFormDocument == null) + { + oFormDocument = _oFormDocument; + } + if (txtFormName.getText().length() == 0) + { + txtFormName.setText(Desktop.getUniqueName(_oFormDocument.oMainFormDBMetaData.getFormDocuments(), _formname)); + } + } + + private void toggleFinishButton() + { + CurUnoDialog.enableFinishButton(txtFormName.getText().length() > 0); + } + + public String getName() + { + return txtFormName.getText(); + } + + public boolean getOpenForEditing() + { + return optModifyForm.getState(); + } + + public boolean finish() + { + return oFormDocument.oMainFormDBMetaData.storeDatabaseDocumentToTempPath(this.oFormDocument.xComponent, getName()); + } +} diff --git a/wizards/com/sun/star/wizards/form/FormConfiguration.java b/wizards/com/sun/star/wizards/form/FormConfiguration.java new file mode 100644 index 000000000..9f74c2437 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/FormConfiguration.java @@ -0,0 +1,246 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.XCheckBox; +import com.sun.star.awt.XFixedText; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.RelationController; +import com.sun.star.wizards.ui.CommandFieldSelection; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.WizardDialog; +import com.sun.star.wizards.ui.event.XActionListenerAdapter; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +/** + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class FormConfiguration +{ + + private WizardDialog CurUnoDialog; + private XRadioButton optOnExistingRelation; + private XCheckBox chkcreateSubForm; + private XRadioButton optSelectManually; + private XFixedText lblRelations; + private XListBox lstRelations; + private String[] sreferencedTables; + private CommandFieldSelection CurSubFormFieldSelection; + private boolean bsupportsRelations; + private RelationController oRelationController = null; + + public FormConfiguration(WizardDialog _CurUnoDialog) + { + this.CurUnoDialog = _CurUnoDialog; + short curtabindex = (short) (FormWizard.SOSUBFORM_PAGE * 100); + Integer ISubFormStep = Integer.valueOf(FormWizard.SOSUBFORM_PAGE); + String sOnExistingRelation = CurUnoDialog.m_oResource.getResText("RID_FORM_5"); + String sOnManualRelation = CurUnoDialog.m_oResource.getResText("RID_FORM_7"); + String sSelectManually = CurUnoDialog.m_oResource.getResText("RID_FORM_4"); + String sSelectRelation = CurUnoDialog.m_oResource.getResText("RID_FORM_8"); + String sSubFormDescription = CurUnoDialog.m_oResource.getResText("RID_FORM_3"); + + // CheckBox 'Add sub form' + chkcreateSubForm = CurUnoDialog.insertCheckBox("chkcreateSubForm", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + toggleSubFormMode(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_CHKCREATESUBFORM", sSelectManually, 97, 26, ISubFormStep, Short.valueOf(curtabindex++), 160 + }); + optOnExistingRelation = CurUnoDialog.insertRadioButton("optOnExistingRelation", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + toggleSteps(); + } + }, + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.FALSE, UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTONEXISTINGRELATION", sOnExistingRelation, 107, 43, ISubFormStep, Short.valueOf(curtabindex++), 160 + }); + optSelectManually = CurUnoDialog.insertRadioButton("optSelectManually", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + toggleSteps(); + } + }, + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.FALSE, UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTSELECTMANUALLY", sOnManualRelation, 107, 99, Short.valueOf((short) 1), ISubFormStep, Short.valueOf(curtabindex++), 160 + }); + lblRelations = CurUnoDialog.insertLabel("lblSelectRelation", + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.FALSE, 19, sSelectRelation, Boolean.TRUE, 119, 56, ISubFormStep, Short.valueOf(curtabindex++), 80 + }); + lstRelations = CurUnoDialog.insertListBox("lstrelations", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + onexistingRelationSelection(); + } + }, new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + onexistingRelationSelection(); + } + }, + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.FALSE, 37, "HID:WIZARDS_HID_DLGFORM_lstRELATIONS", 201, 55, ISubFormStep, Short.valueOf(curtabindex++), 103 + }); + CurUnoDialog.insertLabel("lblSubFormDescription", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 59, sSubFormDescription, Boolean.TRUE, 110, 120, ISubFormStep, Short.valueOf(curtabindex++), 190 + }); + CurUnoDialog.insertInfoImage(97, 120, ISubFormStep.intValue()); + } + + + public RelationController getRelationController() + { + return oRelationController; + } + + public boolean areexistingRelationsdefined() + { + return ((chkcreateSubForm.getState() == 1) && (optOnExistingRelation.getState())); + } + + private void toggleSubFormMode() + { + boolean bdoEnable = (this.chkcreateSubForm.getState() == 1); + Helper.setUnoPropertyValue(UnoDialog.getModel(optOnExistingRelation), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable && bsupportsRelations)); + Helper.setUnoPropertyValue(UnoDialog.getModel(optSelectManually), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable)); + toggleSteps(); + } + + public void initialize(CommandFieldSelection _CurSubFormFieldSelection, RelationController _oRelationController) + { + oRelationController = _oRelationController; + sreferencedTables = oRelationController.getExportedKeys(); + bsupportsRelations = (sreferencedTables.length > 0); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.STRING_ITEM_LIST, sreferencedTables); + this.CurSubFormFieldSelection = _CurSubFormFieldSelection; + toggleRelationsListbox(); + Helper.setUnoPropertyValue(UnoDialog.getModel(optOnExistingRelation), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bsupportsRelations && (chkcreateSubForm.getState() == 1))); + } + + private void toggleSteps() + { + if (chkcreateSubForm.getState() == 1) + { + if (optOnExistingRelation.getState()) + { + onexistingRelationSelection(); + } + else if (optSelectManually.getState()) + { + CurUnoDialog.enablefromStep(FormWizard.SOFIELDLINKER_PAGE, (CurSubFormFieldSelection.getSelectedFieldNames().length > 0)); + CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, true); + } + } + else + { + CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, false); + CurUnoDialog.setStepEnabled(FormWizard.SOFIELDLINKER_PAGE, false); + CurUnoDialog.enablefromStep(FormWizard.SOCONTROL_PAGE, true); + } + toggleRelationsListbox(); + } + + public String getreferencedTableName() + { + if (areexistingRelationsdefined()) + { + short[] iselected = (short[]) Helper.getUnoArrayPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.SELECTED_ITEMS); + if (iselected != null && iselected.length > 0) + { + return sreferencedTables[iselected[0]]; + } + } + return PropertyNames.EMPTY_STRING; + } + + private void onexistingRelationSelection() + { + String scurreferencedTableName = getreferencedTableName(); + if (scurreferencedTableName.length() > 0) + { + if (CurSubFormFieldSelection.getSelectedCommandName().equals(scurreferencedTableName)) + { + CurUnoDialog.enablefromStep(FormWizard.SOSUBFORMFIELDS_PAGE, true); + CurUnoDialog.setStepEnabled(FormWizard.SOFIELDLINKER_PAGE, false); + return; + } + else + { + CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, true); + CurUnoDialog.enablefromStep(FormWizard.SOFIELDLINKER_PAGE, false); + return; + } + } + CurUnoDialog.enablefromStep(FormWizard.SOSUBFORMFIELDS_PAGE, false); + } + + private void toggleRelationsListbox() + { + boolean bdoenable = bsupportsRelations && this.optOnExistingRelation.getState() && (chkcreateSubForm.getState() == 1); + Helper.setUnoPropertyValue(UnoDialog.getModel(lblRelations), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); + } + + public boolean hasSubForm() + { + return (this.chkcreateSubForm.getState() == 1); + } +} diff --git a/wizards/com/sun/star/wizards/form/FormControlArranger.java b/wizards/com/sun/star/wizards/form/FormControlArranger.java new file mode 100644 index 000000000..93becab45 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/FormControlArranger.java @@ -0,0 +1,675 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sdbc.ColumnValue; +import com.sun.star.sdbc.DataType; +import com.sun.star.task.XStatusIndicator; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Exception; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.Resource; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.*; +import com.sun.star.wizards.document.Control; +import com.sun.star.wizards.document.DatabaseControl; +import com.sun.star.wizards.document.FormHandler; +import com.sun.star.wizards.document.Shape; +import com.sun.star.wizards.document.TimeStampControl; + +public class FormControlArranger +{ + + private static final String LABELCONTROL = "LabelControl"; + protected DatabaseControl[] DBControlList = null; + private final XNameContainer xFormName; + private final XMultiServiceFactory xMSF; + private Control[] LabelControlList = null; + private final XStatusIndicator xProgressBar; + private final FieldColumn[] FieldColumns; + // Control curLabelControl; + private int icurArrangement; + private boolean bIsFirstRun; + private boolean bIsVeryFirstRun; + private boolean bControlsareCreated; + private int cXOffset; + private int cYOffset; + private static final int cVertDistance = 200; + private static final int cHoriDistance = 300; + private static final int cLabelGap = 100; + private static final double CMAXREDUCTION = 0.7; + private final FormHandler oFormHandler; + private int iReduceWidth; + private int m_currentLabelPosX; + private int m_currentLabelPosY; + private int m_currentControlPosX; + private int m_currentControlPosY; + private int m_LabelHeight; + private int m_LabelWidth; + private int m_dbControlHeight; + private int m_dbControlWidth; + private int m_MaxLabelWidth; + private int nFormWidth; + private int nFormHeight; + private int m_currentMaxRowHeight; + private int nSecMaxRowY; + private int m_maxPositionX; + private int a; + private int StartA; + private int m_controlMaxPosY = 0; //the maximum YPosition of a DBControl in the form + private Short NBorderType = Short.valueOf((short) 1); //3-D Border + + public FormControlArranger(FormHandler _oFormHandler, XNameContainer _xFormName, CommandMetaData oDBMetaData, XStatusIndicator _xProgressBar, Point _StartPoint, Size _FormSize) + { + FieldColumns = oDBMetaData.FieldColumns; + xMSF = oDBMetaData.xMSF; + xFormName = _xFormName; + xProgressBar = _xProgressBar; + LabelControlList = new Control[FieldColumns.length]; + DBControlList = new DatabaseControl[FieldColumns.length]; + oFormHandler = _oFormHandler; + cXOffset = _StartPoint.X; + cYOffset = _StartPoint.Y; + setFormSize(_FormSize); + } + // Note: on all Controls except for the checkbox the Label has to be set + // a bit under the DBControl because its Height is also smaller + + private int getLabelDiffHeight(int _index) + { + final DatabaseControl curDBControl = DBControlList[_index]; + if (curDBControl != null && curDBControl.getControlType() == FormHandler.SOCHECKBOX) + { + return getCheckBoxDiffHeight(_index); + } + return oFormHandler.getBasicLabelDiffHeight(); + } + + public Control[] getLabelControlList() + { + return LabelControlList; + } + + private int getCheckBoxDiffHeight(int LastIndex) + { + if (LastIndex < DBControlList.length && DBControlList[LastIndex].getControlType() == FormHandler.SOCHECKBOX) + { + return (oFormHandler.getControlReferenceHeight() - DBControlList[LastIndex].getControlHeight()) / 2; + } + return 0; + } + + private boolean isReducable(int _index, int i_labelWidth, int i_dbControlWidth) + { + boolean bisreducable = false; + int ntype = FieldColumns[_index].getFieldType(); + switch (ntype) + { + case DataType.TINYINT: + case DataType.SMALLINT: + case DataType.INTEGER: + case DataType.FLOAT: + case DataType.DATE: + case DataType.TIME: + case DataType.TIMESTAMP: + case DataType.REAL: + case DataType.DOUBLE: + case DataType.NUMERIC: + case DataType.DECIMAL: + case DataType.BIT: + case DataType.BOOLEAN: + bisreducable = false; + break; + case DataType.VARCHAR: + short nTextLen; + try + { + nTextLen = AnyConverter.toShort(DBControlList[_index].xPropertySet.getPropertyValue("MaxTextLen")); + if ((nTextLen == 0) || (nTextLen > 20)) + { + bisreducable = true; + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + break; + case DataType.BIGINT: + bisreducable = true; + break; + default: + bisreducable = true; + } + if (bisreducable && i_labelWidth > 0.9 * CMAXREDUCTION * i_dbControlWidth) + { + bisreducable = false; + } + return bisreducable; + } + + private void checkJustifiedPosition(int a) + { + int nBaseWidth = nFormWidth + cXOffset; + int nLeftDist = m_maxPositionX - nBaseWidth; + int nRightDist = nBaseWidth - (DBControlList[a].getPosition().X - cHoriDistance); + if (nLeftDist < 0.5 * nRightDist) + { + // Fieldwidths in the line can be made smaller... + adjustLineWidth(StartA, a, nLeftDist, -1); + m_currentLabelPosY = m_currentMaxRowHeight + cVertDistance; + m_currentControlPosY = m_currentLabelPosY + m_LabelHeight; + m_currentLabelPosX = cXOffset; + m_currentControlPosX = cXOffset; + bIsFirstRun = true; + StartA = a + 1; + } + else + { + // FieldWidths in the line can be made wider... + if (m_currentControlPosY + m_dbControlHeight == m_currentMaxRowHeight) + { + // The last Control was the highest in the row + m_currentLabelPosY = nSecMaxRowY; + } + else + { + m_currentLabelPosY = m_currentMaxRowHeight; + } + m_currentLabelPosY += cVertDistance; + m_currentControlPosY = m_currentLabelPosY + m_LabelHeight; + m_currentControlPosX = cXOffset; + m_currentLabelPosX = cXOffset; + LabelControlList[a].setPosition(new Point(cXOffset, m_currentLabelPosY)); + DBControlList[a].setPosition(new Point(cXOffset, m_currentControlPosY)); + bIsFirstRun = true; + checkOuterPoints(m_currentControlPosX, m_dbControlWidth > m_LabelWidth ? m_dbControlWidth : m_LabelWidth, m_currentControlPosY, m_dbControlHeight, true); + m_currentLabelPosX = m_maxPositionX + cHoriDistance; + m_currentControlPosX = m_currentLabelPosX; + adjustLineWidth(StartA, a - 1, nRightDist, 1); + StartA = a; + } + } + + private int getCorrWidth(int StartIndex, int EndIndex, int nDist, int Widthfactor) + { + int ShapeCount; + if (Widthfactor > 0) + { + // shapes are made wide + ShapeCount = EndIndex - StartIndex + 1; + } + else + { + // shapes are made more narrow + ShapeCount = iReduceWidth; + } + if(ShapeCount == 0) + return 0; + else + return (nDist) / ShapeCount; + } + + /** + * + * @param StartIndex + * @param EndIndex + * @param nDist + * @param WidthFactor is either '+1' or '-1' and determines whether the control shapes widths are to be made smaller or larger + */ + private void adjustLineWidth(final int StartIndex, final int EndIndex, final int nDist, final int WidthFactor) + { + if(StartIndex <= EndIndex) + { + int CorrWidth = getCorrWidth(StartIndex, EndIndex, nDist, WidthFactor); + int iLocTCPosX = cXOffset; + for (int i = StartIndex; i <= EndIndex; i++) + { + int nControlBaseWidth = 0; + DatabaseControl dbControl = DBControlList[i]; + Control curLabelControl = LabelControlList[i]; + if (i != StartIndex) + { + curLabelControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y)); + dbControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y + m_LabelHeight)); + } + final Size labelSize = curLabelControl.getSize(); + Size controlSize = dbControl.getSize(); + if (((labelSize.Width > controlSize.Width)) && (WidthFactor > 0)) + { + nControlBaseWidth = labelSize.Width; + } + else + { + nControlBaseWidth = controlSize.Width; + } + if (FieldColumns[i].getFieldType() == DataType.TIMESTAMP) + { + TimeStampControl oDBTimeStampControl = (TimeStampControl) dbControl; + nControlBaseWidth = oDBTimeStampControl.getSize().Width; + } + if (WidthFactor > 0 || isReducable(i, labelSize.Width, controlSize.Width)) + { + controlSize.Width = nControlBaseWidth + WidthFactor * CorrWidth; + dbControl.setSize(controlSize); + controlSize = dbControl.getSize(); + } + + if (labelSize.Width > controlSize.Width) + { + iLocTCPosX += labelSize.Width; + } + else + { + iLocTCPosX += controlSize.Width; + } + iLocTCPosX += cHoriDistance; + } + } + if (WidthFactor > 0) + { + iReduceWidth = 1; + } + else + { + iReduceWidth = 0; + } + } + + private void checkOuterPoints(int i_nXPos, int i_nWidth, int i_nYPos, int i_nHeight, boolean i_bIsDBField) + { + if (icurArrangement == FormWizard.IN_BLOCK_TOP && i_bIsDBField) + { + // Only at DBControls you can measure the Value of nMaxRowY + if (bIsFirstRun) + { + m_currentMaxRowHeight = i_nYPos + i_nHeight; + nSecMaxRowY = m_currentMaxRowHeight; + } + else + { + int nRowY = i_nYPos + i_nHeight; + if (nRowY >= m_currentMaxRowHeight) + { + nSecMaxRowY = m_currentMaxRowHeight; + m_currentMaxRowHeight = nRowY; + } + } + } + // Find the outer right point + if (bIsFirstRun) + { + m_maxPositionX = i_nXPos + i_nWidth; + bIsFirstRun = false; + } + else + { + int nColRightX = i_nXPos + i_nWidth; + if (nColRightX > m_maxPositionX) + { + m_maxPositionX = nColRightX; + } + } + } + + public void positionControls(int _icurArrangement, Point _aStartPoint, short _iAlign, Short _NBorderType) + { + try + { + NBorderType = _NBorderType; + setStartPoint(_aStartPoint); + icurArrangement = _icurArrangement; + initializePosSizes(); + initializeControlColumn(-1); + bIsVeryFirstRun = true; + m_currentMaxRowHeight = 0; + nSecMaxRowY = 0; + m_maxPositionX = 0; + xProgressBar.start(PropertyNames.EMPTY_STRING, FieldColumns.length); + for (int i = 0; i < FieldColumns.length; i++) + { + try + { + insertLabel(i, _iAlign); + insertDBControl(i); + bIsVeryFirstRun = false; + DBControlList[i].setPropertyValue(LABELCONTROL, LabelControlList[i].xPropertySet); + resetPosSizes(i); + xProgressBar.setValue(i + 1); + } + catch (RuntimeException e) + { + } + } + xProgressBar.end(); + bControlsareCreated = true; + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public boolean areControlsexisting() + { + if (DBControlList != null) + { + if (DBControlList.length > 0) + { + return (DBControlList[0] != null); + } + } + return false; + } + + private void initializeControlColumn(int LastIndex) + { + bIsFirstRun = true; + StartA = LastIndex + 1; + a = 0; + } + + private void resetPosSizes(int LastIndex) + { + int nYRefPos = m_currentControlPosY; + switch (icurArrangement) + { + case FormWizard.COLUMNAR_LEFT: + m_currentControlPosY = m_currentControlPosY + m_dbControlHeight + cVertDistance + getCheckBoxDiffHeight(LastIndex); + nYRefPos = m_currentControlPosY; + if ((m_currentControlPosY > cYOffset + nFormHeight) || (LastIndex == (FieldColumns.length - 1))) + { + repositionColumnarLeftControls(LastIndex); + m_currentLabelPosX = m_maxPositionX + 2 * cHoriDistance; + m_currentControlPosX = m_currentLabelPosX + cLabelGap + m_MaxLabelWidth; + m_currentControlPosY = cYOffset; + nYRefPos = m_currentControlPosY; + initializeControlColumn(LastIndex); + } + else + { + /*a = a + 1;*/ + /* a += 1;*/ + ++a; + } + m_currentLabelPosY = m_currentControlPosY + getLabelDiffHeight(LastIndex); + if ((nYRefPos + m_dbControlHeight) > m_controlMaxPosY) + { + m_controlMaxPosY = nYRefPos + m_dbControlHeight; + } + + break; + case FormWizard.COLUMNAR_TOP: + m_currentLabelPosY = m_currentControlPosY + m_dbControlHeight + cVertDistance + getCheckBoxDiffHeight(LastIndex); + + if ((m_currentLabelPosY > cYOffset + nFormHeight) || (LastIndex == (FieldColumns.length - 1))) + { + m_currentControlPosX = m_maxPositionX + cHoriDistance; + m_currentLabelPosX = m_currentControlPosX; + nYRefPos = m_currentControlPosY; + m_currentControlPosY = cYOffset + m_LabelHeight + cVertDistance; + m_currentLabelPosY = cYOffset; + initializeControlColumn(LastIndex); + } + else + { + ++a; + } + if ((nYRefPos + m_dbControlHeight + cVertDistance) > m_controlMaxPosY) + { + m_controlMaxPosY = nYRefPos + m_dbControlHeight + cVertDistance; + } + break; + + case FormWizard.IN_BLOCK_TOP: + if (isReducable(a, m_LabelWidth, m_dbControlWidth)) + { + ++iReduceWidth; + } + if (m_maxPositionX > cXOffset + nFormWidth) + { + checkJustifiedPosition(a); + nYRefPos = m_currentControlPosY; + } + else + { + m_currentLabelPosX = m_maxPositionX + cHoriDistance; + } + if (a == FieldColumns.length - 1) + { + checkJustifiedPosition(a); + nYRefPos = m_currentControlPosY; + } + m_currentControlPosX = m_currentLabelPosX; + ++a; + if ((nYRefPos + m_dbControlHeight) > m_controlMaxPosY) + { + m_controlMaxPosY = nYRefPos + m_dbControlHeight; + } + break; + } + } + + private void repositionColumnarLeftControls(int LastIndex) + { + bIsFirstRun = true; + for (int i = StartA; i <= LastIndex; i++) + { + if (i == StartA) + { + m_currentLabelPosX = LabelControlList[i].getPosition().X; + m_currentControlPosX = m_currentLabelPosX + m_MaxLabelWidth + cHoriDistance; + } + LabelControlList[i].setSize(new Size(m_MaxLabelWidth, m_LabelHeight)); + resetDBShape(DBControlList[i], m_currentControlPosX); + checkOuterPoints(m_currentControlPosX, m_dbControlWidth, m_currentControlPosY, m_dbControlHeight, true); + } + } + + private void resetDBShape(Shape _curDBControl, int iXPos) + { + m_dbControlWidth = _curDBControl.getSize().Width; + m_dbControlHeight = _curDBControl.getSize().Height; + _curDBControl.setPosition(new Point(iXPos, _curDBControl.getPosition().Y)); + } + + private void initializePosSizes() + { + m_controlMaxPosY = 0; + m_currentLabelPosX = cXOffset; + m_LabelWidth = 2000; + m_dbControlWidth = 2000; + m_dbControlHeight = oFormHandler.getControlReferenceHeight(); + m_LabelHeight = oFormHandler.getLabelHeight(); + iReduceWidth = 0; + if (icurArrangement == FormWizard.COLUMNAR_LEFT) + { + m_currentLabelPosY = cYOffset + getLabelDiffHeight(0); + m_currentControlPosX = cXOffset + 3050; + m_currentControlPosY = cYOffset; + } + else + { + m_currentControlPosX = cXOffset; + m_currentLabelPosY = cYOffset; + } + } + + private void insertLabel(int i, int _iAlign) + { + try + { + Point aPoint = new Point(m_currentLabelPosX, m_currentLabelPosY); + Size aSize = new Size(m_LabelWidth, m_LabelHeight); + if (bControlsareCreated) + { + LabelControlList[i].setPosition(aPoint); + if (icurArrangement != FormWizard.COLUMNAR_LEFT) + { + m_LabelWidth = LabelControlList[i].getPreferredWidth(FieldColumns[i].getFieldTitle()); + aSize.Width = m_LabelWidth; + LabelControlList[i].setSize(aSize); + } + else + { + m_LabelWidth = LabelControlList[i].getSize().Width; + } + } + else + { + final String sFieldName = FieldColumns[i].getFieldName(); + LabelControlList[i] = new Control(oFormHandler, xFormName, FormHandler.SOLABEL, sFieldName, aPoint, aSize); + if (bIsVeryFirstRun && icurArrangement == FormWizard.COLUMNAR_TOP) + { + m_currentControlPosY = m_currentLabelPosY + m_LabelHeight; + } + final String sTitle = FieldColumns[i].getFieldTitle(); + m_LabelWidth = LabelControlList[i].getPreferredWidth(sTitle); + aSize.Width = m_LabelWidth; + LabelControlList[i].setSize(aSize); + } + Control curLabelControl = LabelControlList[i]; + if (icurArrangement == FormWizard.COLUMNAR_LEFT) + { + // Note This If Sequence must be called before retrieving the outer Points + if (bIsFirstRun) + { + m_MaxLabelWidth = m_LabelWidth; + bIsFirstRun = false; + } + else if (m_LabelWidth > m_MaxLabelWidth) + { + m_MaxLabelWidth = m_LabelWidth; + } + } + checkOuterPoints(m_currentLabelPosX, m_LabelWidth, m_currentLabelPosY, m_LabelHeight, false); + if ((icurArrangement == FormWizard.COLUMNAR_TOP) || (icurArrangement == FormWizard.IN_BLOCK_TOP)) + { + m_currentControlPosX = m_currentLabelPosX; + m_currentControlPosY = m_currentLabelPosY + m_LabelHeight; + curLabelControl.xPropertySet.setPropertyValue(PropertyNames.PROPERTY_ALIGN, Short.valueOf((short) com.sun.star.awt.TextAlign.LEFT)); + } + else + { + curLabelControl.xPropertySet.setPropertyValue(PropertyNames.PROPERTY_ALIGN, Short.valueOf((short) _iAlign)); + } + if (!bControlsareCreated) + { + curLabelControl.setSize(new Size(m_LabelWidth, m_LabelHeight)); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void insertDBControl(int i) + { + try + { + String sFieldName = FieldColumns[i].getFieldName(); + int nFieldType = FieldColumns[i].getFieldType(); + boolean bFieldNullable = AnyConverter.toInt(FieldColumns[i].getXColumnPropertySet().getPropertyValue(PropertyNames.PROPERTY_IS_NULLABLE)) != ColumnValue.NO_NULLS; + boolean bFieldHasDefaultValue = !AnyConverter.toString(FieldColumns[i].getXColumnPropertySet().getPropertyValue(PropertyNames.PROPERTY_DEFAULT_VALUE)).isEmpty(); + + Point aPoint = new Point(m_currentControlPosX, m_currentControlPosY); + if (bControlsareCreated) + { + DBControlList[i].setPosition(aPoint); + } + else + { + if (nFieldType == DataType.TIMESTAMP) + { + DBControlList[i] = new TimeStampControl(new Resource(xMSF), oFormHandler, xFormName, sFieldName, aPoint); + } + else + { + DBControlList[i] = new DatabaseControl(oFormHandler, xFormName, sFieldName, nFieldType, aPoint); + if (DBControlList[i].getControlType() == FormHandler.SOCHECKBOX) + { + // Checkboxes have no Label near by + DBControlList[i].setPropertyValue(PropertyNames.PROPERTY_LABEL, PropertyNames.EMPTY_STRING); + } + } + } + DatabaseControl aDBControl = DBControlList[i]; + m_dbControlHeight = aDBControl.getControlHeight(); + m_dbControlWidth = aDBControl.getControlWidth(); + if (nFieldType != DataType.TIMESTAMP) + { + aDBControl.setSize(new Size(m_dbControlWidth, m_dbControlHeight)); + } + if (aDBControl.getControlType() == FormHandler.SOCHECKBOX) + { + m_currentControlPosY = m_currentControlPosY + /*(int)*/ ((oFormHandler.getControlReferenceHeight() - m_dbControlHeight) / 2); + aPoint = new Point(m_currentControlPosX, m_currentControlPosY); + aDBControl.setPosition(aPoint); + } + if (nFieldType == DataType.LONGVARCHAR) /* memo */ + { + Helper.setUnoPropertyValue(aDBControl.xPropertySet, PropertyNames.PROPERTY_MULTILINE, Boolean.TRUE); + } + checkOuterPoints(m_currentControlPosX, m_dbControlWidth, m_currentControlPosY, m_dbControlHeight, true); + aDBControl.setPropertyValue(PropertyNames.PROPERTY_BORDER, NBorderType); + aDBControl.setPropertyValue(PropertyNames.PROPERTY_INPUT_REQUIRED, !(bFieldNullable || bFieldHasDefaultValue)); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public int getFormHeight() + { + return m_controlMaxPosY - cYOffset; + } + + public int getEntryPointY() + { + if (icurArrangement == FormWizard.COLUMNAR_TOP) + { + Control curLabelControl2 = LabelControlList[0]; + return curLabelControl2.getPosition().Y; + } + else + { + DatabaseControl curDBControl2 = DBControlList[0]; + return curDBControl2.getPosition().Y; + } + } + + public void setStartPoint(Point _aPoint) + { + cXOffset = _aPoint.X; + cYOffset = _aPoint.Y; + } + + + + public void setFormSize(Size _FormSize) + { + nFormHeight = _FormSize.Height; + nFormWidth = _FormSize.Width; + } +} diff --git a/wizards/com/sun/star/wizards/form/FormDocument.java b/wizards/com/sun/star/wizards/form/FormDocument.java new file mode 100644 index 000000000..af7244950 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/FormDocument.java @@ -0,0 +1,554 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import java.util.ArrayList; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.CommandMetaData; +import com.sun.star.wizards.document.Control; +import com.sun.star.wizards.document.DatabaseControl; +import com.sun.star.wizards.document.FormHandler; +import com.sun.star.wizards.document.GridControl; +import com.sun.star.wizards.text.TextDocument; +import com.sun.star.wizards.text.TextStyleHandler; +import com.sun.star.wizards.text.ViewHandler; + +public class FormDocument extends TextDocument +{ + protected ArrayList<ControlForm> oControlForms = new ArrayList<ControlForm>(); + protected CommandMetaData oMainFormDBMetaData; + protected CommandMetaData oSubFormDBMetaData; + protected String[][] LinkFieldNames; + + private FormHandler oFormHandler; + private XPropertySet xPropPageStyle; + private static final int SOFORMGAP = 2000; + private boolean bhasSubForm; + private UIControlArranger curUIControlArranger; + private StyleApplier curStyleApplier; + private int nPageWidth; + private int nPageHeight; + private int nFormWidth; + private int nFormHeight; + private Point aMainFormPoint; + private static final String SOMAINFORM = "MainForm"; + private static final String SOSUBFORM = "SubForm"; + + public FormDocument(XMultiServiceFactory xMSF) + { + super(xMSF, new TextDocument.ModuleIdentifier("com.sun.star.sdb.FormDesign"), true); + try + { + oFormHandler = new FormHandler(xMSF, xTextDocument); + oFormHandler.setDrawObjectsCaptureMode(false); + TextStyleHandler oTextStyleHandler = new TextStyleHandler(xTextDocument); + new ViewHandler(xTextDocument); + oMainFormDBMetaData = new CommandMetaData(xMSF);// , CharLocale); + oSubFormDBMetaData = new CommandMetaData(xMSF);// , CharLocale); + ViewHandler oViewHandler = new ViewHandler(xTextDocument); + TextStyleHandler oTextStyleSupplier = new TextStyleHandler(xTextDocument); + Helper.setUnoPropertyValue(xTextDocument, "ApplyFormDesignMode", Boolean.FALSE); + oViewHandler.setViewSetting("ShowTableBoundaries", Boolean.FALSE); + oViewHandler.setViewSetting("ShowOnlineLayout", Boolean.TRUE); + xPropPageStyle = oTextStyleSupplier.getStyleByName("PageStyles", "Standard"); + Size aSize = oTextStyleHandler.changePageAlignment(xPropPageStyle, true); + nPageWidth = aSize.Width; + nPageHeight = aSize.Height; + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public void addUIFormController(UIControlArranger _curUIControlArranger) + { + this.curUIControlArranger = _curUIControlArranger; + } + + public void addStyleApplier(StyleApplier _curStyleApplier) + { + this.curStyleApplier = _curStyleApplier; + } + + private String getDataSourceName() + { + return this.oMainFormDBMetaData.DataSourceName; + } + + private void adjustPageStyle() + { + try + { + int nMargin; + int totfieldcount = getMainFieldCount() + getSubFieldCount(); + if (totfieldcount > 30) + { + nMargin = 500; + } + else if (totfieldcount > 20) + { + nMargin = 750; + } + else + { + nMargin = 1000; + } + xPropPageStyle.setPropertyValue("RightMargin", Integer.valueOf(nMargin)); + xPropPageStyle.setPropertyValue("LeftMargin", Integer.valueOf(nMargin)); + xPropPageStyle.setPropertyValue("TopMargin", Integer.valueOf(nMargin)); + xPropPageStyle.setPropertyValue("BottomMargin", Integer.valueOf(nMargin)); + aMainFormPoint = new Point(nMargin, nMargin); + nFormWidth = (int) (0.8 * nPageWidth) - 2 * nMargin; + nFormHeight = (int) (0.65 * nPageHeight) - 2 * nMargin; + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public void initialize(boolean _baddParentForm, boolean _bShouldHaveSubForm, boolean _bModifySubForm, Short _NBorderType) + { + bhasSubForm = _bShouldHaveSubForm; + adjustPageStyle(); + if (_baddParentForm) + { + if (oControlForms.isEmpty()) + { + final ControlForm aMainControlForm = new ControlForm(this, SOMAINFORM, aMainFormPoint, getMainFormSize(FormWizard.AS_GRID)); + oControlForms.add(aMainControlForm); + } + else + { + oFormHandler.removeControlsofForm(SOMAINFORM); + oControlForms.get(0).oFormController = null; + } + oControlForms.get(0).initialize(curUIControlArranger.getSelectedArrangement(0), _NBorderType); + } + if (_bShouldHaveSubForm) + { + if (oControlForms.size() == 1) + { + adjustMainFormSize(_NBorderType); + final ControlForm aSubControlForm = new ControlForm(this, SOSUBFORM, getSubFormPoint(), getSubFormSize()); + oControlForms.add(aSubControlForm); + /* ((ControlForm) oControlForms.get(1))*/ + aSubControlForm.initialize(curUIControlArranger.getSelectedArrangement(1), _NBorderType); + } + else if (_bModifySubForm) + { + if (oControlForms.size() > 1) + { + oFormHandler.removeControlsofForm(SOSUBFORM); + oControlForms.get(1).oFormController = null; + oControlForms.get(1).initialize(curUIControlArranger.getSelectedArrangement(1), _NBorderType); + } + } + } + else + { + ControlForm aMainForm = oControlForms.get(0); + // WRONG if (oFormHandler.hasFormByName(SOSUBFORM)) + if (aMainForm.xFormContainer != null && aMainForm.xFormContainer.hasByName(SOSUBFORM)) + { + oFormHandler.removeControlsofForm(SOSUBFORM); + oFormHandler.removeElement( aMainForm.xFormContainer, SOSUBFORM ); + oControlForms.get(1).oFormController = null; + oControlForms.remove(1); + adjustMainFormSize(_NBorderType); + } + } + } + + private int getMainFieldCount() + { + return oMainFormDBMetaData.getFieldNames().length; + } + private int getSubFieldCount() + { + return oSubFormDBMetaData.getFieldNames().length; + } + + private Size getMainFormSize(int _curArrangement) + { + int nMainFormHeight = nFormHeight; + if (bhasSubForm) + { + if (_curArrangement == FormWizard.AS_GRID) + { + nMainFormHeight = (int) ((double) (nFormHeight - SOFORMGAP) / 2); + } + else + { + int nTotalFieldCount = getMainFieldCount() + getSubFieldCount(); + nMainFormHeight = (int) (((double) getMainFieldCount() / (double) nTotalFieldCount) * ((double) (nFormHeight - SOFORMGAP) / 2)); + } + } + return new Size(nFormWidth, nMainFormHeight); + } + + private Size getSubFormSize() + { + int nMainFormHeight = oControlForms.get(0).getActualFormHeight(); + return new Size(nFormWidth, nFormHeight - nMainFormHeight - SOFORMGAP); + } + + private Point getSubFormPoint() + { + ControlForm curMainControlForm = oControlForms.get(0); + return new Point(curMainControlForm.aStartPoint.X, + (curMainControlForm.aStartPoint.Y + curMainControlForm.getFormSize().Height + SOFORMGAP)); + } + + private void adjustMainFormSize(Short _NBorderType) + { + ControlForm oMainControlForm = oControlForms.get(0); + oMainControlForm.setFormSize(getMainFormSize(oMainControlForm.curArrangement)); + if (oMainControlForm.curArrangement == FormWizard.AS_GRID) + { + oMainControlForm.oGridControl.setSize(oMainControlForm.getFormSize()); + } + else + { + oMainControlForm.oFormController.positionControls(oMainControlForm.curArrangement, + oMainControlForm.aStartPoint, + curUIControlArranger.getAlignValue(), + _NBorderType); + } + } + + private void adjustSubFormPosSize(Short _NBorderType) + { + ControlForm oMainControlForm = oControlForms.get(0); + ControlForm oSubControlForm = oControlForms.get(1); + oSubControlForm.setFormSize(new Size(nFormWidth, nFormHeight - oMainControlForm.getFormSize().Height)); + if (oSubControlForm.curArrangement == FormWizard.AS_GRID) + { + Point aPoint = oSubControlForm.oGridControl.getPosition(); + int idiffheight = oSubControlForm.getEntryPointY() - oMainControlForm.getActualFormHeight() - oMainControlForm.aStartPoint.Y - SOFORMGAP; + oSubControlForm.setStartPoint(new Point(aPoint.X, (aPoint.Y - idiffheight))); + oSubControlForm.oGridControl.setPosition(oSubControlForm.aStartPoint); + oSubControlForm.oGridControl.setSize(getSubFormSize()); + } + else + { +// oSubControlForm.oFormController.adjustYPositions(_idiffheight); + oSubControlForm.setStartPoint(new Point(oSubControlForm.aStartPoint.X, oMainControlForm.getActualFormHeight() + oMainControlForm.aStartPoint.Y + SOFORMGAP)); + oSubControlForm.oFormController.positionControls(oSubControlForm.curArrangement, oSubControlForm.aStartPoint, curUIControlArranger.getAlignValue(), _NBorderType); + } + } + + private ControlForm getControlFormByName(String _sname) + { + for (int i = 0; i < oControlForms.size(); i++) + { + ControlForm curControlForm = oControlForms.get(i); + if (curControlForm.Name.equals(_sname)) + { + return curControlForm; + } + } + throw new IllegalArgumentException("Searching for control " + _sname + " failed"); + } + + public boolean finalizeForms(DataEntrySetter _curDataEntrySetter, FieldLinker _curFieldLinker, FormConfiguration _curFormConfiguration) + { + try + { + this.xTextDocument.lockControllers(); + PropertyValue[] aFormProperties = _curDataEntrySetter.getFormProperties(); + ControlForm oMasterControlForm = getControlFormByName(SOMAINFORM); + oMasterControlForm.setFormProperties(aFormProperties, oMainFormDBMetaData); + oMasterControlForm.finalizeControls(); + if (oMasterControlForm.xFormContainer.hasByName(SOSUBFORM)) + { + ControlForm oSubControlForm = getControlFormByName(SOSUBFORM); + oSubControlForm.setFormProperties(aFormProperties, oSubFormDBMetaData); + String sRefTableName = _curFormConfiguration.getreferencedTableName(); + if (sRefTableName.equals(PropertyNames.EMPTY_STRING)) + { + LinkFieldNames = _curFieldLinker.getLinkFieldNames(); + } + else + { + LinkFieldNames = _curFieldLinker.getLinkFieldNames(_curFormConfiguration.getRelationController(), sRefTableName); + } + if (LinkFieldNames != null && LinkFieldNames.length > 0) + { + oSubControlForm.xPropertySet.setPropertyValue("DetailFields", LinkFieldNames[0]); + oSubControlForm.xPropertySet.setPropertyValue("MasterFields", LinkFieldNames[1]); + oSubControlForm.finalizeControls(); + return true; + } + return false; + } + return true; + } + catch (Exception e) + { + e.printStackTrace(System.err); + return false; + } + finally + { + unlockallControllers(); + } + } + + public class ControlForm + { + + private XNameContainer xFormContainer; + GridControl oGridControl; + private FormControlArranger oFormController; + private int curArrangement; + private FormDocument oFormDocument; + private String Name; + private Point aStartPoint; + private Size aFormSize; + private CommandMetaData oDBMetaData; + private XPropertySet xPropertySet; + + public ControlForm(FormDocument _oFormDocument, String _sname, Point _astartPoint, Size _aFormSize) + { + aStartPoint = _astartPoint; + aFormSize = _aFormSize; + oFormDocument = _oFormDocument; + Name = _sname; + if (_sname.equals(SOSUBFORM)) + { + ControlForm oMainControlForm = oControlForms.get(0); + xFormContainer = oFormHandler.insertFormbyName(_sname, oMainControlForm.xFormContainer); + } + else + { + xFormContainer = oFormHandler.insertFormbyName(_sname); + } + xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xFormContainer); + if (_sname.equals(SOMAINFORM)) + { + oDBMetaData = oFormDocument.oMainFormDBMetaData; + } + else + { + oDBMetaData = oFormDocument.oSubFormDBMetaData; + } + } + + public void initialize(int _curArrangement, Short _NBorderType) + { + boolean adaptControlStyles = false; + xTextDocument.lockControllers(); + curArrangement = _curArrangement; + if (oGridControl != null) + { + oFormHandler.xDrawPage.remove(oGridControl.xShape); + oGridControl.xComponent.dispose(); + oGridControl = null; + } + if (oFormController == null) + { + oFormController = new FormControlArranger(oFormHandler, xFormContainer, oDBMetaData, xProgressBar, aStartPoint, aFormSize); + } + else + { + if (curArrangement == FormWizard.AS_GRID) + { + oFormHandler.moveShapesToNirwana(getLabelControls()); + oFormHandler.moveShapesToNirwana(getDatabaseControls()); + } + } + if (curArrangement == FormWizard.AS_GRID) + { + insertGridControl(_NBorderType); + adaptControlStyles = true; + } + else + { + adaptControlStyles = !oFormController.areControlsexisting(); + oFormController.positionControls(_curArrangement, aStartPoint, curUIControlArranger.getAlignValue(), _NBorderType); + } + if (adaptControlStyles) + { + curStyleApplier.applyStyle(true); + } + if ((Name.equals(SOMAINFORM)) && (oControlForms.size() > 1)) + { + ControlForm curSubControlForm = oControlForms.get(1); + if (curSubControlForm != null) + { + adjustSubFormPosSize(_NBorderType); + } + } + setFormSize(new Size(aFormSize.Width, getActualFormHeight())); + unlockallControllers(); + } + + public Control[] getLabelControls() + { + if (oFormController != null) + { + return oFormController.getLabelControlList(); + } + else + { + return null; + } + } + + private Size getFormSize() + { + return aFormSize; + } + + private void setFormSize(Size _aSize) + { + aFormSize = _aSize; + oFormController.setFormSize(aFormSize); + } + + private void setStartPoint(Point _aPoint) + { + aStartPoint = _aPoint; + if (oFormController != null) + { + oFormController.setStartPoint(_aPoint); + } + } + + private int getActualFormHeight() + { + if (curArrangement == FormWizard.AS_GRID) + { + return oGridControl.xShape.getSize().Height; + } + else + { + return oFormController.getFormHeight(); + } + } + + private int getEntryPointY() + { + if (curArrangement == FormWizard.AS_GRID) + { + return oGridControl.xShape.getPosition().Y; + } + else + { + return oFormController.getEntryPointY(); + } + } + + private void setFormProperties(PropertyValue[] _aPropertySetList, CommandMetaData _oDBMetaData) + { + try + { + xPropertySet.setPropertyValue("DataSourceName", getDataSourceName()); + xPropertySet.setPropertyValue(PropertyNames.COMMAND, _oDBMetaData.getCommandName()); + xPropertySet.setPropertyValue(PropertyNames.COMMAND_TYPE, Integer.valueOf(_oDBMetaData.getCommandType())); + for (int i = 0; i < _aPropertySetList.length; i++) + { + xPropertySet.setPropertyValue(_aPropertySetList[i].Name, _aPropertySetList[i].Value); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public DatabaseControl[] getDatabaseControls() + { + if (oFormController != null) + { + return oFormController.DBControlList; + } + else + { + return null; + } + } + + public GridControl getGridControl() + { + return oGridControl; + } + + public int getArrangemode() + { + return curArrangement; + } + + private void insertGridControl(Short _NBorderType) + { + try + { + curArrangement = FormWizard.AS_GRID; + if (Name.equals(SOMAINFORM)) + { + oGridControl = new GridControl(xMSF, Name + "_Grid", oFormHandler, xFormContainer, oDBMetaData.FieldColumns, aStartPoint, getMainFormSize(FormWizard.AS_GRID)); + } + else + { + oGridControl = new GridControl(xMSF, Name + "_Grid", oFormHandler, xFormContainer, oDBMetaData.FieldColumns, aStartPoint, getSubFormSize()); + } + oGridControl.xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, _NBorderType); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void finalizeControls() + { + Control[] oLabelControls = getLabelControls(); + Control[] oDBControls = getDatabaseControls(); + if (oLabelControls != null) + { + for (int i = 0; i < getLabelControls().length; i++) + { + if (curArrangement == FormWizard.AS_GRID) + { + if ((oLabelControls[i] != null) && (oDBControls[i] != null)) + { + oFormHandler.removeShape(oLabelControls[i].xShape); + oFormHandler.removeShape(oDBControls[i].xShape); + } + } + else + { + oFormHandler.groupShapesTogether(xMSF, oLabelControls[i].xShape, oDBControls[i].xShape); + } + } + } + } + } +} diff --git a/wizards/com/sun/star/wizards/form/FormWizard.java b/wizards/com/sun/star/wizards/form/FormWizard.java new file mode 100644 index 000000000..4534d8ac5 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/FormWizard.java @@ -0,0 +1,464 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.XWindowPeer; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sdb.application.DatabaseObject; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.db.DatabaseObjectWizard; +import com.sun.star.wizards.db.RelationController; +import com.sun.star.wizards.document.OfficeDocument; +import com.sun.star.wizards.ui.CommandFieldSelection; +import com.sun.star.wizards.ui.UIConsts; + +public class FormWizard extends DatabaseObjectWizard +{ + + private CommandFieldSelection curDBCommandFieldSelection; + private FormConfiguration curFormConfiguration; + private CommandFieldSelection curSubFormFieldSelection; + private FormDocument curFormDocument; + private FieldLinker curFieldLinker; + private UIControlArranger curControlArranger; + private DataEntrySetter CurDataEntrySetter; + private StyleApplier curStyleApplier; + private Finalizer curFinalizer; + private static String slblFields; + private static String slblSelFields; + private String sShowBinaryFields = PropertyNames.EMPTY_STRING; + private String serrFormNameexists = PropertyNames.EMPTY_STRING; + private static final int SOMAIN_PAGE = 1; + public static final int SOSUBFORM_PAGE = 2; + public static final int SOSUBFORMFIELDS_PAGE = 3; + public static final int SOFIELDLINKER_PAGE = 4; + public static final int SOCONTROL_PAGE = 5; + public static final int SODATA_PAGE = 6; + public static final int SOSTYLE_PAGE = 7; + public static final int SOSTORE_PAGE = 8; + public static final int COLUMNAR_LEFT = 1; + public static final int COLUMNAR_TOP = 2; + public static final int AS_GRID = 3; + public static final int IN_BLOCK_TOP = 4; + private String slblTables; + private boolean m_openForEditing; + private boolean m_success = false; + private String FormName; + + public FormWizard(XMultiServiceFactory i_servicFactory, final PropertyValue[] i_wizardContext) + { + super(i_servicFactory, 34400, i_wizardContext); + super.addResourceHandler(); + Helper.setUnoPropertyValues(xDialogModel, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_MOVEABLE, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_TITLE, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 210, Boolean.TRUE, "DialogForm", 102, 41, 1, Short.valueOf((short) 0), m_oResource.getResText("RID_FORM_0"), 310 + }); + drawNaviBar(); + getFormResources(); + setRightPaneHeaders(m_oResource, "RID_FORM_", 90, 8); + } + + public static void main(String i_args[]) + { + executeWizardFromCommandLine( i_args, new WizardFromCommandLineStarter() { + public void start(XMultiServiceFactory factory, PropertyValue[] curproperties) { + FormWizard wizard = new FormWizard(factory, curproperties); + wizard.start(); + } + }); + } + + // @Override + @Override + protected void enterStep(int nOldStep, int nNewStep) + { + try + { + if ((nOldStep < SOCONTROL_PAGE) && (nNewStep >= SOCONTROL_PAGE)) + { + curFormDocument.initialize(curDBCommandFieldSelection.isModified(), curFormConfiguration.hasSubForm(), curSubFormFieldSelection.isModified(), getBorderType()); + curDBCommandFieldSelection.setModified(false); + curSubFormFieldSelection.setModified(false); + } + switch (nNewStep) + { + case SOMAIN_PAGE: + curDBCommandFieldSelection.setModified(false); + break; + case SOSUBFORM_PAGE: + { + final String sCommandName = curDBCommandFieldSelection.getSelectedCommandName(); + RelationController oRelationController = new RelationController(curFormDocument.oMainFormDBMetaData, sCommandName); + curFormConfiguration.initialize(curSubFormFieldSelection, oRelationController); + } + break; + case SOSUBFORMFIELDS_PAGE: + { + String sPreSelectedTableName = curFormConfiguration.getreferencedTableName(); + boolean bReadOnly = (sPreSelectedTableName.length() > 0); + if (sPreSelectedTableName.length() == 0) + { + final String sTableName = curSubFormFieldSelection.getSelectedCommandName(); + String[] aFieldNames = curSubFormFieldSelection.getSelectedFieldNames(); + curFormDocument.oSubFormDBMetaData.initializeFieldColumns(sTableName, aFieldNames); + } + else + { + curSubFormFieldSelection.preselectCommand(sPreSelectedTableName, bReadOnly); + } + } + break; + case SOFIELDLINKER_PAGE: + { + final String[] aMainFieldNames = curFormDocument.oMainFormDBMetaData.getFieldNames(); + final String[] aSubFieldNames = curFormDocument.oSubFormDBMetaData.getFieldNames(); + curFieldLinker.initialize(aMainFieldNames, aSubFieldNames, curFormDocument.LinkFieldNames); + } + break; + case SOCONTROL_PAGE: + curControlArranger.enableSubFormImageList(curFormConfiguration.hasSubForm()); + break; + case SODATA_PAGE: + break; + case SOSTYLE_PAGE: + break; + case SOSTORE_PAGE: + { + String sTableName = this.curDBCommandFieldSelection.getSelectedCommandName(); + this.curFinalizer.initialize(sTableName, curFormDocument); + } + break; + default: + break; + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + protected Short getBorderType() + { + return curStyleApplier.getBorderType(); + } + + // @Override + @Override + protected void leaveStep(int nOldStep, int nNewStep) + { + switch (nOldStep) + { + case SOMAIN_PAGE: + { + final String sTableName = curDBCommandFieldSelection.getSelectedCommandName(); + final String[] aFieldNames = curDBCommandFieldSelection.getSelectedFieldNames(); + curFormDocument.oMainFormDBMetaData.initializeFieldColumns(sTableName, aFieldNames); + + final String[] aMainFieldNames = curFormDocument.oMainFormDBMetaData.getFieldNames(); + curFormDocument.LinkFieldNames = JavaTools.removeOutdatedFields(curFormDocument.LinkFieldNames, aMainFieldNames, 1); + } + break; + case SOSUBFORM_PAGE: + break; + case SOSUBFORMFIELDS_PAGE: + { + final String sTableName = curSubFormFieldSelection.getSelectedCommandName(); + final String[] aFieldNames = curSubFormFieldSelection.getSelectedFieldNames(); + curFormDocument.oSubFormDBMetaData.initializeFieldColumns(sTableName, aFieldNames); + + final String[] aSubFieldNames = curFormDocument.oSubFormDBMetaData.getFieldNames(); + curFormDocument.LinkFieldNames = JavaTools.removeOutdatedFields(curFormDocument.LinkFieldNames, aSubFieldNames, 0); + } + break; + case SOFIELDLINKER_PAGE: + curFormDocument.LinkFieldNames = curFieldLinker.getLinkFieldNames(); + break; + case SOCONTROL_PAGE: + break; + case SODATA_PAGE: + break; + case SOSTYLE_PAGE: + break; + case SOSTORE_PAGE: + break; + default: + break; + } + } + + private void buildSteps() + { + curDBCommandFieldSelection = new CommandFieldSelection(this, curFormDocument.oMainFormDBMetaData, 92, slblFields, slblSelFields, slblTables, true, 34411); + curDBCommandFieldSelection.addFieldSelectionListener(new FieldSelectionListener()); + curFormDocument.xProgressBar.setValue(20); + // Label Help Text + insertLabel("lblBinaryHelpText", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 28, sShowBinaryFields, Boolean.TRUE, 95, 154, Integer.valueOf(SOMAIN_PAGE), 210 + }); + + curFormConfiguration = new FormConfiguration(this); + curFormDocument.xProgressBar.setValue(30); + + curSubFormFieldSelection = new CommandFieldSelection(this, curFormDocument.oSubFormDBMetaData, SOSUBFORMFIELDS_PAGE, 92, slblFields, slblSelFields, slblTables, true, 34431); + curSubFormFieldSelection.addFieldSelectionListener(new FieldSelectionListener()); + insertLabel("lblSubFormBinaryHelpText", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 28, sShowBinaryFields, Boolean.TRUE, 95, 154, Integer.valueOf(SOSUBFORMFIELDS_PAGE), 210 + }); + + curFormDocument.xProgressBar.setValue(40); + + curFieldLinker = new FieldLinker(this, SOFIELDLINKER_PAGE, 30, 34441); + curFormDocument.xProgressBar.setValue(50); + + curControlArranger = new UIControlArranger(this, curFormDocument); + curFormDocument.addUIFormController(curControlArranger); + curFormDocument.xProgressBar.setValue(60); + + CurDataEntrySetter = new DataEntrySetter(this); + curFormDocument.xProgressBar.setValue(70); + + curStyleApplier = new StyleApplier(this, curFormDocument); + curFormDocument.addStyleApplier(curStyleApplier); + curFormDocument.xProgressBar.setValue(80); + + curFinalizer = new Finalizer(this); + curFormDocument.xProgressBar.setValue(100); + + enableNavigationButtons(false, false, false); + curFormDocument.xProgressBar.end(); + } + + // @Override + @Override + public boolean finishWizard() + { + int ncurStep = getCurrentStep(); + if ((switchToStep(ncurStep, SOSTORE_PAGE)) || (ncurStep == SOSTORE_PAGE)) + { + this.curFinalizer.initialize(curDBCommandFieldSelection.getSelectedCommandName(), this.curFormDocument); + String sNewFormName = curFinalizer.getName(); + if (!curFormDocument.oMainFormDBMetaData.hasFormDocumentByName(sNewFormName)) + { + m_openForEditing = curFinalizer.getOpenForEditing(); + FormName = curFinalizer.getName(); + if (curFormDocument.finalizeForms(CurDataEntrySetter, curFieldLinker, curFormConfiguration)) + { + + if (curFinalizer.finish()) + { + m_success = true; + xDialog.endExecute(); + return true; + } + } + } + else + { + String smessage = JavaTools.replaceSubString(serrFormNameexists, sNewFormName, "%FORMNAME"); + showMessageBox("WarningBox", com.sun.star.awt.VclWindowPeerAttribute.OK, smessage); + } + } + return false; + } + + // @Override + @Override + public void cancelWizard() + { + m_success = false; + xDialog.endExecute(); + } + + private void insertFormRelatedSteps() + { + addRoadmap(); + int i = 0; + i = insertRoadmapItem(0, true, m_oResource.getResText("RID_FORM_80"), SOMAIN_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_81"), SOSUBFORM_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_82"), SOSUBFORMFIELDS_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_83"), SOFIELDLINKER_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_84"), SOCONTROL_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_85"), SODATA_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_86"), SOSTYLE_PAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_FORM_87"), SOSTORE_PAGE); + setRoadmapInteractive(true); + setRoadmapComplete(true); + setCurrentRoadmapItemID((short) 1); + } + + public void start() + { + try + { + curFormDocument = new FormDocument(xMSF); + if (curFormDocument.oMainFormDBMetaData.getConnection(m_wizardContext)) + { + curFormDocument.oSubFormDBMetaData.getConnection(new PropertyValue[] + { + Properties.createProperty(PropertyNames.ACTIVE_CONNECTION, curFormDocument.oMainFormDBMetaData.DBConnection) + }); + curFormDocument.xProgressBar.setValue(20); + buildSteps(); + this.curDBCommandFieldSelection.preselectCommand(m_wizardContext, false); + XWindowPeer xWindowPeer2 = createWindowPeer(curFormDocument.xWindowPeer); + curFormDocument.oMainFormDBMetaData.setWindowPeer(xWindowPeer2); + insertFormRelatedSteps(); + short dialogReturn = executeDialog(curFormDocument.xFrame); + xComponent.dispose(); + if ((dialogReturn == 0) && m_success) + { + curFormDocument.oMainFormDBMetaData.addFormDocument(curFormDocument.xComponent); + loadSubComponent(DatabaseObject.FORM, FormName, m_openForEditing); + } + } + } + catch (java.lang.Exception jexception) + { + jexception.printStackTrace(System.err); + } + if ((!m_success) && (curFormDocument != null)) + { + OfficeDocument.close(curFormDocument.xComponent); + } + } + + private void getFormResources() + { + sShowBinaryFields = m_oResource.getResText("RID_FORM_2"); + slblTables = m_oResource.getResText("RID_FORM_6"); + slblFields = m_oResource.getResText("RID_FORM_12"); + slblSelFields = m_oResource.getResText("RID_FORM_1"); + serrFormNameexists = m_oResource.getResText("RID_FORM_98"); + } + + private class FieldSelectionListener implements com.sun.star.wizards.ui.XFieldSelectionListener + { + + private int ID; + + // @Override + public void setID(String sIncSuffix) + { + ID = 1; + if (sIncSuffix != null) + { + if ((!sIncSuffix.equals(PropertyNames.EMPTY_STRING)) && (!sIncSuffix.equals("_"))) + { + String sID = JavaTools.ArrayoutofString(sIncSuffix, "_")[1]; + ID = Integer.parseInt(sID); + } + } + } + + // @Override + public void shiftFromLeftToRight(String[] SelItems, String[] NewItems) + { + if (ID == 1) + { + toggleMainFormSteps(); + } + else + { + toggleSubFormSteps(); + } + } + + // @Override + public void shiftFromRightToLeft(String[] SelItems, String[] NewItems) + { + // TODO When the ListFieldbox is refilled only fields of the current Command may be merged into the Listbox + if (ID == 1) + { + toggleMainFormSteps(); + } + else + { + toggleSubFormSteps(); + } + } + // @Override + + public void moveItemDown(String item) + { + } + + // @Override + public void moveItemUp(String item) + { + } + + private boolean toggleSubFormSteps() + { + curSubFormFieldSelection.setModified(true); + boolean benabled = curSubFormFieldSelection.getSelectedFieldNames().length > 0; + enablefromStep(SOFIELDLINKER_PAGE, benabled); + if (benabled) + curFieldLinker.enable(!curFormConfiguration.areexistingRelationsdefined()); + return benabled; + } + + private void toggleMainFormSteps() + { + curDBCommandFieldSelection.setModified(true); + boolean enabled = curDBCommandFieldSelection.getSelectedFieldNames().length > 0; + enablefromStep(SOSUBFORM_PAGE, enabled); + setControlProperty("btnWizardNext", PropertyNames.PROPERTY_ENABLED, enabled); + if (enabled) + { + if (curFormConfiguration.hasSubForm()) + { + enabled = toggleSubFormSteps(); + } + else + { + setStepEnabled(SOSUBFORMFIELDS_PAGE, false); + setStepEnabled(SOFIELDLINKER_PAGE, false); + } + } + setControlProperty("btnWizardFinish", PropertyNames.PROPERTY_ENABLED, enabled); + } + } +} diff --git a/wizards/com/sun/star/wizards/form/MANIFEST.MF b/wizards/com/sun/star/wizards/form/MANIFEST.MF new file mode 100644 index 000000000..af4c0a07d --- /dev/null +++ b/wizards/com/sun/star/wizards/form/MANIFEST.MF @@ -0,0 +1,2 @@ +RegistrationClassName: com.sun.star.wizards.form.CallFormWizard +UNO-Type-Path: diff --git a/wizards/com/sun/star/wizards/form/StyleApplier.java b/wizards/com/sun/star/wizards/form/StyleApplier.java new file mode 100644 index 000000000..f780273a9 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/StyleApplier.java @@ -0,0 +1,444 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Configuration; +import com.sun.star.wizards.common.FileAccess; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.NoValidPathException; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.document.Control; +import com.sun.star.wizards.document.DatabaseControl; +import com.sun.star.wizards.document.GridControl; +import com.sun.star.wizards.document.TimeStampControl; +import com.sun.star.wizards.text.TextStyleHandler; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.WizardDialog; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +public class StyleApplier +{ + + private final XPropertySet xPageStylePropertySet; + private final XMultiServiceFactory xMSF; + private final XRadioButton optNoBorder; + private final XRadioButton opt3DLook; + private final XListBox lstStyles; + private final FormDocument curFormDocument; + private short iOldLayoutPos; + private String[] StyleNames; + private String[] FileNames; + private static final int SOBACKGROUNDCOLOR = 0; + private static final int SODBTEXTCOLOR = 1; + private static final int SOLABELTEXTCOLOR = 2; + private static final int SOBORDERCOLOR = 5; + private Short IBorderValue = Short.valueOf((short) 1); + + public StyleApplier(WizardDialog CurUnoDialog, FormDocument _curFormDocument) + { + this.curFormDocument = _curFormDocument; + xMSF = curFormDocument.xMSF; + + TextStyleHandler oTextStyleHandler = new TextStyleHandler(curFormDocument.xTextDocument); + xPageStylePropertySet = oTextStyleHandler.getStyleByName("PageStyles", "Standard"); + short curtabindex = (short) (FormWizard.SOSTYLE_PAGE * 100); + Integer IStyleStep = Integer.valueOf(FormWizard.SOSTYLE_PAGE); + String sPageStyles = CurUnoDialog.m_oResource.getResText("RID_FORM_86"); + String sNoBorder = CurUnoDialog.m_oResource.getResText("RID_FORM_29"); + String s3DLook = CurUnoDialog.m_oResource.getResText("RID_FORM_30"); + String sFlat = CurUnoDialog.m_oResource.getResText("RID_FORM_31"); + String sFieldBorder = CurUnoDialog.m_oResource.getResText("RID_FORM_28"); + setStyles(); + short[] SelLayoutPos; + SelLayoutPos = new short[] + { + 0 + }; + + CurUnoDialog.insertLabel("lblStyles", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], sPageStyles, 92, 25, IStyleStep, Short.valueOf(curtabindex++), 90 + }); + + lstStyles = CurUnoDialog.insertListBox("lstStyles", null, new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + changeLayout(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.SELECTED_ITEMS, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 143, "HID:WIZARDS_HID_DLGFORM_LSTSTYLES", 92, 35, SelLayoutPos, IStyleStep, this.StyleNames, Short.valueOf(curtabindex++), 90 + }); + + optNoBorder = CurUnoDialog.insertRadioButton("otpNoBorder", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + changeBorderLayouts(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDNOBORDER", sNoBorder, 196, 39, IStyleStep, Short.valueOf(curtabindex++), "0", 93 + }); + + opt3DLook = CurUnoDialog.insertRadioButton("otp3DLook", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + changeBorderLayouts(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMD3DBORDER", s3DLook, 196, 53, Short.valueOf((short) 1), IStyleStep, Short.valueOf(curtabindex++), "1", 93 + }); + + CurUnoDialog.insertRadioButton("otpFlat", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + changeBorderLayouts(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDSIMPLEBORDER", sFlat, 196, 67, IStyleStep, Short.valueOf(curtabindex++), "2", 93 + }); + + CurUnoDialog.insertFixedLine("lnFieldBorder", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], sFieldBorder, 192, 25, IStyleStep, Short.valueOf(curtabindex++), 98 + }); + } + + private void setStyles() + { + try + { + Object oRootNode = Configuration.getConfigurationRoot(xMSF, "org.openoffice.Office.FormWizard/FormWizard/Styles", false); + XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oRootNode); + String[] StyleNodeNames = xNameAccess.getElementNames(); + StyleNames = new String[StyleNodeNames.length]; + FileNames = new String[StyleNodeNames.length]; + for (int i = 0; i < StyleNodeNames.length; i++) + { + Object oStyleNode = xNameAccess.getByName(StyleNodeNames[i]); + StyleNames[i] = (String) Helper.getUnoPropertyValue(oStyleNode, PropertyNames.PROPERTY_NAME); + FileNames[i] = (String) Helper.getUnoPropertyValue(oStyleNode, "CssHref"); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private short getStyleIndex() + { + try + { + short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(lstStyles), PropertyNames.SELECTED_ITEMS)); + if (SelFields != null) + { + return SelFields[0]; + } + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + } + return (short) -1; + } + + public void applyStyle(boolean _bapplyalways) + { + short iStyle = getStyleIndex(); + if ((iStyle != iOldLayoutPos) || _bapplyalways) + { + if (iStyle > -1) + { + iOldLayoutPos = iStyle; + String sFileName = FileNames[iStyle]; + int[] iStyles = getStyleColors(sFileName); + applyDBControlProperties(iStyles); + } + } + } + + private void changeLayout() + { + short iPos = lstStyles.getSelectedItemPos(); + if (iPos != iOldLayoutPos) + { + iOldLayoutPos = iPos; + String sFileName = FileNames[iPos]; + int[] iStyles = getStyleColors(sFileName); + applyDBControlProperties(iStyles); + } + curFormDocument.unlockallControllers(); + } + + public Short getBorderType() + { + return IBorderValue; + } + + private void changeBorderLayouts() + { + try + { + curFormDocument.xTextDocument.lockControllers(); + + if (optNoBorder.getState()) + { + IBorderValue = Short.valueOf((short) 0); + } + else if (opt3DLook.getState()) + { + IBorderValue = Short.valueOf((short) 1); + } + else + { + IBorderValue = Short.valueOf((short) 2); + } + for (int m = 0; m < curFormDocument.oControlForms.size(); m++) + { + FormDocument.ControlForm curControlForm = curFormDocument.oControlForms.get(m); + if (curControlForm.getArrangemode() == FormWizard.AS_GRID) + { + GridControl oGridControl = curControlForm.getGridControl(); + oGridControl.xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue); + } + else + { + DatabaseControl[] DBControls = curControlForm.getDatabaseControls(); + for (int n = 0; n < DBControls.length; n++) + { + if (DBControls[n].xServiceInfo.supportsService("com.sun.star.drawing.ShapeCollection")) + { + TimeStampControl oTimeStampControl = (TimeStampControl) DBControls[n]; + for (int i = 0; i < 2; i++) + { + XPropertySet xPropertySet = oTimeStampControl.getControlofGroupShapeByIndex(i); + if (xPropertySet == null) { + continue; + } + if (xPropertySet.getPropertySetInfo().hasPropertyByName(PropertyNames.PROPERTY_BORDER)) + { + xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue); + } + } + } + else + { + if (DBControls[n].xPropertySet.getPropertySetInfo().hasPropertyByName(PropertyNames.PROPERTY_BORDER)) + { + DBControls[n].xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue); + } + } + } + } + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + curFormDocument.unlockallControllers(); + } + + + + private int getStyleColor(String[] _sDataList, String _sHeader, String _sPropertyDescription) + { + int index = JavaTools.FieldInList(_sDataList, _sHeader); + if (index > -1) + { + String sPropName = PropertyNames.EMPTY_STRING; + while (((sPropName.indexOf('}') < 0) && (index < _sDataList.length - 1))) + { + String scurline = _sDataList[index++]; + if ((scurline.indexOf(_sPropertyDescription)) > 0) + { + if (scurline.indexOf(':') > 0) + { + String[] sPropList = JavaTools.ArrayoutofString(scurline, ":"); + String sPropValue = sPropList[1]; + sPropValue = sPropValue.trim(); + if (sPropValue.indexOf('#') > -1) + { + sPropValue = JavaTools.replaceSubString(sPropValue, PropertyNames.EMPTY_STRING, PropertyNames.SEMI_COLON); + sPropValue = JavaTools.replaceSubString(sPropValue, PropertyNames.EMPTY_STRING, PropertyNames.SPACE); + return Integer.decode(sPropValue).intValue(); + } + } + } + } + } + return -1; + } + + private String getStylePath() + { + String StylesPath = ""; + try + { + StylesPath = FileAccess.getOfficePath(xMSF, "Config", "", ""); + StylesPath = FileAccess.combinePaths(xMSF, StylesPath, "/wizard/form/styles"); + } + catch (NoValidPathException e) + { + } + return StylesPath; + } + + private int[] getStyleColors(String _filename) + { + String sFilePath = getStylePath() + "/" + _filename; + int[] oStylePropList = new int[6]; + String[] sData = FileAccess.getDataFromTextFile(xMSF, sFilePath); + if (sData != null) { + oStylePropList[SOBACKGROUNDCOLOR] = getStyleColor(sData, ".toctitle {", "background-color:"); + oStylePropList[SODBTEXTCOLOR] = getStyleColor(sData, ".doctitle {", "color:"); + oStylePropList[SOLABELTEXTCOLOR] = getStyleColor(sData, ".toctitle {", "color:"); + oStylePropList[SOBORDERCOLOR] = getStyleColor(sData, ".tcolor {", "border-color:"); + } + return oStylePropList; + } + + private void setDBControlColors(XPropertySet xPropertySet, int[] _iStyleColors) + { + try + { + if (xPropertySet.getPropertySetInfo().hasPropertyByName("TextColor")) + { + if (_iStyleColors[SODBTEXTCOLOR] > -1) + { + xPropertySet.setPropertyValue("TextColor", Integer.decode("#00000")); + } + } + if (xPropertySet.getPropertySetInfo().hasPropertyByName("BackgroundColor")) + { + xPropertySet.setPropertyValue("BackgroundColor", Integer.decode("#DDDDDD")); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void applyDBControlProperties(int[] _iStyleColors) + { + try + { + for (int m = 0; m < curFormDocument.oControlForms.size(); m++) + { + FormDocument.ControlForm curControlForm = curFormDocument.oControlForms.get(m); + if (curControlForm.getArrangemode() == FormWizard.AS_GRID) + { + if (_iStyleColors[SOLABELTEXTCOLOR] > -1) + { + curControlForm.oGridControl.xPropertySet.setPropertyValue("TextColor", Integer.valueOf(_iStyleColors[SODBTEXTCOLOR])); + } + curControlForm.oGridControl.xPropertySet.setPropertyValue("BackgroundColor", Integer.decode("#DDDDDD")); + } + else + { + DatabaseControl[] DBControls = curControlForm.getDatabaseControls(); + for (int n = 0; n < DBControls.length; n++) + { + if (_iStyleColors[SODBTEXTCOLOR] > -1) + { + DatabaseControl aDBControl = DBControls[n]; + if (aDBControl != null) + { + if (aDBControl.xServiceInfo.supportsService("com.sun.star.drawing.ShapeCollection")) + { + TimeStampControl oTimeStampControl = (TimeStampControl) aDBControl; + for (int i = 0; i < 2; i++) + { + XPropertySet xPropertySet = oTimeStampControl.getControlofGroupShapeByIndex(i); + if (xPropertySet == null) { + continue; + } + setDBControlColors(xPropertySet, _iStyleColors); + } + } + else + { + setDBControlColors(aDBControl.xPropertySet, _iStyleColors); + } + } + } + } + Control[] LabelControls = curControlForm.getLabelControls(); + for (int n = 0; n < LabelControls.length; n++) + { + if (_iStyleColors[SOLABELTEXTCOLOR] > -1) + { + LabelControls[n].xPropertySet.setPropertyValue("TextColor", Integer.valueOf(_iStyleColors[SOLABELTEXTCOLOR])); + } + } + } + } + xPageStylePropertySet.setPropertyValue("BackColor", Integer.valueOf(_iStyleColors[SOBACKGROUNDCOLOR])); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } +} diff --git a/wizards/com/sun/star/wizards/form/UIControlArranger.java b/wizards/com/sun/star/wizards/form/UIControlArranger.java new file mode 100644 index 000000000..8f92e8ce6 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/UIControlArranger.java @@ -0,0 +1,295 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.form; + +import java.util.Map; +import java.util.HashMap; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.Size; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XItemListener; +import com.sun.star.awt.XRadioButton; +import com.sun.star.lang.EventObject; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.IRenderer; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.document.Control; +import com.sun.star.wizards.ui.ButtonList; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +import javax.swing.DefaultListModel; +import javax.swing.ListModel; + +public class UIControlArranger +{ + + private final FormWizard CurUnoDialog; + private final FormDocument curFormDocument; + private short curtabindex; + private final XRadioButton optAlignLeft; + private final XRadioButton optAlignRight; + private final XControl flnLabelPlacement; + private final Map<String,String> helpTexts = new HashMap<String,String>(4); + private final ArrangeButtonList[] m_aArrangeList = new ArrangeButtonList[2]; + private final Integer IControlStep; + private static final int SOBASEIMAGEYPOSITION = 66; + private static final int SOIMAGELISTHEIGHT = 60; + private static final String ARRANGELISTSIDE = "private:graphicrepository/wizards/res/formarrangelistside_42.png"; + private static final String ARRANGELISTTOP = "private:graphicrepository/wizards/res/formarrangelisttop_42.png"; + private static final String ARRANGETABLE = "private:graphicrepository/wizards/res/formarrangetable_42.png"; + private static final String ARRANGEFREE = "private:graphicrepository/wizards/res/formarrangefree_42.png"; + + public UIControlArranger(FormWizard _CurUnoDialog, FormDocument _curFormDocument) + { + this.CurUnoDialog = _CurUnoDialog; + this.curFormDocument = _curFormDocument; + curtabindex = (short) (FormWizard.SOCONTROL_PAGE * 100); + IControlStep = Integer.valueOf(FormWizard.SOCONTROL_PAGE); + String sLabelPlacment = CurUnoDialog.m_oResource.getResText("RID_FORM_32"); + String sAlignLeft = CurUnoDialog.m_oResource.getResText("RID_FORM_33"); + String sAlignRight = CurUnoDialog.m_oResource.getResText("RID_FORM_34"); + + // Label "Label Placement" ----------------- + flnLabelPlacement = CurUnoDialog.insertFixedLine("lnLabelPlacement", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], sLabelPlacment, 97, 25, IControlStep, Short.valueOf(curtabindex++), 207 + }); + // Radio Button "Align Left" + optAlignLeft = CurUnoDialog.insertRadioButton("optAlignLeft", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + alignLabelControls(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDALIGNLEFT", sAlignLeft, 107, 38, Short.valueOf((short) 1), IControlStep, Short.valueOf(curtabindex++), 171 + }); + // Radio Button "Align Right" + optAlignRight = CurUnoDialog.insertRadioButton("optAlignRight", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + alignLabelControls(); + } + }, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDALIGNRIGHT", sAlignRight, Boolean.TRUE, 107, 50, IControlStep, Short.valueOf(curtabindex++), 171 + }); + + + DefaultListModel<String> imageModel = new DefaultListModel<String>(); + imageModel.addElement(ARRANGELISTSIDE); + imageModel.addElement(ARRANGELISTTOP); + imageModel.addElement(ARRANGETABLE); + imageModel.addElement(ARRANGEFREE); + + // "Columnar - Labels Left" + helpTexts.put(ARRANGELISTSIDE, CurUnoDialog.m_oResource.getResText("RID_FORM_36")); + + // "Columnar - Labels of Top" + helpTexts.put(ARRANGELISTTOP, CurUnoDialog.m_oResource.getResText("RID_FORM_37")); + + // "As Data Sheet" + helpTexts.put(ARRANGETABLE, CurUnoDialog.m_oResource.getResText("RID_FORM_40")); + + // "In Blocks - Labels Above" + helpTexts.put(ARRANGEFREE, CurUnoDialog.m_oResource.getResText("RID_FORM_39")); + + String sMainArrangementHeader = CurUnoDialog.m_oResource.getResText("RID_FORM_41"); // "Arrangement of the main form" + m_aArrangeList[0] = new ArrangeButtonList(0, imageModel, sMainArrangementHeader); + + String sSubArrangementHeader = CurUnoDialog.m_oResource.getResText("RID_FORM_42"); // "Arrangement of the sub form" + m_aArrangeList[1] = new ArrangeButtonList(1, imageModel, sSubArrangementHeader); + enableAlignControlGroup(false); + } + + public int getSelectedArrangement(int _formindex) + { + return m_aArrangeList[_formindex].m_aButtonList.getSelected() + 1; + } + + private class LayoutRenderer implements IRenderer + { + public String render(Object listItem) + { + if (listItem == null) + { + return PropertyNames.EMPTY_STRING; + } + return (String) helpTexts.get(listItem); + + } + } + + public void enableSubFormImageList(boolean _bdoEnable) + { + m_aArrangeList[1].m_aButtonList.setenabled(_bdoEnable); + CurUnoDialog.setControlProperty("lnLabelPlacment_2", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoEnable)); + } + + public short getAlignValue() + { + return optAlignLeft.getState() ? (short)0 : (short)2; + } + + private void alignLabelControls() + { + try + { + short iAlignValue = getAlignValue(); + for (int m = 0; m < curFormDocument.oControlForms.size(); m++) + { + FormDocument.ControlForm curControlForm = curFormDocument.oControlForms.get(m); + if (curControlForm.getArrangemode() == FormWizard.COLUMNAR_LEFT) + { + Control[] LabelControls = curControlForm.getLabelControls(); + if (LabelControls == null) { + continue; + } + for (int n = 0; n < LabelControls.length; n++) + { + LabelControls[n].xPropertySet.setPropertyValue(PropertyNames.PROPERTY_ALIGN, Short.valueOf(iAlignValue)); + } + } + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void enableAlignControlGroup(boolean _bEnableAlignControlGroup) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(flnLabelPlacement), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnableAlignControlGroup)); + Helper.setUnoPropertyValue(UnoDialog.getModel(optAlignLeft), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnableAlignControlGroup)); + Helper.setUnoPropertyValue(UnoDialog.getModel(optAlignRight), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnableAlignControlGroup)); + } + + private class ArrangeButtonList implements XItemListener + { + + private final int formindex; + private final ButtonList m_aButtonList; + + public ArrangeButtonList(int _formindex, ListModel model, String _sArrangementHeader) + { + formindex = _formindex; + Integer YPos = Integer.valueOf(SOBASEIMAGEYPOSITION + _formindex * SOIMAGELISTHEIGHT); + // Label ArrangementHeader ---------------------- + CurUnoDialog.insertFixedLine("lnLabelPlacment_" + (_formindex + 1), + new String[] + { + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], + _sArrangementHeader, + 97, + YPos, + IControlStep, + Short.valueOf(curtabindex++), + 207 + }); + + int nypos = SOBASEIMAGEYPOSITION + 12 - 5 + _formindex * SOIMAGELISTHEIGHT; + m_aButtonList = new ButtonList(); + m_aButtonList.setPos(new Size(107, nypos)); + m_aButtonList.setButtonSize(new Size(26 + 6, 26 + 5)); + m_aButtonList.setCols(4); + m_aButtonList.setRows(1); + m_aButtonList.setName( "ButtonList_" + formindex ); + m_aButtonList.setStep(Short.valueOf((short) FormWizard.SOCONTROL_PAGE)); + m_aButtonList.setShowButtons(false); // shows a button line at ''wrong'' position like |<| 1..4/4 |>| + m_aButtonList.setRenderer(new LayoutRenderer()); + m_aButtonList.setGap(new Size(3, 3)); +// m_aButtonList.scaleImages = Boolean.FALSE; + m_aButtonList.tabIndex = curtabindex++; + m_aButtonList.helpURL = 34453 + (formindex * 4); + + m_aButtonList.setListModel(model); + m_aButtonList.create(CurUnoDialog); + m_aButtonList.setSelected(FormWizard.AS_GRID - 1); + m_aButtonList.addItemListener(this); + } + + public void itemStateChanged(ItemEvent arg0) + { + try + { + if (m_aArrangeList[formindex].m_aButtonList.isenabled()) + { + boolean bEnableAlignControlGroup; + if (curFormDocument.oControlForms.size() == 2) + { + final int nSelected0 = (m_aArrangeList[0].m_aButtonList.getSelected() + 1); + final int nSelected1 = (m_aArrangeList[1].m_aButtonList.getSelected() + 1); + + bEnableAlignControlGroup = ((nSelected0 == FormWizard.COLUMNAR_LEFT) || + (nSelected1 == FormWizard.COLUMNAR_LEFT)); + } + else + { + final int nSelected0 = (m_aArrangeList[0].m_aButtonList.getSelected() + 1); + bEnableAlignControlGroup = (nSelected0 == FormWizard.COLUMNAR_LEFT); + } + enableAlignControlGroup(bEnableAlignControlGroup); + final Short nBorderType = CurUnoDialog.getBorderType(); + final int nSelected = m_aButtonList.getSelected() + 1; + curFormDocument.oControlForms.get(formindex).initialize(nSelected, nBorderType); + } + } + catch (RuntimeException e) + { + e.printStackTrace(); + } + } + + /* (non-Javadoc) + * @see com.sun.star.lang.XEventListener#disposing(com.sun.star.lang.EventObject) + */ + public void disposing(EventObject arg0) + { + // TODO Auto-generated method stub + } + } +} diff --git a/wizards/com/sun/star/wizards/form/form.component b/wizards/com/sun/star/wizards/form/form.component new file mode 100644 index 000000000..27ea341a9 --- /dev/null +++ b/wizards/com/sun/star/wizards/form/form.component @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.Java2" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation + name="com.sun.star.wizards.form.CallFormWizard$FormWizardImplementation"> + <service name="com.sun.star.wizards.form.CallFormWizard"/> + </implementation> +</component> |