diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /wizards/com/sun/star/wizards/table | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wizards/com/sun/star/wizards/table')
-rw-r--r-- | wizards/com/sun/star/wizards/table/CGCategory.java | 71 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/CGTable.java | 82 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/CallTableWizard.java | 175 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/FieldDescription.java | 152 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/FieldFormatter.java | 444 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/Finalizer.java | 349 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/MANIFEST.MF | 2 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java | 459 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/ScenarioSelector.java | 364 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/TableWizard.java | 412 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/table/table.component | 26 |
11 files changed, 2536 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/table/CGCategory.java b/wizards/com/sun/star/wizards/table/CGCategory.java new file mode 100644 index 000000000..c0a1148f9 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/CGCategory.java @@ -0,0 +1,71 @@ +/* + * 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.table; + +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Configuration; + +/** + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CGCategory +{ + + private static final String CGROOTPATH = "/org.openoffice.Office.TableWizard/TableWizard/"; + private XMultiServiceFactory xMSF; + XNameAccess xNameAccessTablesNode; + private XNameAccess xNameAccessCurBusinessNode; + + public CGCategory(XMultiServiceFactory _xMSF) + { + xMSF = _xMSF; + } + + public void initialize(String category) + { + try + { + Object oconfigView = Configuration.getConfigurationRoot(xMSF, CGROOTPATH, false); //business/Tables + xNameAccessCurBusinessNode = Configuration.getChildNodebyName( + UnoRuntime.queryInterface(XNameAccess.class, oconfigView), + category); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public String[] getTableNames() + { + try + { + xNameAccessTablesNode = UnoRuntime.queryInterface(XNameAccess.class, xNameAccessCurBusinessNode.getByName("Tables")); + return Configuration.getNodeDisplayNames(xNameAccessTablesNode); + } + catch (Exception e) + { + e.printStackTrace(System.err); + return null; + } + } +} diff --git a/wizards/com/sun/star/wizards/table/CGTable.java b/wizards/com/sun/star/wizards/table/CGTable.java new file mode 100644 index 000000000..1b6313b4b --- /dev/null +++ b/wizards/com/sun/star/wizards/table/CGTable.java @@ -0,0 +1,82 @@ +/* + * 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.table; + +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.wizards.common.Configuration; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.PropertyNames; + +public class CGTable +{ + + private XMultiServiceFactory xMSF; + XNameAccess xNameAccessFieldsNode; + + public CGTable(XMultiServiceFactory _xMSF) + { + xMSF = _xMSF; + } + + public void initialize(XNameAccess _xNameAccessParentNode, int _index) + { + try + { + XNameAccess xNameAccessTableNode = Configuration.getChildNodebyIndex(_xNameAccessParentNode, _index); + xNameAccessFieldsNode = Configuration.getChildNodebyName(xNameAccessTableNode, "Fields"); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public String[] getFieldNames(boolean _bgetbyShortName, int _imaxcolumnchars) + { + try + { + String[] fieldnames = null; + if (_bgetbyShortName) + { + fieldnames = Configuration.getNodeChildNames(xNameAccessFieldsNode, "ShortName"); + for (int i = 0; i < fieldnames.length; i++) + { + if (fieldnames[i].length() > _imaxcolumnchars) + { + fieldnames[i] = fieldnames[i].substring(0, _imaxcolumnchars); + } + } + } + else + { + fieldnames = Configuration.getNodeChildNames(xNameAccessFieldsNode, PropertyNames.PROPERTY_NAME); + } + for (int i = 0; i < fieldnames.length; i++) + { + fieldnames[i] = Desktop.removeSpecialCharacters(xMSF, Configuration.getLocale(xMSF), fieldnames[i]); + } + return fieldnames; + } + catch (Exception e) + { + e.printStackTrace(System.err); + return null; + } + } +} diff --git a/wizards/com/sun/star/wizards/table/CallTableWizard.java b/wizards/com/sun/star/wizards/table/CallTableWizard.java new file mode 100644 index 000000000..1a437b53e --- /dev/null +++ b/wizards/com/sun/star/wizards/table/CallTableWizard.java @@ -0,0 +1,175 @@ +/* + * 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.table; + +import com.sun.star.beans.PropertyAttribute; +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 CallTableWizard +{ + + /** 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(TableWizardImplementation.class.getName())) + { + xsingleservicefactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory(TableWizardImplementation.class, TableWizardImplementation.__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 TableWizardImplementation 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 next two fields are accessed by reflection, do not delete! + public String Command; + public final Integer CommandType = com.sun.star.sdb.CommandType.TABLE; + + /** The constructor of the inner class has a XMultiServiceFactory parameter. + */ + public TableWizardImplementation(com.sun.star.lang.XMultiServiceFactory i_serviceFactory) + { + super(); + m_serviceFactory = i_serviceFactory; + registerProperty( PropertyNames.COMMAND, (short)( PropertyAttribute.READONLY | PropertyAttribute.MAYBEVOID ) ); + registerProperty( PropertyNames.COMMAND_TYPE, PropertyAttribute.READONLY ); + } + + public void trigger( String sEvent ) + { + try + { + if ( sEvent.equals(PropertyNames.START) ) + { + TableWizard CurTableWizard = new TableWizard( m_serviceFactory, m_wizardContext ); + CurTableWizard.startTableWizard(); + } + } + 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.table.CallTableWizard"; + /** 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 TableWizardImplementation.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.lang.XInitialization.class) + }; + } + catch (Exception exception) + { + System.err.println(exception); + } + + return typeReturn; + } + } +} diff --git a/wizards/com/sun/star/wizards/table/FieldDescription.java b/wizards/com/sun/star/wizards/table/FieldDescription.java new file mode 100644 index 000000000..95a847136 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/FieldDescription.java @@ -0,0 +1,152 @@ +/* + * 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.table; + +import java.util.ArrayList; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.Locale; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Configuration; +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.common.PropertyNames; + +public class FieldDescription +{ + private String tablename = PropertyNames.EMPTY_STRING; + private XPropertySet xPropertySet; + private final ArrayList<PropertyValue> aPropertyValues; + private String Name; + + public FieldDescription(XMultiServiceFactory _xMSF, Locale _aLocale, ScenarioSelector _curscenarioselector, String _fieldname, String keyname, int _nmaxcharCount) + { + tablename = _curscenarioselector.getTableName(); + Name = _fieldname; + aPropertyValues = new ArrayList<PropertyValue>(); + XNameAccess xNameAccessTableNode = _curscenarioselector.oCGTable.xNameAccessFieldsNode; + XNameAccess xNameAccessFieldNode; + if (_curscenarioselector.bcolumnnameislimited) + { + xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(_xMSF, _aLocale, xNameAccessTableNode, keyname, "ShortName", _nmaxcharCount); + } + else + { + xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(_xMSF, _aLocale, xNameAccessTableNode, keyname, PropertyNames.PROPERTY_NAME, _nmaxcharCount); + } + setFieldProperties(xNameAccessFieldNode); + } + + public FieldDescription(String _fieldname) + { + Name = _fieldname; + aPropertyValues = new ArrayList<PropertyValue>(); + Integer Type = Integer.valueOf(com.sun.star.sdbc.DataType.VARCHAR); + aPropertyValues.add(Properties.createProperty(PropertyNames.PROPERTY_NAME, _fieldname)); + aPropertyValues.add(Properties.createProperty("Type", Type)); + } + + public void setName(String _newfieldname) + { + for (int i = 0; i < aPropertyValues.size(); i++) + { + PropertyValue aPropertyValue = aPropertyValues.get(i); + if (aPropertyValue.Name.equals(PropertyNames.PROPERTY_NAME)) + { + aPropertyValue.Value = _newfieldname; + aPropertyValues.set(i, aPropertyValue); + Name = _newfieldname; + return; + } + } + } + + public String getName() + { + return Name; + } + + public String gettablename() + { + return tablename; + } + + private boolean propertyexists(String _propertyname) + { + boolean bexists = false; + try + { + if (xPropertySet.getPropertySetInfo().hasPropertyByName(_propertyname)) + { + Object oValue = xPropertySet.getPropertyValue(_propertyname); + bexists = (!com.sun.star.uno.AnyConverter.isVoid(oValue)); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return bexists; + } + + private void setFieldProperties(XNameAccess _xNameAccessFieldNode) + { + try + { + xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, _xNameAccessFieldNode); + if (propertyexists(PropertyNames.PROPERTY_NAME)) + { + aPropertyValues.add(Properties.createProperty(PropertyNames.PROPERTY_NAME, Name)); + } + if (propertyexists("Type")) + { + aPropertyValues.add(Properties.createProperty("Type", xPropertySet.getPropertyValue("Type"))); + } + if (propertyexists("Scale")) + { + aPropertyValues.add(Properties.createProperty("Scale", xPropertySet.getPropertyValue("Scale"))); + } + if (propertyexists("Precision")) + { + aPropertyValues.add(Properties.createProperty("Precision", xPropertySet.getPropertyValue("Precision"))); + } + if (propertyexists("DefaultValue")) + { + aPropertyValues.add(Properties.createProperty("DefaultValue", xPropertySet.getPropertyValue("DefaultValue")));// DefaultValue = (Boolean) xPropertySet.getPropertyValue("DefaultValue"); + //Type = 4; // TODO where is the error?(Integer) xPropertySet.getPropertyValue("Type"); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public PropertyValue[] getPropertyValues() + { + if (aPropertyValues != null) + { + PropertyValue[] aProperties = new PropertyValue[aPropertyValues.size()]; + aPropertyValues.toArray(aProperties); + return aProperties; + } + return null; + } +} diff --git a/wizards/com/sun/star/wizards/table/FieldFormatter.java b/wizards/com/sun/star/wizards/table/FieldFormatter.java new file mode 100644 index 000000000..75a1ade73 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/FieldFormatter.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.table; + +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.FontDescriptor; +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.XButton; +import com.sun.star.awt.XItemListener; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XTextComponent; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.TableDescriptor; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.event.XActionListenerAdapter; +import com.sun.star.wizards.ui.event.XTextListenerAdapter; + +public class FieldFormatter implements XItemListener +{ + + private TableWizard CurUnoDialog; + private TableDescriptor curTableDescriptor; + private Object oColumnDescriptorModel; + private XTextComponent txtfieldname; + private XListBox xlstFieldNames; + private XButton btnminus; + private XButton btnShiftUp; + private XButton btnShiftDown; + private short curtabindex; + private String suntitled; + private Integer IFieldFormatStep; + + public FieldFormatter(TableWizard _CurUnoDialog) + { + this.CurUnoDialog = _CurUnoDialog; + curtabindex = (short) (TableWizard.SOFIELDSFORMATPAGE * 100); + IFieldFormatStep = Integer.valueOf(TableWizard.SOFIELDSFORMATPAGE); + String sFieldName = CurUnoDialog.m_oResource.getResText("RID_TABLE_23"); + String sFieldNames = CurUnoDialog.m_oResource.getResText("RID_TABLE_25"); + String sfieldinfo = CurUnoDialog.m_oResource.getResText("RID_TABLE_20"); + String sbtnplushelptext = CurUnoDialog.m_oResource.getResText("RID_TABLE_45"); + String sbtnminushelptext = CurUnoDialog.m_oResource.getResText("RID_TABLE_46"); + + suntitled = CurUnoDialog.m_oResource.getResText("RID_TABLE_43"); + + CurUnoDialog.insertLabel("lblFieldNames", + 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], sFieldNames, 91, 27, IFieldFormatStep, Short.valueOf(curtabindex++), 67 + }); + + try + { + xlstFieldNames = CurUnoDialog.insertListBox("lstfieldnames", 3, null, this, + new String[] + { + 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[] + { + 133, "HID:WIZARDS_HID_DLGTABLE_LB_SELFIELDNAMES", 92, 37, IFieldFormatStep, Short.valueOf(curtabindex++), 62 + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + + FontDescriptor oFontDesc = new FontDescriptor(); + oFontDesc.Name = "StarSymbol"; + + btnShiftUp = CurUnoDialog.insertButton("btnShiftUp", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + shiftFieldNameUp(); + } + }, + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, 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, oFontDesc, 14, "HID:WIZARDS_HID_DLGTABLE_CMDMOVEFIELDUP", String.valueOf((char) 8743), 158, 139, IFieldFormatStep, Short.valueOf(curtabindex++), 14 + }); + + btnShiftDown = CurUnoDialog.insertButton("btnShiftDown", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + shiftFieldNameDown(); + } + }, + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, 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, oFontDesc, 14, "HID:WIZARDS_HID_DLGTABLE_CMDMOVEFIELDDOWN", String.valueOf((char) 8744), 158, 156, IFieldFormatStep, Short.valueOf(curtabindex++), 14 + }); + oFontDesc = new FontDescriptor(); + oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD; + oFontDesc.Height = (short) 13; + btnminus = CurUnoDialog.insertButton("btnminus", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + removeFieldName(); + } + }, + new String[] + { + PropertyNames.FONT_DESCRIPTOR, 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[] + { + oFontDesc, 14, "HID:WIZARDS_HID_DLGTABLE_CMDMINUS", "-", 118, 175, IFieldFormatStep, Short.valueOf(curtabindex++), 14 + }); + + XButton btnplus = CurUnoDialog.insertButton("btnplus", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + addFieldName(); + } + }, + new String[] + { + PropertyNames.FONT_DESCRIPTOR, 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[] + { + oFontDesc, 14, "HID:WIZARDS_HID_DLGTABLE_CMDPLUS", "+", 137, 175, IFieldFormatStep, Short.valueOf(curtabindex++), 14 + }); + + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "ColDescriptorHeader", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, sfieldinfo, 0, 158, 27, IFieldFormatStep, Short.valueOf(curtabindex++), 165 + }); + + + CurUnoDialog.insertLabel("lblFieldName", + 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], sFieldName, 158, 39, IFieldFormatStep, Short.valueOf(curtabindex++), 94 + }); + + txtfieldname = CurUnoDialog.insertTextField("txtfieldname", new XTextListenerAdapter() { + @Override + public void textChanged(TextEvent event) { + modifyFieldName(); + } + }, + 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_DLGTABLE_COLNAME", 274, 37, IFieldFormatStep, Short.valueOf(curtabindex++), PropertyNames.EMPTY_STRING, 50 + }); + txtfieldname.addTextListener(CurUnoDialog); + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnplus, sbtnplushelptext); + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnminus, sbtnminushelptext); + } + + public void initialize(TableDescriptor _curTableDescriptor, String[] _fieldnames) + { + if (oColumnDescriptorModel == null) + { + oColumnDescriptorModel = CurUnoDialog.insertControlModel("com.sun.star.sdb.ColumnDescriptorControlModel", "oColumnDescriptor", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH, "EditWidth" + }, // PropertyNames.PROPERTY_HELPURL + new Object[] + { + 82, 158, 52, IFieldFormatStep, Short.valueOf(curtabindex++), 166, 50 + }); //, "HID:WIZARDS_HID_DLGTABLE_COLMODIFIER" + curTableDescriptor = _curTableDescriptor; + Helper.setUnoPropertyValue(oColumnDescriptorModel, PropertyNames.ACTIVE_CONNECTION, _curTableDescriptor.DBConnection); + txtfieldname.setMaxTextLen((short) this.curTableDescriptor.getMaxColumnNameLength()); + } + else + { + int nStep = ((Integer) Helper.getUnoPropertyValue(oColumnDescriptorModel, PropertyNames.PROPERTY_STEP)).intValue(); + if (nStep > IFieldFormatStep.intValue()) + { + Helper.setUnoPropertyValue(oColumnDescriptorModel, PropertyNames.PROPERTY_STEP, IFieldFormatStep); + CurUnoDialog.repaintDialogStep(); + } + } + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST, _fieldnames); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + 0 + }); + updateColumnDescriptor(_fieldnames[0], curTableDescriptor.getByName(_fieldnames[0])); + toggleButtons(); + CurUnoDialog.setFocus("lstfieldnames"); + } + + private void toggleButtons() + { + boolean benableShiftUpButton = false; + boolean benableShiftDownButton = false; + boolean bfieldnameisselected = Helper.getUnoArrayPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS) != null; + int ilistcount = /* xlstFieldNames.getItemCount();*/ UnoDialog.getListBoxItemCount(xlstFieldNames); + boolean blistispopulated = (ilistcount > 0); + if (bfieldnameisselected) + { + int iselpos = xlstFieldNames.getSelectedItemPos(); + benableShiftUpButton = (iselpos != 0); + benableShiftDownButton = (iselpos != ilistcount - 1); + } + Helper.setUnoPropertyValue(UnoDialog.getModel(btnShiftUp), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableShiftUpButton)); + Helper.setUnoPropertyValue(UnoDialog.getModel(btnShiftDown), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableShiftDownButton)); + Helper.setUnoPropertyValue(UnoDialog.getModel(btnminus), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(blistispopulated)); + CurUnoDialog.setcompleted(TableWizard.SOFIELDSFORMATPAGE, blistispopulated); + } + + private void addFieldName() + { + String snewfieldname = Desktop.getUniqueName(xlstFieldNames.getItems(), suntitled, PropertyNames.EMPTY_STRING); + short icount = xlstFieldNames.getItemCount(); + if (CurUnoDialog.verifyfieldcount(icount)) + { + xlstFieldNames.addItem(snewfieldname, icount); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + icount + }); + toggleButtons(); + FieldDescription curfielddescription = new FieldDescription(snewfieldname); + CurUnoDialog.fielditems.put(snewfieldname, curfielddescription); + curTableDescriptor.addColumn(curfielddescription.getPropertyValues()); + updateColumnDescriptor(snewfieldname, curTableDescriptor.getByName(snewfieldname)); + CurUnoDialog.setControlVisible("oColumnDescriptor", true); + CurUnoDialog.repaintDialogStep(); + } + } + + private void removeFieldName() + { + String[] fieldnames = (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST); + short ipos = UnoDialog.getSelectedItemPos(xlstFieldNames); + String fieldname = fieldnames[ipos]; + xlstFieldNames.removeItems(ipos, (short) 1); + CurUnoDialog.fielditems.remove(fieldname); + int ilistcount = /* xlstFieldNames.getItemCount();*/ UnoDialog.getListBoxItemCount(xlstFieldNames); + if ((ipos) < ilistcount) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + ipos + }); + } + else + { + if (ilistcount > -1) + { + ipos = (short) ((short) ilistcount - (short) 1); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + ipos + }); + } + } + curTableDescriptor.dropColumnbyName(fieldname); + fieldnames = (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST); + boolean benable = ((ipos > -1) && (ipos < fieldnames.length)); + if (benable) + { + String snewfieldname = fieldnames[ipos]; + updateColumnDescriptor(snewfieldname, curTableDescriptor.getByName(snewfieldname)); + toggleButtons(); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(txtfieldname), "Text", PropertyNames.EMPTY_STRING); + Helper.setUnoPropertyValue(UnoDialog.getModel(btnminus), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benable)); + CurUnoDialog.setcompleted(TableWizard.SOFIELDSFORMATPAGE, benable); + } + Helper.setUnoPropertyValue(UnoDialog.getModel(btnminus), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benable)); + CurUnoDialog.setControlVisible("oColumnDescriptor", benable); + CurUnoDialog.repaintDialogStep(); + } + + private void modifyFieldName() + { + String newfieldname = txtfieldname.getText(); + String oldfieldname = xlstFieldNames.getSelectedItem(); + if (!newfieldname.equals(oldfieldname)) + { + if (curTableDescriptor.modifyColumnName(oldfieldname, newfieldname)) + { + Object oColumn = Helper.getUnoPropertyValue(oColumnDescriptorModel, "Column"); + Helper.setUnoPropertyValue(oColumn, PropertyNames.PROPERTY_NAME, newfieldname); + FieldDescription curfielddescription = CurUnoDialog.fielditems.get(oldfieldname); + CurUnoDialog.fielditems.remove(oldfieldname); + curfielddescription.setName(newfieldname); + CurUnoDialog.fielditems.put(newfieldname, curfielddescription); + String[] fieldnames = xlstFieldNames.getItems(); + short ipos = xlstFieldNames.getSelectedItemPos(); + fieldnames[ipos] = newfieldname; + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST, fieldnames); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + ipos + }); + } + } + } + + private void shiftFieldNameUp() + { + short ipos = xlstFieldNames.getSelectedItemPos(); + String[] snewlist = shiftArrayItem(xlstFieldNames.getItems(), ipos, -1); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST, snewlist); + if ((ipos - 1) > -1) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + (short) (ipos - 1) + }); + curTableDescriptor.moveColumn(ipos, ipos - 1); + } + toggleButtons(); + } + + private void shiftFieldNameDown() + { + short ipos = xlstFieldNames.getSelectedItemPos(); + String[] snewlist = shiftArrayItem(xlstFieldNames.getItems(), ipos, 1); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST, snewlist); + if ((ipos + 1) < xlstFieldNames.getItemCount()) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.SELECTED_ITEMS, new short[] + { + (short) (ipos + 1) + }); + curTableDescriptor.moveColumn(ipos, ipos + 1); + } + toggleButtons(); + } + + private String[] shiftArrayItem(String[] _slist, int _oldindex, int _shiftcount) + { + int newindex = _oldindex + _shiftcount; + if ((newindex >= 0) && (newindex < _slist.length)) + { + String buffer = _slist[newindex]; + _slist[newindex] = _slist[_oldindex]; + _slist[_oldindex] = buffer; + } + return _slist; + } + + public boolean updateColumnofColumnDescriptor() + { + Object oColumn = Helper.getUnoPropertyValue(oColumnDescriptorModel, "Column"); + XPropertySet xColPropertySet = UnoRuntime.queryInterface(XPropertySet.class, oColumn); + if (xColPropertySet != null) + { + curTableDescriptor.modifyColumn(txtfieldname.getText(), xColPropertySet); + return true; + } + return false; + } + + private void updateColumnDescriptor(String _ColumnName, XPropertySet _xColumn) + { + updateColumnofColumnDescriptor(); + XPropertySet xNewPropertySet = curTableDescriptor.clonePropertySet(_ColumnName, _xColumn); + if (xNewPropertySet != null) + { + Helper.setUnoPropertyValue(oColumnDescriptorModel, "Column", xNewPropertySet); + } + txtfieldname.setText(_ColumnName); + } + + + + public void itemStateChanged(ItemEvent arg0) + { + String fieldname = xlstFieldNames.getSelectedItem(); + XPropertySet xColumn = curTableDescriptor.getByName(fieldname); + updateColumnDescriptor(fieldname, xColumn); + toggleButtons(); + } + + public boolean iscompleted() + { + String[] sfieldnames = (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST); + return sfieldnames.length > 0; + } + + public String[] getFieldNames() + { + return (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xlstFieldNames), PropertyNames.STRING_ITEM_LIST); + } + + /* (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/table/Finalizer.java b/wizards/com/sun/star/wizards/table/Finalizer.java new file mode 100644 index 000000000..ce6c4bb31 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/Finalizer.java @@ -0,0 +1,349 @@ +/* + * 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.table; + +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.awt.XTextComponent; +import com.sun.star.sdbc.SQLException; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.TableDescriptor; +import com.sun.star.wizards.ui.*; +import com.sun.star.wizards.ui.event.XTextListenerAdapter; + +public class Finalizer +{ + + private TableWizard CurUnoDialog; + private XRadioButton optModifyTable; + private XRadioButton optWorkWithTable; + private XTextComponent txtTableName; + private XListBox xCatalogListBox; + private XListBox xSchemaListBox; + private TableDescriptor curtabledescriptor; + private static int WORKWITHTABLEMODE = 0; + public static int MODIFYTABLEMODE = 1; + public static int STARTFORMWIZARDMODE = 2; + + public Finalizer(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor) + { + try + { + this.CurUnoDialog = _CurUnoDialog; + this.curtabledescriptor = _curtabledescriptor; + short curtabindex = (short) (TableWizard.SOFINALPAGE * 100); + Integer IFINALSTEP = Integer.valueOf(TableWizard.SOFINALPAGE); + String slblTableName = CurUnoDialog.m_oResource.getResText("RID_TABLE_34"); + String slblProceed = CurUnoDialog.m_oResource.getResText("RID_TABLE_36"); + String sWorkWithTable = CurUnoDialog.m_oResource.getResText("RID_TABLE_38"); + String sStartFormWizard = CurUnoDialog.m_oResource.getResText("RID_TABLE_39"); + String sModifyTable = CurUnoDialog.m_oResource.getResText("RID_TABLE_37"); + String sCongratulations = CurUnoDialog.m_oResource.getResText("RID_TABLE_35"); + String slblCatalog = CurUnoDialog.m_oResource.getResText("RID_TABLE_49"); + String slblSchema = CurUnoDialog.m_oResource.getResText("RID_TABLE_50"); + String[] sCatalogNames = curtabledescriptor.getCatalogNames(); + String[] sSchemaNames = curtabledescriptor.getSchemaNames(); + int nListBoxPosX = 97; + int ndiffPosY = 0; + boolean bsupportsSchemata = false; + boolean bsupportsCatalogs = false; + + CurUnoDialog.insertLabel("lblTableName", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + UIConsts.INTEGERS[8], slblTableName, 97, 25, IFINALSTEP, 220 + }); + txtTableName = CurUnoDialog.insertTextField("txtTableName", new XTextListenerAdapter() { + @Override + public void textChanged(TextEvent event) { + setCompletionFlag(); + } + }, + 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_DLGTABLE_TXT_NAME", 97, 35, IFINALSTEP, Short.valueOf(curtabindex++), PropertyNames.EMPTY_STRING, 223 + }); + txtTableName.addTextListener(CurUnoDialog); + txtTableName.setMaxTextLen((short) this.curtabledescriptor.getMaxTableNameLength()); + if (this.curtabledescriptor.xDBMetaData.supportsCatalogsInTableDefinitions()) + { + if (sCatalogNames != null && sCatalogNames.length > 0) + { + bsupportsCatalogs = true; + String sCatalog = PropertyNames.EMPTY_STRING; + try + { + sCatalog = curtabledescriptor.DBConnection.getCatalog(); + } + catch (SQLException e1) + { + e1.printStackTrace(System.err); + } + CurUnoDialog.insertLabel("lblCatalog", + 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, slblCatalog, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 120 + }); + + try + { + xCatalogListBox = CurUnoDialog.insertListBox("lstCatalog", null, null, + new String[] + { + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_CATALOG", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sCatalogNames, Short.valueOf(curtabindex++), 80 + }); + int isel = JavaTools.FieldInList(sCatalogNames, sCatalog); + if (isel < 0) + { + isel = 0; + } + CurUnoDialog.setControlProperty("lstCatalog", PropertyNames.SELECTED_ITEMS, new short[] + { + (short) isel + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + nListBoxPosX = 200; + } + } + if (this.curtabledescriptor.xDBMetaData.supportsSchemasInTableDefinitions()) + { + if (sSchemaNames != null && sSchemaNames.length > 0) + { + bsupportsSchemata = true; + String sSchema = PropertyNames.EMPTY_STRING; + try + { + sSchema = (String) curtabledescriptor.getDataSourcePropertySet().getPropertyValue("User"); + } + catch (Exception e1) + { + e1.printStackTrace(System.err); + } + CurUnoDialog.insertLabel("lblSchema", + 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, slblSchema, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 80 + }); + + try + { + xSchemaListBox = CurUnoDialog.insertListBox("lstSchema", null, null, + new String[] + { + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_SCHEMA", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sSchemaNames, Short.valueOf(curtabindex++), 80 + }); + int isel = JavaTools.FieldInList(sSchemaNames, sSchema); + if (isel < 0) + { + isel = 0; + } + CurUnoDialog.setControlProperty("lstSchema", PropertyNames.SELECTED_ITEMS, new short[] + { + (short) isel + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + } + if ((!bsupportsCatalogs) && (!bsupportsSchemata)) + { + CurUnoDialog.insertLabel("lblcongratulations", + 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[] + { + 16, sCongratulations, Boolean.TRUE, 97, 62, IFINALSTEP, Short.valueOf(curtabindex++), 226 + }); + } + else + { + ndiffPosY = 10; + } + 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, Integer.valueOf(82 + ndiffPosY), IFINALSTEP, Short.valueOf(curtabindex++), 227 + }); + optWorkWithTable = CurUnoDialog.insertRadioButton("optWorkWithTable", 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_DLGTABLE_OPT_WORKWITHTABLE", sWorkWithTable, 101, Integer.valueOf(97 + ndiffPosY), Short.valueOf((short) 1), IFINALSTEP, Short.valueOf(curtabindex++), 177 + }); + optModifyTable = CurUnoDialog.insertRadioButton("optModifyTable", 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_DLGTABLE_OPT_MODIFYTABLE", sModifyTable, 101, Integer.valueOf(109 + ndiffPosY), IFINALSTEP, Short.valueOf(curtabindex++), 177 + }); + CurUnoDialog.insertRadioButton("optStartFormWizard", 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_DLGTABLE_OPT_STARTFORMWIZARD", sStartFormWizard, 101, Integer.valueOf(121 + ndiffPosY), IFINALSTEP, Short.valueOf(curtabindex++), 177 + }); + } + catch (SQLException e) + { + e.printStackTrace(System.err); + } + } + + public void initialize(String _firsttablename) + { + setTableName(_firsttablename); + } + + public int finish() + { + if (optWorkWithTable.getState()) + { + return WORKWITHTABLEMODE; + } + else if (optModifyTable.getState()) + { + return MODIFYTABLEMODE; + } + else + { + return STARTFORMWIZARDMODE; + } + } + + public String getComposedTableName(String _stablename) + { + String scatalogname = null; + String sschemaname = null; + if (xCatalogListBox != null) + { + scatalogname = xCatalogListBox.getSelectedItem(); + } + if (xSchemaListBox != null) + { + sschemaname = xSchemaListBox.getSelectedItem(); + } + return curtabledescriptor.getComposedTableName(scatalogname, sschemaname, _stablename); + } + + private void setTableName(String _tablename) + { + if (txtTableName.getText().equals(PropertyNames.EMPTY_STRING)) + { + String ssuffix = Desktop.getIncrementSuffix(curtabledescriptor.getTableNamesAsNameAccess(), getComposedTableName(_tablename)); + txtTableName.setText(_tablename + ssuffix); + setCompletionFlag(); + } + } + + public String getTableName(String _firsttablename) + { + if (txtTableName.getText().equals(PropertyNames.EMPTY_STRING)) + { + setTableName(_firsttablename); + } + return txtTableName.getText(); + } + + public String getSchemaName() + { + if (xSchemaListBox != null) + { + return this.xSchemaListBox.getSelectedItem(); + } + else + { + return PropertyNames.EMPTY_STRING; + } + } + + public String getCatalogName() + { + if (xCatalogListBox != null) + { + return this.xCatalogListBox.getSelectedItem(); + } + else + { + return PropertyNames.EMPTY_STRING; + } + } + + public boolean iscompleted() + { + return (txtTableName.getText().length() > 0); + } + + private void setCompletionFlag() + { + CurUnoDialog.setcompleted(TableWizard.SOFINALPAGE, iscompleted()); + } + + public void setFocusToTableNameControl() + { + CurUnoDialog.setFocus("txtTableName"); + } +} diff --git a/wizards/com/sun/star/wizards/table/MANIFEST.MF b/wizards/com/sun/star/wizards/table/MANIFEST.MF new file mode 100644 index 000000000..0fcfe1d3e --- /dev/null +++ b/wizards/com/sun/star/wizards/table/MANIFEST.MF @@ -0,0 +1,2 @@ +RegistrationClassName: com.sun.star.wizards.table.CallTableWizard +UNO-Type-Path: diff --git a/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java b/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java new file mode 100644 index 000000000..289f76dd3 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java @@ -0,0 +1,459 @@ +/* + * 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.table; + +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.beans.XPropertySet; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.uno.AnyConverter; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.TableDescriptor; +import com.sun.star.wizards.ui.FieldSelection; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.XFieldSelectionListener; +import com.sun.star.wizards.ui.event.XActionListenerAdapter; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +public class PrimaryKeyHandler implements XFieldSelectionListener +{ + + private final TableWizard CurUnoDialog; + private final XRadioButton optAddAutomatically; + private final XRadioButton optUseExisting; + private final XRadioButton optUseSeveral; + private final XCheckBox chkcreatePrimaryKey; + private final XCheckBox chkApplyAutoValueExisting; + private final XCheckBox chkApplyAutoValueAutomatic; + private final XListBox lstSinglePrimeKey; + private final XFixedText lblPrimeFieldName; + private final FieldSelection curPrimaryKeySelection; + private String[] fieldnames; + private final TableDescriptor curTableDescriptor; + private final boolean bAutoPrimaryKeysupportsAutoIncrementation; + private static final String SAUTOMATICKEYFIELDNAME = "ID"; + + public PrimaryKeyHandler(TableWizard _CurUnoDialog, TableDescriptor _curTableDescriptor) + { + this.CurUnoDialog = _CurUnoDialog; + curTableDescriptor = _curTableDescriptor; + bAutoPrimaryKeysupportsAutoIncrementation = curTableDescriptor.oTypeInspector.isAutoIncrementationSupported(); + short curtabindex = (short) ((TableWizard.SOPRIMARYKEYPAGE * 100) - 20); + Integer IPRIMEKEYSTEP = Integer.valueOf(TableWizard.SOPRIMARYKEYPAGE); + final String sExplanations = CurUnoDialog.m_oResource.getResText("RID_TABLE_26"); + final String screatePrimaryKey = CurUnoDialog.m_oResource.getResText("RID_TABLE_27"); + final String slblPrimeFieldName = CurUnoDialog.m_oResource.getResText("RID_TABLE_31"); + final String sApplyAutoValue = CurUnoDialog.m_oResource.getResText("RID_TABLE_33"); + final String sAddAutomatically = CurUnoDialog.m_oResource.getResText("RID_TABLE_28"); + final String sUseExisting = CurUnoDialog.m_oResource.getResText("RID_TABLE_29"); + final String sUseSeveral = CurUnoDialog.m_oResource.getResText("RID_TABLE_30"); + final String slblAvailableFields = CurUnoDialog.m_oResource.getResText("RID_QUERY_4"); + final String slblSelPrimaryFields = CurUnoDialog.m_oResource.getResText("RID_TABLE_32"); + CurUnoDialog.insertLabel("lblExplanation", + 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[] + { + 40, sExplanations, Boolean.TRUE, 91, 27, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 233 + }); + + chkcreatePrimaryKey = CurUnoDialog.insertCheckBox("chkcreatePrimaryKey", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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_DLGTABLE_CHK_USEPRIMEKEY", screatePrimaryKey, 97, 70, Short.valueOf((short) 1), IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 160 + }); + + optAddAutomatically = CurUnoDialog.insertRadioButton("optAddAutomatically", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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_DLGTABLE_OPT_PK_AUTOMATIC", sAddAutomatically, 106, 82, Short.valueOf((short) 1), IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 200 + }); + + optUseExisting = CurUnoDialog.insertRadioButton("optUseExisting", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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 + }, //94 + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPT_PK_SINGLE", sUseExisting, 106, 104, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 200 + }); + + optUseSeveral = CurUnoDialog.insertRadioButton("optUseSeveral", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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_DLGTABLE_OPT_PK_SEVERAL", sUseSeveral, 106, 132, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 200 + }); + + chkApplyAutoValueAutomatic = CurUnoDialog.insertCheckBox("chkApplyAutoValueAutomatic", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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 + }, //107 + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_CK_PK_AUTOVALUE_AUTOMATIC", sApplyAutoValue, 116, 92, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 68 + }); + + lblPrimeFieldName = CurUnoDialog.insertLabel("lblPrimeFieldName", + 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.FALSE, UIConsts.INTEGERS[8], slblPrimeFieldName, 116, 117, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 46 + }); + + lstSinglePrimeKey = CurUnoDialog.insertListBox("lstSinglePrimeKey", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + onPrimeKeySelected(); + } + }, null, + 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.FALSE, + 12, + "HID:WIZARDS_HID_DLGTABLE_LB_PK_FIELDNAME", + Short.valueOf(UnoDialog.getListBoxLineCount()), + 162, + 115, + IPRIMEKEYSTEP, + Short.valueOf(curtabindex++), + 80 + }); + + chkApplyAutoValueExisting = CurUnoDialog.insertCheckBox("chkApplyAutoValueExisting", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + togglePrimeKeyFields(); + } + }, + 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 + }, //107 + new Object[] + { + UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_CK_PK_AUTOVALUE", sApplyAutoValue, 248, 117, IPRIMEKEYSTEP, Short.valueOf(curtabindex++), 66 + }); + curPrimaryKeySelection = new FieldSelection(CurUnoDialog, IPRIMEKEYSTEP.intValue(), 116, 142, 208, 47, slblAvailableFields, slblSelPrimaryFields, 41234, false); + curPrimaryKeySelection.addFieldSelectionListener(this); + + } + + public void initialize() + { + // boolean breselect; + fieldnames = curTableDescriptor.getNonBinaryFieldNames(); + String[] skeyfieldnames = curPrimaryKeySelection.getSelectedFieldNames(); + curPrimaryKeySelection.initialize(fieldnames, false); + if (skeyfieldnames != null && skeyfieldnames.length > 0) + { + String[] snewkeyfieldnames = JavaTools.removeOutdatedFields(skeyfieldnames, fieldnames); + curPrimaryKeySelection.setSelectedFieldNames(snewkeyfieldnames); + } + String selfield = lstSinglePrimeKey.getSelectedItem(); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSinglePrimeKey), PropertyNames.STRING_ITEM_LIST, fieldnames); + if (selfield != null) + { + if (JavaTools.FieldInList(fieldnames, selfield) > -1) + { + lstSinglePrimeKey.selectItem(selfield, true); + } + } + togglePrimeKeyFields(); + } + + public boolean iscompleted() + { + if (chkcreatePrimaryKey.getState() == 0) + { + return true; + } + if (this.optAddAutomatically.getState()) + { + return true; + } + if (optUseExisting.getState()) + { + fieldnames = curTableDescriptor.getNonBinaryFieldNames(); + String selfield = lstSinglePrimeKey.getSelectedItem(); + if (selfield != null) + { + return (JavaTools.FieldInList(fieldnames, selfield) > -1); + } + } + if (optUseSeveral.getState()) + { + fieldnames = curTableDescriptor.getNonBinaryFieldNames(); + String[] skeyfieldnames = curPrimaryKeySelection.getSelectedFieldNames(); + String[] snewkeyfieldnames = JavaTools.removeOutdatedFields(skeyfieldnames, fieldnames); + return (snewkeyfieldnames.length > 0); + } + return false; + } + + private void togglePrimeKeyFields() + { + boolean bdoEnable = (this.chkcreatePrimaryKey.getState() == 1); + Helper.setUnoPropertyValue(UnoDialog.getModel(optAddAutomatically), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueAutomatic), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bAutoPrimaryKeysupportsAutoIncrementation && bdoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(optUseExisting), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(optUseSeveral), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable)); + //toggle subcontrols of the radiobuttons... + toggleAutomaticAutoValueCheckBox(); + boolean benableSinglePrimekeyControls = bdoEnable && optUseExisting.getState(); + toggleSinglePrimeKeyFields(benableSinglePrimekeyControls); + boolean benableSeveralPrimekeyControls = bdoEnable && optUseSeveral.getState(); + curPrimaryKeySelection.toggleListboxControls(Boolean.valueOf(benableSeveralPrimekeyControls)); + // toggle the following steps of the dialog... + if (!bdoEnable) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, true); + } + else + { + if (benableSeveralPrimekeyControls) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, (curPrimaryKeySelection.getSelectedFieldNames().length > 0)); + } + else if (benableSinglePrimekeyControls) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, UnoDialog.isListBoxSelected(lstSinglePrimeKey)); //.getSelectedItemPos() != -1); + } + else if (optAddAutomatically.getState()) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, true); + } + } + } + + private boolean isAutoIncrementatable(String _fieldname) + { + try + { + XPropertySet xColPropertySet = curTableDescriptor.getByName(_fieldname); + if (xColPropertySet != null && curTableDescriptor.getDBDataTypeInspector() != null) + { + return curTableDescriptor.getDBDataTypeInspector().isAutoIncrementable(xColPropertySet); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return false; + } + + public boolean isAutomaticMode() + { + boolean bisAutomaticMode = false; + if (chkcreatePrimaryKey.getState() == 1) + { + bisAutomaticMode = ((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(optAddAutomatically), PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; + } + return bisAutomaticMode; + } + + public String getAutomaticFieldName() + { + return SAUTOMATICKEYFIELDNAME; + } + + public boolean isAutoIncremented() + { + boolean bischecked = false; + if (chkcreatePrimaryKey.getState() == 1) + { + boolean bisAutomaticMode = ((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(optAddAutomatically), PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; + boolean bisExistingMode = ((Short) Helper.getUnoPropertyValue(UnoDialog.getModel(optUseExisting), PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; + if (bisAutomaticMode) + { + bischecked = chkApplyAutoValueAutomatic.getState() == (short) 1; + } + else if (bisExistingMode) + { + bischecked = chkApplyAutoValueExisting.getState() == (short) 1; + } + } + return bischecked; + } + + private void onPrimeKeySelected() + { + try + { + String selfieldname = lstSinglePrimeKey.getSelectedItem(); + boolean bdoenable = isAutoIncrementatable(selfieldname); + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, lstSinglePrimeKey.getSelectedItemPos() != -1); + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueExisting), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); + XPropertySet xColPropertySet = curTableDescriptor.getByName(selfieldname); + boolean bIsAutoIncremented = ((Boolean) xColPropertySet.getPropertyValue("IsAutoIncrement")).booleanValue(); + if (bIsAutoIncremented) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueExisting), PropertyNames.PROPERTY_STATE, Short.valueOf((short) 1)); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueExisting), PropertyNames.PROPERTY_STATE, Short.valueOf((short) 0)); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void toggleAutomaticAutoValueCheckBox() + { + try + { + boolean bisAutomaticMode = AnyConverter.toBoolean(Helper.getUnoPropertyValue(UnoDialog.getModel(optAddAutomatically), PropertyNames.PROPERTY_ENABLED)); + boolean bdoenable = bAutoPrimaryKeysupportsAutoIncrementation && optAddAutomatically.getState() && bisAutomaticMode; + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueAutomatic), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + } + } + + private void toggleSinglePrimeKeyFields(boolean _bdoenable) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(lblPrimeFieldName), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(lstSinglePrimeKey), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueExisting), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + boolean bdoenableAutoValueCheckBox = (isAutoIncrementatable(lstSinglePrimeKey.getSelectedItem()) && _bdoenable); + Helper.setUnoPropertyValue(UnoDialog.getModel(chkApplyAutoValueExisting), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenableAutoValueCheckBox)); + } + + public String[] getPrimaryKeyFields() + { + if (chkcreatePrimaryKey.getState() == 0) + { + return null; + } + if (fieldnames == null) + { + initialize(); + } + if (optUseSeveral.getState()) + { + return curPrimaryKeySelection.getSelectedFieldNames(); + } + else if (optUseExisting.getState()) + { + return new String[] + { + lstSinglePrimeKey.getSelectedItem() + }; + } + else if (optAddAutomatically.getState()) + { + return new String[] + { + SAUTOMATICKEYFIELDNAME + }; + } + return null; + } + + public void moveItemDown(String Selitem) + { + } + + public void moveItemUp(String Selitem) + { + } + + public void setID(String sIncSuffix) + { + } + + public void shiftFromLeftToRight(String[] SelItems, String[] NewItems) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, (curPrimaryKeySelection.getSelectedFieldNames().length > 0)); + } + + public void shiftFromRightToLeft(String[] OldSelItems, String[] NewItems) + { + CurUnoDialog.setcompleted(TableWizard.SOPRIMARYKEYPAGE, (curPrimaryKeySelection.getSelectedFieldNames().length > 0)); + } +} diff --git a/wizards/com/sun/star/wizards/table/ScenarioSelector.java b/wizards/com/sun/star/wizards/table/ScenarioSelector.java new file mode 100644 index 000000000..720700589 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/ScenarioSelector.java @@ -0,0 +1,364 @@ +/* + * 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.table; + +import java.util.ArrayList; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.XItemListener; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.Locale; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.wizards.common.Configuration; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.TableDescriptor; +import com.sun.star.wizards.ui.FieldSelection; +import com.sun.star.wizards.ui.UIConsts; +import com.sun.star.wizards.ui.UnoDialog; +import com.sun.star.wizards.ui.XFieldSelectionListener; +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 ScenarioSelector extends FieldSelection implements XItemListener, XFieldSelectionListener +{ + private static final int PRIVATE = 0; + private static final int BUSINESS = 1; + + private final XRadioButton optBusiness; + private XListBox xTableListBox; + private final TableWizard CurTableWizardUnoDialog; + private final TableDescriptor curtabledescriptor; + private final CGCategory oCGCategory; + protected CGTable oCGTable; + protected boolean bcolumnnameislimited; + private final int imaxcolumnchars; + private final String smytable; + private final Locale aLocale; + private final XMultiServiceFactory xMSF; + + public ScenarioSelector(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor, String _reslblFields, String _reslblSelFields) + { + super(_CurUnoDialog, TableWizard.SOMAINPAGE, 91, 108, 230, 80, _reslblFields, _reslblSelFields, 41209, true); + CurTableWizardUnoDialog = _CurUnoDialog; + xMSF = CurUnoDialog.xMSF; + aLocale = Configuration.getLocale(xMSF); + curtabledescriptor = _curtabledescriptor; + imaxcolumnchars = this.curtabledescriptor.getMaxColumnNameLength(); + bcolumnnameislimited = (imaxcolumnchars > 0) && (imaxcolumnchars < 16); + addFieldSelectionListener(this); + short pretabindex = (short) (50); + String sExplanation = CurUnoDialog.m_oResource.getResText("RID_TABLE_14"); + String sCategories = CurUnoDialog.m_oResource.getResText("RID_TABLE_15"); + String sBusiness = CurUnoDialog.m_oResource.getResText("RID_TABLE_16"); + String sPrivate = CurUnoDialog.m_oResource.getResText("RID_TABLE_17"); + String sTableNames = CurUnoDialog.m_oResource.getResText("RID_TABLE_18"); + smytable = CurUnoDialog.m_oResource.getResText("RID_TABLE_44"); + Integer IMAINSTEP = Integer.valueOf(TableWizard.SOMAINPAGE); + oCGCategory = new CGCategory(CurUnoDialog.xMSF); + oCGTable = new CGTable(CurUnoDialog.xMSF); + CurUnoDialog.insertLabel("lblScenarioExplanation", + 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[] + { + 32, sExplanation, Boolean.TRUE, 91, 27, IMAINSTEP, Short.valueOf(pretabindex++), 233 + }); + + CurUnoDialog.insertLabel("lblCategories", + 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, sCategories, 91, 60, IMAINSTEP, Short.valueOf(pretabindex++), 100 + }); + + optBusiness = CurTableWizardUnoDialog.insertRadioButton("optBusiness", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + selectCategory(); + } + }, + 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_DLGTABLE_OPTBUSINESS", sBusiness, 98, 70, Short.valueOf((short) 1), IMAINSTEP, Short.valueOf(pretabindex++), 78 + }); + + CurTableWizardUnoDialog.insertRadioButton("optPrivate", new XItemListenerAdapter() { + @Override + public void itemStateChanged(ItemEvent event) { + selectCategory(); + } + }, + 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_DLGTABLE_OPTPRIVATE", sPrivate, 182, 70, IMAINSTEP, Short.valueOf(pretabindex++), 90 + }); + + CurUnoDialog.insertLabel("lblTableNames", + 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, sTableNames, 91, 82, IMAINSTEP, Short.valueOf(pretabindex++), 80 + }); + + try + { + xTableListBox = CurUnoDialog.insertListBox("lstTableNames", 3, null, this, + new String[] + { + "Dropdown", 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, 12, "HID:WIZARDS_HID_DLGTABLE_LBTABLES", Short.valueOf(UnoDialog.getListBoxLineCount()), 91, 92, IMAINSTEP, Short.valueOf(pretabindex++), getListboxWidth() + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + initializeCategory(BUSINESS); + } + + private void selectCategory() + { + if (optBusiness.getState()) + { + initializeCategory(BUSINESS); + } + else + { + initializeCategory(PRIVATE); + } + } + + private void initializeCategory(int _iCategory) + { + try + { + oCGCategory.initialize( + _iCategory == PRIVATE ? "private" : "business"); + xTableListBox.removeItems((short) 0, xTableListBox.getItemCount()); + xTableListBox.addItems(oCGCategory.getTableNames(), (short) _iCategory); + initializeTable(0); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void initializeTable(int _iTable) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] + { + (short) _iTable + }); + oCGTable.initialize(oCGCategory.xNameAccessTablesNode, _iTable); + super.initialize(oCGTable.getFieldNames(bcolumnnameislimited, imaxcolumnchars), true); + } + + @Override + public String[] getSelectedFieldNames() + { + String[] displayfieldnames = super.getSelectedFieldNames(); + ArrayList<String> afieldnameVector = new ArrayList<String>(); + for (int i = 0; i < displayfieldnames.length; i++) + { + try + { + FieldDescription ofielddescription = CurTableWizardUnoDialog.fielditems.get(displayfieldnames[i]); + if (ofielddescription != null) + { + afieldnameVector.add(ofielddescription.getName()); + } + } + catch (RuntimeException e) + { + e.printStackTrace(System.err); + } + } + String[] fieldnames = new String[afieldnameVector.size()]; + return afieldnameVector.toArray(fieldnames); + } + + public boolean iscompleted() + { + return getSelectedFieldNames().length > 0; + } + + public void addColumnsToDescriptor() + { + String[] fieldnames = getSelectedFieldNames(); + for (int i = 0; i < fieldnames.length; i++) + { + try + { + FieldDescription curfielddescription = CurTableWizardUnoDialog.fielditems.get(fieldnames[i]); + PropertyValue[] aProperties = curfielddescription.getPropertyValues(); + if (aProperties != null) { + this.curtabledescriptor.addColumn(aProperties); + } + } + catch (RuntimeException e) + { + e.printStackTrace(System.err); + } + } + } + + public String getTableName() + { + return xTableListBox.getSelectedItem(); + } + + public String getFirstTableName() + { + String[] fieldnames = super.getSelectedFieldNames(); + if ((fieldnames.length) > 0) + { + for (int i = 0; i < CurTableWizardUnoDialog.fielditems.size(); i++) + { + String stablename = PropertyNames.EMPTY_STRING; + try + { + FieldDescription ofielddescription = CurTableWizardUnoDialog.fielditems.get(fieldnames[i]); + stablename = ofielddescription.gettablename(); + } + catch (RuntimeException e) + { + e.printStackTrace(System.err); + } + if (!stablename.equals(PropertyNames.EMPTY_STRING)) + { + return stablename; + } + } + } + return smytable; + } + + + + + + + /* (non-Javadoc) + * @see com.sun.star.awt.XItemListener#itemStateChanged(com.sun.star.awt.ItemEvent) + */ + public void itemStateChanged(ItemEvent arg0) + { + initializeTable(xTableListBox.getSelectedItemPos()); + } + + /* (non-Javadoc) + * @see com.sun.star.lang.XEventListener#disposing(com.sun.star.lang.EventObject) + */ + public void disposing(EventObject arg0) + { + } + + public void setID(String sIncSuffix) + { + } + + public void shiftFromLeftToRight(String[] SelItems, String[] NewItems) + { + if (!CurTableWizardUnoDialog.verifyfieldcount(NewItems.length)) + { + for (int i = 0; i < SelItems.length; i++) + { + int selindex = JavaTools.FieldInList(NewItems, SelItems[i]); + super.xSelectedFieldsListBox.removeItems((short) selindex, (short) 1); + /**TODO In this context the items should be better placed at their original position. + * but how is this position retrieved? + */ + super.xFieldsListBox.addItem(SelItems[i], xFieldsListBox.getItemCount()); + } + } + else + { + for (int i = 0; i < NewItems.length; i++) + { + int iduplicate; + if (CurTableWizardUnoDialog.fielditems.containsKey(NewItems[i])) + { + iduplicate = JavaTools.getDuplicateFieldIndex(NewItems, NewItems[i]); + if (iduplicate != -1) + { + String sdisplayname = Desktop.getUniqueName(NewItems, NewItems[iduplicate], PropertyNames.EMPTY_STRING); + FieldDescription curfielddescription = new FieldDescription(xMSF, aLocale, this, sdisplayname, NewItems[iduplicate], imaxcolumnchars); + CurTableWizardUnoDialog.fielditems.put(sdisplayname, curfielddescription); + NewItems[iduplicate] = sdisplayname; + setSelectedFieldNames(NewItems); + } + } + else + { + CurTableWizardUnoDialog.fielditems.put(NewItems[i], new FieldDescription(xMSF, aLocale, this, NewItems[i], NewItems[i], imaxcolumnchars)); + } + } + } + CurTableWizardUnoDialog.setcompleted(TableWizard.SOMAINPAGE, NewItems.length > 0); + } + + public void shiftFromRightToLeft(String[] SelItems, String[] NewItems) + { + for (int i = 0; i < SelItems.length; i++) + { + if (CurTableWizardUnoDialog.fielditems.containsKey(SelItems[i])) + { + CurTableWizardUnoDialog.fielditems.remove(SelItems[i]); + this.curtabledescriptor.dropColumnbyName(SelItems[i]); + } + } + CurTableWizardUnoDialog.setcompleted(TableWizard.SOMAINPAGE, NewItems.length > 0); + } + + public void moveItemDown(String item) + { + } + + public void moveItemUp(String item) + { + } +} diff --git a/wizards/com/sun/star/wizards/table/TableWizard.java b/wizards/com/sun/star/wizards/table/TableWizard.java new file mode 100644 index 000000000..67e0f537f --- /dev/null +++ b/wizards/com/sun/star/wizards/table/TableWizard.java @@ -0,0 +1,412 @@ +/* + * 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.table; + +import java.util.HashMap; + +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.VclWindowPeerAttribute; +import com.sun.star.awt.XTextListener; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sdb.CommandType; +import com.sun.star.sdb.application.DatabaseObject; +import com.sun.star.sdbc.SQLException; +import com.sun.star.task.XJobExecutor; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.*; +import com.sun.star.wizards.db.DatabaseObjectWizard; +import com.sun.star.wizards.db.TableDescriptor; +import com.sun.star.wizards.ui.*; + +public class TableWizard extends DatabaseObjectWizard implements XTextListener +{ + + private static String slblFields; + private static String slblSelFields; + private Finalizer curFinalizer; + private ScenarioSelector curScenarioSelector; + private FieldFormatter curFieldFormatter; + private PrimaryKeyHandler curPrimaryKeyHandler; + HashMap<String, FieldDescription> fielditems; + private int wizardmode; + private String tablename; + private String serrToManyFields; + private String serrTableNameexists; + private String scomposedtablename; + private TableDescriptor curTableDescriptor; + public static final int SOMAINPAGE = 1; + public static final int SOFIELDSFORMATPAGE = 2; + public static final int SOPRIMARYKEYPAGE = 3; + public static final int SOFINALPAGE = 4; + private String sMsgColumnAlreadyExists = PropertyNames.EMPTY_STRING; + + private String m_tableName; + + public TableWizard( XMultiServiceFactory xMSF, PropertyValue[] i_wizardContext ) + { + super( xMSF, 41200, i_wizardContext ); + super.addResourceHandler(); + String sTitle = m_oResource.getResText("RID_TABLE_1"); + 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[] + { + 218, Boolean.TRUE, "DialogTable", 102, 41, 1, Short.valueOf((short) 0), sTitle, 330 + }); + drawNaviBar(); + fielditems = new HashMap<String, FieldDescription>(); + //TODO if reportResources cannot be gotten dispose officedocument + if (getTableResources()) + { + setRightPaneHeaders(m_oResource, "RID_TABLE_", 8, 4); + } + } + + @Override + protected void leaveStep(int nOldStep, int nNewStep) + { + switch (nOldStep) + { + case SOMAINPAGE: + curScenarioSelector.addColumnsToDescriptor(); + break; + case SOFIELDSFORMATPAGE: + curFieldFormatter.updateColumnofColumnDescriptor(); + String[] sfieldnames = curFieldFormatter.getFieldNames(); + super.setStepEnabled(SOFIELDSFORMATPAGE, sfieldnames.length > 0); + curScenarioSelector.setSelectedFieldNames(sfieldnames); + break; + case SOPRIMARYKEYPAGE: + break; + case SOFINALPAGE: + break; + default: + break; + } + } + + @Override + protected void enterStep(int nOldStep, int nNewStep) + { + switch (nNewStep) + { + case SOMAINPAGE: + break; + case SOFIELDSFORMATPAGE: + curFieldFormatter.initialize(curTableDescriptor, this.curScenarioSelector.getSelectedFieldNames()); + break; + case SOPRIMARYKEYPAGE: + curPrimaryKeyHandler.initialize(); + break; + case SOFINALPAGE: + curFinalizer.initialize(curScenarioSelector.getFirstTableName()); + break; + default: + break; + } + } + + + private boolean iscompleted(int _ndialogpage) + { + switch (_ndialogpage) + { + case SOMAINPAGE: + return curScenarioSelector.iscompleted(); + case SOFIELDSFORMATPAGE: + return this.curFieldFormatter.iscompleted(); + case SOPRIMARYKEYPAGE: + if (curPrimaryKeyHandler != null) + { + return this.curPrimaryKeyHandler.iscompleted(); + } + case SOFINALPAGE: + return this.curFinalizer.iscompleted(); + default: + return false; + } + } + + + public void setcompleted(int _ndialogpage, boolean _biscompleted) + { + boolean bScenarioiscompleted = _biscompleted; + boolean bPrimaryKeysiscompleted = _biscompleted; + boolean bFinalPageiscompleted = _biscompleted; + if (_ndialogpage == SOMAINPAGE) + { + curFinalizer.initialize(curScenarioSelector.getFirstTableName()); + } + else + { + bScenarioiscompleted = iscompleted(SOMAINPAGE); + } + if (_ndialogpage != TableWizard.SOPRIMARYKEYPAGE && (this.curPrimaryKeyHandler != null)) + { + bPrimaryKeysiscompleted = iscompleted(SOPRIMARYKEYPAGE); + } + if (_ndialogpage != TableWizard.SOFINALPAGE) + { + bFinalPageiscompleted = iscompleted(SOFINALPAGE); // Basically the finalpage is always enabled + } + if (bScenarioiscompleted) + { + super.setStepEnabled(SOFIELDSFORMATPAGE, true); + super.setStepEnabled(SOPRIMARYKEYPAGE, true); + if (bPrimaryKeysiscompleted) + { + super.enablefromStep(SOFINALPAGE, true); + super.enableFinishButton(bFinalPageiscompleted); + } + else + { + super.enablefromStep(SOFINALPAGE, false); + enableNextButton(false); + } + } + else if (_ndialogpage == SOFIELDSFORMATPAGE) + { + super.enablefromStep(super.getCurrentStep() + 1, iscompleted(SOFIELDSFORMATPAGE)); + } + else + { + super.enablefromStep(super.getCurrentStep() + 1, false); + } + } + +/* + public static void main(String args[]) + { + String ConnectStr = "uno:socket,host=localhost,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.NamingService"; + PropertyValue[] curproperties = null; + try + { + XMultiServiceFactory xLocMSF = com.sun.star.wizards.common.Desktop.connect(ConnectStr); + TableWizard CurTableWizard = new TableWizard(xLocMSF); + if (xLocMSF != null) + { + System.out.println("Connected to " + ConnectStr); + curproperties = new PropertyValue[1]; + curproperties[0] = Properties.createProperty("DataSourceName", "Bibliography"); + //curproperties[0] = Properties.createProperty("DatabaseLocation", "file:///path/to/database.odb"); + CurTableWizard.startTableWizard(xLocMSF, curproperties); + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } +*/ + private void buildSteps() + { + curScenarioSelector = new ScenarioSelector(this, this.curTableDescriptor, slblFields, slblSelFields); + curFieldFormatter = new FieldFormatter(this); + if ( this.curTableDescriptor.supportsPrimaryKeys() ) + { + curPrimaryKeyHandler = new PrimaryKeyHandler(this, curTableDescriptor); + } + curFinalizer = new Finalizer(this, curTableDescriptor); + enableNavigationButtons(false, false, false); + } + + private boolean createTable() + { + boolean bIsSuccessful = true; + boolean bTableCreated = false; + String schemaname = curFinalizer.getSchemaName(); + String catalogname = curFinalizer.getCatalogName(); + if (curTableDescriptor.supportsPrimaryKeys()) + { + String[] keyfieldnames = curPrimaryKeyHandler.getPrimaryKeyFields(); + if (keyfieldnames != null && keyfieldnames.length > 0) + { + boolean bIsAutoIncrement = curPrimaryKeyHandler.isAutoIncremented(); + bIsSuccessful = curTableDescriptor.createTable(catalogname, schemaname, tablename, keyfieldnames, bIsAutoIncrement); + bTableCreated = true; + } + } + if (!bTableCreated) + { + bIsSuccessful = curTableDescriptor.createTable(catalogname, schemaname, tablename); + } + if ((!bIsSuccessful) && (curPrimaryKeyHandler.isAutomaticMode())) + { + curTableDescriptor.dropColumnbyName(curPrimaryKeyHandler.getAutomaticFieldName()); + } + return bIsSuccessful; + } + + @Override + public boolean finishWizard() + { + super.switchToStep(super.getCurrentStep(), SOFINALPAGE); + tablename = curFinalizer.getTableName(curScenarioSelector.getFirstTableName()); + scomposedtablename = curFinalizer.getComposedTableName(tablename); + if (this.curTableDescriptor.isSQL92CheckEnabled()) + { + Desktop.removeSpecialCharacters(curTableDescriptor.xMSF, Configuration.getLocale(this.curTableDescriptor.xMSF), tablename); + } + if ( tablename.length() > 0 ) + { + if (!curTableDescriptor.hasTableByName(scomposedtablename)) + { + wizardmode = curFinalizer.finish(); + if (createTable()) + { + final boolean editTableDesign = (wizardmode == Finalizer.MODIFYTABLEMODE ); + loadSubComponent( DatabaseObject.TABLE, curTableDescriptor.getComposedTableName(), editTableDesign ); + m_tableName = curTableDescriptor.getComposedTableName(); + super.xDialog.endExecute(); + return true; + } + } + else + { + String smessage = JavaTools.replaceSubString(serrTableNameexists, tablename, "%TABLENAME"); + super.showMessageBox("WarningBox", com.sun.star.awt.VclWindowPeerAttribute.OK, smessage); + curFinalizer.setFocusToTableNameControl(); + } + } + return false; + } + + private void callFormWizard() + { + try + { + Object oFormWizard = this.xMSF.createInstance("com.sun.star.wizards.form.CallFormWizard"); + + NamedValueCollection wizardContext = new NamedValueCollection(); + wizardContext.put( PropertyNames.ACTIVE_CONNECTION, curTableDescriptor.DBConnection ); + wizardContext.put( "DataSource", curTableDescriptor.getDataSource() ); + wizardContext.put( PropertyNames.COMMAND_TYPE, CommandType.TABLE ); + wizardContext.put( PropertyNames.COMMAND, scomposedtablename ); + wizardContext.put( "DocumentUI", m_docUI ); + XInitialization xInitialization = UnoRuntime.queryInterface( XInitialization.class, oFormWizard ); + xInitialization.initialize( wizardContext.getPropertyValues() ); + XJobExecutor xJobExecutor = UnoRuntime.queryInterface( XJobExecutor.class, oFormWizard ); + xJobExecutor.trigger(PropertyNames.START); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + @Override + public void cancelWizard() + { + xDialog.endExecute(); + } + + private void insertFormRelatedSteps() + { + addRoadmap(); + int i = 0; + i = insertRoadmapItem(0, true, m_oResource.getResText("RID_TABLE_2"), SOMAINPAGE); + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_TABLE_3"), SOFIELDSFORMATPAGE); + if (this.curTableDescriptor.supportsPrimaryKeys()) + { + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_TABLE_4"), SOPRIMARYKEYPAGE); + } + i = insertRoadmapItem(i, false, m_oResource.getResText("RID_TABLE_5"), SOFINALPAGE); // Orderby is always supported + setRoadmapInteractive(true); + setRoadmapComplete(true); + setCurrentRoadmapItemID((short) 1); + } + + public String startTableWizard( ) + { + try + { + curTableDescriptor = new TableDescriptor(xMSF, super.xWindow, this.sMsgColumnAlreadyExists); + if ( curTableDescriptor.getConnection( m_wizardContext ) ) + { + buildSteps(); + createWindowPeer(); + curTableDescriptor.setWindowPeer(this.xControl.getPeer()); + insertFormRelatedSteps(); + short RetValue = executeDialog(); + xComponent.dispose(); + if ( RetValue == 0 ) + { + if ( wizardmode == Finalizer.STARTFORMWIZARDMODE ) + callFormWizard(); + return m_tableName; + } + } + } + catch (java.lang.Exception jexception) + { + jexception.printStackTrace(System.err); + } + return PropertyNames.EMPTY_STRING; + } + + private boolean getTableResources() + { + super.m_oResource.getResText("RID_TABLE_1"); + slblFields = m_oResource.getResText("RID_TABLE_19"); + slblSelFields = m_oResource.getResText("RID_TABLE_25"); + serrToManyFields = m_oResource.getResText("RID_TABLE_47"); + serrTableNameexists = m_oResource.getResText("RID_TABLE_48"); + sMsgColumnAlreadyExists = m_oResource.getResText("RID_TABLE_51"); + return true; + } + + public boolean verifyfieldcount(int _icount) + { + try + { + int maxfieldcount = curTableDescriptor.getMaxColumnsInTable(); + if (_icount >= (maxfieldcount - 1)) + { // keep one column as reserve for the automatically created key + String smessage = serrToManyFields; + smessage = JavaTools.replaceSubString(smessage, String.valueOf(maxfieldcount), "%COUNT"); + showMessageBox("ErrorBox", VclWindowPeerAttribute.OK, smessage); + return false; + } + } + catch (SQLException e) + { + e.printStackTrace(System.err); + } + return true; + } + + + /* (non-Javadoc) + * @see com.sun.star.awt.XTextListener#textChanged(com.sun.star.awt.TextEvent) + */ + public void textChanged(TextEvent aTextEvent) + { + if (this.curTableDescriptor.isSQL92CheckEnabled()) + { + Object otextcomponent = UnoDialog.getModel(aTextEvent.Source); + String sName = (String) Helper.getUnoPropertyValue(otextcomponent, "Text"); + sName = Desktop.removeSpecialCharacters(curTableDescriptor.xMSF, Configuration.getLocale(curTableDescriptor.xMSF), sName); + Helper.setUnoPropertyValue(otextcomponent, "Text", sName); + } + } +} diff --git a/wizards/com/sun/star/wizards/table/table.component b/wizards/com/sun/star/wizards/table/table.component new file mode 100644 index 000000000..a407c9723 --- /dev/null +++ b/wizards/com/sun/star/wizards/table/table.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.table.CallTableWizard$TableWizardImplementation"> + <service name="com.sun.star.wizards.table.CallTableWizard"/> + </implementation> +</component> |