Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java')
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.menu/src/org/eclipse/papyrus/uml/nattable/menu/util/TableMenuUtils.java97
1 files changed, 97 insertions, 0 deletions
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