Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2015-11-24 11:49:20 +0000
committerGerrit Code Review @ Eclipse.org2016-01-07 14:42:36 +0000
commitfd7d122d0e2d3e7d1d314c9591c0a37eb6fc812d (patch)
treef65e945980bb879eef6ef2b6a2e1984b8c5510ca /plugins
parent8b2074398cf9f12771b0019793e698ed9bc6ccf0 (diff)
downloadorg.eclipse.papyrus-fd7d122d0e2d3e7d1d314c9591c0a37eb6fc812d.tar.gz
org.eclipse.papyrus-fd7d122d0e2d3e7d1d314c9591c0a37eb6fc812d.tar.xz
org.eclipse.papyrus-fd7d122d0e2d3e7d1d314c9591c0a37eb6fc812d.zip
Bug 482443: [Table] Table Catalog does not integrate fully the ViewPoint
mechanism -> provide tables which can not be created https://bugs.eclipse.org/bugs/show_bug.cgi?id=482443 Rewrite of the table creation wizard to manage the tables to create by their viewpoint. Some code must be refactored when the table creation API is merged. Change-Id: I7f6bbe250c8fd6c6eab93404a54f478ab6c47ed9 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/CreateNatTableFromCatalogHandler.java435
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/ChooseNattableConfigWizardPage.java781
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/CreateNattableFromCatalogWizard.java223
3 files changed, 774 insertions, 665 deletions
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 d6cfc9bd0bd..e8bf7217996 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
@@ -1,217 +1,218 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.common.handlers;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
-import org.eclipse.papyrus.infra.nattable.common.Activator;
-import org.eclipse.papyrus.infra.nattable.common.wizards.CreateNattableFromCatalogWizard;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable;
-import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Handler to display the wizard to display the catalog of existing Nattable
- * configurations.
- */
-public class CreateNatTableFromCatalogHandler extends AbstractHandler {
-
-
-
- // OLD code before ViewPrototype
-
- // /**
- // * We open the dialog, request the user for the desired configuration
- // *
- // * @see org.eclipse.papyrus.infra.nattable.common.handlers.AbstractCreateNattableEditorHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- // *
- // * @param event
- // * @return
- // * @throws ExecutionException
- // */
- // @Override
- // public Object execute(ExecutionEvent event) throws ExecutionException {
- // final EObject context = getSelection().get(0);
- // CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context);
- // WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
- // ServicesRegistry serviceRegistry = null;
- // TransactionalEditingDomain domain = null;
- // try {
- // serviceRegistry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- // domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
- // } catch (ServiceException e) {
- // Activator.log.error(e);
- // return null;
- // }
- //
- // if (dialog.open() == Window.OK) {
- // CompoundCommand compoundCommand = new CompoundCommand("Create tables from Catalog"); //$NON-NLS-1$
- //
- // for (TableConfiguration tableConfiguration : wizard.getSelectedConfig().keySet()) {
- // CreateNatTableEditorHandler handler = new CreateNatTableEditorHandler();
- // handler.setType(tableConfiguration.getType());
- //
- // // See how many tables were required for this type
- // Integer tablesQuantity = wizard.getSelectedConfig().get(tableConfiguration);
- //
- // // Get the chosen name for the tables under this configuration
- // final String tableConfigName = wizard.getTableNames().get(tableConfiguration);
- // for (int i = 0; i < tablesQuantity; i++) {
- // try {
- // Command cmd = handler.getCreateNattableEditorCommandWithNameInitialization(domain, serviceRegistry, event, tableConfigName + "_" + i);//$NON-NLS-1$
- // compoundCommand.append(cmd);
- // } catch (ServiceException e) {
- // Activator.log.error(e);
- // }
- // }
- // }
- // if (!compoundCommand.isEmpty()) {
- // domain.getCommandStack().execute(compoundCommand);
- // }
- //
- // }
- // return null;
- // }
-
-
-
- // NEW CODE using ViewPrototype
- /**
- * We open the dialog, request the user for the desired configuration
- *
- * @see org.eclipse.papyrus.infra.nattable.common.handlers.AbstractCreateNattableEditorHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- *
- * @param event
- * @return
- * @throws ExecutionException
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final EObject context = getSelection().get(0);
- final CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context);
- WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
- ServicesRegistry serviceRegistry = null;
- TransactionalEditingDomain domain = null;
- try {
- serviceRegistry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
- } catch (ServiceException e) {
- Activator.log.error(e);
- return null;
- }
-
- if (dialog.open() == Window.OK) {
-
- // we get the prototype available for the current selection
- final List<ViewPrototype> data = new ArrayList<ViewPrototype>();
- for (final ViewPrototype proto : PolicyChecker.getCurrent().getPrototypesFor(context)) {
- if (!(proto.getConfiguration() instanceof PapyrusTable || proto.getConfiguration() instanceof PapyrusSyncTable)) {
- continue;
- }
- data.add(proto);
- }
-
- final RecordingCommand rc = new RecordingCommand(domain) {
-
- @Override
- protected void doExecute() {
- for (final TableConfiguration tableConfiguration : wizard.getSelectedConfig().keySet()) {
-
-
- ViewPrototype protoToUse = null;
- int j = 0;
- while (j < data.size() && protoToUse == null) {
- ViewPrototype current = data.get(j);
- j++;
- if (current.getImplementation().equals(tableConfiguration.getType())) {
- protoToUse = current;
- }
- }
- if (protoToUse == null) {
- continue; // we do nothing in this case to avoid to create a new table which won't be displayed in the ModelExplorer
- }
- // See how many tables were required for this type
- Integer tablesQuantity = wizard.getSelectedConfig().get(tableConfiguration);
-
- // Get the chosen name for the tables under this configuration
- final String tableConfigName = wizard.getTableNames().get(tableConfiguration);
- for (int i = 0; i < tablesQuantity; i++) {
- PolicyDefinedTableHandler handler2 = new PolicyDefinedTableHandler(tableConfiguration.eResource().getURI(), context, tableConfigName + "_" + i);
- handler2.execute(protoToUse);
- }
-
- }
- }
- };
- domain.getCommandStack().execute(rc);
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.common.handlers.CreateNatTableEditorHandler#setEnabled(java.lang.Object)
- *
- * @param evaluationContext
- */
- @Override
- public void setEnabled(Object evaluationContext) {
- setBaseEnabled(getSelection().size() == 1);
- }
-
- /**
- *
- * @return
- */
- protected List<EObject> getSelection() {
- final List<EObject> selectedElements = new ArrayList<EObject>();
- final IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (ww != null) {
- final ISelection selection = ww.getSelectionService().getSelection();
- if (selection instanceof IStructuredSelection) {
- final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- final Iterator<?> it = structuredSelection.iterator();
- while (it.hasNext()) {
- final Object object = it.next();
- final EObject currentEObject = EMFHelper.getEObject(object);
- if (currentEObject != null) {
- selectedElements.add(currentEObject);
- }
- }
- }
- }
- return selectedElements;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 482443
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.handlers;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
+import org.eclipse.papyrus.infra.nattable.common.Activator;
+import org.eclipse.papyrus.infra.nattable.common.helper.TableViewPrototype;
+import org.eclipse.papyrus.infra.nattable.common.wizards.CreateNattableFromCatalogWizard;
+import org.eclipse.papyrus.infra.nattable.nattableconfiguration.NattableConfigurationRegistry;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Handler to display the wizard to display the catalog of existing Nattable
+ * configurations.
+ */
+public class CreateNatTableFromCatalogHandler extends AbstractHandler {
+
+
+
+ // OLD code before ViewPrototype
+
+ // /**
+ // * We open the dialog, request the user for the desired configuration
+ // *
+ // * @see org.eclipse.papyrus.infra.nattable.common.handlers.AbstractCreateNattableEditorHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ // *
+ // * @param event
+ // * @return
+ // * @throws ExecutionException
+ // */
+ // @Override
+ // public Object execute(ExecutionEvent event) throws ExecutionException {
+ // final EObject context = getSelection().get(0);
+ // CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context);
+ // WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ // ServicesRegistry serviceRegistry = null;
+ // TransactionalEditingDomain domain = null;
+ // try {
+ // serviceRegistry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
+ // domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
+ // } catch (ServiceException e) {
+ // Activator.log.error(e);
+ // return null;
+ // }
+ //
+ // if (dialog.open() == Window.OK) {
+ // CompoundCommand compoundCommand = new CompoundCommand("Create tables from Catalog"); //$NON-NLS-1$
+ //
+ // for (TableConfiguration tableConfiguration : wizard.getSelectedConfig().keySet()) {
+ // CreateNatTableEditorHandler handler = new CreateNatTableEditorHandler();
+ // handler.setType(tableConfiguration.getType());
+ //
+ // // See how many tables were required for this type
+ // Integer tablesQuantity = wizard.getSelectedConfig().get(tableConfiguration);
+ //
+ // // Get the chosen name for the tables under this configuration
+ // final String tableConfigName = wizard.getTableNames().get(tableConfiguration);
+ // for (int i = 0; i < tablesQuantity; i++) {
+ // try {
+ // Command cmd = handler.getCreateNattableEditorCommandWithNameInitialization(domain, serviceRegistry, event, tableConfigName + "_" + i);//$NON-NLS-1$
+ // compoundCommand.append(cmd);
+ // } catch (ServiceException e) {
+ // Activator.log.error(e);
+ // }
+ // }
+ // }
+ // if (!compoundCommand.isEmpty()) {
+ // domain.getCommandStack().execute(compoundCommand);
+ // }
+ //
+ // }
+ // return null;
+ // }
+
+
+
+ // NEW CODE using ViewPrototype
+ /**
+ * We open the dialog, request the user for the desired configuration.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.common.handlers.AbstractCreateNattableEditorHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ final EObject context = getSelection().get(0);
+ final CreateNattableFromCatalogWizard wizard = new CreateNattableFromCatalogWizard(context);
+ final WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ ServicesRegistry serviceRegistry = null;
+ TransactionalEditingDomain domain = null;
+ try {
+ serviceRegistry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
+ domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ return null;
+ }
+
+ if (Window.OK == dialog.open()) {
+
+ final RecordingCommand rc = new RecordingCommand(domain) {
+
+ @Override
+ protected void doExecute() {
+ for (final ViewPrototype viewPrototype : wizard.getSelectedViewPrototypes().keySet()) {
+ if (null != viewPrototype) {
+ // See how many tables were required for this type
+ Integer tablesQuantity = wizard.getSelectedViewPrototypes().get(viewPrototype);
+
+ // Get the chosen name for the tables under this configuration
+ final String tableConfigName = wizard.getTableNames().get(viewPrototype);
+ for (int i = 0; i < tablesQuantity; i++) {
+ // 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$
+ handler.execute(viewPrototype);
+ }
+ }
+
+ }
+ }
+ };
+ domain.getCommandStack().execute(rc);
+ }
+ return null;
+ }
+
+ /**
+ * TODO : To remove when the API for table creation is merged
+ *
+ * @param viewPrototype
+ * a view {@link TableViewPrototype}, must not be <code>null</code>
+ * @return
+ * the {@link URI} of the nattable configuration, or <code>null</code> if not found
+ */
+ private URI getTableConfigurationURI(final TableViewPrototype viewPrototype) {
+ if (viewPrototype.getConfiguration() instanceof PapyrusTable) {
+ PapyrusTable papyrusTable = (PapyrusTable) viewPrototype.getConfiguration();
+ String uri = papyrusTable.getConfiguration();
+ if (uri != null && uri.length() > 0) {
+ return URI.createURI(uri);
+ }
+ }
+ if (viewPrototype.getConfiguration() instanceof PapyrusSyncTable) {
+ return NattableConfigurationRegistry.INSTANCE.getConfigurationURI(((PapyrusSyncTable) viewPrototype.getConfiguration()).getImplementationID());
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.common.handlers.CreateNatTableEditorHandler#setEnabled(java.lang.Object)
+ *
+ * @param evaluationContext
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ setBaseEnabled(getSelection().size() == 1);
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected List<EObject> getSelection() {
+ final List<EObject> selectedElements = new ArrayList<EObject>();
+ final IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (ww != null) {
+ final ISelection selection = ww.getSelectionService().getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ final Iterator<?> it = structuredSelection.iterator();
+ while (it.hasNext()) {
+ final Object object = it.next();
+ final EObject currentEObject = EMFHelper.getEObject(object);
+ if (currentEObject != null) {
+ selectedElements.add(currentEObject);
+ }
+ }
+ }
+ }
+ return selectedElements;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/ChooseNattableConfigWizardPage.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/ChooseNattableConfigWizardPage.java
index ed11031d0e6..95a66bfa848 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/ChooseNattableConfigWizardPage.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/ChooseNattableConfigWizardPage.java
@@ -1,347 +1,434 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.common.wizards;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.ICellEditorValidator;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.ViewerColumn;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.infra.nattable.common.messages.Messages;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
-import org.eclipse.papyrus.infra.nattable.nattableconfiguration.NattableConfigurationRegistry;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-/**
- * Wizard page (unique) to select the desired table configurations.
- *
- */
-public class ChooseNattableConfigWizardPage extends WizardPage {
-
- private Map<TableConfiguration, Integer> selectedConfigs = new HashMap<TableConfiguration, Integer>();
-
- private Map<TableConfiguration, String> tableNames = new HashMap<TableConfiguration, String>();
-
- private Object context;
-
- private static final Image CHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable.common", "icons/checked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final Image UNCHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable.common", "icons/unchecked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
-
- /**
- *
- * Constructor.
- *
- * @param pageName
- * @param context
- */
- protected ChooseNattableConfigWizardPage(String pageName, EObject context) {
- super(pageName);
- this.context = context;
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- *
- * @param parent
- */
- @Override
- public void createControl(Composite parent) {
- setPageComplete(false);
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 2;
-
- createTableViewer(container);
- setControl(container);
- }
-
-
-
- /**
- * Create the table to display the catalog of existing configurations
- *
- * @param container
- */
- public void createTableViewer(final Composite container) {
- final TableViewer viewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
- viewer.setContentProvider(new ArrayContentProvider());
- final Table table = viewer.getTable();
- table.setHeaderVisible(true);
- ViewerColumn colCheckbox = createTableViewerColumn("", 23, viewer); //$NON-NLS-1$
- Collection<TableConfiguration> configs = loadConfigs();
- colCheckbox.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return ""; //$NON-NLS-1$
- }
-
- @Override
- public Image getImage(Object element) {
- if (selectedConfigs.containsKey(element)) {
- return CHECKED;
- } else {
- return UNCHECKED;
- }
- }
-
- });
- colCheckbox.setEditingSupport(new EditingSupport(viewer) {
-
- private CheckboxCellEditor checkboxCellEditor;
-
- @Override
- protected void setValue(Object element, Object value) {
- if (Boolean.TRUE.equals(checkboxCellEditor.getValue())) {
- selectedConfigs.put((TableConfiguration) element, 1);
- } else {
- selectedConfigs.remove(element);
- }
- viewer.update(element, null);
- }
-
- @Override
- protected Object getValue(Object element) {
- return selectedConfigs.containsKey(element);
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- checkboxCellEditor = new CheckboxCellEditor(container, SWT.CHECK | SWT.READ_ONLY);
- return checkboxCellEditor;
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- TableViewerColumn colType = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_6, 250, viewer);
- colType.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- TableConfiguration tc = (TableConfiguration) element;
- return tc.getType();
- }
-
- @Override
- public Image getImage(Object element) {
- TableConfiguration tc = (TableConfiguration) element;
- Image image = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(tc.getIconPath());
- return image;
- }
-
-
- });
-
- TableViewerColumn colName = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_7, 200, viewer);
- colName.setEditingSupport(new EditingSupport(viewer) {
-
- @Override
- protected void setValue(Object element, Object value) {
- tableNames.put((TableConfiguration) element, (String) value);
- viewer.update(element, null);
- }
-
- @Override
- protected Object getValue(Object element) {
- if (tableNames.containsKey(element)) {
- return tableNames.get(element);
- }
- return ""; //$NON-NLS-1$
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- return new TextCellEditor(viewer.getTable());
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- colName.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return tableNames.get(element);
- }
- });
-
- TableViewerColumn colQuantity = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_9, 30, viewer);
- colQuantity.setEditingSupport(new EditingSupport(viewer) {
-
- @Override
- protected void setValue(Object element, Object value) {
- selectedConfigs.put((TableConfiguration) element, Integer.parseInt((String) value));
- viewer.update(element, null);
- }
-
- @Override
- protected Object getValue(Object element) {
- if (selectedConfigs.containsKey(element)) {
- return selectedConfigs.get(element).toString();
- }
- return "0"; //$NON-NLS-1$
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- TextCellEditor textCellEditor = new TextCellEditor(viewer.getTable());
- textCellEditor.setValidator(new ICellEditorValidator() {
-
- @Override
- public String isValid(Object value) {
- if (!(value instanceof Integer)) {
- return null;
- }
- return value.toString();
- }
- });
- return textCellEditor;
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- colQuantity.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (selectedConfigs.containsKey(element)) {
- return selectedConfigs.get(element).toString();
- }
- return ""; //$NON-NLS-1$
- }
- });
-
- TableViewerColumn colDescription = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_12, 400, viewer);
- colDescription.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- TableConfiguration tc = (TableConfiguration) element;
- return tc.getDescription();
- }
-
- });
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- if (selectedConfigs.size() > 0) {
- setPageComplete(true);
- } else {
- setPageComplete(false);
- }
- }
- });
- GridData gridData = new GridData();
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalSpan = 2;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.horizontalAlignment = GridData.FILL;
- viewer.getControl().setLayoutData(gridData);
- viewer.setInput(configs);
- }
-
- /**
- * Constructor.
- *
- * @param title
- * @param bound
- * @param viewer
- * @return
- */
- private TableViewerColumn createTableViewerColumn(String title, int bound, TableViewer viewer) {
- final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
- final TableColumn column = viewerColumn.getColumn();
- column.setText(title);
- column.setWidth(bound);
- column.setResizable(true);
- column.setMoveable(false);
- return viewerColumn;
- }
-
- /**
- * Get configurations from the configuration registry with their default names
- *
- * @return
- */
- public Collection<TableConfiguration> loadConfigs() {
- Collection<TableConfiguration> tableConfigurations = new ArrayList<TableConfiguration>(NattableConfigurationRegistry.INSTANCE.getTableConfigurations());
-
- final ArrayList<TableConfiguration> tableConfigurationsToRemove = new ArrayList<TableConfiguration>();
- for (TableConfiguration tableConfiguration : tableConfigurations) {
-
- if (NattableConfigurationRegistry.INSTANCE.canCreateTable(tableConfiguration.getType(), context).isOK()) {
-
- tableNames.put(tableConfiguration, tableConfiguration.getName());
- } else {
- tableConfigurationsToRemove.add(tableConfiguration);
- }
- }
- tableConfigurations.removeAll(tableConfigurationsToRemove);
- return tableConfigurations;
- }
-
-
- /**
- * Getter for selected table configurations
- *
- * @return
- */
- public Map<TableConfiguration, Integer> getSelectedConfigs() {
- return selectedConfigs;
- }
-
-
- /**
- * Getter for the selected table names
- *
- * @return
- */
- public Map<TableConfiguration, String> getTableNames() {
- return tableNames;
- }
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 482443
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.wizards;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ICellEditorValidator;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.ViewerColumn;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.papyrus.infra.nattable.common.Activator;
+import org.eclipse.papyrus.infra.nattable.common.helper.TableViewPrototype;
+import org.eclipse.papyrus.infra.nattable.common.messages.Messages;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
+import org.eclipse.papyrus.infra.nattable.nattableconfiguration.NattableConfigurationRegistry;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ * Wizard page (unique) to select the desired table configurations.
+ *
+ */
+public class ChooseNattableConfigWizardPage extends WizardPage {
+
+ /**
+ * The selected view prototypes in the wizard.
+ */
+ private Map<ViewPrototype, Integer> selectedViewPrototypes = new HashMap<ViewPrototype, Integer>();
+
+ /**
+ * The table name by view prototype.
+ */
+ private Map<ViewPrototype, String> tableNames = new HashMap<ViewPrototype, String>();
+
+ /**
+ * The context of the future table.
+ */
+ private Object context;
+
+ /**
+ * The checked image for the table to select the view prototypes.
+ */
+ private static final Image CHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.PLUGIN_ID, "icons/checked.gif"); //$NON-NLS-1
+
+ /**
+ * The unchecked image for the table to select the view prototypes.
+ */
+ private static final Image UNCHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.PLUGIN_ID, "icons/unchecked.gif"); //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ *
+ * @param pageName
+ * The page name.
+ * @param context
+ * The context of the table to create.
+ */
+ protected ChooseNattableConfigWizardPage(final String pageName, final EObject context) {
+ super(pageName);
+ this.context = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(final Composite parent) {
+ setPageComplete(false);
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+
+ createTableViewer(container);
+ setControl(container);
+ }
+
+ /**
+ * Create the table to display the catalog of existing view prototypes corresponding to the tables viewpoint.
+ *
+ * @param container
+ * The container composite.
+ */
+ public void createTableViewer(final Composite container) {
+ final TableViewer viewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ viewer.setContentProvider(new ArrayContentProvider());
+ final Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ ViewerColumn colCheckbox = createTableViewerColumn("", 23, viewer); //$NON-NLS-1$
+ Collection<ViewPrototype> viewPrototypes = loadConfigs();
+
+ // Calculate the TableConfiguration for the icon and the description of table
+ final Map<ViewPrototype, TableConfiguration> tableConfigurations = new HashMap<ViewPrototype, TableConfiguration>(viewPrototypes.size());
+ for (ViewPrototype viewPrototype : viewPrototypes) {
+ final ResourceSet resourceSet = new ResourceSetImpl();
+ // TODO : The following code line must be replaced by TableEditorCreationHelper.getTableConfigurationURI when the API for table creation is merged
+ final Resource resource = resourceSet.getResource(getTableConfigurationURI((TableViewPrototype) viewPrototype), true);
+ tableConfigurations.put(viewPrototype, (TableConfiguration) resource.getContents().get(0));
+ }
+
+ colCheckbox.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Image getImage(final Object element) {
+ if (selectedViewPrototypes.containsKey(element)) {
+ return CHECKED;
+ } else {
+ return UNCHECKED;
+ }
+ }
+
+ });
+ colCheckbox.setEditingSupport(new EditingSupport(viewer) {
+
+ private CheckboxCellEditor checkboxCellEditor;
+
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ if (Boolean.TRUE.equals(checkboxCellEditor.getValue())) {
+ selectedViewPrototypes.put((ViewPrototype) element, 1);
+ } else {
+ selectedViewPrototypes.remove(element);
+ }
+ viewer.update(element, null);
+ }
+
+ @Override
+ protected Object getValue(final Object element) {
+ return selectedViewPrototypes.containsKey(element);
+ }
+
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ checkboxCellEditor = new CheckboxCellEditor(container, SWT.CHECK | SWT.READ_ONLY);
+ return checkboxCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+ });
+ TableViewerColumn colType = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_6, 250, viewer);
+ colType.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ ViewPrototype viewPrototype = (ViewPrototype) element;
+ return viewPrototype.getConfiguration().getImplementationID();
+ }
+
+ @Override
+ public Image getImage(final Object element) {
+ final ViewPrototype viewPrototype = (ViewPrototype) element;
+ final TableConfiguration tableConfiguration = tableConfigurations.get(viewPrototype);
+ Image image = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(tableConfiguration.getIconPath());
+ return image;
+ }
+
+
+ });
+
+ TableViewerColumn colName = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_7, 200, viewer);
+ colName.setEditingSupport(new EditingSupport(viewer) {
+
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ tableNames.put((ViewPrototype) element, (String) value);
+ viewer.update(element, null);
+ }
+
+ @Override
+ protected Object getValue(final Object element) {
+ if (tableNames.containsKey(element)) {
+ return tableNames.get(element);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ return new TextCellEditor(viewer.getTable());
+ }
+
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+ });
+ colName.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ return tableNames.get(element);
+ }
+ });
+
+ TableViewerColumn colQuantity = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_9, 30, viewer);
+ colQuantity.setEditingSupport(new EditingSupport(viewer) {
+
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ // When the quantity is not filled, only one table must be created
+ if (value.toString().isEmpty()) {
+ selectedViewPrototypes.put((ViewPrototype) element, 1);
+ } else {
+ selectedViewPrototypes.put((ViewPrototype) element, Integer.parseInt((String) value));
+ }
+ viewer.update(element, null);
+ }
+
+ @Override
+ protected Object getValue(final Object element) {
+ if (selectedViewPrototypes.containsKey(element)) {
+ return selectedViewPrototypes.get(element).toString();
+ }
+ return "0"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ TextCellEditor textCellEditor = new TextCellEditor(viewer.getTable());
+ textCellEditor.setValidator(new ICellEditorValidator() {
+
+ @Override
+ public String isValid(final Object value) {
+ if (!(value instanceof Integer)) {
+ return null;
+ }
+ return value.toString();
+ }
+ });
+ return textCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+ });
+ colQuantity.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ if (selectedViewPrototypes.containsKey(element)) {
+ return selectedViewPrototypes.get(element).toString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+ });
+
+ TableViewerColumn colDescription = createTableViewerColumn(Messages.ChooseNattableConfigWizardPage_12, 400, viewer);
+ colDescription.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ final ViewPrototype viewPrototype = (ViewPrototype) element;
+ final TableConfiguration tableConfiguration = tableConfigurations.get(viewPrototype);
+ return tableConfiguration.getDescription();
+ }
+
+ });
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(final SelectionChangedEvent event) {
+ if (selectedViewPrototypes.size() > 0) {
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
+ }
+ });
+ GridData gridData = new GridData();
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 2;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ viewer.getControl().setLayoutData(gridData);
+ viewer.setInput(viewPrototypes);
+ }
+
+ /**
+ * This allows to create a table viewer column.
+ *
+ * @param title
+ * The title of the wizard page.
+ * @param bound
+ * The width.
+ * @param viewer
+ * The table viewer.
+ * @return The created table viewer column.
+ */
+ private TableViewerColumn createTableViewerColumn(final String title, final int bound, final TableViewer viewer) {
+ final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+ column.setText(title);
+ column.setWidth(bound);
+ column.setResizable(true);
+ column.setMoveable(false);
+ return viewerColumn;
+ }
+
+ /**
+ * Get configurations from the configuration registry with their default names
+ *
+ * @return
+ */
+ public Collection<ViewPrototype> loadConfigs() {
+ final List<ViewPrototype> viewPrototypes = new ArrayList<ViewPrototype>();
+
+ // build a list of all the available prototypes corresponding to the context
+ for (final ViewPrototype proto : PolicyChecker.getCurrent().getAllPrototypes()) {
+ if ((proto.getConfiguration() instanceof PapyrusTable || proto.getConfiguration() instanceof PapyrusSyncTable)) {
+ if (NattableConfigurationRegistry.INSTANCE.canCreateTable(proto.getImplementation(), context).isOK()) {
+ viewPrototypes.add(proto);
+ }
+ }
+ }
+
+ // sort them
+ Collections.sort(viewPrototypes, new ViewPrototype.Comp());
+
+ return viewPrototypes;
+ }
+
+ /**
+ * TODO : To remove when the API for table creation is merged
+ *
+ * @param viewPrototype
+ * a view {@link TableViewPrototype}, must not be <code>null</code>
+ * @return
+ * the {@link URI} of the nattable configuration, or <code>null</code> if not found
+ */
+ private URI getTableConfigurationURI(final TableViewPrototype viewPrototype) {
+ if (viewPrototype.getConfiguration() instanceof PapyrusTable) {
+ PapyrusTable papyrusTable = (PapyrusTable) viewPrototype.getConfiguration();
+ String uri = papyrusTable.getConfiguration();
+ if (uri != null && uri.length() > 0) {
+ return URI.createURI(uri);
+ }
+ }
+ if (viewPrototype.getConfiguration() instanceof PapyrusSyncTable) {
+ return NattableConfigurationRegistry.INSTANCE.getConfigurationURI(((PapyrusSyncTable) viewPrototype.getConfiguration()).getImplementationID());
+ }
+ return null;
+ }
+
+ /**
+ * Getter for selected view prototypes.
+ *
+ * @return The selected view prototypes.
+ */
+ public Map<ViewPrototype, Integer> getSelectedViewPrototypes() {
+ return selectedViewPrototypes;
+ }
+
+
+ /**
+ * Getter for the selected table names.
+ *
+ * @return The selected table names.
+ */
+ public Map<ViewPrototype, String> getTableNames() {
+ return tableNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (null != selectedViewPrototypes) {
+ selectedViewPrototypes.clear();
+ selectedViewPrototypes = null;
+ }
+
+ if (null != tableNames) {
+ tableNames.clear();
+ tableNames = null;
+ }
+ super.dispose();
+ }
+
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/CreateNattableFromCatalogWizard.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/CreateNattableFromCatalogWizard.java
index 61fe8b69a41..9c5be6928a2 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/CreateNattableFromCatalogWizard.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/wizards/CreateNattableFromCatalogWizard.java
@@ -1,101 +1,122 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.common.wizards;
-
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.papyrus.infra.nattable.common.messages.Messages;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
-
-/**
- * Wizard declaration to display and choose existing Nattable configurations
- */
-public class CreateNattableFromCatalogWizard extends Wizard {
-
- private ChooseNattableConfigWizardPage page;
-
- private Map<TableConfiguration, Integer> selectedConfigs;
-
- private Map<TableConfiguration, String> tableNames;
-
- private EObject context;
-
- public CreateNattableFromCatalogWizard(EObject context) {
- this.context = context;
- }
-
- /**
- * Getter for selected configurations.
- *
- * @return
- */
- public Map<TableConfiguration, Integer> getSelectedConfig() {
- return selectedConfigs;
- }
-
- /**
- * Enables the finish button when there's at least one selected configuration
- *
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- *
- * @return
- */
- @Override
- public boolean performFinish() {
- this.selectedConfigs = page.getSelectedConfigs();
- this.tableNames = page.getTableNames();
- if (this.selectedConfigs != null && this.tableNames != null) {
- if (this.selectedConfigs.size() > 0) {
-
- return true;
- }
- }
- return false;
- }
-
-
- public Map<TableConfiguration, String> getTableNames() {
- return tableNames;
- }
-
- /**
- * Create and add the unique page to the wizard
- *
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- *
- */
- @Override
- public void addPages() {
- String description = Messages.CreateNattableFromCatalogWizard_0;
- page = new ChooseNattableConfigWizardPage(description, context);
- page.setTitle(Messages.CreateNattableFromCatalogWizard_1);
- page.setDescription(description);
- addPage(page);
- }
-
- /**
- * Declare wizard title
- *
- * @see org.eclipse.jface.wizard.Wizard#getWindowTitle()
- *
- * @return
- */
- @Override
- public String getWindowTitle() {
- return Messages.CreateNattableFromCatalogWizard_2;
- }
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 482443
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.wizards;
+
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.papyrus.infra.nattable.common.messages.Messages;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * Wizard declaration to display and choose existing Nattable configurations
+ */
+public class CreateNattableFromCatalogWizard extends Wizard {
+
+ /**
+ * The page which allow to select the table to create.
+ */
+ private ChooseNattableConfigWizardPage page;
+
+ /**
+ * The selected view prototypes in the wizard.
+ */
+ private Map<ViewPrototype, Integer> selectedViewPrototypes;
+
+ /**
+ * The table name by view prototype.
+ */
+ private Map<ViewPrototype, String> tableNames;
+
+ /**
+ * The context of the future table.
+ */
+ private EObject context;
+
+ /**
+ * Constructor.
+ *
+ * @param context
+ * The context of the table to create
+ */
+ public CreateNattableFromCatalogWizard(final EObject context) {
+ this.context = context;
+ }
+
+ /**
+ * Enables the finish button when there's at least one selected configuration.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ this.selectedViewPrototypes = page.getSelectedViewPrototypes();
+ this.tableNames = page.getTableNames();
+ if (this.selectedViewPrototypes != null && this.tableNames != null) {
+ if (this.selectedViewPrototypes.size() > 0) {
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Create and add the unique page to the wizard
+ *
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ *
+ */
+ @Override
+ public void addPages() {
+ String description = Messages.CreateNattableFromCatalogWizard_0;
+ page = new ChooseNattableConfigWizardPage(description, context);
+ page.setTitle(Messages.CreateNattableFromCatalogWizard_1);
+ page.setDescription(description);
+ addPage(page);
+ }
+
+ /**
+ * Declare wizard title
+ *
+ * @see org.eclipse.jface.wizard.Wizard#getWindowTitle()
+ *
+ * @return
+ */
+ @Override
+ public String getWindowTitle() {
+ return Messages.CreateNattableFromCatalogWizard_2;
+ }
+
+ /**
+ * Getter for selected view prototypes.
+ *
+ * @return The selected view prototypes.
+ */
+ public Map<ViewPrototype, Integer> getSelectedViewPrototypes() {
+ return selectedViewPrototypes;
+ }
+
+
+ /**
+ * Getter for the selected table names.
+ *
+ * @return The selected table names.
+ */
+ public Map<ViewPrototype, String> getTableNames() {
+ return tableNames;
+ }
+
+}

Back to the top