Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2013-09-09 12:42:14 +0000
committerVincent Lorenzo2013-09-09 12:42:14 +0000
commit741e67351f12f31d6cbe2e2de1844aaa59906192 (patch)
tree1a1f496d60837b2af34a9ea55f6dbb2779c6df4c /plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu
parent08affe02de8ee362ff59784a08389cb83cc8b3b7 (diff)
downloadorg.eclipse.papyrus-741e67351f12f31d6cbe2e2de1844aaa59906192.tar.gz
org.eclipse.papyrus-741e67351f12f31d6cbe2e2de1844aaa59906192.tar.xz
org.eclipse.papyrus-741e67351f12f31d6cbe2e2de1844aaa59906192.zip
416817: [Table 2] The new tables must replace the old tables in Luna
https://bugs.eclipse.org/bugs/show_bug.cgi?id=416817 Move the nattable plugins from extraplugins/table to : plugins/infra/nattable or plugins/uml/nattable or plugins/sysml/nattable
Diffstat (limited to 'plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu')
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/Activator.java72
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java76
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java35
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/Messages.java28
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/messages.properties1
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java97
6 files changed, 309 insertions, 0 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/Activator.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/Activator.java
new file mode 100644
index 00000000000..a8e6ce1d7e8
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/Activator.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * 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;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.nattable.menu"; //$NON-NLS-1$
+
+
+ /** The log service */
+ public static LogHelper log;
+
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(plugin);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
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
new file mode 100644
index 00000000000..2afa9925989
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/AbstractUmlNattableCreateCommandHandler.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * 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.AbstractUmlCreateCommandHandler;
+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 AbstractUmlCreateCommandHandler {
+
+
+ /**
+ * <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>
+ */
+ 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
+ */
+ protected ICommandContext getCommandContext() {
+ return TableMenuUtils.getTableCommandContext(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
+ */
+ 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
new file mode 100644
index 00000000000..58b3762b7c0
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/handlers/UmlNattableCreateMenu.java
@@ -0,0 +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);
+ }
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/Messages.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/Messages.java
new file mode 100644
index 00000000000..790a7f7be9a
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/Messages.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * 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.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.nattable.menu.messages.messages"; //$NON-NLS-1$
+
+ public static String AbstractNattableCreateCommandHandler_AddElementCommand;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/messages.properties b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/messages.properties
new file mode 100644
index 00000000000..aa84a372d23
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/messages/messages.properties
@@ -0,0 +1 @@
+AbstractNattableCreateCommandHandler_AddElementCommand=Add element to the table
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
new file mode 100644
index 00000000000..20107d73847
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * 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 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.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.INattableModelManagerUtils;
+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.PlatformUI;
+
+/**
+ * Utilities for the creation of contextual menus from the Nattable editor
+ */
+public class TableMenuUtils {
+
+ /**
+ *
+ *
+ * @param tableManager
+ * the table manager
+ * @return
+ * the command context to use to create new elements in the table
+ */
+ 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 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));
+
+ // depends on the synchronization of the axis manager
+ cmd.add(new AbstractTransactionalCommand(createElementRequest.getEditingDomain(), Messages.AbstractNattableCreateCommandHandler_AddElementCommand, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ 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;
+ }
+
+}

Back to the top