Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-05-24 08:09:16 +0000
committervlorenzo2013-05-24 08:09:16 +0000
commite9eb12d1ea6ebb5bfd60a0ccb23285a733e7ca7d (patch)
tree606f0cae43c8f218fdc4d0058d260e86097ca094 /plugins/sysml
parent476515552f6ba04fd8ca27cd81520aa316fc41d2 (diff)
downloadorg.eclipse.papyrus-e9eb12d1ea6ebb5bfd60a0ccb23285a733e7ca7d.tar.gz
org.eclipse.papyrus-e9eb12d1ea6ebb5bfd60a0ccb23285a733e7ca7d.tar.xz
org.eclipse.papyrus-e9eb12d1ea6ebb5bfd60a0ccb23285a733e7ca7d.zip
408217: [ModelExplorer] The handlers to create UML/SysML elements must be moved in an upper plugin
https://bugs.eclipse.org/bugs/show_bug.cgi?id=408217 Small refactrouing for the creation elements
Diffstat (limited to 'plugins/sysml')
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF3
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/menu/AbstractCreateSysmlChildMenu.java92
2 files changed, 8 insertions, 87 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
index efd2c632cda..599c38bcf40 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.services.edit;bundle-version="0.10.0",
org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
org.eclipse.uml2.uml.profile.l2;bundle-version="1.0.0",
- org.eclipse.core.expressions
+ org.eclipse.core.expressions,
+ org.eclipse.papyrus.infra.tools;bundle-version="0.10.0"
Export-Package: org.eclipse.papyrus.sysml.service.types,
org.eclipse.papyrus.sysml.service.types.element,
org.eclipse.papyrus.sysml.service.types.handlers,
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
index 9417cb2d93c..bacaa503732 100644
--- 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
@@ -11,102 +11,22 @@
*****************************************************************************/
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;
+import org.eclipse.papyrus.infra.tools.util.AbstractCreateMenuFromCommandCategory;
/**
* Abstract menu for the creation of Sysml elements
*/
-public abstract class AbstractCreateSysmlChildMenu extends ExtensionContributionFactory {
+public abstract class AbstractCreateSysmlChildMenu extends AbstractCreateMenuFromCommandCategory {
+
+ /** the cateogory of the command used to create SysML elements */
+ public static final String SYSML_CREATION_COMMAND_CATEGORY = "org.eclipse.papyrus.sysml.service.types.sysmlElementCreationCommands"; //$NON-NLS-1$
/**
* 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()));
- try {
- for(Command command : commands) {
- if(command.getCategory().equals(sysmlCategory)) {
- IHandler handler = command.getHandler();
- if(handler == null) {
- continue;
- }
-
- ((AbstractHandler)handler).setEnabled(null);
- boolean isEnabled = handler.isEnabled();
- if(isEnabled) {
- 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;
+ super(SYSML_CREATION_COMMAND_CATEGORY);
}
}

Back to the top