Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2010-12-02 16:25:09 +0000
committeraradermache2010-12-02 16:25:09 +0000
commit2dbbdea0d0a834366dc9cc828bb88aed44e460be (patch)
treeb0a47922a912cd9a490ee899017dd182195fe31b
parentbbe0f215db288fb1c83e455d96d6861762768c7f (diff)
downloadorg.eclipse.papyrus-2dbbdea0d0a834366dc9cc828bb88aed44e460be.tar.gz
org.eclipse.papyrus-2dbbdea0d0a834366dc9cc828bb88aed44e460be.tar.xz
org.eclipse.papyrus-2dbbdea0d0a834366dc9cc828bb88aed44e460be.zip
Changed from ValidateAction to ValidateCommand
=> fix for bugs 331518 and 331519 +[Nicer validation icon]
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/deletemarkers.gifbin233 -> 0 bytes
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/validate.gifbin99 -> 104 bytes
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/plugin.xml194
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ValidateModelAction.java241
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/AbstractValidateCommand.java199
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromModelCommand.java43
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromSubtreeCommand.java43
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateModelCommand.java45
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateSubtreeCommand.java40
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java4
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromModelHandler.java33
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromSubtreeHandler.java33
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateModelHandler.java33
-rw-r--r--plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateSubtreeHandler.java33
14 files changed, 607 insertions, 334 deletions
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/deletemarkers.gif b/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/deletemarkers.gif
deleted file mode 100644
index f0c02348f1e..00000000000
--- a/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/deletemarkers.gif
+++ /dev/null
Binary files differ
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/validate.gif b/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/validate.gif
index 6efaebec95b..a7753cd9c01 100644
--- a/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/validate.gif
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/icons/etool16/validate.gif
Binary files differ
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/plugin.xml b/plugins/core/org.eclipse.papyrus.modelexplorer/plugin.xml
index da6ec02a981..29ffdfe8b00 100644
--- a/plugins/core/org.eclipse.papyrus.modelexplorer/plugin.xml
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/plugin.xml
@@ -145,49 +145,6 @@
label="Create Query">
</action>
</objectContribution>
- <objectContribution
- adaptable="true"
- id="org.eclipse.papyrus.papyrusgmfgenextension.popupactions"
- objectClass="org.eclipse.emf.ecore.EObject">
- <menu
- icon="icons/etool16/validate.gif"
- id="org.eclipse.papyrus.modelexplorer.popupaction.validation"
- label="Validation"
- path="papyrus">
- </menu>
- <action
- class="org.eclipse.papyrus.modelexplorer.actions.ValidateModelAction"
- enablesFor="*"
- icon="icons/etool16/validate.gif"
- id="org.eclipse.papyrus.modelexplorer.popupaction.ValidateModel"
- label="Validate model"
- menubarPath="org.eclipse.papyrus.modelexplorer.popupaction.validation/modelOps">
- </action>
- <action
- class="org.eclipse.papyrus.modelexplorer.actions.ValidateModelAction"
- enablesFor="*"
- icon="icons/etool16/deletemarkers.gif"
- id="org.eclipse.papyrus.modelexplorer.popupaction.DeleteMarkersModel"
- label="Remove markers from model"
- menubarPath="org.eclipse.papyrus.modelexplorer.popupaction.validation/modelOps">
- </action>
- <action
- class="org.eclipse.papyrus.modelexplorer.actions.ValidateModelAction"
- enablesFor="*"
- icon="icons/etool16/validate.gif"
- id="org.eclipse.papyrus.modelexplorer.popupaction.ValidateSubTree"
- label="Validate subtree"
- menubarPath="org.eclipse.papyrus.modelexplorer.popupaction.validation/subtreeOps">
- </action>
- <action
- class="org.eclipse.papyrus.modelexplorer.actions.ValidateModelAction"
- enablesFor="*"
- icon="icons/etool16/deletemarkers.gif"
- id="org.eclipse.papyrus.modelexplorer.popupaction.DeleteMarkersSubTree"
- label="Remove markers from subtree"
- menubarPath="org.eclipse.papyrus.modelexplorer.popupaction.validation/subtreeOps">
- </action>
- </objectContribution>
</extension>
<extension
point="org.eclipse.papyrus.modelexplorer.actionHandler">
@@ -202,7 +159,7 @@
<extension point="org.eclipse.ui.menus">
- <!-- ModelExplorer toolbar -->
+ <!-- ModelExplorer toolbar -->
<menuContribution locationURI="toolbar:org.eclipse.papyrus.modelexplorer.modelexplorer"
allPopups="false">
@@ -230,51 +187,83 @@
style="toggle">
</command>
</menuContribution>
-
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup">
+ <menu
+ id="org.eclipse.papyrus.modelexplorer.popupmenu.createchild"
+ label="New Child">
+ </menu>
+ <menu
+ id="org.eclipse.papyrus.modelexplorer.popupmenu.creatediagram"
+ label="New Diagram">
+ </menu>
+ <command
+ commandId="org.eclipse.ui.edit.delete"
+ disabledIcon="IMG_TOOL_DELETE_DISABLED"
+ icon="IMG_TOOL_DELETE"
+ label="Delete"
+ style="push"
+ tooltip="Delete">
+ <visibleWhen
+ checkEnabled="true">
+ <and>
+ <with
+ variable="selection">
+ <iterate>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </iterate>
+ </with>
+ </and>
+ </visibleWhen>
+ </command>
+ <menu
+ icon="icons/etool16/validate.gif"
+ id="org.eclipse.papyrus.modelexplorer.popup.validation"
+ label="Validation"
+ path="papyrus">
+ </menu>
+ </menuContribution>
<!-- ModelExplorer Contextual menu -->
- <menuContribution locationURI="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup"
- allPopups="false">
-
- <!-- Create child sub menu declaration -->
- <menu
- id="org.eclipse.papyrus.modelexplorer.popupmenu.createchild"
- label="New Child">
- </menu>
-
- <!-- Create diagram sub menu declaration -->
- <menu
- id="org.eclipse.papyrus.modelexplorer.popupmenu.creatediagram"
- label="New Diagram">
- </menu>
-
- <!-- Delete element command
-
- Note : ISharedImage constants are used to select the command icon.
- A warning may be shown (icon not found) while editing this
- plugin.xml file, but should be ignored (the platform supports
- this notation and should be able to retrieve the icon).
- -->
- <command
- commandId="org.eclipse.ui.edit.delete"
- disabledIcon="IMG_TOOL_DELETE_DISABLED"
- icon="IMG_TOOL_DELETE"
- label="Delete"
- style="push"
- tooltip="Delete">
- <visibleWhen
- checkEnabled="true">
- <and>
- <with
- variable="selection">
- <iterate>
- <adapt
- type="org.eclipse.emf.ecore.EObject">
- </adapt>
- </iterate>
- </with>
- </and>
- </visibleWhen>
- </command>
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.papyrus.modelexplorer.popup.validation">
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.ValidateModelCommand"
+ icon="icons/etool16/validate.gif"
+ id="org.eclipse.papyrus.modelexplorer.ValidateModel"
+ label="Validate model"
+ tooltip="Validate model">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ commandId="org.eclipse.papyrus.modelexplorer.ValidateSubtreeCommand"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.ValidateModelHandler"
+ description="Validate Model"
+ icon="icons/etool16/validate.gif"
+ id="org.eclipse.papyrus.modelexplorer.ValidateSubtree"
+ label="Validate subtree"
+ name="Validate Model"
+ tooltip="Validate subtree">
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.ValidateDelMarkersFromModelCommand"
+ disabledIcon="IMG_TOOL_DELETE_DISABLED"
+ icon="IMG_TOOL_DELETE"
+ id="org.eclipse.papyrus.modelexplorer.DeleteMarkersFromModel"
+ label="Remove markers from model"
+ tooltip="Validate model">
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.ValidateDelMarkersFromSubtreeCommand"
+ disabledIcon="IMG_TOOL_DELETE_DISABLED"
+ icon="IMG_TOOL_DELETE"
+ id="org.eclipse.papyrus.modelexplorer.DelMarkersFromSubtree"
+ label="Remove markers from subtree"
+ tooltip="Validate model">
+ </command>
<!-- <visibleWhen checkEnabled="true"/> -->
</menuContribution>
@@ -310,7 +299,34 @@
categoryId="org.eclipse.papyrus.editor.category"
defaultHandler="org.eclipse.papyrus.modelexplorer.handler.DeleteCommandHandler">
</command>
-
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.ValidateModelHandler"
+ description="ValidateModel"
+ id="org.eclipse.papyrus.modelexplorer.ValidateModelCommand"
+ name="ValidateModel">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.ValidateSubtreeHandler"
+ description="ValidateSubtree"
+ id="org.eclipse.papyrus.modelexplorer.ValidateSubtreeCommand"
+ name="ValidateSubtree">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.ValidateDelMarkersFromModelHandler"
+ description="ValidateDelMarkersFromModel"
+ id="org.eclipse.papyrus.modelexplorer.ValidateDelMarkersFromModelCommand"
+ name="ValidateDelMarkersFromModel">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.ValidateDelMarkersFromSubtreeHandler"
+ description="ValidateDelMarkersFromSubtree"
+ id="org.eclipse.papyrus.modelexplorer.ValidateDelMarkersFromSubtreeCommand"
+ name="ValidateDelMarkersFromSubtree">
+ </command>
</extension>
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ValidateModelAction.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ValidateModelAction.java
deleted file mode 100644
index fa80b385439..00000000000
--- a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ValidateModelAction.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.modelexplorer.actions;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.ecore.ENamedElement;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EValidator;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.ui.action.ValidateAction;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.modelexplorer.validation.ValidationTool;
-import org.eclipse.ui.IActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Action used for pasting either a model element or a shape (i.e. the model element represented
- * by the shape). Delegates to PasteShapeOrElementCommand
- *
- * @author Ansgar Radermacher (CEA LIST)
- */
-public class ValidateModelAction extends ValidateAction implements IActionDelegate
-{
- public ValidateModelAction () {
- super();
- // this.domain = domain;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isEnabled()
- {
- // updateSelectedEObject ();
- // EObject selectedObj = getSelectedEObject ();
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object execute(ExecutionEvent event) throws ExecutionException
- {
- // return super.execute (event);
- return null;
- }
-
- @Override
- protected void handleDiagnostic(Diagnostic diagnostic)
- {
- // Do not show a dialog, as in the original version since the user sees the result directly
- // in the model explorer
- Resource resource = getResource();
- if (resource != null) {
- if (selectedObjects.size () > 0) {
- EObject selectedObject = selectedObjects.get(0);
-
- ValidationTool vt = new ValidationTool(selectedObject);
- vt.deleteSubMarkers();
- }
-
- // IPath path = new Path(resource.getURI().toPlatformString (false));
- // IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
- // IFile file = wsRoot.getFile(path);
- // eclipseResourcesUtil.deleteMarkers (file);
-
- for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
- eclipseResourcesUtil.createMarkers(resource, childDiagnostic);
- // createMarkersOnDi (file, childDiagnostic);
- }
- }
- }
-
- private Resource getResource() {
- Resource resource = eclipseResourcesUtil != null ? domain.getResourceSet().getResources().get(0) : null;
- return resource;
- }
-
- /**
- * create resources on di instead of on UML file. Probably already obsolete, since we want to create the markers
- * on a UML resource.
- * @param resource
- * @param diagnostic
- */
- @Deprecated
- private void createMarkersOnDi (IFile file, Diagnostic diagnostic)
- {
- try {
- if (!diagnostic.getData().isEmpty()) {
- Object object = diagnostic.getData().get(0);
-
- if (object instanceof EObject) {
- if (file != null && file.exists()) {
- IMarker marker = file.createMarker(EValidator.MARKER);
- // TODO: define useful constant
- // marker.setAttribute(IDE.EDITOR_ID_ATTR, "org.eclipse.papyrus.core.papyrusEditor");
- int severity = diagnostic.getSeverity();
- if (severity < Diagnostic.WARNING) {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
- }
- else if (severity < Diagnostic.ERROR) {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- }
- else {
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
- }
- String message = diagnostic.getMessage ();
- marker.setAttribute(IMarker.MESSAGE, message);
- String uriOfMarkedObj = EcoreUtil.getURI((EObject) object).toString();
- // this URI is used by the UML model editor to jump to the right place
- marker.setAttribute(EValidator.URI_ATTRIBUTE, uriOfMarkedObj);
-
- String name;
- if (object instanceof ENamedElement) {
- name = ((ENamedElement) object).getName();
- }
- else if (object instanceof EObject) {
- name = EcoreUtil.getIdentification((EObject) object);
- }
- else {
- name = "unknown";
- }
- marker.setAttribute (IMarker.LOCATION, name);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void run(IAction action) {
- // TODO Auto-generated method stub
- String id = action.getId();
- if (selectedObjects.size () > 0) {
- EObject selectedObject = selectedObjects.get(0);
- domain = TransactionUtil.getEditingDomain(selectedObject);
- if (id.endsWith ("Model")) {
- // replace selection by model instead of current selection
- while (selectedObject.eContainer() != null) {
- selectedObject = selectedObject.eContainer ();
- }
- selectedObjects.set(0, selectedObject);
- }
- if (id.endsWith("ValidateSubTree") || id.endsWith("ValidateModel")) {
- run();
- }
- else if (id.endsWith ("DeleteMarkersSubTree")) {
- ValidationTool vt = new ValidationTool(selectedObject);
- vt.deleteSubMarkers();
- }
- else if (id.endsWith("DeleteMarkersModel")) {
- Resource resource = getResource();
- if ((resource != null) && (eclipseResourcesUtil != null)) {
- eclipseResourcesUtil.deleteMarkers(getResource());
- }
- }
- }
- }
-
- /**
- * Convert each selected elements from the explorer menu, or modeling view
- * to an EObject and add it to a list
- *
- * @return list of EObject
- */
- public void updateSelectedEObject()
- {
- Vector<EObject> currentSelectedEObjects = new Vector<EObject>();
-
- // Retrieve selected elements
- IStructuredSelection selection = (IStructuredSelection) PlatformUI
- .getWorkbench().getActiveWorkbenchWindow()
- .getSelectionService().getSelection();
- Iterator<?> eltIt = (Iterator<?>) selection.iterator();
-
- while (eltIt.hasNext()) {
- Object currentObject = eltIt.next();
-
- // If the object is an edit part, try to get semantic bridge
- if (currentObject instanceof GraphicalEditPart) {
- GraphicalEditPart editPart = (GraphicalEditPart) currentObject;
- if (editPart.getModel () instanceof View) {
- View view = (View) editPart.getModel ();
- if (view.getElement() instanceof EObject){
- currentObject = (EObject) view.getElement();
- }
- }
- }
-
- // check whether part of model explorer
- if (currentObject instanceof IAdaptable) {
- // modisco ModelElementItem supports IAdaptable (cleaner than cast / dependency with modisco)
- currentObject = ((IAdaptable) currentObject).getAdapter (EObject.class);
- }
-
- // If element is a UML Element
- if (currentObject instanceof EObject) {
- currentSelectedEObjects.add((EObject) currentObject);
- }
-
- }
- selectedObjects = currentSelectedEObjects;
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- // method from action-delegate
- updateSelectedEObject (); // required??
- }
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // TODO Auto-generated method stub
- }
-}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/AbstractValidateCommand.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/AbstractValidateCommand.java
new file mode 100644
index 00000000000..a18db6a40f5
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/AbstractValidateCommand.java
@@ -0,0 +1,199 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
+import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.papyrus.modelexplorer.validation.ValidationTool;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element represented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+abstract public class AbstractValidateCommand extends AbstractTransactionalCommand {
+
+ protected EclipseResourcesUtil eclipseResourcesUtil =
+ EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE ? new EclipseResourcesUtil() : null;
+
+ protected TransactionalEditingDomain domain;
+ protected EObject selectedElement;
+
+ /**
+ * Creates a new ImportLibraryFromRepositoryCommand
+ *
+ * @param editingDomain
+ * editing domain that manages the changed objects
+ * @param runnable
+ * process that executes the modifications
+ * @param label
+ * the label of the command
+ * @param description
+ * description of the command
+ */
+
+ public AbstractValidateCommand(String label, TransactionalEditingDomain domain, EObject selectedElement) {
+ super (domain, label, Collections.EMPTY_LIST);
+ this.domain = domain;
+ this.selectedElement = selectedElement;
+ }
+
+ protected void handleDiagnostic(Diagnostic diagnostic)
+ {
+ // Do not show a dialog, as in the original version since the user sees the result directly
+ // in the model explorer
+ Resource resource = getResource();
+ if (resource != null) {
+ if (selectedElement != null) {
+ ValidationTool vt = new ValidationTool(selectedElement);
+ vt.deleteSubMarkers();
+ }
+
+ // IPath path = new Path(resource.getURI().toPlatformString (false));
+ // IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ // IFile file = wsRoot.getFile(path);
+ // eclipseResourcesUtil.deleteMarkers (file);
+
+ for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
+ eclipseResourcesUtil.createMarkers(resource, childDiagnostic);
+ // createMarkersOnDi (file, childDiagnostic);
+ }
+ }
+ }
+
+ protected Resource getResource() {
+ Resource resource = eclipseResourcesUtil != null ? domain.getResourceSet().getResources().get(0) : null;
+ return resource;
+ }
+
+ protected void runValidation (final EObject validateElement) {
+ final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress()
+ {
+ public void run(final IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException
+ {
+ try {
+ final Diagnostic diagnostic = validate(progressMonitor, validateElement);
+ shell.getDisplay().asyncExec (new Runnable() {
+ public void run()
+ {
+ if (progressMonitor.isCanceled()) {
+ handleDiagnostic(Diagnostic.CANCEL_INSTANCE);
+ }
+ else {
+ handleDiagnostic(diagnostic);
+ }
+ }
+ });
+ }
+ finally {
+ progressMonitor.done();
+ }
+ }
+ };
+
+ if (eclipseResourcesUtil != null) {
+ runnableWithProgress = eclipseResourcesUtil.getWorkspaceModifyOperation(runnableWithProgress);
+ }
+
+ try {
+ // This runs the operation, and shows progress.
+ // (It appears to be a bad thing to fork this onto another thread.)
+ new ProgressMonitorDialog(shell).run(true, true, runnableWithProgress);
+ }
+ catch (Exception exception) {
+ EMFEditUIPlugin.INSTANCE.log(exception);
+ }
+ }
+
+ /**
+ * This simply execute the command.
+ */
+ protected Diagnostic validate(IProgressMonitor progressMonitor, EObject validateElement)
+ {
+ int count = 0;
+ for (Iterator<?> i = validateElement.eAllContents(); i.hasNext(); i.next()) {
+ ++count;
+ }
+
+ progressMonitor.beginTask("", count);
+
+ AdapterFactory adapterFactory =
+ domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
+ Diagnostician diagnostician = createDiagnostician(adapterFactory, progressMonitor);
+
+ BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(validateElement);
+ Map<Object, Object> context = diagnostician.createDefaultContext();
+
+ progressMonitor.setTaskName(EMFEditUIPlugin.INSTANCE.getString("_UI_Validating_message", new Object [] {diagnostician.getObjectLabel(validateElement)}));
+ diagnostician.validate(validateElement, diagnostic, context);
+
+ return diagnostic;
+ }
+
+ protected Diagnostician createDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor)
+ {
+ return new Diagnostician() {
+ @Override
+ public String getObjectLabel(EObject eObject) {
+ if (adapterFactory != null && !eObject.eIsProxy())
+ {
+ IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
+ if (itemLabelProvider != null) {
+ return itemLabelProvider.getText(eObject);
+ }
+ }
+ return super.getObjectLabel(eObject);
+ }
+
+ @Override
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ progressMonitor.worked(1);
+ return super.validate(eClass, eObject, diagnostics, context);
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute() {
+ return (selectedElement != null);
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromModelCommand.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromModelCommand.java
new file mode 100644
index 00000000000..5991af1fcef
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromModelCommand.java
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+
+
+public class ValidateDelMarkersFromModelCommand extends AbstractValidateCommand {
+
+ public ValidateDelMarkersFromModelCommand (EObject selectedElement) {
+ super ("Delete markers from model", TransactionUtil.getEditingDomain (selectedElement), selectedElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Resource resource = getResource();
+ if ((resource != null) && (eclipseResourcesUtil != null)) {
+ eclipseResourcesUtil.deleteMarkers(getResource());
+ }
+ return null;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromSubtreeCommand.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromSubtreeCommand.java
new file mode 100644
index 00000000000..4b4146a1214
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateDelMarkersFromSubtreeCommand.java
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.modelexplorer.validation.ValidationTool;
+
+
+public class ValidateDelMarkersFromSubtreeCommand extends AbstractValidateCommand {
+
+ public ValidateDelMarkersFromSubtreeCommand (EObject selectedElement) {
+ super ("Delete markers from subtree", TransactionUtil.getEditingDomain (selectedElement), selectedElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ ValidationTool vt = new ValidationTool(selectedElement);
+ vt.deleteSubMarkers();
+
+ return null;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateModelCommand.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateModelCommand.java
new file mode 100644
index 00000000000..c1b9620cc04
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateModelCommand.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+
+
+public class ValidateModelCommand extends AbstractValidateCommand {
+
+ public ValidateModelCommand (EObject selectedElement) {
+ super ("Validate model", TransactionUtil.getEditingDomain (selectedElement), selectedElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ EObject selectedObject = selectedElement;
+ // replace selection by model instead of current selection
+ while (selectedObject.eContainer() != null) {
+ selectedObject = selectedObject.eContainer ();
+ }
+ runValidation (selectedObject);
+
+ return null;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateSubtreeCommand.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateSubtreeCommand.java
new file mode 100644
index 00000000000..c7bc33398b4
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/ValidateSubtreeCommand.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+
+
+public class ValidateSubtreeCommand extends AbstractValidateCommand {
+
+ public ValidateSubtreeCommand (EObject selectedElement) {
+ super ("Validate subtree", TransactionUtil.getEditingDomain (selectedElement), selectedElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ runValidation (selectedElement);
+ return null;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java
index dd2c97cbd48..a4e19467177 100644
--- a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java
@@ -17,8 +17,6 @@ package org.eclipse.papyrus.modelexplorer.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.gmt.modisco.infra.browser.uicore.CustomizationManager;
import org.eclipse.jface.viewers.TreeViewer;
@@ -31,9 +29,7 @@ import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.CommonViewerSorter;
-import org.eclipse.ui.navigator.INavigatorContentService;
/**
* this handler is used to set a sorter on the model explorer
*
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromModelHandler.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromModelHandler.java
new file mode 100644
index 00000000000..e685c344ea1
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromModelHandler.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrus.modelexplorer.commands.ValidateDelMarkersFromModelCommand;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element represented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class ValidateDelMarkersFromModelHandler extends AbstractCommandHandler
+{
+ @Override
+ protected Command getCommand() {
+ // not useful to cache command, since selected element may change
+ return new GMFtoEMFCommandWrapper(new ValidateDelMarkersFromModelCommand(getSelectedElement()));
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromSubtreeHandler.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromSubtreeHandler.java
new file mode 100644
index 00000000000..61f94bd0072
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateDelMarkersFromSubtreeHandler.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrus.modelexplorer.commands.ValidateDelMarkersFromSubtreeCommand;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element represented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class ValidateDelMarkersFromSubtreeHandler extends AbstractCommandHandler
+{
+ @Override
+ protected Command getCommand() {
+ // not useful to cache command, since selected element may change
+ return new GMFtoEMFCommandWrapper(new ValidateDelMarkersFromSubtreeCommand(getSelectedElement()));
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateModelHandler.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateModelHandler.java
new file mode 100644
index 00000000000..ec6e7f61186
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateModelHandler.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrus.modelexplorer.commands.ValidateModelCommand;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element represented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class ValidateModelHandler extends AbstractCommandHandler
+{
+ @Override
+ protected Command getCommand() {
+ // not useful to cache command, since selected element may change
+ return new GMFtoEMFCommandWrapper(new ValidateModelCommand(getSelectedElement()));
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateSubtreeHandler.java b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateSubtreeHandler.java
new file mode 100644
index 00000000000..4097ccc4fef
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/ValidateSubtreeHandler.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrus.modelexplorer.commands.ValidateSubtreeCommand;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element represented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class ValidateSubtreeHandler extends AbstractCommandHandler
+{
+ @Override
+ protected Command getCommand() {
+ // not useful to cache command, since selected element may change
+ return new GMFtoEMFCommandWrapper(new ValidateSubtreeCommand(getSelectedElement()));
+ }
+}

Back to the top