Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/META-INF/MANIFEST.MF2
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java186
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java151
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CloseHandler.java235
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/OpenHandler.java295
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/RedoHandler.java16
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/UndoHandler.java16
7 files changed, 292 insertions, 609 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/META-INF/MANIFEST.MF b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/META-INF/MANIFEST.MF
index aa96b938291..c5000f26146 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/META-INF/MANIFEST.MF
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Require-Bundle: org.eclipse.emf.converter;bundle-version="[2.7.0,3.0.0)",
org.eclipse.emf.ecore.editor;bundle-version="[2.11.0,3.0.0)",
org.eclipse.emf.workspace.ui;bundle-version="[1.3.0,2.0.0)",
org.eclipse.papyrus.infra.services.edit;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.views.modelexplorer;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.views.modelexplorer;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.services.resourceloading;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java
deleted file mode 100644
index b5c29fc0ee9..00000000000
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
- * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.handler;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
-import org.eclipse.papyrus.views.modelexplorer.Activator;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * <pre>
- *
- * This abstract command handler manages:
- * - current selection in order to build a list of the selected {@link EObject}
- * - execute the command (returned by children) in Papyrus {@link TransactionalEditingDomain}
- * - calculate the command enablement and visibility regarding the command executability
- * (the command is now shown in menu if not executable).
- *
- * </pre>
- *
- * @deprecated Use the {@link org.eclipse.papyrus.infra.ui.command.AbstractCommandHandler} API, instead.
- */
-@Deprecated
-public abstract class AbstractCommandHandler extends AbstractModelExplorerHandler {
-
- private List<?> selection = Collections.EMPTY_LIST;
-
- /**
- * <pre>
- *
- * Returns the command to execute (to be implemented
- * in children implementing this class)
- *
- * &#64;return the command to execute
- *
- * </pre>
- */
- protected abstract Command getCommand();
-
- protected List<?> getSelection() {
- return selection;
- }
-
- /**
- * <pre>
- * Get the selected element, the first selected element if several are selected or null
- * if no selection or the selection is not an {@link EObject}.
- *
- * @return selected {@link EObject} or null
- * </pre>
- *
- */
- protected EObject getSelectedElement() {
- EObject eObject = null;
-
- // Get current selection
- List<?> selection = getSelection();
-
- // Treat non-null selected object (try to adapt and return EObject)
- if (!selection.isEmpty()) {
-
- // Get first element if the selection is an IStructuredSelection
- Object first = selection.get(0);
-
- EObject businessObject = EMFHelper.getEObject(first);
- if (businessObject != null) {
- eObject = businessObject;
- }
- }
-
- return eObject;
- }
-
- /**
- * <pre>
- * Parse current selection and extract the list of {@link EObject} from
- * this selection.
- *
- * This also tries to adapt selected element into {@link EObject}
- * (for example to get the {@link EObject} from a selection in the ModelExplorer).
- *
- * @return a list of currently selected {@link EObject}
- * </pre>
- *
- */
- protected List<EObject> getSelectedElements() {
-
- List<EObject> selectedEObjects = new ArrayList<EObject>();
-
- // Get current selection
- Collection<?> selection = getSelection();
-
- // Treat non-null selected object (try to adapt and return EObject)
- if (!selection.isEmpty()) {
-
- // Parse current selection
- for (Object current : selection) {
- // Adapt current selection to EObject
- EObject selectedEObject = EMFHelper.getEObject(current);
- if (selectedEObject != null) {
- // we avoid to add null element in the list!
- selectedEObjects.add(selectedEObject);
- }
- }
- }
-
- return selectedEObjects;
- }
-
- /**
- *
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- *
- * @param event
- * @return null
- * @throws ExecutionException
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- try {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- this.selection = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).toList() : Collections.EMPTY_LIST;
-
- ServiceUtilsForHandlers.getInstance().getTransactionalEditingDomain(event).getCommandStack().execute(getCommand());
- } catch (ServiceException e) {
- Activator.log.error("Unexpected error while executing command.", e); //$NON-NLS-1$
- } finally {
- // clear the selection
- this.selection = Collections.EMPTY_LIST;
- }
-
- return null;
- }
-
- protected boolean computeEnabled() {
- boolean result = false;
-
- Command command = getCommand();
- if (command != null) {
- result = getCommand().canExecute();
- command.dispose();
- }
-
- return result;
- }
-
- @Override
- public void setEnabled(Object evaluationContext) {
- if (evaluationContext instanceof IEvaluationContext) {
- Object selection = ((IEvaluationContext) evaluationContext).getDefaultVariable();
- if (selection instanceof Collection<?>) {
- this.selection = (selection instanceof List<?>) ? (List<?>) selection : new java.util.ArrayList<Object>((Collection<?>) selection);
- setBaseEnabled(computeEnabled());
- this.selection = Collections.EMPTY_LIST;
- }
- }
- super.setEnabled(evaluationContext);
- }
-}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java
deleted file mode 100644
index e13d4ae9b2e..00000000000
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.ui.command.AbstractPapyrusHandler;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * This provides facilities to get the TransactionEditingDomain and the PageManager from the Model Explorer
- *
- *
- * @deprecated Use the {@link AbstractPapyrusHandler} API, instead.
- */
-@Deprecated
-public abstract class AbstractModelExplorerHandler extends AbstractPapyrusHandler {
-
- /**
- * Returns the
- *
- * @return
- * the current editing domain
- */
- @Deprecated
- protected TransactionalEditingDomain getEditingDomain() {
- return getEditingDomain((ExecutionEvent) null);
- }
-
- /**
- * Returns the page manager
- *
- * @return
- * the page manager
- */
- @Deprecated
- protected IPageManager getPageManager() {
- return getPageManager((ExecutionEvent) null);
- }
-
- /**
- * Adapt the specified object to the requested type, if possible.
- * Return null if the object can't be adapted.
- *
- * @param object
- * @param expectedClassType
- * @return The adapted object, or null.
- */
- @SuppressWarnings("unchecked")
- private <T> T adapt(Object object, Class<T> expectedClassType) {
-
-
- EObject eobject = EMFHelper.getEObject(object);
-
- if (eobject != null && expectedClassType.isInstance(eobject)) {
- return (T) eobject;
- }
-
-
-
- // Try global mechanism
- {
- T ele = Platform.getAdapterManager().getAdapter(object, expectedClassType);
- if (ele != null) {
- return ele;
- }
- // Try as EObject if the expectedClasType is sub-type of EObject.
- if (EObject.class.isAssignableFrom(expectedClassType)) {
- // to EObject
- eobject = Platform.getAdapterManager().getAdapter(object, EObject.class);
-
- if (eobject != null && expectedClassType.isInstance(eobject)) {
-
- return (T) eobject;
- }
- }
- }
- // Can't be adapted
- return null;
-
- }
-
- /**
- * Filter the list, and only retain objects that can be adapted to the specified type
- *
- * @param objects
- * @param class1
- * @return
- */
- private <T> List<T> getAllElementAdaptedToType(List<Object> list, Class<T> expectedClassType) {
-
- List<T> res = new ArrayList<T>();
-
- for (Object cur : list) {
-
- T adapted = adapt(cur, expectedClassType);
- if (adapted != null) {
- res.add(adapted);
- }
- }
- return res;
- }
-
- /**
- * Get all selected element of the specified type.
- *
- * @param expectedType
- * @return
- * @throws ExecutionException
- */
- @Override
- @SuppressWarnings("unchecked")
- protected <T> List<T> getCurrentSelectionAdaptedToType(ExecutionEvent event, Class<T> expectedType) throws ExecutionException {
-
- // Get selection from the workbench
- ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
-
- // Get the selected objects according to the type of the selected
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- return getAllElementAdaptedToType(structuredSelection.toList(), expectedType);
- } else if (selection instanceof TreeSelection) {
- TreeSelection treeSelection = (TreeSelection) selection;
- return getAllElementAdaptedToType(treeSelection.toList(), expectedType);
-
- }
- return null;
- }
-}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CloseHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CloseHandler.java
index 17d5aa9ba23..7b899c25180 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CloseHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CloseHandler.java
@@ -1,117 +1,118 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.handler;
-
-import java.util.Hashtable;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
-
-/**
- * This handler allows to Close Diagrams and Tables
- *
- *
- *
- */
-public class CloseHandler extends AbstractModelExplorerHandler implements IExecutableExtension {
-
- /** parameters for this action */
- /**
- * close all open elements
- */
- public static final String PARAMETER_ALL = "all"; //$NON-NLS-1$
-
- /**
- * Close only the selected elements
- */
- public static final String PARAMETER_SELECTION = "selection"; //$NON-NLS-1$
-
- /** parameter for this handler */
- protected String parameter = null;
-
- /** parameter ID */
- protected String parameterID = "close_parameter"; //$NON-NLS-1$
-
- /**
- *
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- *
- * @param event
- * @return
- * @throws ExecutionException
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- final IPageManager pageMngr;
-
- try {
- ServicesRegistry registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- pageMngr = registry.getService(IPageManager.class);
- } catch (ServiceException ex) {
- throw new ExecutionException(ex.getMessage(), ex);
- }
-
- // What kind of command ?
- if (PARAMETER_ALL.equals(parameter)) {
- pageMngr.closeAllOpenedPages();
-
- return null;
- }
-
- // Try to close each selected editor.
- // There is no common type for object representing an editor. So,
- // We try to get the EObject, and try to close it as an Editor.
- List<EObject> selectedProperties = getCurrentSelectionAdaptedToType(event, EObject.class);
- if (selectedProperties == null) {
- // nothing to do
- return null;
- }
-
- // Check each selected object
- for (EObject selected : selectedProperties) {
- if (pageMngr.isOpen(selected)) {
- pageMngr.closePage(selected);
- }
- }
-
- return null;
- }
-
- /**
- *
- * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
- *
- * @param config
- * @param propertyName
- * @param data
- * @throws CoreException
- */
- @Override
- public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
- if (data instanceof Hashtable && this.parameterID != null) {
- this.parameter = (String) ((Hashtable) data).get(this.parameterID);
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import java.util.Hashtable;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.ui.command.AbstractPapyrusHandler;
+import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
+
+/**
+ * This handler allows to Close Diagrams and Tables
+ *
+ *
+ *
+ */
+public class CloseHandler extends AbstractPapyrusHandler implements IExecutableExtension {
+
+ /** parameters for this action */
+ /**
+ * close all open elements
+ */
+ public static final String PARAMETER_ALL = "all"; //$NON-NLS-1$
+
+ /**
+ * Close only the selected elements
+ */
+ public static final String PARAMETER_SELECTION = "selection"; //$NON-NLS-1$
+
+ /** parameter for this handler */
+ protected String parameter = null;
+
+ /** parameter ID */
+ protected String parameterID = "close_parameter"; //$NON-NLS-1$
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ final IPageManager pageMngr;
+
+ try {
+ ServicesRegistry registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
+ pageMngr = registry.getService(IPageManager.class);
+ } catch (ServiceException ex) {
+ throw new ExecutionException(ex.getMessage(), ex);
+ }
+
+ // What kind of command ?
+ if (PARAMETER_ALL.equals(parameter)) {
+ pageMngr.closeAllOpenedPages();
+
+ return null;
+ }
+
+ // Try to close each selected editor.
+ // There is no common type for object representing an editor. So,
+ // We try to get the EObject, and try to close it as an Editor.
+ List<EObject> selectedProperties = getCurrentSelectionAdaptedToType(event, EObject.class);
+ if (selectedProperties == null) {
+ // nothing to do
+ return null;
+ }
+
+ // Check each selected object
+ for (EObject selected : selectedProperties) {
+ if (pageMngr.isOpen(selected)) {
+ pageMngr.closePage(selected);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ *
+ * @param config
+ * @param propertyName
+ * @param data
+ * @throws CoreException
+ */
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ if (data instanceof Hashtable && this.parameterID != null) {
+ this.parameter = (String) ((Hashtable) data).get(this.parameterID);
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/OpenHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/OpenHandler.java
index 726b957edb7..b5c8ad1b0cc 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/OpenHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/OpenHandler.java
@@ -1,146 +1,149 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.handler;
-
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-
-/**
- * This handler allows to Open Diagrams and Tables
- *
- *
- *
- */
-public class OpenHandler extends AbstractModelExplorerHandler implements IExecutableExtension {
-
-
- /**
- * Close only the selected elements
- */
- public static final String IS_DUPLICATE_EDITOR_ALLOWED_PARAMETER = "isDuplicateEditorAllowed"; //$NON-NLS-1$
-
-
- /**
- * Return true if the open command allow to duplicate editor that are already
- * opened.
- * Return false if open command should not duplicate already opened editor.
- * This property can be set from the plugin.xml.
- */
- protected boolean isDuplicateDiagramAllowed = false;
-
-
- /**
- *
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- *
- * @param event
- * @return
- * @throws ExecutionException
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final IPageManager pageManager = getPageManager();
- if (pageManager == null) {
- return null;
- }
-
- // Try to close each selected editor.
- // There is no common type for object representing an editor. So,
- // We try to get the EObject, and try to close it as an Editor.
- List<EObject> selectedProperties = getCurrentSelectionAdaptedToType(event, EObject.class);
- if (selectedProperties == null) {
- // nothing to do
- return null;
- }
-
- // Check each selected object
- final List<EObject> pagesToOpen = new LinkedList<EObject>();
- List<EObject> pagesToSelect = new LinkedList<EObject>();
- for (EObject selected : selectedProperties) {
- if (!canOpenByPolicy(selected)) {
- continue;
- }
- if (!pageManager.isOpen(selected) || isDuplicateDiagramAllowed) {
- pagesToOpen.add(selected);
- } else {
- pagesToSelect.add(selected);
- }
- }
-
- if (!pagesToOpen.isEmpty()) {
- for (EObject page : pagesToOpen) {
- pageManager.openPage(page);
- }
- }
-
- for (EObject page : pagesToSelect) {
- pageManager.selectPage(page);
- }
-
- return null;
- }
-
- /**
- * Determines whether the current policy allows this object to be opened
- *
- * @param selection
- * The object to open
- * @return <code>true</code> if the object can be opened
- */
- private boolean canOpenByPolicy(EObject selection) {
- if (selection instanceof Diagram) {
- Diagram diagram = (Diagram) selection;
- ViewPrototype proto = DiagramUtils.getPrototype(diagram);
- return (proto != ViewPrototype.UNAVAILABLE_VIEW && proto != ViewPrototype.UNAVAILABLE_DIAGRAM);
- }
- return true;
- }
-
- /**
- *
- * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
- *
- * @param config
- * @param propertyName
- * @param data
- * @throws CoreException
- */
- public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
- if (!(data instanceof Hashtable)) {
- return;
- }
-
- @SuppressWarnings("rawtypes")
- Hashtable map = (Hashtable) data;
-
- try {
- isDuplicateDiagramAllowed = Boolean.parseBoolean((String) map.get(IS_DUPLICATE_EDITOR_ALLOWED_PARAMETER));
- } catch (Exception e) {
- // silently fail;
- }
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.ui.command.AbstractPapyrusHandler;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * This handler allows to Open Diagrams and Tables
+ *
+ *
+ *
+ */
+public class OpenHandler extends AbstractPapyrusHandler implements IExecutableExtension {
+
+
+ /**
+ * Close only the selected elements
+ */
+ public static final String IS_DUPLICATE_EDITOR_ALLOWED_PARAMETER = "isDuplicateEditorAllowed"; //$NON-NLS-1$
+
+
+ /**
+ * Return true if the open command allow to duplicate editor that are already
+ * opened.
+ * Return false if open command should not duplicate already opened editor.
+ * This property can be set from the plugin.xml.
+ */
+ protected boolean isDuplicateDiagramAllowed = false;
+
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final IPageManager pageManager = getPageManager(event);
+ if (pageManager == null) {
+ return null;
+ }
+
+ // Try to close each selected editor.
+ // There is no common type for object representing an editor. So,
+ // We try to get the EObject, and try to close it as an Editor.
+ List<EObject> selectedProperties = getCurrentSelectionAdaptedToType(event, EObject.class);
+ if (selectedProperties == null) {
+ // nothing to do
+ return null;
+ }
+
+ // Check each selected object
+ final List<EObject> pagesToOpen = new LinkedList<EObject>();
+ List<EObject> pagesToSelect = new LinkedList<EObject>();
+ for (EObject selected : selectedProperties) {
+ if (!canOpenByPolicy(selected)) {
+ continue;
+ }
+ if (!pageManager.isOpen(selected) || isDuplicateDiagramAllowed) {
+ pagesToOpen.add(selected);
+ } else {
+ pagesToSelect.add(selected);
+ }
+ }
+
+ if (!pagesToOpen.isEmpty()) {
+ for (EObject page : pagesToOpen) {
+ pageManager.openPage(page);
+ }
+ }
+
+ for (EObject page : pagesToSelect) {
+ pageManager.selectPage(page);
+ }
+
+ return null;
+ }
+
+ /**
+ * Determines whether the current policy allows this object to be opened
+ *
+ * @param selection
+ * The object to open
+ * @return <code>true</code> if the object can be opened
+ */
+ private boolean canOpenByPolicy(EObject selection) {
+ if (selection instanceof Diagram) {
+ Diagram diagram = (Diagram) selection;
+ ViewPrototype proto = DiagramUtils.getPrototype(diagram);
+ return (proto != ViewPrototype.UNAVAILABLE_VIEW && proto != ViewPrototype.UNAVAILABLE_DIAGRAM);
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ *
+ * @param config
+ * @param propertyName
+ * @param data
+ * @throws CoreException
+ */
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ if (!(data instanceof Hashtable)) {
+ return;
+ }
+
+ @SuppressWarnings("rawtypes")
+ Hashtable map = (Hashtable) data;
+
+ try {
+ isDuplicateDiagramAllowed = Boolean.parseBoolean((String) map.get(IS_DUPLICATE_EDITOR_ALLOWED_PARAMETER));
+ } catch (Exception e) {
+ // silently fail;
+ }
+ }
+
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/RedoHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/RedoHandler.java
index c24f5432f14..98b3ccdbd01 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/RedoHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/RedoHandler.java
@@ -16,7 +16,9 @@ package org.eclipse.papyrus.views.modelexplorer.handler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.ui.command.AbstractPapyrusHandler;
/**
* Handler for the Redo Action
@@ -24,7 +26,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
*
*
*/
-public class RedoHandler extends AbstractModelExplorerHandler {
+public class RedoHandler extends AbstractPapyrusHandler {
/**
@@ -36,7 +38,7 @@ public class RedoHandler extends AbstractModelExplorerHandler {
* @throws ExecutionException
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
- EditingDomain domain = getEditingDomain();
+ EditingDomain domain = getEditingDomain(event);
if (domain != null) {
domain.getCommandStack().redo();
}
@@ -50,8 +52,14 @@ public class RedoHandler extends AbstractModelExplorerHandler {
*/
@Override
public void setEnabled(Object evaluationContext) {
- EditingDomain domain = getEditingDomain();
- if (domain != null) {
+ EditingDomain domain;
+ if (evaluationContext instanceof IEvaluationContext) {
+ domain = getEditingDomain((IEvaluationContext) evaluationContext);
+ } else {
+ domain = getEditingDomain((IEvaluationContext) null);
+ }
+
+ if (null != domain) {
setBaseEnabled(domain.getCommandStack().canRedo());
} else {
setBaseEnabled(false);
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/UndoHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/UndoHandler.java
index 3eb26e137a7..725e31a0531 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/UndoHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/UndoHandler.java
@@ -16,7 +16,9 @@ package org.eclipse.papyrus.views.modelexplorer.handler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.ui.command.AbstractPapyrusHandler;
/**
* Handler for the Undo Action
@@ -24,7 +26,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
*
*
*/
-public class UndoHandler extends AbstractModelExplorerHandler {
+public class UndoHandler extends AbstractPapyrusHandler {
/**
*
@@ -35,7 +37,7 @@ public class UndoHandler extends AbstractModelExplorerHandler {
* @throws ExecutionException
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
- EditingDomain domain = getEditingDomain();
+ EditingDomain domain = getEditingDomain(event);
if (domain != null) {
domain.getCommandStack().undo();
}
@@ -49,8 +51,14 @@ public class UndoHandler extends AbstractModelExplorerHandler {
*/
@Override
public void setEnabled(Object evaluationContext) {
- EditingDomain domain = getEditingDomain();
- if (domain != null) {
+ EditingDomain domain;
+ if (evaluationContext instanceof IEvaluationContext) {
+ domain = getEditingDomain((IEvaluationContext) evaluationContext);
+ } else {
+ domain = getEditingDomain((IEvaluationContext) null);
+ }
+
+ if (null != domain) {
setBaseEnabled(domain.getCommandStack().canUndo());
} else {
setBaseEnabled(false);

Back to the top