Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Bonnet2013-09-05 14:35:04 +0000
committerStephane Bonnet2013-09-05 14:35:04 +0000
commit5cf53378e4a084aefb90d9648d5db61d83881f58 (patch)
treed1187a4a39864273af2fccfd85f6e1eb4aff07fc /plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java
downloadorg.eclipse.sirius-5cf53378e4a084aefb90d9648d5db61d83881f58.tar.gz
org.eclipse.sirius-5cf53378e4a084aefb90d9648d5db61d83881f58.tar.xz
org.eclipse.sirius-5cf53378e4a084aefb90d9648d5db61d83881f58.zip
Initial version.
Diffstat (limited to 'plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java')
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java133
1 files changed, 133 insertions, 0 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java
new file mode 100644
index 0000000000..f6af464111
--- /dev/null
+++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutScope.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2010 THALES GLOBAL SERVICES.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.diagram.sequence.business.internal.refresh;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+
+import com.google.common.base.Predicate;
+
+import org.eclipse.sirius.DDiagramElement;
+import org.eclipse.sirius.SiriusPackage;
+import org.eclipse.sirius.WorkspaceImage;
+import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractNodeEvent;
+import org.eclipse.sirius.diagram.sequence.business.internal.elements.EndOfLife;
+import org.eclipse.sirius.diagram.sequence.business.internal.elements.InstanceRole;
+import org.eclipse.sirius.diagram.sequence.business.internal.util.BendpointsHelper;
+import org.eclipse.sirius.diagram.sequence.util.NotificationQuery;
+
+/**
+ * Default refresh layout scope for sequence diagram. This predicate decides
+ * whether or not we need to refresh the graphical layout, i.e. launch a
+ * non-packing layout
+ *
+ * @author mporhel
+ */
+public class RefreshLayoutScope implements Predicate<Notification> {
+
+ private final Predicate<Notification> isLayoutConstraintNotationChange = new Predicate<Notification>() {
+ Object[] features = new Object[] { NotationPackage.eINSTANCE.getRelativeBendpoints_Points(), NotationPackage.eINSTANCE.getLocation_Y(), NotationPackage.eINSTANCE.getLocation_X(),
+ NotationPackage.eINSTANCE.getSize_Width(), NotationPackage.eINSTANCE.getSize_Height(), };
+
+ public boolean apply(Notification input) {
+ NotificationQuery nq = new NotificationQuery(input);
+ return nq.isNotationChange() && isLayout(input.getFeature()) && !input.isTouch();
+ }
+
+ private boolean isLayout(Object feature) {
+ for (Object feature2 : features) {
+ if (feature == feature2) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+ private final Predicate<Notification> isSructuralNotationChange = new Predicate<Notification>() {
+ int[] types = new int[] { Notification.ADD, Notification.ADD_MANY, Notification.MOVE, Notification.REMOVE, Notification.REMOVE_MANY };
+
+ public boolean apply(Notification input) {
+ NotificationQuery nq = new NotificationQuery(input);
+ return nq.isNotationChange() && isStructural(input.getEventType());
+ }
+
+ private boolean isStructural(int eventType) {
+ for (int type : types) {
+ if (eventType == type) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean apply(Notification input) {
+ return needsLayout(input);
+ }
+
+ private boolean needsLayout(Notification notification) {
+ return !isLayoutTouch(notification) && (containsStructuralNotationChanges(notification) || containsLayoutConstraintNotationChanges(notification) || containsSetWkpImgApplication(notification));
+ }
+
+ private boolean containsLayoutConstraintNotationChanges(Notification notification) {
+ return isLayoutConstraintNotationChange.apply(notification);
+ }
+
+ private boolean containsStructuralNotationChanges(Notification notification) {
+
+ return isSructuralNotationChange.apply(notification);
+ }
+
+ private boolean isLayoutTouch(Notification notification) {
+ boolean result = true;
+
+ boolean isTouch = notification.isTouch();
+ if (!isTouch) {
+ if (NotationPackage.eINSTANCE.getRelativeBendpoints_Points().equals(notification.getFeature())) {
+ isTouch = BendpointsHelper.areSameBendpoints(notification.getOldValue(), notification.getNewValue());
+ }
+ }
+
+ if (!isTouch) {
+ result = false;
+ }
+
+ return result;
+ }
+
+ private boolean containsSetWkpImgApplication(Notification notification) {
+ boolean newStyle = false;
+ boolean wkpImageCustomization = false;
+ boolean wkpImageDeCustomization = false;
+
+ if (notification.getEventType() == Notification.SET && SiriusPackage.eINSTANCE.getDNode_OwnedStyle().equals(notification.getFeature()) && hasSequenceMapping(notification.getNotifier())) {
+ newStyle = true;
+ } else if (SiriusPackage.eINSTANCE.getCustomizable_CustomFeatures().equals(notification.getFeature()) && notification.getNotifier() instanceof WorkspaceImage) {
+ WorkspaceImage workspaceImage = (WorkspaceImage) notification.getNotifier();
+ wkpImageCustomization = !workspaceImage.getCustomFeatures().isEmpty();
+ wkpImageDeCustomization = !wkpImageCustomization;
+ }
+
+ return newStyle && (wkpImageCustomization || wkpImageDeCustomization);
+ }
+
+ private boolean hasSequenceMapping(Object notifier) {
+ if (notifier instanceof DDiagramElement) {
+ DDiagramElement dde = (DDiagramElement) notifier;
+ return AbstractNodeEvent.viewpointElementPredicate().apply(dde) || EndOfLife.viewpointElementPredicate().apply(dde) || InstanceRole.viewpointElementPredicate().apply(dde);
+ }
+ return false;
+ }
+}

Back to the top