Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-05-03 11:10:32 +0000
committervlorenzo2013-05-03 11:10:32 +0000
commitadda585483bf0714f34ceea3acf30ec66aab5469 (patch)
tree0bfdf917d784205c0b91ebb1a84dacffd260acd7 /plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml
parentdf3284d02c0e92178036247c540693f0658d7053 (diff)
downloadorg.eclipse.papyrus-adda585483bf0714f34ceea3acf30ec66aab5469.tar.gz
org.eclipse.papyrus-adda585483bf0714f34ceea3acf30ec66aab5469.tar.xz
org.eclipse.papyrus-adda585483bf0714f34ceea3acf30ec66aab5469.zip
400801: [Table 2] Tabular Editor must allow to create new element and add it to the table
https://bugs.eclipse.org/bugs/show_bug.cgi?id=400801
Diffstat (limited to 'plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml')
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/handlers/AbstractSysmlCreateCommandHandler.java33
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/menu/AbstractCreateSysmlChildMenu.java117
2 files changed, 150 insertions, 0 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/handlers/AbstractSysmlCreateCommandHandler.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/handlers/AbstractSysmlCreateCommandHandler.java
new file mode 100644
index 00000000000..45312f342fc
--- /dev/null
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/handlers/AbstractSysmlCreateCommandHandler.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * 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.sysml.service.types.handlers;
+
+import org.eclipse.papyrus.sysml.service.types.filter.SysmlCommandFilter;
+import org.eclipse.papyrus.uml.service.types.handlers.AbstractCreateCommandHandler;
+
+
+
+/**
+ *
+ * Abstract handler for every creation command for Sysml elements
+ * used in the ModelExplorer contextual ("Create new child") menu
+ *
+ */
+public abstract class AbstractSysmlCreateCommandHandler extends AbstractCreateCommandHandler {
+
+ @Override
+ protected void initFilter() {
+ filter = new SysmlCommandFilter();
+ }
+
+
+}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/menu/AbstractCreateSysmlChildMenu.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/menu/AbstractCreateSysmlChildMenu.java
new file mode 100644
index 00000000000..19b6c5d4681
--- /dev/null
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/menu/AbstractCreateSysmlChildMenu.java
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * 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.sysml.service.types.menu;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Category;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.sysml.service.types.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandImageService;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.menus.CommandContributionItem;
+import org.eclipse.ui.menus.CommandContributionItemParameter;
+import org.eclipse.ui.menus.ExtensionContributionFactory;
+import org.eclipse.ui.menus.IContributionRoot;
+import org.eclipse.ui.services.IServiceLocator;
+
+
+/**
+ * Abstract menu for the creation of Sysml elements
+ */
+public abstract class AbstractCreateSysmlChildMenu extends ExtensionContributionFactory {
+
+ /**
+ * Constructor.
+ *
+ */
+ public AbstractCreateSysmlChildMenu() {
+ }
+
+ @Override
+ public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
+ //test to know if we can create elements if it is possible...
+ Expression visibleWhen = new Expression() {
+
+ @Override
+ public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
+ return EvaluationResult.TRUE;
+ }
+ };
+ for(CommandContributionItem item : addCreationItems(serviceLocator, additions, null)) {
+ additions.addContributionItem(item, visibleWhen);
+ }
+
+ }
+
+ private List<CommandContributionItem> addCreationItems(IServiceLocator serviceLocator, IContributionRoot additions, IContributionManager parent) {
+ ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+ String categoryId = "org.eclipse.papyrus.sysml.service.types.sysmlElementCreationCommands"; //$NON-NLS-1$
+ List<CommandContributionItem> items = new ArrayList<CommandContributionItem>();
+ Category sysmlCategory = commandService.getCategory(categoryId);
+ Set<Command> commands = new TreeSet<Command>();
+ commands.addAll(Arrays.asList(commandService.getDefinedCommands()));
+ ArrayList<Command> commandsForMenuItems = new ArrayList<Command>();
+ try {
+ for(Command command : commands) {
+
+ IHandler handler = command.getHandler();
+ if(handler == null) {
+ continue;
+ }
+ if(command.getCategory().equals(sysmlCategory)) {
+ //FIXME : verify utility of setEnabled(null)
+ ((AbstractHandler)handler).setEnabled(null);
+ boolean isEnabled = handler.isEnabled();
+ if(isEnabled) {
+ commandsForMenuItems.add(command);
+ }
+ }
+ }
+ for(Command command : commandsForMenuItems) {
+ String commandId = command.getId();
+ CommandContributionItemParameter p = new CommandContributionItemParameter(serviceLocator, "", commandId, SWT.PUSH); //$NON-NLS-1$
+ p.label = command.getDescription();
+ p.icon = getCommandIcon(command);
+ CommandContributionItem item = new CommandContributionItem(p);
+ items.add(item);
+ }
+ } catch (NotDefinedException e) {
+ Activator.log.error(e.getLocalizedMessage(), e);
+ }
+ return items;
+
+ }
+
+ private ImageDescriptor getCommandIcon(Command command) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ ICommandImageService service = (ICommandImageService)workbench.getService(ICommandImageService.class);
+ ImageDescriptor imageDescriptor = service.getImageDescriptor(command.getId());
+ return imageDescriptor;
+ }
+}

Back to the top