Browse Source

Removed State figure compartment.

Andreas Mülder 12 years ago
parent
commit
730afdc0c3

+ 1 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/figures/utils/MapModeUtils.java

@@ -20,7 +20,7 @@ public final class MapModeUtils {
 
 	
 	private static final int DEFAULT_NODE_WIDTH = 40;
-	private static final int DEFAULT_NODE_HEIGHT = 40;
+	private static final int DEFAULT_NODE_HEIGHT = 50;
 
 	public static Dimension getDefaultSizeDimension(IMapMode mode) {
 		return new Dimension(mode.DPtoLP(DEFAULT_NODE_WIDTH), mode.DPtoLP(DEFAULT_NODE_HEIGHT));

+ 3 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/RegionCompartmentEditPart.java

@@ -24,7 +24,8 @@ import org.eclipse.gmf.runtime.notation.View;
 import org.yakindu.sct.ui.editor.DiagramActivator;
 import org.yakindu.sct.ui.editor.policies.CompartmentCreationEditPolicy;
 import org.yakindu.sct.ui.editor.policies.RegionCompartmentCanonicalEditPolicy;
-import org.yakindu.sct.ui.editor.policies.RegionCompartmentXYLayoutEditPolicy;
+
+import de.itemis.gmf.runtime.commons.editparts.FixedXYLayoutEditPolicy;
 
 /**
  * @author muelder
@@ -42,7 +43,7 @@ public class RegionCompartmentEditPart extends ShapeCompartmentEditPart {
 		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentCreationEditPolicy());
 		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new RegionCompartmentCanonicalEditPolicy());
 		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
-		installEditPolicy(EditPolicy.LAYOUT_ROLE, new RegionCompartmentXYLayoutEditPolicy());
+		installEditPolicy(EditPolicy.LAYOUT_ROLE, new FixedXYLayoutEditPolicy());
 		// Removes the collapse expand handler
 		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableEditPolicyEx());
 	}

+ 25 - 58
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateEditPart.java

@@ -17,35 +17,36 @@ import org.eclipse.draw2d.IFigure;
 import org.eclipse.draw2d.StackLayout;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
 import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
 import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
 import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
 import org.eclipse.gmf.runtime.notation.Compartment;
-import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.ui.editor.editor.figures.StateFigure;
 import org.yakindu.sct.ui.editor.editor.figures.utils.GridDataFactory;
 import org.yakindu.sct.ui.editor.editor.figures.utils.MapModeUtils;
-import org.yakindu.sct.ui.editor.policies.PreferredSizeHandlerEditPolicy;
+import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
 import org.yakindu.sct.ui.editor.policies.EnlargeContainerEditPolicy;
+import org.yakindu.sct.ui.editor.policies.PreferredSizeHandlerEditPolicy;
 import org.yakindu.sct.ui.editor.preferences.StatechartColorConstants;
+import org.yakindu.sct.ui.editor.providers.SemanticHints;
 
 /**
  * The EditPart for the State.
@@ -110,7 +111,7 @@ public class StateEditPart extends ShapeNodeEditPart implements IPrimaryEditPart
 		return figure;
 	}
 
-	private Dimension getDefaultSize() {
+	protected Dimension getDefaultSize() {
 		return MapModeUtils.getDefaultSizeDimension(getMapMode());
 	}
 
@@ -122,40 +123,38 @@ public class StateEditPart extends ShapeNodeEditPart implements IPrimaryEditPart
 	protected void createDefaultEditPolicies() {
 		super.createDefaultEditPolicies();
 		removeEditPolicy(EditPolicyRoles.CREATION_ROLE);
-
-		if (isCollapsed()) {
-			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicyEx());
-		} else {
-			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PreferredSizeHandlerEditPolicy());
-		}
-
+		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PreferredSizeHandlerEditPolicy());
 		installEditPolicy(EnlargeContainerEditPolicy.ROLE, new EnlargeContainerEditPolicy());
 	}
 
 	@Override
 	protected void refreshVisuals() {
-		refreshCompartmentStates();
+		refreshCompartmentLayout();
 		super.refreshVisuals();
 	}
 
-	private void refreshCompartmentStates() {
+	private void refreshCompartmentLayout() {
 		if (getTextCompartment().isCollapsed()) {
 			getPrimaryShape().setConstraint(getPrimaryShape().getTextCompartmentPane(), getCollapsedData());
 		} else {
 			GridData expandedData = getExpandedData();
-			if (!getFigureCompartment().isCollapsed())
+			if (figureCompartmentVisible())
 				expandedData.grabExcessVerticalSpace = false;
 			getPrimaryShape().setConstraint(getPrimaryShape().getTextCompartmentPane(), expandedData);
 		}
-		if (getFigureCompartment().isCollapsed()) {
+		if (!figureCompartmentVisible()) {
 			getPrimaryShape().setConstraint(getPrimaryShape().getFigureCompartmentPane(), getCollapsedData());
 		} else {
-			GridData expandedData = getExpandedData();
-
-			getPrimaryShape().setConstraint(getPrimaryShape().getFigureCompartmentPane(), expandedData);
+			getPrimaryShape().setConstraint(getPrimaryShape().getFigureCompartmentPane(), getExpandedData());
 		}
 	}
 
+	private boolean figureCompartmentVisible() {
+		BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineStyle(getNotationView());
+		return resolveSemanticElement().getRegions().size() > 0
+				&& (inlineStyle == null || inlineStyle.isBooleanValue());
+	}
+
 	private GridData getExpandedData() {
 		return GridDataFactory.fillDefaults().grab(true, true).getData();
 	}
@@ -164,36 +163,8 @@ public class StateEditPart extends ShapeNodeEditPart implements IPrimaryEditPart
 		return GridDataFactory.fillDefaults().grab(false, false).getData();
 	}
 
-	@Override
-	protected void refreshBounds() {
-
-		// TODO: Calculate the 'default' size
-		int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
-		int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
-
-		Dimension size = new Dimension(width, height);
-		int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
-		int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
-		Point loc = new Point(x, y);
-
-		if (isCollapsed()) {
-			((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(loc, new Dimension(
-					58, 66)));
-		} else {
-			((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(loc, size));
-		}
-	}
-
-	private Compartment getFigureCompartment() {
-		return (Compartment) getNotationView().getChildren().get(2);
-	}
-
 	private Compartment getTextCompartment() {
-		return (Compartment) getNotationView().getChildren().get(1);
-	}
-
-	public boolean isCollapsed() {
-		return getFigureCompartment().isCollapsed() && getTextCompartment().isCollapsed();
+		return (Compartment) ViewUtil.getChildBySemanticHint(getNotationView(), SemanticHints.STATE_TEXT_COMPARTMENT);
 	}
 
 	@Override
@@ -241,15 +212,14 @@ public class StateEditPart extends ShapeNodeEditPart implements IPrimaryEditPart
 	@Override
 	protected void addNotationalListeners() {
 		super.addNotationalListeners();
-		addListenerFilter("TextCompartmentView", this, (Node) getNotationView().getChildren().get(1));
-		addListenerFilter("FigureCompartmentView", this, (Node) getNotationView().getChildren().get(2));
+		addListenerFilter("TextCompartmentView", this,
+				ViewUtil.getChildBySemanticHint(getNotationView(), SemanticHints.STATE_TEXT_COMPARTMENT));
 	}
 
 	@Override
 	protected void removeNotationalListeners() {
 		super.removeNotationalListeners();
 		removeListenerFilter("TextCompartmentView");
-		removeListenerFilter("FigureCompartmentView");
 	}
 
 	/**
@@ -275,13 +245,10 @@ public class StateEditPart extends ShapeNodeEditPart implements IPrimaryEditPart
 		if (notification.getFeature() == NotationPackage.Literals.BOOLEAN_VALUE_STYLE__BOOLEAN_VALUE) {
 			refresh();
 		}
-
 		if (notification.getFeature() == NotationPackage.Literals.DRAWER_STYLE__COLLAPSED) {
-			if (isCollapsed()) {
-				installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicyEx());
-			} else {
-				installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PreferredSizeHandlerEditPolicy());
-			}
+			refreshVisuals();
+		}
+		if (notification.getFeature() == SGraphPackage.Literals.COMPOSITE_ELEMENT__REGIONS) {
 			refreshVisuals();
 		}
 		super.handleNotificationEvent(notification);

+ 10 - 41
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateFigureCompartmentEditPart.java

@@ -10,14 +10,14 @@
  */
 package org.yakindu.sct.ui.editor.editparts;
 
+import org.eclipse.draw2d.Figure;
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
 import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
 import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
@@ -37,27 +37,12 @@ import de.itemis.gmf.runtime.commons.editpolicies.CompartmentLayoutEditPolicy;
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class StateFigureCompartmentEditPart extends ResizableCompartmentEditPart {
-
-	private static final String PARENT_VIEW = "parent_view";
+public class StateFigureCompartmentEditPart extends CompartmentEditPart {
 
 	public StateFigureCompartmentEditPart(View view) {
 		super(view);
 	}
 
-	// Listeners for the parent view to get notified when layout is changed
-	@Override
-	protected void addNotationalListeners() {
-		addListenerFilter(PARENT_VIEW, this, getParent().getNotationView());
-		super.addNotationalListeners();
-	}
-
-	@Override
-	protected void removeNotationalListeners() {
-		removeListenerFilter(PARENT_VIEW);
-		super.removeNotationalListeners();
-	}
-
 	@Override
 	protected void createDefaultEditPolicies() {
 		super.createDefaultEditPolicies();
@@ -66,42 +51,26 @@ public class StateFigureCompartmentEditPart extends ResizableCompartmentEditPart
 		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
 		installEditPolicy(EditPolicy.LAYOUT_ROLE, new CompartmentLayoutEditPolicy(
 				SGraphPackage.Literals.COMPOSITE_ELEMENT__REGIONS));
+		removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
 	}
 
 	@Override
-	protected void refreshVisuals() {
-		super.refreshVisuals();
-		((ResizableCompartmentFigure) getFigure()).getScrollPane().setScrollBarVisibility(
-				org.eclipse.draw2d.ScrollPane.NEVER);
+	public boolean isSelectable() {
+		return false;
 	}
-	
+
 	@Override
 	public State resolveSemanticElement() {
 		return (State) super.resolveSemanticElement();
 	}
 
-	@Override
-	public boolean isSelectable() {
-		return false;
-	}
-
 	@Override
 	protected IFigure createFigure() {
-		ResizableCompartmentFigure figure = (ResizableCompartmentFigure) super.createFigure();
-		figure.getContentPane().setLayoutManager(new StateFigureCompartmentLayout(getAlignment()));
-		figure.setBorder(null);
-		// Should be initialized with null to display nothing.
-		figure.setToolTip((String) null);
-		figure.getScrollPane().setScrollBarVisibility(
-				org.eclipse.draw2d.ScrollPane.NEVER);
+		figure = new Figure();
+		figure.setLayoutManager(new StateFigureCompartmentLayout(getAlignment()));
 		return figure;
 	}
 
-	@Override
-	public ResizableCompartmentFigure getFigure() {
-		return (ResizableCompartmentFigure) super.getFigure();
-	}
-
 	@Override
 	public StateEditPart getParent() {
 		return (StateEditPart) super.getParent();
@@ -122,7 +91,7 @@ public class StateFigureCompartmentEditPart extends ResizableCompartmentEditPart
 	}
 
 	private void updateLayout() {
-		getFigure().getContentPane().setLayoutManager(new StateFigureCompartmentLayout(getAlignment()));
+		getFigure().setLayoutManager(new StateFigureCompartmentLayout(getAlignment()));
 	}
 
 	private static final class StateFigureCompartmentLayout extends ConstrainedToolbarLayout {

+ 0 - 76
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/RegionCompartmentXYLayoutEditPolicy.java

@@ -1,76 +0,0 @@
-/**
- * Copyright (c) 2011 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * Contributors:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.ui.editor.policies;
-
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.yakindu.sct.ui.editor.editparts.RegionCompartmentEditPart;
-import org.yakindu.sct.ui.editor.editparts.StateEditPart;
-
-import de.itemis.gmf.runtime.commons.editparts.FixedXYLayoutEditPolicy;
-
-/**
- * Special implementation of {@link XYLayoutEditPolicy} for the
- * {@link RegionCompartmentEditPart}.
- * 
- * If a State within the region compartment is collapsed, this Edit Policy does
- * not change the width and height in the Notation model for this state.
- * 
- * So the original width and height of the state before it was collapsed, is
- * remembered and used when the state is expanded again.
- * 
- * @author muelder
- * 
- */
-public class RegionCompartmentXYLayoutEditPolicy extends FixedXYLayoutEditPolicy {
-
-	@Override
-	protected Command createChangeConstraintCommand(EditPart child,
-			Object constraint) {
-		if (child instanceof StateEditPart
-				&& ((StateEditPart) child).isCollapsed()) {
-			Rectangle newBounds = (Rectangle) constraint;
-			View shapeView = (View) child.getModel();
-			// Override the new bounds with the original bounds from the
-			// notation model here
-			newBounds.width = (Integer) ViewUtil.getStructuralFeatureValue(
-					shapeView, NotationPackage.eINSTANCE.getSize_Width());
-			newBounds.height = (Integer) ViewUtil.getStructuralFeatureValue(
-					shapeView, NotationPackage.eINSTANCE.getSize_Height());
-			ICommand boundsCommand = new SetBoundsCommand(getHost()
-					.getEditingDomain(),
-					DiagramUIMessages.SetLocationCommand_Label_Resize,
-					new EObjectAdapter(shapeView), newBounds);
-			return new ICommandProxy(boundsCommand);
-		} else {
-			return super.createChangeConstraintCommand(child, constraint);
-		}
-	}
-
-	@Override
-	public IGraphicalEditPart getHost() {
-		return (IGraphicalEditPart) super.getHost();
-	}
-	
-
-	
-}

+ 0 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/StateCompartmentCreationEditPolicy.java

@@ -31,9 +31,7 @@ public class StateCompartmentCreationEditPolicy extends CompartmentCreationEditP
 
 	@Override
 	protected Command getCreateCommand(CreateViewRequest request) {
-
 		StateEditPart parent = (StateEditPart) getHost().getParent();
-
 		BooleanValueStyle isInline = GMFNotationUtil.getBooleanValueStyle(parent.getNotationView(),
 				DiagramPartitioningUtil.INLINE_STYLE);
 		if (isInline != null && !isInline.isBooleanValue())