Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbblajer2007-02-02 17:14:34 +0000
committerbblajer2007-02-02 17:14:34 +0000
commita59068bf7ff3370061e6dc803638845d6d330a8c (patch)
treedd44329eb46b0bf25472aff6c58a1ef9eba91745 /plugins/org.eclipse.gmf.runtime.lite/src/org
parentbbd9e1bfd5c93ab4b00f227f5e8f20bcc3bd4a98 (diff)
downloadorg.eclipse.gmf-tooling-a59068bf7ff3370061e6dc803638845d6d330a8c.tar.gz
org.eclipse.gmf-tooling-a59068bf7ff3370061e6dc803638845d6d330a8c.tar.xz
org.eclipse.gmf-tooling-a59068bf7ff3370061e6dc803638845d6d330a8c.zip
Several templates are rewritten with xpand;
lite-specific TextEmitter is back (otherwise importManager is sometimes passed to xpand templates)
Diffstat (limited to 'plugins/org.eclipse.gmf.runtime.lite/src/org')
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/AbstractDecorationManager.java63
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/ConnectionDecorationManager.java80
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecoratableEditPart.java22
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecorationManager.java30
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/PaneDecorationManager.java83
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateListener.java28
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateUpdater.java35
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/Severity.java59
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationDecorationProvider.java104
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationState.java122
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateEvent.java64
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateManager.java73
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ViolationDescriptor.java140
13 files changed, 903 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/AbstractDecorationManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/AbstractDecorationManager.java
new file mode 100644
index 000000000..06cfcf3c3
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/AbstractDecorationManager.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.edit.parts.decorations;
+
+import java.util.HashMap;
+
+import org.eclipse.draw2d.IFigure;
+
+/**
+ * @author bblajer
+ */
+public abstract class AbstractDecorationManager implements IDecorationManager {
+ private final IFigure myDecorationParent;
+ private HashMap<String, IFigure> myDecorations;
+
+ public AbstractDecorationManager(IFigure decorationParent) {
+ myDecorationParent = decorationParent;
+ }
+
+ public void installDecoration(String key, IFigure decoration) {
+ IFigure currentDecoration = getDecoration(key);
+ if (currentDecoration != null) {
+ myDecorations.remove(key);
+ myDecorationParent.remove(currentDecoration);
+ }
+ if (decoration != null) {
+ putDecoration(key, decoration);
+ myDecorationParent.add(decoration, getConstraint(key, decoration));
+ }
+ }
+
+ public IFigure getDecoration(String key) {
+ return myDecorations == null ? null : myDecorations.get(key);
+ }
+
+ private void putDecoration(String key, IFigure decoration) {
+ if (myDecorations == null) {
+ myDecorations = new HashMap<String, IFigure>();
+ }
+ myDecorations.put(key, decoration);
+ }
+
+ protected IFigure getDecorationParent() {
+ return myDecorationParent;
+ }
+
+ /**
+ * Returns the constraint with which the decoration will be added to the parent figure.
+ * @param key
+ * @param decoration
+ * @return
+ */
+ protected abstract Object getConstraint(String key, IFigure decoration);
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/ConnectionDecorationManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/ConnectionDecorationManager.java
new file mode 100644
index 000000000..8ee97e856
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/ConnectionDecorationManager.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.edit.parts.decorations;
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Locator;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Decoration manager that places decorations over the given connection figure.
+ * The actual position of the decoration
+ * is controlled by the {@link #getDecorationPosition(String)} method.
+ * @author bblajer
+ */
+public class ConnectionDecorationManager extends AbstractDecorationManager {
+ public ConnectionDecorationManager(Connection decorationParent) {
+ super(decorationParent);
+ }
+
+ @Override
+ protected Object getConstraint(String key, IFigure decoration) {
+ return new DecorationLocator(getDecorationPosition(key));
+ }
+
+ /**
+ * Returns the {@link PositionConstants position} where the decorator with the given key
+ * should appear. By default, all decorators are positioned in the center of the connection
+ * Subclasses may reimplement.
+ * @param key the key which is used to install the decorator
+ */
+ protected DecorationPosition getDecorationPosition(String key) {
+ return DecorationPosition.CENTER;
+ }
+
+ public static enum DecorationPosition {
+ SOURCE,
+ CENTER,
+ TARGET
+ }
+
+ private class DecorationLocator implements Locator {
+ private final DecorationPosition myPosition;
+ public DecorationLocator(DecorationPosition position) {
+ myPosition = position;
+ }
+ public void relocate(IFigure target) {
+ Dimension size = target.getPreferredSize();
+ Connection connection = (Connection) getDecorationParent();
+ Point pt;
+ switch (myPosition) {
+ case SOURCE:
+ pt = connection.getPoints().getFirstPoint();
+ break;
+ case CENTER:
+ pt = connection.getPoints().getMidpoint();
+ break;
+ case TARGET:
+ pt = connection.getPoints().getLastPoint();
+ break;
+ default:
+ pt = connection.getPoints().getMidpoint();
+ break;
+ }
+ target.setBounds(new Rectangle(pt, size));
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecoratableEditPart.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecoratableEditPart.java
new file mode 100644
index 000000000..81794c73e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecoratableEditPart.java
@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.edit.parts.decorations;
+
+import org.eclipse.gef.GraphicalEditPart;
+
+/**
+ * Edit part that know how to decorate itself externally.
+ * @author bblajer
+ */
+public interface IDecoratableEditPart extends GraphicalEditPart {
+ public IDecorationManager getDecorationManager();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecorationManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecorationManager.java
new file mode 100644
index 000000000..4706b4fe1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/IDecorationManager.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.edit.parts.decorations;
+
+import org.eclipse.draw2d.IFigure;
+
+/**
+ * An object that may be decorated externally. Decorations may be installed for arbitrary {@link String}
+ * keys. Installing a decoration automatically replaces any previous decoration for the same key.
+ * Installing a <code>null</code> decoration is the same as uninstalling the decoration for the given key.
+ * <p/>Clients should not implement this interface directly, {@link AbstractDecorationManager} class should be subclassed instead.
+ * @author bblajer
+ */
+public interface IDecorationManager {
+ /**
+ * Installs the decoration with the given key.
+ * @param key
+ * @param decoration
+ */
+ public void installDecoration(String key, IFigure decoration);
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/PaneDecorationManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/PaneDecorationManager.java
new file mode 100644
index 000000000..8c6bf80d4
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/decorations/PaneDecorationManager.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.edit.parts.decorations;
+
+import org.eclipse.draw2d.DelegatingLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Locator;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Decoration manager that places decorations as children of a given figure.
+ * The actual position of the decoration
+ * is controlled by the {@link #getDecorationPosition(String)} method.
+ * @author bblajer
+ */
+public class PaneDecorationManager extends AbstractDecorationManager {
+ public PaneDecorationManager(IFigure decorationParent) {
+ super(decorationParent);
+ decorationParent.setLayoutManager(new DelegatingLayout());
+ }
+
+ @Override
+ protected Object getConstraint(String key, IFigure decoration) {
+ return new DecorationLocator(getDecorationPosition(key));
+ }
+
+ /**
+ * Returns the {@link PositionConstants position} where the decorator with the given key
+ * should appear. By default, all decorators are positioned to the north-west of the parent figure.
+ * Subclasses may reimplement.
+ * @param key the key which is used to install the decorator
+ */
+ protected int getDecorationPosition(String key) {
+ return PositionConstants.NORTH_WEST;
+ }
+
+ private class DecorationLocator implements Locator {
+ private final int myPosition;
+ public DecorationLocator(int position) {
+ myPosition = position;
+ }
+ public void relocate(IFigure target) {
+ Rectangle bounds = getDecorationParent().getBounds().getCopy();
+ Dimension size = target.getPreferredSize();
+ Point pt = bounds.getTopLeft();
+ switch (myPosition & PositionConstants.EAST_WEST) {
+ case PositionConstants.WEST:
+ break;
+ case 0:
+ case PositionConstants.EAST_WEST:
+ pt.x += (bounds.width - size.width)/2;
+ break;
+ case PositionConstants.EAST:
+ pt.x += bounds.width - size.width;
+ break;
+ }
+ switch (myPosition & PositionConstants.NORTH_SOUTH) {
+ case PositionConstants.NORTH:
+ break;
+ case 0:
+ case PositionConstants.NORTH_SOUTH:
+ pt.y += (bounds.height - size.height)/2;
+ break;
+ case PositionConstants.SOUTH:
+ pt.y += bounds.height - size.height;
+ break;
+ }
+ target.setBounds(new Rectangle(pt, size));
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateListener.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateListener.java
new file mode 100644
index 000000000..5a03ba721
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateListener.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import java.util.EventListener;
+
+/**
+ * Listener that is notified when a validation state is changed.
+ * @see ValidationStateManager#addValidationStateListener(IValidationStateListener)
+ * @see ValidationStateManager#removeValidationStateListener(IValidationStateListener)
+ */
+public interface IValidationStateListener extends EventListener {
+ /**
+ * Notifies the listener about the change in the validation state.
+ * The event object is only valid for the duration of the invocation of this method.
+ * @param event
+ */
+ public void validationStateChanged(ValidationStateEvent event);
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateUpdater.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateUpdater.java
new file mode 100644
index 000000000..50f5dfd8e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/IValidationStateUpdater.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+/**
+ * Allows to update the violations for a given validation state (and thus for a given diagram).
+ * Violations may be updated using {@link #addViolation(ViolationDescriptor)} and {@link #removeViolation(ViolationDescriptor)} methods.
+ * <p/>After the violations are updated, {@link #commitChanges()} method should be used to commit the updated state
+ * and notify the listeners about the update. If changes are invalid for some reason, {@link #discardChanges()} method
+ * may be used to revert all the changes and invalidate the updater.
+ * @see ValidationState#startUpdate(boolean)
+ */
+public interface IValidationStateUpdater {
+ public void addViolation(ViolationDescriptor violation);
+
+ /**
+ * Completes the update and reports changes.
+ * After this method has been called, this instance must not be used.
+ */
+ public void commitChanges();
+ /**
+ * Reverts all the changes.
+ * After this method has been called, this instance must not be used.
+ */
+ public void discardChanges();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/Severity.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/Severity.java
new file mode 100644
index 000000000..e6a3f5b1f
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/Severity.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Represents the severity of a problem.
+ * @author bblajer
+ */
+public enum Severity {
+ INFO,
+ WARNING,
+ ERROR;
+
+ public Image getImage() {
+ String key = null;
+ switch (this) {
+ case INFO:
+ key = ISharedImages.IMG_OBJS_INFO_TSK;
+ break;
+ case WARNING:
+ key = ISharedImages.IMG_OBJS_WARN_TSK;
+ break;
+ case ERROR:
+ key = ISharedImages.IMG_OBJS_ERROR_TSK;
+ break;
+ }
+ return PlatformUI.getWorkbench().getSharedImages().getImage(key);
+ }
+
+ /**
+ * Converts the severity into one of severity constants defined in {@link IStatus}.
+ */
+ public int toStatusSeverity() {
+ switch (this) {
+ case INFO:
+ return IStatus.INFO;
+ case WARNING:
+ return IStatus.WARNING;
+ case ERROR:
+ return IStatus.ERROR;
+ default:
+ return IStatus.CANCEL;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationDecorationProvider.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationDecorationProvider.java
new file mode 100644
index 000000000..cfbe1f2a9
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationDecorationProvider.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright (c) 2007 Borland Software Corp.
+ *
+ * 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.ImageFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gmf.runtime.lite.edit.parts.decorations.IDecoratableEditPart;
+import org.eclipse.gmf.runtime.lite.edit.parts.decorations.IDecorationManager;
+
+/**
+ * @author bblajer
+ */
+public abstract class ValidationDecorationProvider implements IValidationStateListener {
+ public static final String VALIDATION_KEY = "validation"; //$NON-NLS-1$
+
+ public ValidationDecorationProvider() {
+ }
+
+ public void dispose() {
+ }
+
+ public void validationStateChanged(ValidationStateEvent event) {
+ EObject sourceDiagram = getResourceSet().getEObject(event.getSourceValidationState().getDiagramUri(), false);
+ if (sourceDiagram == null || !sourceDiagram.equals(getGraphicalViewer().getContents().getModel())) {
+ return;
+ }
+ for(URI uri : event.getViolationKeys()) {
+ EObject nextView = getResourceSet().getEObject(uri, false);
+ GraphicalEditPart editPart = (GraphicalEditPart) getGraphicalViewer().getEditPartRegistry().get(nextView);
+ if (editPart instanceof IDecoratableEditPart) {
+ IDecoratableEditPart decoratableEditPart = (IDecoratableEditPart) editPart;
+ IDecorationManager decorationManager = decoratableEditPart.getDecorationManager();
+ if (decorationManager != null) {
+ updateDecorations(decorationManager, event.getOldViolations(uri), event.getNewViolations(uri));
+ }
+ }
+ }
+ }
+
+ /**
+ * @param decorationManager
+ * @param newViolations
+ */
+ protected void updateDecorations(IDecorationManager decorationManager, Collection<ViolationDescriptor> oldViolations, Collection<ViolationDescriptor> newViolations) {
+ if (newViolations.isEmpty()) {
+ decorationManager.installDecoration(VALIDATION_KEY, null);
+ return;
+ }
+ List<String> messages = new ArrayList<String>(newViolations.size());
+ Severity highestSeverity = null;
+ for (ViolationDescriptor next : newViolations) {
+ Severity nextSeverity = next.getSeverity();
+ if (highestSeverity == null || highestSeverity.compareTo(nextSeverity) < 0) {
+ messages.clear();
+ highestSeverity = nextSeverity;
+ }
+ if (highestSeverity.equals(nextSeverity)) {
+ messages.add(next.getMessage());
+ }
+ }
+ IFigure decoration = new ImageFigure(highestSeverity.getImage());
+ String tooltip = formatLabel(messages);
+ if (tooltip != null) {
+ Label label = new Label(tooltip);
+ decoration.setToolTip(label);
+ }
+ decorationManager.installDecoration(VALIDATION_KEY, decoration);
+ }
+
+ protected String formatLabel(List<String> messages) {
+ assert !messages.isEmpty();
+ if (messages.size() == 1) {
+ return messages.get(0);
+ }
+ StringBuilder result = new StringBuilder();
+ result.append("Multiple problems:");
+ for(String next : messages) {
+ result.append("\n").append(next);
+ }
+ return result.toString();
+ }
+
+ protected abstract ResourceSet getResourceSet();
+ protected abstract GraphicalViewer getGraphicalViewer();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationState.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationState.java
new file mode 100644
index 000000000..8fa1a8faa
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationState.java
@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Represents a state of validation of a single diagram.
+ */
+public class ValidationState {
+ private final URI myDiagramUri;
+ private final ValidationStateManager myStateManager;
+ private HashMap<URI, Collection<ViolationDescriptor>> myViolations = new HashMap<URI, Collection<ViolationDescriptor>>();
+ private ValidationStateUpdater myUpdater;
+
+ public ValidationState(ValidationStateManager stateManager, URI diagramUri) {
+ myDiagramUri = diagramUri;
+ myStateManager = stateManager;
+ }
+
+ /**
+ * @return the diagramUri
+ */
+ public URI getDiagramUri() {
+ return myDiagramUri;
+ }
+
+ public Collection<ViolationDescriptor> getViolations(URI uri) {
+ return myViolations.get(uri);
+ }
+
+ public Collection<ViolationDescriptor> getAllViolations() {
+ Collection<ViolationDescriptor> result = new ArrayList<ViolationDescriptor>();
+ for (Collection<ViolationDescriptor> next : myViolations.values()) {
+ result.addAll(next);
+ }
+ return result;
+ }
+
+ /**
+ * Starts an update operation. The operation will typically create the violations based on
+ * the current state of the validation and report completion
+ * using {@link IValidationStateUpdater#commitChanges()} method.
+ * After the operation is completed successfully, the {@link IValidationStateListener listeners}
+ * registered to the {@link ValidationStateManager} will be notified about the change.
+ * It is expected that a single command may be active at any given time, and that a command will
+ * not be used after is has been reported as completed.
+ */
+ public IValidationStateUpdater startUpdate() {
+ if (myUpdater != null) {
+ throw new IllegalStateException();
+ }
+ myUpdater = new ValidationStateUpdater();
+ return myUpdater;
+ }
+
+ private class ValidationStateUpdater implements IValidationStateUpdater {
+ private HashMap<URI, Collection<ViolationDescriptor>> myUpdatedViolations;
+ public ValidationStateUpdater() {
+ myUpdatedViolations = new HashMap<URI, Collection<ViolationDescriptor>>();
+ }
+ public void addViolation(ViolationDescriptor violation) {
+ if (violation == null) {
+ return;
+ }
+ URI uri = violation.getUri();
+ Collection<ViolationDescriptor> descriptors = get(uri, true);
+ if (!descriptors.contains(violation)) {
+ descriptors.add(violation);
+ }
+ }
+ public void removeViolation(ViolationDescriptor violation) {
+ if (violation == null) {
+ return;
+ }
+ URI uri = violation.getUri();
+ Collection<ViolationDescriptor> descriptors = get(uri, false);
+ if (descriptors != null) {
+ descriptors.remove(violation);
+ }
+ }
+ private Collection<ViolationDescriptor> get(URI uri, boolean createIfMissing) {
+ Collection<ViolationDescriptor> result = myUpdatedViolations.get(uri);
+ if (result == null && createIfMissing) {
+ result = new ArrayList<ViolationDescriptor>();
+ myUpdatedViolations.put(uri, result);
+ }
+ return result;
+ }
+ public void commitChanges() {
+ if (myUpdater != this) {
+ throw new IllegalStateException();
+ }
+ try {
+ HashMap<URI, Collection<ViolationDescriptor>> oldViolations = myViolations;
+ myViolations = myUpdatedViolations;
+ myStateManager.fireValidationStateChanged(ValidationState.this, Collections.unmodifiableMap(oldViolations), Collections.unmodifiableMap(myUpdatedViolations));
+ } finally {
+ myUpdater = null;
+ }
+ }
+ public void discardChanges() {
+ if (myUpdater == this) {
+ myUpdater = null;
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateEvent.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateEvent.java
new file mode 100644
index 000000000..fa80af8b3
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateEvent.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Event that describes the change in a validation state.
+ * @see IValidationStateListener
+ */
+@SuppressWarnings("serial")
+public class ValidationStateEvent extends EventObject {
+ private final Map<URI, Collection<ViolationDescriptor>> myOldViolations;
+ private final Map<URI, Collection<ViolationDescriptor>> myNewViolations;
+ private final Set<URI> myAllKeys;
+
+ public ValidationStateEvent(ValidationState state, Map<URI, Collection<ViolationDescriptor>> oldViolations, Map<URI, Collection<ViolationDescriptor>> newViolations) {
+ super(state);
+ myOldViolations = oldViolations;
+ myNewViolations = newViolations;
+ myAllKeys = new HashSet<URI>(myOldViolations.keySet());
+ myAllKeys.addAll(myNewViolations.keySet());
+ }
+
+ public ValidationState getSourceValidationState() {
+ return (ValidationState) getSource();
+ }
+
+ public Collection<ViolationDescriptor> getOldViolations(URI uri) {
+ Collection<ViolationDescriptor> result = myOldViolations.get(uri);
+ if (result == null) {
+ return Collections.emptyList();
+ }
+ return result;
+ }
+
+ public Collection<ViolationDescriptor> getNewViolations(URI uri) {
+ Collection<ViolationDescriptor> result = myNewViolations.get(uri);
+ if (result == null) {
+ return Collections.emptyList();
+ }
+ return result;
+ }
+
+ public Iterable<URI> getViolationKeys() {
+ return myAllKeys;
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateManager.java
new file mode 100644
index 000000000..c1ddba084
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ValidationStateManager.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Manages the state of the validation and reports changes to registered {@link IValidationStateListener listeners}.
+ */
+public class ValidationStateManager {
+// private static ValidationStateManager INSTANCE;
+
+ private ArrayList<IValidationStateListener> myListeners = new ArrayList<IValidationStateListener>();
+ private HashMap<URI, WeakReference<ValidationState>> myValidationStates = new HashMap<URI, WeakReference<ValidationState>>();
+
+// public static ValidationStateManager getInstance() {
+// if (INSTANCE == null) {
+// INSTANCE = new ValidationStateManager();
+// }
+// return INSTANCE;
+// }
+
+ public ValidationStateManager() {
+ }
+
+ public void addValidationStateListener(IValidationStateListener listener) {
+ if (listener != null && !myListeners.contains(listener)) {
+ myListeners.add(listener);
+ }
+ }
+
+ public void removeValidationStateListener(IValidationStateListener listener) {
+ myListeners.remove(listener);
+ }
+
+ public ValidationState getValidationState(URI diagramUri) {
+ WeakReference<ValidationState> ref = myValidationStates.get(diagramUri);
+ ValidationState result = null;
+ if (ref != null) {
+ result = ref.get();
+ }
+ if (result == null) {
+ result = new ValidationState(this, diagramUri);
+ myValidationStates.put(diagramUri, new WeakReference<ValidationState>(result));
+ }
+ return result;
+ }
+
+ void fireValidationStateChanged(ValidationState source, Map<URI, Collection<ViolationDescriptor>> oldViolations, Map<URI, Collection<ViolationDescriptor>> newViolations) {
+ if (myListeners.isEmpty()) {
+ return;
+ }
+ ValidationStateEvent evt = new ValidationStateEvent(source, oldViolations, newViolations);
+ for (IValidationStateListener next : new ArrayList<IValidationStateListener>(myListeners)) {
+ next.validationStateChanged(evt);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ViolationDescriptor.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ViolationDescriptor.java
new file mode 100644
index 000000000..16a47d055
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/validation/ViolationDescriptor.java
@@ -0,0 +1,140 @@
+/**
+ * Copyright (c) 2007 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:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.validation;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * Represents a description of a validation problem.
+ * @author bblajer
+ */
+public class ViolationDescriptor {
+ private final String myMessage;
+ private final URI myUri;
+ private final Severity mySeverity;
+ private final Object myReferent;
+
+ /**
+ * Creates a new instance of a violation description with the specified attributes.
+ * @param severity
+ * @param message
+ * @param uri
+ */
+ public ViolationDescriptor(Severity severity, String message, URI uri, Object data) {
+ mySeverity = severity;
+ myMessage = message;
+ myUri = uri;
+ myReferent = data;
+ }
+
+ /**
+ * Returns the message associated with this violation
+ */
+ public String getMessage() {
+ return myMessage;
+ }
+
+ /**
+ * Returns the severity of this violation
+ */
+ public Severity getSeverity() {
+ return mySeverity;
+ }
+
+ /**
+ * Returns the URI of the element associated with this violation
+ */
+ public URI getUri() {
+ return myUri;
+ }
+
+ /**
+ * Returns the representation this descriptor was created from.
+ */
+ public Object getReferent() {
+ return myReferent;
+ }
+
+// @Override
+// public boolean equals(Object obj) {
+// if (obj == this) {
+// return true;
+// }
+// if (obj instanceof ViolationDescriptor) {
+// ViolationDescriptor that = (ViolationDescriptor) obj;
+// if (!this.myUri.equals(that.myUri)) {
+// return false;
+// }
+// if (!this.mySeverity.equals(that.mySeverity)) {
+// return false;
+// }
+// if (!this.myMessage.equals(that.myMessage)) {
+// return false;
+// }
+// return true;
+// }
+// return false;
+// }
+
+ @Override
+ public int hashCode() {
+ return myUri.hashCode() + 17*mySeverity.hashCode() + 31*myMessage.hashCode();
+ }
+
+ /**
+ * Returns an instance of <code>ViolationDescriptor</code> from the given status or <code>null</code> if the status cannot be
+ * represented as a violation descriptor. Children of the status are not taken into account.
+ */
+ public static ViolationDescriptor create(View view, IStatus validationStatus) {
+ Severity severity;
+ switch (validationStatus.getSeverity()) {
+ case IStatus.INFO:
+ severity = Severity.INFO;
+ break;
+ case IStatus.WARNING:
+ severity = Severity.WARNING;
+ break;
+ case IStatus.ERROR:
+ severity = Severity.ERROR;
+ break;
+ default:
+ return null;
+ }
+ return new ViolationDescriptor(severity, validationStatus.getMessage(), EcoreUtil.getURI(view), validationStatus);
+ }
+
+ /**
+ * Returns an instance of <code>ViolationDescriptor</code> from the given diagnostic or <code>null</code> if diagnostic cannot be
+ * represented as a violation descriptor. Children of the diagnostic are not taken into account.
+ */
+ public static ViolationDescriptor create(View view, Diagnostic diagnostic) {
+ Severity severity;
+ switch (diagnostic.getSeverity()) {
+ case Diagnostic.INFO:
+ severity = Severity.INFO;
+ break;
+ case Diagnostic.WARNING:
+ severity = Severity.WARNING;
+ break;
+ case Diagnostic.ERROR:
+ severity = Severity.ERROR;
+ break;
+ default:
+ return null;
+ }
+ return new ViolationDescriptor(severity, diagnostic.getMessage(), EcoreUtil.getURI(view), diagnostic);
+ }
+}

Back to the top