Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-02-11 02:48:20 +0000
committerGerrit Code Review @ Eclipse.org2016-02-12 15:31:41 +0000
commitecd4928b327f5561364c5068c9ff5f1668e92d13 (patch)
tree7c34f46cf82a1d65ac753fa92c2a5d55371b8dba /plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus
parent751a204d74e15eb2db6b41c937691fc56dcc1252 (diff)
downloadorg.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.tar.gz
org.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.tar.xz
org.eclipse.papyrus-ecd4928b327f5561364c5068c9ff5f1668e92d13.zip
Bug 485220: [Architecture] Provide a more modular architecture
https://bugs.eclipse.org/bugs/show_bug.cgi?id=485220 Factor UI dependencies out of the UML Element Types bundle. This includes moving some advices that interact with the user into a new org.eclipse.papyrus.uml.service.types.ui bundle. Pull up the PasteCommandService and IPasteCommandProvider API into the Infra Diagram layer where the extension point is defined. Deprecate the old API in the UML layer. Introduce a service for participation of languages in CSS styling: * styling reset actions in the Reset Style command * access to semantic model classes and properties to make available to CSS Factor PapyrusObservableValue and cohorts out of the UML Tools bundle into the Infra Layer for more general reuse and to relieve the Diagram Infrastructure layer of UML dependencies. The old API remains as deprecated. Remove the Infra Diagram Layer dependency on UML Layer for property testers governing deletion in the diagram. Includes introduction of a new IGraphicalDeletionHelper OSGi service for delegation of the determination of whether an element can be deleted from the diagram and replacement of the XML expression properties * org.eclipse.papyrus.uml.diagram.common.isSemanticDeletion * org.eclipse.papyrus.uml.diagram.common.isReadOnly by * org.eclipse.papyrus.infra.gmfdiag.common.isSemanticDeletion * org.eclipse.papyrus.infra.gmfdiag.common.canDelete (where the latter is the negation of the property that it supersedes) Extract UML dependencies from the Diagram Outline and CSS Editor bundles. Remove unused MDTUtil APIs that referenced a UML-specific annotation. Move the Diagram Infrastructure CSS Palette bundle into the UML layer because it serves to provide extensions on the Palette Service, which is an overtly UML-specific capability. All client APIs for the Properties View are moved from org.eclipse.papyrus.views.properties bundle to a new org.eclipse.papyrus.infra.properties.ui bundle. This includes renaming of: * extension points * label-provider contexts * XWT namespaces Add an "all UI tests" suite. Define a componentized hierarchical build layout of the main plug-ins Change-Id: I43f8f3644857a18b69715f5a2f1da9b1cf286d67
Diffstat (limited to 'plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus')
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java158
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java70
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java344
3 files changed, 286 insertions, 286 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java
index c55720743cc..58e46c67bf3 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java
@@ -1,79 +1,79 @@
-/*****************************************************************************
- * 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.uml.nattable.menu.handlers;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.utils.INattableModelManagerUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.uml.nattable.menu.util.TableMenuUtils;
-import org.eclipse.papyrus.uml.service.types.handlers.AbstractUmlCreateElementCommandHandler;
-import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
-
-/**
- * Abstract handler for the creation commands of UML elements in the Nattable editor
- *
- */
-public abstract class AbstractUmlNattableCreateCommandHandler extends AbstractUmlCreateElementCommandHandler {
-
-
- /**
- * <pre>
- *
- * Build the create command for an element creation in the selected container.
- * The create command is given by the {@link IElementEditService} of selected
- * element.
- *
- * @return the composite creation command for current selection
- *
- * </pre>
- */
- @Override
- protected Command buildCommand() {
- Command createCmd = super.buildCommand();
- return TableMenuUtils.buildNattableCreationCommand(createCmd, this.createRequest);
-
- }
-
- /**
- * Obtain the context of the active table editor.
- *
- * @see org.eclipse.papyrus.uml.service.types.handlers.AbstractUmlCreateCommandHandler#getCommandContext()
- *
- * @return
- */
- @Override
- protected ICommandContext getCommandContext() {
- return TableMenuUtils.getTableCreateElementCommandContext(INattableModelManagerUtils.getTableManagerFromWorkbenchPart(getActiveWorkbenchPart()));
-
- }
-
- /**
- * Verify if this handler is currently active and the command can execute. Additionally, verify if this table can add this type of element.
- *
- * @see org.eclipse.papyrus.uml.service.types.handlers.AbstractCreateCommandHandler#setEnabled(java.lang.Object)
- *
- * @param evaluationContext
- */
- @Override
- public void setEnabled(Object evaluationContext) {
- INattableModelManager tableManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(getActiveWorkbenchPart());
- boolean isEnabled = tableManager.canCreateRowElement(getElementTypeToCreate().getId());
- if (isEnabled) {
- // we test the enable of the super implementation
- super.setEnabled(evaluationContext);
- isEnabled = super.isEnabled();
- }
- setBaseEnabled(isEnabled);
- }
-
-}
+/*****************************************************************************
+ * 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.uml.nattable.menu.handlers;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.INattableModelManagerUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.uml.nattable.menu.util.TableMenuUtils;
+import org.eclipse.papyrus.uml.service.types.ui.handlers.AbstractUmlCreateElementCommandHandler;
+import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
+
+/**
+ * Abstract handler for the creation commands of UML elements in the Nattable editor
+ *
+ */
+public abstract class AbstractUmlNattableCreateCommandHandler extends AbstractUmlCreateElementCommandHandler {
+
+
+ /**
+ * <pre>
+ *
+ * Build the create command for an element creation in the selected container.
+ * The create command is given by the {@link IElementEditService} of selected
+ * element.
+ *
+ * @return the composite creation command for current selection
+ *
+ * </pre>
+ */
+ @Override
+ protected Command buildCommand() {
+ Command createCmd = super.buildCommand();
+ return TableMenuUtils.buildNattableCreationCommand(createCmd, this.createRequest);
+
+ }
+
+ /**
+ * Obtain the context of the active table editor.
+ *
+ * @see org.eclipse.papyrus.uml.service.types.ui.handlers.AbstractUmlCreateCommandHandler#getCommandContext()
+ *
+ * @return
+ */
+ @Override
+ protected ICommandContext getCommandContext() {
+ return TableMenuUtils.getTableCreateElementCommandContext(INattableModelManagerUtils.getTableManagerFromWorkbenchPart(getActiveWorkbenchPart()));
+
+ }
+
+ /**
+ * Verify if this handler is currently active and the command can execute. Additionally, verify if this table can add this type of element.
+ *
+ * @see org.eclipse.papyrus.uml.service.types.ui.handlers.AbstractCreateCommandHandler#setEnabled(java.lang.Object)
+ *
+ * @param evaluationContext
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ INattableModelManager tableManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(getActiveWorkbenchPart());
+ boolean isEnabled = tableManager.canCreateRowElement(getElementTypeToCreate().getId());
+ if (isEnabled) {
+ // we test the enable of the super implementation
+ super.setEnabled(evaluationContext);
+ isEnabled = super.isEnabled();
+ }
+ setBaseEnabled(isEnabled);
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java
index d80365a8dc8..21bfb7e1a19 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java
@@ -1,35 +1,35 @@
-/*****************************************************************************
- * 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.uml.nattable.menu.handlers;
-
-import org.eclipse.papyrus.infra.nattable.utils.NattableWidgetPropertyTester;
-import org.eclipse.papyrus.uml.service.types.menu.AbstractCreateUmlChildMenu;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.menus.IContributionRoot;
-import org.eclipse.ui.services.IServiceLocator;
-
-/**
- * Menu contributions for the creation of UML elements from the Nattable editor
- */
-public class UmlNattableCreateMenu extends AbstractCreateUmlChildMenu {
-
- private NattableWidgetPropertyTester tester = new NattableWidgetPropertyTester();
-
- @Override
- public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
- IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
- if (tester.test(part, NattableWidgetPropertyTester.IS_NATTABLE_WIDGET, null, Boolean.TRUE)) {
- super.createContributionItems(serviceLocator, additions);
- }
- }
-}
+/*****************************************************************************
+ * 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.uml.nattable.menu.handlers;
+
+import org.eclipse.papyrus.infra.nattable.utils.NattableWidgetPropertyTester;
+import org.eclipse.papyrus.uml.service.types.ui.menu.AbstractCreateUmlChildMenu;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.menus.IContributionRoot;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * Menu contributions for the creation of UML elements from the Nattable editor
+ */
+public class UmlNattableCreateMenu extends AbstractCreateUmlChildMenu {
+
+ private NattableWidgetPropertyTester tester = new NattableWidgetPropertyTester();
+
+ @Override
+ public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
+ IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ if (tester.test(part, NattableWidgetPropertyTester.IS_NATTABLE_WIDGET, null, Boolean.TRUE)) {
+ super.createContributionItems(serviceLocator, additions);
+ }
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java
index 96ebb43678c..065b79057c5 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java
@@ -1,172 +1,172 @@
-/*****************************************************************************
- * 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.uml.nattable.menu.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectTreeItemAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
-import org.eclipse.papyrus.infra.nattable.provider.TableSelectionProvider;
-import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.nattable.utils.INattableModelManagerUtils;
-import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
-import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
-import org.eclipse.papyrus.uml.nattable.menu.messages.Messages;
-import org.eclipse.papyrus.uml.service.types.utils.CommandContext;
-import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
-import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Element;
-
-/**
- * Utilities for the creation of contextual menus from the Nattable editor
- */
-public class TableMenuUtils {
-
- /**
- * key registered in the parameter map of the CommandContext to know is we need to create a new IAxis for the created element.
- * An IAxis will be created in all cases, excepted is the value associated to this key is <code>false</code>
- */
- public static final String CREATE_NEW_AXIS_IN_TABLE_KEY = "CreateNewAxisInTable"; //$NON-NLS-1$
-
- /**
- *
- *
- * @param tableManager
- * the table manager
- * @return
- * the command context to use to create new elements in the table
- *
- * @Deprecated : use {@link #getTableCreateElementCommandContext(INattableModelManager)} instead
- */
- @Deprecated
- public static ICommandContext getTableCommandContext(final INattableModelManager tableManager) {
- // INattableModelManager manager = tableManager;
- // if (manager != null) {
- // final EObject container = manager.getTable().getContext();
- // ICommandContext context = null;
- // if (container != null) {
- // context = new CommandContext(container);
- // }
- // return context;
- // }
- return getTableCreateElementCommandContext(tableManager);
- }
-
- /**
- *
- *
- * @param tableManager
- * the table manager
- * @return
- * the command context to use to create new elements in the table
- */
- public static ICommandContext getTableCreateElementCommandContext(final INattableModelManager tableManager) {
- INattableModelManager manager = tableManager;
- Map<Object, Object> parameters = new HashMap<Object, Object>();
- if (manager != null) {
- EObject container = manager.getTable().getContext();
- if (TableHelper.isTreeTable(tableManager) && tableManager instanceof ITreeNattableModelManager) {
- // TODO : table manager should provide its selection provider
- ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
- ISelection selection = service.getSelection();
- if (selection instanceof TableStructuredSelection) {
- TableStructuredSelection selectionprovider = (TableStructuredSelection) selection;
- TableSelectionWrapper selectionWrapper = (TableSelectionWrapper) selectionprovider.getAdapter(TableSelectionWrapper.class);
- Map<Integer, Object> rows = selectionWrapper.getFullySelectedRows();
- if (rows.size() == 1) {
- Object fullySelectedRow = rows.values().iterator().next();
- if (fullySelectedRow instanceof EObjectTreeItemAxis && ((EObjectTreeItemAxis) fullySelectedRow).getElement() instanceof Element) {
- container = ((EObjectTreeItemAxis) fullySelectedRow).getElement();
- parameters.put(CREATE_NEW_AXIS_IN_TABLE_KEY, Boolean.FALSE);
- // we should verify the depth of the hierarchic table to forbid the creation when the element will not be displayed as new column
-
- // List<ITreeItemAxis> path = new ArrayList<ITreeItemAxis>();
- // ((ITreeNattableModelManager)tableManager).getTreeFormat().getPath(path, (ITreeItemAxis) fullySelectedRow);
- // int depth = path.size()-1;
- // container = ((EObjectTreeItemAxis) fullySelectedRow).getElement();
- }
- }
- }
- }
- ICommandContext context = null;
- if (container != null) {
- context = new CommandContext(container, null, parameters);
- }
- return context;
- }
- return null;
- }
-
- /**
- *
- * @param createCmd
- * the create command
- * @param createElementRequest
- * the create element request
- * @return
- * the command to use to create elements in the table editor
- */
- public static Command buildNattableCreationCommand(Command createCmd, final CreateElementRequest createElementRequest) {
- final INattableModelManager nattableModelManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart());
- if (nattableModelManager != null) {
- CompositeCommand cmd = new CompositeCommand(""); //$NON-NLS-1$
- cmd.add(new EMFtoGMFCommandWrapper(createCmd));
-
- Object value = createElementRequest.getParameters().get(CREATE_NEW_AXIS_IN_TABLE_KEY);
- // depends on the synchronization of the axis manager
- if (value == null || Boolean.TRUE.equals(value)) {
- cmd.add(new AbstractTransactionalCommand(createElementRequest.getEditingDomain(), Messages.AbstractNattableCreateCommandHandler_AddElementCommand, null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- //see 469376: [Table] Memory Leak : (Tree)NattableWidgetManager, EObjectTreeItemAxis and others objects are not disposed when the table is closed
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=469376
- final INattableModelManager nattableModelManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart());
- EObject newElement = createElementRequest.getNewElement();
- Collection<Object> toAdd = new ArrayList<Object>();
- toAdd.add(newElement);
- Command tmp = nattableModelManager.getAddRowElementCommand(toAdd);
- if (tmp != null) {
- tmp.execute();
- }
- return CommandResult.newOKCommandResult();
- }
- });
- }
- return new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(cmd);
-
- }
- return UnexecutableCommand.INSTANCE;
- }
-
-}
+/*****************************************************************************
+ * 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.uml.nattable.menu.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectTreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.provider.TableSelectionProvider;
+import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.INattableModelManagerUtils;
+import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
+import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
+import org.eclipse.papyrus.uml.nattable.menu.messages.Messages;
+import org.eclipse.papyrus.uml.service.types.utils.CommandContext;
+import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * Utilities for the creation of contextual menus from the Nattable editor
+ */
+public class TableMenuUtils {
+
+ /**
+ * key registered in the parameter map of the CommandContext to know is we need to create a new IAxis for the created element.
+ * An IAxis will be created in all cases, excepted is the value associated to this key is <code>false</code>
+ */
+ public static final String CREATE_NEW_AXIS_IN_TABLE_KEY = "CreateNewAxisInTable"; //$NON-NLS-1$
+
+ /**
+ *
+ *
+ * @param tableManager
+ * the table manager
+ * @return
+ * the command context to use to create new elements in the table
+ *
+ * @Deprecated : use {@link #getTableCreateElementCommandContext(INattableModelManager)} instead
+ */
+ @Deprecated
+ public static ICommandContext getTableCommandContext(final INattableModelManager tableManager) {
+ // INattableModelManager manager = tableManager;
+ // if (manager != null) {
+ // final EObject container = manager.getTable().getContext();
+ // ICommandContext context = null;
+ // if (container != null) {
+ // context = new CommandContext(container);
+ // }
+ // return context;
+ // }
+ return getTableCreateElementCommandContext(tableManager);
+ }
+
+ /**
+ *
+ *
+ * @param tableManager
+ * the table manager
+ * @return
+ * the command context to use to create new elements in the table
+ */
+ public static ICommandContext getTableCreateElementCommandContext(final INattableModelManager tableManager) {
+ INattableModelManager manager = tableManager;
+ Map<Object, Object> parameters = new HashMap<Object, Object>();
+ if (manager != null) {
+ EObject container = manager.getTable().getContext();
+ if (TableHelper.isTreeTable(tableManager) && tableManager instanceof ITreeNattableModelManager) {
+ // TODO : table manager should provide its selection provider
+ ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = service.getSelection();
+ if (selection instanceof TableStructuredSelection) {
+ TableStructuredSelection selectionprovider = (TableStructuredSelection) selection;
+ TableSelectionWrapper selectionWrapper = (TableSelectionWrapper) selectionprovider.getAdapter(TableSelectionWrapper.class);
+ Map<Integer, Object> rows = selectionWrapper.getFullySelectedRows();
+ if (rows.size() == 1) {
+ Object fullySelectedRow = rows.values().iterator().next();
+ if (fullySelectedRow instanceof EObjectTreeItemAxis && ((EObjectTreeItemAxis) fullySelectedRow).getElement() instanceof Element) {
+ container = ((EObjectTreeItemAxis) fullySelectedRow).getElement();
+ parameters.put(CREATE_NEW_AXIS_IN_TABLE_KEY, Boolean.FALSE);
+ // we should verify the depth of the hierarchic table to forbid the creation when the element will not be displayed as new column
+
+ // List<ITreeItemAxis> path = new ArrayList<ITreeItemAxis>();
+ // ((ITreeNattableModelManager)tableManager).getTreeFormat().getPath(path, (ITreeItemAxis) fullySelectedRow);
+ // int depth = path.size()-1;
+ // container = ((EObjectTreeItemAxis) fullySelectedRow).getElement();
+ }
+ }
+ }
+ }
+ ICommandContext context = null;
+ if (container != null) {
+ context = new CommandContext(container, null, parameters);
+ }
+ return context;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param createCmd
+ * the create command
+ * @param createElementRequest
+ * the create element request
+ * @return
+ * the command to use to create elements in the table editor
+ */
+ public static Command buildNattableCreationCommand(Command createCmd, final CreateElementRequest createElementRequest) {
+ final INattableModelManager nattableModelManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart());
+ if (nattableModelManager != null) {
+ CompositeCommand cmd = new CompositeCommand(""); //$NON-NLS-1$
+ cmd.add(new EMFtoGMFCommandWrapper(createCmd));
+
+ Object value = createElementRequest.getParameters().get(CREATE_NEW_AXIS_IN_TABLE_KEY);
+ // depends on the synchronization of the axis manager
+ if (value == null || Boolean.TRUE.equals(value)) {
+ cmd.add(new AbstractTransactionalCommand(createElementRequest.getEditingDomain(), Messages.AbstractNattableCreateCommandHandler_AddElementCommand, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ //see 469376: [Table] Memory Leak : (Tree)NattableWidgetManager, EObjectTreeItemAxis and others objects are not disposed when the table is closed
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=469376
+ final INattableModelManager nattableModelManager = INattableModelManagerUtils.getTableManagerFromWorkbenchPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart());
+ EObject newElement = createElementRequest.getNewElement();
+ Collection<Object> toAdd = new ArrayList<Object>();
+ toAdd.add(newElement);
+ Command tmp = nattableModelManager.getAddRowElementCommand(toAdd);
+ if (tmp != null) {
+ tmp.execute();
+ }
+ return CommandResult.newOKCommandResult();
+ }
+ });
+ }
+ return new org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper(cmd);
+
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+}

Back to the top