From 1b59801d998020b11758b2a2e520173549bb5e94 Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Thu, 16 Jun 2016 11:22:02 +0200 Subject: Bug 492246; [Table] Impossible to create a table from the catalog https://bugs.eclipse.org/bugs/show_bug.cgi?id=492246 The wizard was disposed before to get its needed informations. We need to get this ones before the dispose. + Some minor changements for the table name (to not get a table named 'null'). Change-Id: I1578135de28093453f57b6adc1a78b5e2f320ded Signed-off-by: Nicolas FAUVERGUE --- .../handlers/CreateNatTableFromCatalogHandler.java | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'plugins/infra') diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/CreateNatTableFromCatalogHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/CreateNatTableFromCatalogHandler.java index 29aea00f822..fba7df713cd 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/CreateNatTableFromCatalogHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/CreateNatTableFromCatalogHandler.java @@ -13,8 +13,10 @@ package org.eclipse.papyrus.infra.nattable.common.handlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -106,7 +108,15 @@ public class CreateNatTableFromCatalogHandler extends AbstractHandler { // return null; // } - + /** + * The view prototypes to create by the table creation wizard. + */ + private Map viewPrototypes = null; + + /** + * The view prototypes names of the table to create (names from wizard). + */ + private Map tableNames = null; // NEW CODE using ViewPrototype /** @@ -118,7 +128,17 @@ public class CreateNatTableFromCatalogHandler extends AbstractHandler { @Override public Object execute(final ExecutionEvent event) throws ExecutionException { final EObject context = getSelection().get(0); - final CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context); + final CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context){ + + @Override + public void dispose() { + // Get the view prototypes and the table names before the dispose values + // Create a new hashmap because the reference must be deleted with the dispose + viewPrototypes = new HashMap(this.getSelectedViewPrototypes()); + tableNames = new HashMap(this.getTableNames()); + super.dispose(); + } + }; final WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); ServicesRegistry serviceRegistry = null; TransactionalEditingDomain domain = null; @@ -131,26 +151,30 @@ public class CreateNatTableFromCatalogHandler extends AbstractHandler { } if (Window.OK == dialog.open()) { - + final RecordingCommand rc = new RecordingCommand(domain) { @Override protected void doExecute() { - for (final ViewPrototype viewPrototype : wizard.getSelectedViewPrototypes().keySet()) { + for (final ViewPrototype viewPrototype : viewPrototypes.keySet()) { if (null != viewPrototype) { // See how many tables were required for this type - Integer tablesQuantity = wizard.getSelectedViewPrototypes().get(viewPrototype); + final Integer tablesQuantity = viewPrototypes.get(viewPrototype); // Get the chosen name for the tables under this configuration - final String tableConfigName = wizard.getTableNames().get(viewPrototype); + final String tableConfigName = null != tableNames.get(viewPrototype) && !tableNames.get(viewPrototype).isEmpty() ? tableNames.get(viewPrototype) : viewPrototype.getLabel(); for (int i = 0; i < tablesQuantity; i++) { + final String tableNameToCreate = 1 < tablesQuantity ? tableConfigName + "_" + i : tableConfigName; //$NON-NLS-1$ // TODO : The following code line must be replaced by TableEditorCreationHelper.getTableConfigurationURI when the API for table creation is merged - PolicyDefinedTableHandler handler = new PolicyDefinedTableHandler(getTableConfigurationURI((TableViewPrototype) viewPrototype), context, tableConfigName + "_" + i); //$NON-NLS-1$ + PolicyDefinedTableHandler handler = new PolicyDefinedTableHandler(getTableConfigurationURI((TableViewPrototype) viewPrototype), context, tableNameToCreate); handler.execute(viewPrototype); } } } + // Re-initialize the global variables because we don't need it after + viewPrototypes = null; + tableNames = null; } }; domain.getCommandStack().execute(rc); -- cgit v1.2.3