Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2010-10-29 12:30:46 +0000
committeraradermache2010-10-29 12:30:46 +0000
commit82b01e0cf135982485628ba30ef7b1e42d7e02f5 (patch)
treeff3f1e4eeda48a77748b0f9a85008eefced0a373
parent176bc2676a829fb27d5c01794d4c8dc6cc7bd9fd (diff)
downloadorg.eclipse.papyrus-82b01e0cf135982485628ba30ef7b1e42d7e02f5.tar.gz
org.eclipse.papyrus-82b01e0cf135982485628ba30ef7b1e42d7e02f5.tar.xz
org.eclipse.papyrus-82b01e0cf135982485628ba30ef7b1e42d7e02f5.zip
Added tailored version of ValidationDecoratorProvider that provides checks for EMF problems in addition to GMF problems
-rw-r--r--plugins/developer/org.eclipse.papyrus.def/dynamic-templates3.5/codegen/xpt/providers/ValidationDecoratorProvider.xpt458
1 files changed, 458 insertions, 0 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.def/dynamic-templates3.5/codegen/xpt/providers/ValidationDecoratorProvider.xpt b/plugins/developer/org.eclipse.papyrus.def/dynamic-templates3.5/codegen/xpt/providers/ValidationDecoratorProvider.xpt
new file mode 100644
index 00000000000..596d54b0dd9
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.def/dynamic-templates3.5/codegen/xpt/providers/ValidationDecoratorProvider.xpt
@@ -0,0 +1,458 @@
+/*
+ * Copyright (c) 2007, 2009 Borland Software Corporation
+ *
+ * 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:
+ * Dmitry Stadnik (Borland) - initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
+
+«DEFINE ValidationDecoratorProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «validationDecoratorProviderClassName»
+ extends org.eclipse.gmf.runtime.common.core.service.AbstractProvider
+ implements org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static final String KEY = "validationStatus"; «EXPAND xpt::Common::nonNLS»
+ «IF editorGen.application = null-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static final String MARKER_TYPE = «editorGen.plugin.getActivatorQualifiedClassName()».ID +
+ ".«getValidationDiagnosticMarkerType()»"; «EXPAND xpt::Common::nonNLS»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static MarkerObserver fileObserver;
+ «ENDIF-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static java.util.Map/*<String, List<IDecorator>>*/ allDecorators = new java.util.HashMap();
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) decoratorTarget.getAdapter(org.eclipse.gef.EditPart.class);
+ if (editPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart ||
+ editPart instanceof org.eclipse.gef.editparts.AbstractConnectionEditPart) {
+ Object model = editPart.getModel();
+ if ((model instanceof org.eclipse.gmf.runtime.notation.View)) {
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) model;
+ if (!(view instanceof org.eclipse.gmf.runtime.notation.Edge) && !view.isSetElement()) {
+ return;
+ }
+ }
+ org.eclipse.gef.EditDomain ed = editPart.getViewer().getEditDomain();
+ if (!(ed instanceof org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain)) {
+ return;
+ }
+ if (((org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain) ed).getEditorPart() instanceof
+ «editorGen.editor.getQualifiedClassName()») {
+ decoratorTarget.installDecorator(KEY, new StatusDecorator(decoratorTarget));
+ }
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (!(operation instanceof org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation)) {
+ return false;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget =
+ ((org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation) operation).getDecoratorTarget();
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) decoratorTarget.getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ return view != null && «EXPAND xpt::editor::VisualIDRegistry::modelID».equals(«EXPAND xpt::editor::VisualIDRegistry::getModelIDMethodCall»(view));
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static void refreshDecorators(org.eclipse.gmf.runtime.notation.View view) {
+ refreshDecorators(org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view), view.getDiagram());
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static void refreshDecorators(String viewId, org.eclipse.gmf.runtime.notation.Diagram diagram) {
+ final java.util.List decorators = viewId != null ? (java.util.List) allDecorators.get(viewId) : null;
+ if (decorators == null || decorators.isEmpty() || diagram == null) {
+ return;
+ }
+ final org.eclipse.gmf.runtime.notation.Diagram fdiagram = diagram;
+ org.eclipse.ui.PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ try {
+ org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(fdiagram).runExclusive(new Runnable() {
+
+ public void run() {
+ for (java.util.Iterator it = decorators.iterator(); it.hasNext();) {
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator decorator =
+ (org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator) it.next();
+ decorator.refresh();
+ }
+ }
+ });
+ } catch (Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Decorator refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ }
+ });
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ /**
+ * Return the EObject retrieved from the URI attribute in the map. Retrieve it either via the marker itself
+ * or via the attribute mapping (required in case a deleted marker)
+ * @param marker the problem marker
+ * @param attributes a map of the problem marker
+ * @param domain the editing domain used for the conversion from URI to eObecjt
+ * @return
+ */
+ private static org.eclipse.emf.ecore.EObject getEObjectFromMarkerOrMap (org.eclipse.core.resources.IMarker marker, java.util.Map attributes, org.eclipse.emf.edit.domain.EditingDomain domain) {
+ String uriAttribute;
+ if (marker != null) {
+ uriAttribute = marker.getAttribute(org.eclipse.emf.ecore.EValidator.URI_ATTRIBUTE, null);
+ }
+ else {
+ uriAttribute = (String) attributes.get(org.eclipse.emf.ecore.EValidator.URI_ATTRIBUTE);
+ }
+ if(uriAttribute != null) {
+ // get EObject from marker via resourceSet of domain
+ return domain.getResourceSet().getEObject(org.eclipse.emf.common.util.URI.createURI(uriAttribute), true);
+ }
+ return null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class StatusDecorator extends org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String viewId;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public StatusDecorator(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ super(decoratorTarget);
+ try {
+ final org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() {
+
+ public void run() {
+ StatusDecorator.this.viewId = view != null ?
+ org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view) : null;
+ }
+ });
+ } catch (Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "ViewID access failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void refresh() {
+ removeDecoration();
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ if (view == null || view.eResource() == null) {
+ return;
+ }
+ org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) getDecoratorTarget().getAdapter(org.eclipse.gef.EditPart.class);
+ if (editPart == null || editPart.getViewer() == null) {
+ return;
+ }
+
+ // query for all the validation markers of the current resource
+ «IF editorGen.application = null-»
+ String elementId = org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view);
+ if (elementId == null) {
+ return;
+ }
+ int severity = org.eclipse.core.resources.IMarker.SEVERITY_INFO;
+ org.eclipse.core.resources.IMarker foundMarker = null;
+ org.eclipse.core.resources.IResource gmfResource = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(view.eResource());
+ if (gmfResource == null || !gmfResource.exists()) {
+ return;
+ }
+ org.eclipse.core.resources.IResource emfResource = null;
+ if (view.getElement() != null) {
+ emfResource = WorkspaceSynchronizer.getFile(view.getElement().eResource());
+ // allow emfResource being empty, since there might be gmf views without an EObject behind;
+ }
+
+ org.eclipse.core.resources.IMarker[] gmfMarkers = null;
+ org.eclipse.core.resources.IMarker[] emfMarkers = new org.eclipse.core.resources.IMarker [0];
+ try {
+ gmfMarkers = gmfResource.findMarkers(MARKER_TYPE, true, org.eclipse.core.resources.IResource.DEPTH_INFINITE);
+ if (emfResource != null) {
+ emfMarkers = emfResource.findMarkers(org.eclipse.core.resources.IMarker.PROBLEM, true, org.eclipse.core.resources.IResource.DEPTH_INFINITE);
+ }
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Validation markers refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ «ELSE-»
+ int severity = org.eclipse.core.runtime.IStatus.INFO;
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName» foundMarker = null;
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName»[] gmfMarkers =
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName».getMarkers(editPart.getViewer(), viewId);
+ «ENDIF-»
+ if(gmfMarkers == null) {
+ // indicates an exception, findMarkers returns an empty array, if there are no markers
+ return;
+ }
+ org.eclipse.draw2d.Label toolTip = null;
+ // look for GMF markers
+ for(int i = 0; i < gmfMarkers.length+emfMarkers.length; i++) {
+ «IF editorGen.application = null-»
+ org.eclipse.core.resources.IMarker marker;
+ boolean markerIsForMe = false;
+ if (i < gmfMarkers.length) {
+ // get marker from GMF list
+ marker = gmfMarkers[i];
+ String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); «EXPAND xpt::Common::nonNLS»
+ markerIsForMe = attribute.equals(elementId);
+ }
+ else {
+ // get marker from EMF list
+ marker = emfMarkers[i-gmfMarkers.length];
+ org.eclipse.emf.ecore.EObject eObjectOfMarker = getEObjectFromMarkerOrMap(marker, null, TransactionUtil.getEditingDomain(view));
+ markerIsForMe = (eObjectOfMarker == view.getElement());
+ }
+ if (markerIsForMe) {
+ int nextSeverity = marker.getAttribute(org.eclipse.core.resources.IMarker.SEVERITY,
+ org.eclipse.core.resources.IMarker.SEVERITY_INFO);
+ «ELSE-»
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName» marker = gmfMarkers[i];
+ int nextSeverity = marker.getStatusSeverity();
+ «ENDIF-»
+ org.eclipse.swt.graphics.Image nextImage = getImage(nextSeverity);
+ if (foundMarker == null) {
+ foundMarker = marker;
+ toolTip = new org.eclipse.draw2d.Label(
+ «IF editorGen.application = null-»
+ marker.getAttribute(org.eclipse.core.resources.IMarker.MESSAGE, ""), «EXPAND xpt::Common::nonNLS»
+ «ELSE-»
+ marker.getMessage(),
+ «ENDIF-»
+ nextImage);
+ } else {
+ if (toolTip.getChildren().isEmpty()) {
+ org.eclipse.draw2d.Label comositeLabel = new org.eclipse.draw2d.Label();
+ org.eclipse.draw2d.FlowLayout fl = new org.eclipse.draw2d.FlowLayout(false);
+ fl.setMinorSpacing(0);
+ comositeLabel.setLayoutManager(fl);
+ comositeLabel.add(toolTip);
+ toolTip = comositeLabel;
+ }
+ toolTip.add(new org.eclipse.draw2d.Label(
+ «IF editorGen.application = null-»
+ marker.getAttribute(org.eclipse.core.resources.IMarker.MESSAGE, ""), «EXPAND xpt::Common::nonNLS»
+ «ELSE-»
+ marker.getMessage(),
+ «ENDIF-»
+ nextImage));
+ }
+ severity = (nextSeverity > severity) ? nextSeverity : severity;
+ «IF editorGen.application = null-»
+ }
+ «ENDIF-»
+ }
+ if (foundMarker == null) {
+ return;
+ }
+
+ // add decoration
+ if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
+ if (view instanceof org.eclipse.gmf.runtime.notation.Edge) {
+ setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true));
+ } else {
+ int margin = -1;
+ if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
+ margin = org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil.getMapMode(
+ ((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()).DPtoLP(margin);
+ }
+ setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity),
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Direction.NORTH_EAST, margin, true));
+ }
+ getDecoration().setToolTip(toolTip);
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.swt.graphics.Image getImage(int severity) {
+ String imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ switch (severity) {
+ «IF editorGen.application = null-»
+ case org.eclipse.core.resources.IMarker.SEVERITY_ERROR:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ break;
+ case org.eclipse.core.resources.IMarker.SEVERITY_WARNING:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_WARN_TSK;
+ break;
+ «ELSE-»
+ case org.eclipse.core.runtime.IStatus.ERROR:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ break;
+ case org.eclipse.core.runtime.IStatus.WARNING:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_WARN_TSK;
+ break;
+ «ENDIF-»
+ default:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_INFO_TSK;
+ }
+ return org.eclipse.ui.PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void activate() {
+ if (viewId == null) {
+ return;
+ }
+
+ // add self to global decorators registry
+ java.util.List list = (java.util.List) allDecorators.get(viewId);
+ if (list == null) {
+ list = new java.util.ArrayList(2);
+ list.add(this);
+ allDecorators.put(viewId, list);
+ } else if (!list.contains(this)) {
+ list.add(this);
+ }
+ «IF editorGen.application = null-»
+
+ // start listening to changes in resources
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ if (view == null) {
+ return;
+ }
+ org.eclipse.gmf.runtime.notation.Diagram diagramView = view.getDiagram();
+ if (diagramView == null) {
+ return;
+ }
+ if (fileObserver == null) {
+ org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager.getInstance().addFileObserver(
+ fileObserver = new MarkerObserver(diagramView));
+ }
+ «ENDIF-»
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void deactivate() {
+ if (viewId == null) {
+ return;
+ }
+
+ // remove self from global decorators registry
+ java.util.List list = (java.util.List) allDecorators.get(viewId);
+ if (list != null) {
+ list.remove(this);
+ if (list.isEmpty()) {
+ allDecorators.remove(viewId);
+ }
+ }
+ «IF editorGen.application = null-»
+
+ // stop listening to changes in resources if there are no more decorators
+ if (fileObserver != null && allDecorators.isEmpty()) {
+ org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager.getInstance().removeFileObserver(fileObserver);
+ fileObserver = null;
+ }
+ «ENDIF-»
+ super.deactivate();
+ }
+ }
+ «IF editorGen.application = null-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ static class MarkerObserver implements org.eclipse.gmf.runtime.common.ui.resources.IFileObserver {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.gmf.runtime.notation.Diagram diagram;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private MarkerObserver(org.eclipse.gmf.runtime.notation.Diagram diagram) {
+ this.diagram = diagram;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileRenamed(org.eclipse.core.resources.IFile oldFile, org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileMoved(org.eclipse.core.resources.IFile oldFile, org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileDeleted(org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileChanged(org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerAdded(org.eclipse.core.resources.IMarker marker) {
+ handleMarkerChanged(marker);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerDeleted(org.eclipse.core.resources.IMarker marker, java.util.Map attributes) {
+ String viewId = (String)attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID);
+ if(viewId != null) {
+ refreshDecorators(viewId, diagram);
+ }
+ else /* if (getType(marker).equals(IMarker.PROBLEM)) */ {
+ // no viewID => assume EMF validation marker
+ org.eclipse.emf.ecore.EObject eObjectFromMarker = getEObjectFromMarkerOrMap (null, attributes, TransactionUtil.getEditingDomain(diagram));
+
+ if (eObjectFromMarker != null) {
+ // loop over all views that reference the eObject from the marker
+ for (org.eclipse.gmf.runtime.notation.View view : org.eclipse.papyrus.core.utils.CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) {
+ refreshDecorators(view);
+ }
+ }
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerChanged(org.eclipse.core.resources.IMarker marker) {
+ if(getType(marker).equals(MARKER_TYPE)) {
+ String viewId = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$
+ refreshDecorators(viewId, diagram);
+ }
+ else /* if (getType(marker).equals(IMarker.PROBLEM)) */ {
+ org.eclipse.emf.ecore.EObject eObjectFromMarker = getEObjectFromMarkerOrMap (marker, null, TransactionUtil.getEditingDomain(diagram));
+
+ if (eObjectFromMarker != null) {
+ // loop over all views that reference the eObject from the marker
+ for (org.eclipse.gmf.runtime.notation.View view : org.eclipse.papyrus.core.utils.CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) {
+ refreshDecorators(view);
+ }
+ }
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String getType(org.eclipse.core.resources.IMarker marker) {
+ try {
+ return marker.getType();
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Validation marker refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ return ""; «EXPAND xpt::Common::nonNLS»
+ }
+ }
+ }
+ «ENDIF-»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»

Back to the top