diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-02-03 11:52:40 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-02-03 11:52:40 +0100 |
commit | a31b27b704d5c669674afdf135a61cdf1f30ff3b (patch) | |
tree | 65081feed990f995fd8c67aef3c99e54fd91efc5 /wizards/com | |
parent | 6242c77610b6d6c4206da895dfa430b781f60996 (diff) |
autorecovery: re-work the table wizard so that it does not open the table itself, but uses XDatabaseDocumentUI
Consequently, it does not need to return the created model/controller anymore. This way, the application controller
has full control over its sub components, which didn't work reliably before.
Other wizards (query/form/report) are to follow. For this purpose, they're also to be based on the newly introduced
DatabaseObjectWizard class.
Diffstat (limited to 'wizards/com')
8 files changed, 212 insertions, 126 deletions
diff --git a/wizards/com/sun/star/wizards/common/NamedValueCollection.java b/wizards/com/sun/star/wizards/common/NamedValueCollection.java new file mode 100644 index 000000000000..f8f2cd05224a --- /dev/null +++ b/wizards/com/sun/star/wizards/common/NamedValueCollection.java @@ -0,0 +1,90 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.sun.star.wizards.common; + +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.PropertyValue; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +/** + * + * @author frank.schoenheit@sun.com + */ +public class NamedValueCollection +{ + final private HashMap< String, Object > m_values = new HashMap< String, Object >(); + + public NamedValueCollection() + { + } + + public NamedValueCollection( final PropertyValue[] i_values ) + { + for ( int i = 0; i < i_values.length; ++i ) + m_values.put( i_values[i].Name, i_values[i].Value ); + } + + public final void put( final String i_name, final Object i_value ) + { + m_values.put( i_name, i_value ); + } + + @SuppressWarnings("unchecked") + public final < T extends Object > T getOrDefault( final String i_key, final T i_default ) + { + if ( m_values.containsKey( i_key ) ) + { + final Object value = m_values.get( i_key ); + try + { + return (T)value; + } + catch ( ClassCastException e ) { } + } + return i_default; + } + + @SuppressWarnings("unchecked") + public final < T extends XInterface > T queryOrDefault( final String i_key, final T i_default, Class i_interfaceClass ) + { + if ( m_values.containsKey( i_key ) ) + { + final Object value = m_values.get( i_key ); + return (T)UnoRuntime.queryInterface( i_interfaceClass, value ); + } + return i_default; + } + + public final boolean has( final String i_key ) + { + return m_values.containsKey( i_key ); + } + + public final PropertyValue[] getPropertyValues() + { + PropertyValue[] values = new PropertyValue[ m_values.size() ]; + + Iterator< Entry< String, Object > > iter = m_values.entrySet().iterator(); + int i = 0; + while ( iter.hasNext() ) + { + Entry< String, Object > entry = iter.next(); + values[i++] = new PropertyValue( + entry.getKey(), + 0, + entry.getValue(), + PropertyState.DIRECT_VALUE + ); + } + + return values; + } +} diff --git a/wizards/com/sun/star/wizards/db/DatabaseObjectWizard.java b/wizards/com/sun/star/wizards/db/DatabaseObjectWizard.java new file mode 100644 index 000000000000..5c65d73794f0 --- /dev/null +++ b/wizards/com/sun/star/wizards/db/DatabaseObjectWizard.java @@ -0,0 +1,75 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.sun.star.wizards.db; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.frame.XController; +import com.sun.star.frame.XFrame; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sdb.application.XDatabaseDocumentUI; +import com.sun.star.sdbc.SQLException; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.NamedValueCollection; +import com.sun.star.wizards.ui.WizardDialog; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * is a base class for a wizard creating a database object + * @author frank.schoenheit@sun.com + */ +public abstract class DatabaseObjectWizard extends WizardDialog +{ + protected final PropertyValue[] m_wizardContext; + protected final XDatabaseDocumentUI m_docUI; + protected final XFrame m_frame; + + protected DatabaseObjectWizard( final XMultiServiceFactory i_orb, final int i_helpIDBase, final PropertyValue[] i_wizardContext ) + { + super( i_orb, i_helpIDBase ); + m_wizardContext = i_wizardContext; + + final NamedValueCollection wizardContext = new NamedValueCollection( m_wizardContext ); + m_docUI = wizardContext.queryOrDefault( "DocumentUI", (XDatabaseDocumentUI)null, XDatabaseDocumentUI.class ); + + if ( m_docUI != null ) + { + XController docController = UnoRuntime.queryInterface( XController.class, m_docUI ); + m_frame = docController.getFrame(); + } + else + { + XFrame parentFrame = wizardContext.queryOrDefault( "ParentFrame", (XFrame)null, XFrame.class ); + if ( parentFrame != null ) + m_frame = parentFrame; + else + m_frame = Desktop.getActiveFrame( xMSF ); + } + } + + protected final void loadSubComponent( final int i_type, final String i_name, final boolean i_forEditing ) + { + try + { + m_docUI.loadComponent( i_type, i_name, i_forEditing ); + } + catch ( IllegalArgumentException ex ) + { + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex ); + } + catch ( NoSuchElementException ex ) + { + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex ); + } + catch ( SQLException ex ) + { + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex ); + } + } +} diff --git a/wizards/com/sun/star/wizards/db/TableDescriptor.java b/wizards/com/sun/star/wizards/db/TableDescriptor.java index aa9986b8d9db..74930e6d1bb6 100644 --- a/wizards/com/sun/star/wizards/db/TableDescriptor.java +++ b/wizards/com/sun/star/wizards/db/TableDescriptor.java @@ -36,7 +36,6 @@ import com.sun.star.lang.IllegalArgumentException; import com.sun.star.lang.WrappedTargetException; import com.sun.star.sdbc.SQLException; import com.sun.star.wizards.common.JavaTools; -import com.sun.star.wizards.ui.WizardDialog; import java.util.Vector; import com.sun.star.awt.VclWindowPeerAttribute; @@ -120,13 +119,13 @@ public class TableDescriptor extends CommandMetaData implements XContainerListen { // XTablesSupplier xDBTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, DBConnection); // xTableNames = xDBTables.getTables(); - xTableAppend = (XAppend) UnoRuntime.queryInterface(XAppend.class, getTableNamesAsNameAccess()); - xTableDrop = (XDrop) UnoRuntime.queryInterface(XDrop.class, getTableNamesAsNameAccess()); - xTableDataDescriptorFactory = (XDataDescriptorFactory) UnoRuntime.queryInterface(XDataDescriptorFactory.class, getTableNamesAsNameAccess()); + xTableAppend = UnoRuntime.queryInterface( XAppend.class, getTableNamesAsNameAccess() ); + xTableDrop = UnoRuntime.queryInterface( XDrop.class, getTableNamesAsNameAccess() ); + xTableDataDescriptorFactory = UnoRuntime.queryInterface( XDataDescriptorFactory.class, getTableNamesAsNameAccess() ); xPropTableDataDescriptor = xTableDataDescriptorFactory.createDataDescriptor(); - XColumnsSupplier xColumnsSupplier = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, xPropTableDataDescriptor); + XColumnsSupplier xColumnsSupplier = UnoRuntime.queryInterface( XColumnsSupplier.class, xPropTableDataDescriptor ); xNameAccessColumns = xColumnsSupplier.getColumns(); - xColumnDataDescriptorFactory = (XDataDescriptorFactory) UnoRuntime.queryInterface(XDataDescriptorFactory.class, xNameAccessColumns); + xColumnDataDescriptorFactory = UnoRuntime.queryInterface( XDataDescriptorFactory.class, xNameAccessColumns ); try { createTypeInspector(); diff --git a/wizards/com/sun/star/wizards/makefile.mk b/wizards/com/sun/star/wizards/makefile.mk index d876d1903d5d..ac4e2d87ece0 100644 --- a/wizards/com/sun/star/wizards/makefile.mk +++ b/wizards/com/sun/star/wizards/makefile.mk @@ -82,6 +82,7 @@ JAVAFILES= \ common$/DebugHelper.java \ common$/PropertySetHelper.java \ common$/NumericalHelper.java \ + common$/NamedValueCollection.java \ db$/DBMetaData.java \ db$/CommandMetaData.java \ db$/QueryMetaData.java \ @@ -94,6 +95,7 @@ JAVAFILES= \ db$/RelationController.java \ db$/TableDescriptor.java \ db$/SQLQueryComposer.java \ + db$/DatabaseObjectWizard.java \ ui$/event$/AbstractListener.java \ ui$/event$/CommonListener.java \ ui$/event$/DataAware.java \ diff --git a/wizards/com/sun/star/wizards/table/CallTableWizard.java b/wizards/com/sun/star/wizards/table/CallTableWizard.java index 7455df894c73..8f7cab8732d6 100644 --- a/wizards/com/sun/star/wizards/table/CallTableWizard.java +++ b/wizards/com/sun/star/wizards/table/CallTableWizard.java @@ -31,7 +31,6 @@ package com.sun.star.wizards.table; import com.sun.star.beans.PropertyAttribute; import com.sun.star.beans.PropertyValue; -import com.sun.star.lang.XComponent; import com.sun.star.uno.Type; import com.sun.star.wizards.common.Properties; @@ -86,41 +85,31 @@ public class CallTableWizard 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.lang.XTypeProvider, com.sun.star.task.XJobExecutor { - PropertyValue[] databaseproperties; - public XComponent Document = null; - public XComponent DocumentDefinition = null; + private PropertyValue[] m_wizardContext; + // <properties> + public String Command; + public final Integer CommandType = com.sun.star.sdb.CommandType.TABLE; + // </properties> /** The constructor of the inner class has a XMultiServiceFactory parameter. - * @param xmultiservicefactoryInitialization A special service factory - * could be introduced while initializing. + * @param i_serviceFactory */ - public TableWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization) + public TableWizardImplementation(com.sun.star.lang.XMultiServiceFactory i_serviceFactory) { super(); - xmultiservicefactory = xmultiservicefactoryInitialization; - registerProperty("Document", (short) (PropertyAttribute.READONLY | PropertyAttribute.MAYBEVOID)); - registerProperty("DocumentDefinition", (short) (PropertyAttribute.READONLY | PropertyAttribute.MAYBEVOID)); + m_serviceFactory = i_serviceFactory; + registerProperty( "Command", (short)( PropertyAttribute.READONLY | PropertyAttribute.MAYBEVOID ) ); + registerProperty( "CommandType", PropertyAttribute.READONLY ); } - public void trigger(String sEvent) + public void trigger( String sEvent ) { try { - if (sEvent.compareTo("start") == 0) + if ( sEvent.compareTo("start") == 0 ) { - TableWizard CurTableWizard = new TableWizard(xmultiservicefactory); - XComponent[] obj = CurTableWizard.startTableWizard(xmultiservicefactory, databaseproperties); - if (obj != null) - { - DocumentDefinition = obj[1]; - Document = obj[0]; - } - } - else if (sEvent.compareTo("end") == 0) - { - DocumentDefinition = null; - Document = null; - databaseproperties = null; + TableWizard CurTableWizard = new TableWizard( m_serviceFactory, m_wizardContext ); + CurTableWizard.startTableWizard(); } } catch (Exception exception) @@ -134,7 +123,7 @@ public class CallTableWizard private static final String __serviceName = "com.sun.star.wizards.table.CallTableWizard"; /** The service manager, that gives access to all registered services. */ - private com.sun.star.lang.XMultiServiceFactory xmultiservicefactory; + private com.sun.star.lang.XMultiServiceFactory m_serviceFactory; /** This method is a member of the interface for initializing an object * directly after its creation. @@ -145,7 +134,7 @@ public class CallTableWizard */ public void initialize(Object[] object) throws com.sun.star.uno.Exception { - databaseproperties = Properties.convertToPropertyValueArray(object); + m_wizardContext = Properties.convertToPropertyValueArray(object); } /** This method returns an array of all supported service names. diff --git a/wizards/com/sun/star/wizards/table/TableWizard.java b/wizards/com/sun/star/wizards/table/TableWizard.java index 8b4e0288ef8c..1995a442d58c 100644 --- a/wizards/com/sun/star/wizards/table/TableWizard.java +++ b/wizards/com/sun/star/wizards/table/TableWizard.java @@ -35,20 +35,19 @@ 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.beans.XPropertySet; -import com.sun.star.frame.XFrame; -import com.sun.star.lang.XComponent; 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 WizardDialog implements XTextListener, XCompletion +public class TableWizard extends DatabaseObjectWizard implements XTextListener, XCompletion { static String slblFields; @@ -71,13 +70,11 @@ public class TableWizard extends WizardDialog implements XTextListener, XComplet public static final int SOPRIMARYKEYPAGE = 3; public static final int SOFINALPAGE = 4; private String sMsgColumnAlreadyExists = ""; - XComponent[] components = null; - XFrame CurFrame; String WizardHeaderText[] = new String[8]; - public TableWizard(XMultiServiceFactory xMSF) + public TableWizard( XMultiServiceFactory xMSF, PropertyValue[] i_wizardContext ) { - super(xMSF, 41200); + super( xMSF, 41200, i_wizardContext ); super.addResourceHandler("TableWizard", "dbw"); String sTitle = m_oResource.getResText(UIConsts.RID_TABLE + 1); Helper.setUnoPropertyValues(xDialogModel, @@ -298,21 +295,15 @@ public class TableWizard extends WizardDialog implements XTextListener, XComplet { Desktop.removeSpecialCharacters(curTableDescriptor.xMSF, Configuration.getOfficeLocale(this.curTableDescriptor.xMSF), tablename); } - if (tablename != "") + if ( tablename.length() > 0 ) { if (!curTableDescriptor.hasTableByName(scomposedtablename)) { wizardmode = curFinalizer.finish(); if (createTable()) { - if (wizardmode == Finalizer.MODIFYTABLEMODE) - { - components = curTableDescriptor.switchtoDesignmode(curTableDescriptor.getComposedTableName(), com.sun.star.sdb.CommandType.TABLE, CurFrame); - } - else if (wizardmode == Finalizer.WORKWITHTABLEMODE) - { - components = curTableDescriptor.switchtoDataViewmode(curTableDescriptor.getComposedTableName(), com.sun.star.sdb.CommandType.TABLE, CurFrame); - } + final boolean editTableDesign = (wizardmode == Finalizer.MODIFYTABLEMODE ); + loadSubComponent( DatabaseObject.TABLE, curTableDescriptor.getComposedTableName(), editTableDesign ); super.xDialog.endExecute(); } } @@ -330,18 +321,17 @@ public class TableWizard extends WizardDialog implements XTextListener, XComplet try { Object oFormWizard = this.xMSF.createInstance("com.sun.star.wizards.form.CallFormWizard"); - PropertyValue[] aProperties = new PropertyValue[4]; - aProperties[0] = Properties.createProperty("ActiveConnection", curTableDescriptor.DBConnection); - aProperties[1] = Properties.createProperty("DataSource", curTableDescriptor.getDataSource()); - aProperties[2] = Properties.createProperty("CommandType", new Integer(CommandType.TABLE)); - aProperties[3] = Properties.createProperty("Command", scomposedtablename); - XInitialization xInitialization = (XInitialization) UnoRuntime.queryInterface(XInitialization.class, oFormWizard); - xInitialization.initialize(aProperties); - XJobExecutor xJobExecutor = (XJobExecutor) UnoRuntime.queryInterface(XJobExecutor.class, oFormWizard); + + NamedValueCollection wizardContext = new NamedValueCollection(); + wizardContext.put( "ActiveConnection", curTableDescriptor.DBConnection ); + wizardContext.put( "DataSource", curTableDescriptor.getDataSource() ); + wizardContext.put( "CommandType", CommandType.TABLE ); + wizardContext.put( "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("start"); - XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xJobExecutor); - components[0] = (XComponent) prop.getPropertyValue("Document"); - components[1] = (XComponent) prop.getPropertyValue("DocumentDefinition"); } catch (Exception e) { @@ -370,39 +360,24 @@ public class TableWizard extends WizardDialog implements XTextListener, XComplet setCurrentRoadmapItemID((short) 1); } - public XComponent[] startTableWizard(XMultiServiceFactory _xMSF, PropertyValue[] CurPropertyValue) + public void startTableWizard( ) { try { curTableDescriptor = new TableDescriptor(xMSF, super.xWindow, this.sMsgColumnAlreadyExists); - if (curTableDescriptor.getConnection(CurPropertyValue)) + if ( curTableDescriptor.getConnection( m_wizardContext ) ) { - if (Properties.hasPropertyValue(CurPropertyValue, "ParentFrame")) - { - CurFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, Properties.getPropertyValue(CurPropertyValue, "ParentFrame")); - } - else - { - CurFrame = Desktop.getActiveFrame(xMSF); - } buildSteps(); createWindowPeer(); curTableDescriptor.setWindowPeer(this.xControl.getPeer()); - // setAutoMnemonic("lblDialogHeader", false); insertFormRelatedSteps(); short RetValue = executeDialog(); xComponent.dispose(); - switch (RetValue) + if ( ( RetValue == 0 ) + && ( wizardmode == Finalizer.STARTFORMWIZARDMODE ) + ) { - case 0: // via Cancelbutton or via sourceCode with "endExecute" - if (wizardmode == Finalizer.STARTFORMWIZARDMODE) - { - callFormWizard(); - } - break; - case 1: - - break; + callFormWizard(); } } } @@ -410,7 +385,6 @@ public class TableWizard extends WizardDialog implements XTextListener, XComplet { jexception.printStackTrace(System.out); } - return components; } public boolean getTableResources() diff --git a/wizards/com/sun/star/wizards/table/XCallTableWizard.java b/wizards/com/sun/star/wizards/table/XCallTableWizard.java deleted file mode 100644 index 47cba7da9314..000000000000 --- a/wizards/com/sun/star/wizards/table/XCallTableWizard.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - ************************************************************************ - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: XCallTableWizard.java,v $ - * - * $Revision: 1.3.192.1 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -package com.sun.star.wizards.table; - -public interface XCallTableWizard extends com.sun.star.uno.XInterface -{ - // Methods - public void CallTableDialog(); // static Member - public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = - { - new com.sun.star.lib.uno.typeinfo.MethodTypeInfo("CallTableDialog", 0, 0) - }; -} diff --git a/wizards/com/sun/star/wizards/table/makefile.mk b/wizards/com/sun/star/wizards/table/makefile.mk index d845f6456efb..d0d689fabed7 100644 --- a/wizards/com/sun/star/wizards/table/makefile.mk +++ b/wizards/com/sun/star/wizards/table/makefile.mk @@ -61,7 +61,6 @@ JAVAFILES= \ PrimaryKeyHandler.java \ ScenarioSelector.java \ TableWizard.java \ - XCallTableWizard.java JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) |