diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Switch.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Switch.java index 80da6c3dce01c1ad3e0c1f70958600eb8eb2dccf..bd5fd4fbed676298420c9b703429f5d776166eac 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Switch.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Switch.java @@ -6,6 +6,9 @@ package de.bmotionstudio.gef.editor.model; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.draw2d.geometry.Rectangle; import de.bmotionstudio.gef.editor.AttributeConstants; @@ -59,28 +62,37 @@ public class Switch extends BControl { track2.setAttributeValue(AttributeConstants.ATTRIBUTE_LABEL, ""); track1.setAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM, "LEFT"); - track1.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setEditable( - false); + AbstractAttribute a1 = track1 + .getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM); + a1.setEditable(false); + a1.setShow(false); track2.setAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM, "RIGHT"); - track2.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setEditable( - false); + AbstractAttribute a2 = track2.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM); + a2.setEditable(false); + a2.setShow(false); tracknode1.setAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM, "1"); tracknode1.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM) .setEditable(false); + tracknode1.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setShow( + false); tracknode1.getAttribute(AttributeConstants.ATTRIBUTE_COORDINATES) .setShow(false); tracknode2.setAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM, "2"); tracknode2.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM) .setEditable(false); + tracknode2.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setShow( + false); tracknode2.getAttribute(AttributeConstants.ATTRIBUTE_COORDINATES) .setShow(false); tracknode3.setAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM, "3"); tracknode3.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM) .setEditable(false); + tracknode3.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setShow( + false); tracknode3.getAttribute(AttributeConstants.ATTRIBUTE_COORDINATES) .setShow(false); @@ -99,45 +111,38 @@ public class Switch extends BControl { initAttribute(AttributeConstants.ATTRIBUTE_SWITCH_POSITION, AttributeSwitchPosition.UNKNOWN); - for (BControl c : getChildrenArray()) { - c.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setShow(false); - c.getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM).setEditable( - false); - c.getAttribute(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( - false); - c.getAttribute(AttributeConstants.ATTRIBUTE_COORDINATES) - .setEditable(false); - } - } // We have to set the two tracks of the switch, since their are set to // transient protected Object readResolve() { + super.readResolve(); + for (BControl control : getChildrenArray()) { - for (Track n : ((TrackNode) control).getSourceTracks()) { - AbstractAttribute a2 = n - .getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM); - a2.setEditable(false); - if (a2.getValue().equals("LEFT")) { - track1 = n; - } else if (a2.getValue().equals("RIGHT")) { - track2 = n; - } - } - for (Track n : ((TrackNode) control).getTargetTracks()) { + + List<Track> tracks = new ArrayList<Track>(); + tracks.addAll(((TrackNode) control).getSourceTracks()); + tracks.addAll(((TrackNode) control).getTargetTracks()); + + for (Track n : tracks) { AbstractAttribute a2 = n .getAttribute(AttributeConstants.ATTRIBUTE_CUSTOM); - a2.setEditable(false); if (a2.getValue().equals("LEFT")) { + a2.setEditable(false); + a2.setShow(false); track1 = n; } else if (a2.getValue().equals("RIGHT")) { track2 = n; + a2.setEditable(false); + a2.setShow(false); } } + } + return this; + } @Override diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/SwitchPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/SwitchPart.java index aacb1b509d09b019af55357f0d93bc6ee0e49228..6b17cb7005708a61f18f97a597b7a6c192e4e5c8 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/SwitchPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/SwitchPart.java @@ -19,6 +19,7 @@ import de.bmotionstudio.gef.editor.editpolicy.BMSDeletePolicy; import de.bmotionstudio.gef.editor.figure.SwitchFigure; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.Switch; +import de.bmotionstudio.gef.editor.model.Track; public class SwitchPart extends BMSAbstractEditPart { @@ -38,19 +39,26 @@ public class SwitchPart extends BMSAbstractEditPart { Switch sw = (Switch) model; - sw.getTrack1().setAttributeValue( - AttributeConstants.ATTRIBUTE_VISIBLE, true); - sw.getTrack2().setAttributeValue( - AttributeConstants.ATTRIBUTE_VISIBLE, true); - - if (value.equals(AttributeSwitchPosition.LEFT)) { - sw.getTrack1().setAttributeValue( - AttributeConstants.ATTRIBUTE_VISIBLE, false); - } else if (value.equals(AttributeSwitchPosition.RIGHT)) { - sw.getTrack2().setAttributeValue( - AttributeConstants.ATTRIBUTE_VISIBLE, false); + Track track1 = sw.getTrack1(); + Track track2 = sw.getTrack2(); + + if (track1 != null && track2 != null) { + + track1.setAttributeValue(AttributeConstants.ATTRIBUTE_VISIBLE, + true); + track2.setAttributeValue(AttributeConstants.ATTRIBUTE_VISIBLE, + true); + + if (value.equals(AttributeSwitchPosition.LEFT)) { + track1.setAttributeValue( + AttributeConstants.ATTRIBUTE_VISIBLE, false); + } else if (value.equals(AttributeSwitchPosition.RIGHT)) { + track2.setAttributeValue( + AttributeConstants.ATTRIBUTE_VISIBLE, false); + } + } - + } if (aID.equals(AttributeConstants.ATTRIBUTE_SWITCH_DIRECTION))