diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/ButtonGroupHelper.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/ButtonGroupHelper.java index 802557645e171563ed1c1f936f59a82199cb4a5c..4c30b270af2e797f9c4ecafbca86d808c1fba015 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/ButtonGroupHelper.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/ButtonGroupHelper.java @@ -17,6 +17,7 @@ public class ButtonGroupHelper { private static HashMap<String, Collection<BControl>> map = new HashMap<String, Collection<BControl>>(); public ButtonGroupHelper() { + System.out.println("REGISTER"); } public static Collection<BControl> getButtonGroup(String buttonGroupID) { @@ -38,4 +39,8 @@ public class ButtonGroupHelper { map.remove(buttonGroupID); } + public static void reset() { + map.clear(); + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeButtonGroup.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeButtonGroup.java index dea0957c61f2d6b3111d9d87110af87cec8c2cf8..e15182719126fc38f4fd36bd599f1938e6f6c0f0 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeButtonGroup.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeButtonGroup.java @@ -22,7 +22,7 @@ public class BAttributeButtonGroup extends AbstractAttribute { @Override public String getName() { - return "Button"; + return "Group Name"; } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/CheckboxFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/CheckboxFigure.java index 7cdc32c23df9074f2f6de28ec765eb35004b2bc6..6ab54c357e703e8a972c04db22475bf6fe6b5f93 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/CheckboxFigure.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/CheckboxFigure.java @@ -41,5 +41,10 @@ public class CheckboxFigure extends AbstractBMotionFigure { public void setTextColor(Color color) { textLb.setForegroundColor(color); } + + public void setBtEnabled(Boolean bool) { + textLb.setEnabled(bool); + repaint(); + } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/RadioButtonFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/RadioButtonFigure.java index ebb81912b6139103cb0f3122e0a483af9711bf26..100671a13438d7a02b882bc717f4c65824284bea 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/RadioButtonFigure.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/RadioButtonFigure.java @@ -46,6 +46,11 @@ public class RadioButtonFigure extends AbstractBMotionFigure { foregroundColor = new Color(Display.getDefault(), rgb); textLb.setForegroundColor(foregroundColor); } + + public void setBtEnabled(Boolean bool) { + textLb.setEnabled(bool); + repaint(); + } /* * (non-Javadoc) diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BCheckbox.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BCheckbox.java index 95b46552e1c5d6250f6b7ac9722b8970d1e31558..d6984cb85849810f7ae44ef5ebc48d3c7e883d40 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BCheckbox.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BCheckbox.java @@ -11,6 +11,7 @@ import org.eclipse.swt.graphics.RGB; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.attribute.BAttributeButtonGroup; import de.bmotionstudio.gef.editor.attribute.BAttributeChecked; +import de.bmotionstudio.gef.editor.attribute.BAttributeEnabled; import de.bmotionstudio.gef.editor.attribute.BAttributeFalseValue; import de.bmotionstudio.gef.editor.attribute.BAttributeText; import de.bmotionstudio.gef.editor.attribute.BAttributeTextColor; @@ -42,6 +43,7 @@ public class BCheckbox extends BControl { initAttribute(new BAttributeTextColor(new RGB(0, 0, 0))); initAttribute(new BAttributeChecked(true)); initAttribute(new BAttributeValue("")); + initAttribute(new BAttributeEnabled(true)); initAttribute(new BAttributeButtonGroup("")); initAttribute(new BAttributeTrueValue("")); initAttribute(new BAttributeFalseValue("")); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BRadioButton.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BRadioButton.java index 4afdda7f530120b9880822696432cd6f104da418..a05d99e1161b2e256d6e214ab911cd01dbb3a40f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BRadioButton.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BRadioButton.java @@ -12,9 +12,9 @@ import org.eclipse.swt.graphics.RGB; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.ButtonGroupHelper; -import de.bmotionstudio.gef.editor.attribute.BAttributeBackgroundColor; import de.bmotionstudio.gef.editor.attribute.BAttributeButtonGroup; import de.bmotionstudio.gef.editor.attribute.BAttributeChecked; +import de.bmotionstudio.gef.editor.attribute.BAttributeEnabled; import de.bmotionstudio.gef.editor.attribute.BAttributeText; import de.bmotionstudio.gef.editor.attribute.BAttributeTextColor; import de.bmotionstudio.gef.editor.attribute.BAttributeValue; @@ -46,11 +46,11 @@ public class BRadioButton extends BControl { @Override protected void initAttributes() { initAttribute(new BAttributeText(DEFAULT_TEXT)); - initAttribute(new BAttributeBackgroundColor(new RGB(192, 192, 192))); initAttribute(new BAttributeTextColor(new RGB(0, 0, 0))); initAttribute(new BAttributeChecked(true)); initAttribute(new BAttributeValue("")); initAttribute(new BAttributeButtonGroup("")); + initAttribute(new BAttributeEnabled(true)); getAttribute(AttributeConstants.ATTRIBUTE_HEIGHT).setValue(21); getAttribute(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable(false); } @@ -77,7 +77,7 @@ public class BRadioButton extends BControl { AttributeConstants.ATTRIBUTE_VALUE).toString(); } } - return null; + return ""; } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java index bc5e5523997539f20c68b4d0272d0a42c492eb53..69ba62cef155c8fc5b03ba690932a5bdd4390678 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java @@ -1,345 +1,348 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.model; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.draw2d.PositionConstants; - -import de.be4.classicalb.core.parser.exceptions.BException; -import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.IAddErrorListener; -import de.bmotionstudio.gef.editor.internal.Animation; -import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; -import de.prob.core.command.ExecuteOperationCommand; -import de.prob.core.command.GetOperationByPredicateCommand; -import de.prob.core.domainobjects.Operation; -import de.prob.exceptions.ProBException; - -public class Visualization extends BControl { - - public static transient String TYPE = "de.bmotionstudio.gef.editor.text"; - - protected String bmachine, language, version; - - protected BMotionRuler leftRuler, topRuler; - - private boolean rulersVisibility, snapToGeometry, gridEnabled; - - private transient List<String> allBControlIDs; - - public List<String> getAllBControlIDs() { - if (allBControlIDs == null) - allBControlIDs = getAllBControlNames(); - return allBControlIDs; - } - - private transient Boolean isRunning; - - private transient Animation animation; - - private transient IFile projectFile; - - private transient ArrayList<IAddErrorListener> errorListener; - - private transient Thread operationSchedulerThread; - - private ArrayList<PredicateOperation> schedulerOperations; - - public Visualization(String bmachine, String language, String version) { - super(null); - setVisualization(this); - this.rulersVisibility = true; - this.bmachine = bmachine; - this.language = language; - this.version = version; - this.errorListener = new ArrayList<IAddErrorListener>(); - this.isRunning = false; - createRulers(); - } - - @Override - protected Object readResolve() { - super.readResolve(); - this.isRunning = false; - populateVisualization(this); - createRulers(); - this.errorListener = new ArrayList<IAddErrorListener>(); - // this.errorMessages = new ArrayList<ErrorMessage>(); - // setAttributeValue(AttributeConstants.ATTRIBUTE_ID, "surface", false); - return this; - } - - public void startOperationScheduler() { - - if (!getSchedulerOperations().isEmpty()) { - - operationSchedulerThread = new Thread(new Runnable() { - public void run() { - while (true) { - - for (PredicateOperation p : getSchedulerOperations()) { - - if (animation.getCurrentStateOperation(p - .getOperationName()) != null) { - - try { - - String fpredicate = "1=1"; - - if (p.getPredicate().length() > 0) { - fpredicate = p.getPredicate(); - } - - Operation op = GetOperationByPredicateCommand - .getOperation(animation - .getAnimator(), animation - .getState().getId(), p - .getOperationName(), - fpredicate); - ExecuteOperationCommand.executeOperation( - animation.getAnimator(), op); - - } catch (ProBException e) { - break; - } catch (BException e) { - break; - } - - } - - } - - try { - Thread.sleep(500); - } catch (InterruptedException e) { - break; - } - - } - } - }); - operationSchedulerThread.start(); - - } - - } - - public void stopOperationScheduler() { - if (operationSchedulerThread != null) - operationSchedulerThread.interrupt(); - } - - public void setIsRunning(Boolean bol) { - this.isRunning = bol; - } - - public Boolean isRunning() { - return isRunning; - } - - public IFile getProjectFile() { - return projectFile; - } - - public void setProjectFile(IFile pf) { - projectFile = pf; - } - - public String getMachineName() { - return this.bmachine; - } - - public void setMachineName(String machineName) { - this.bmachine = machineName; - } - - public String getLanguage() { - return this.language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public void setAnimation(Animation animation) { - this.animation = animation; - } - - public Animation getAnimation() { - return this.animation; - } - - public List<String> getAllBControlNames() { - return getAllBControlNames(getChildrenArray()); - } - - private List<String> getAllBControlNames(List<BControl> children) { - List<String> list = new ArrayList<String>(); - for (BControl bcontrol : children) { - list.add(bcontrol - .getAttributeValue(AttributeConstants.ATTRIBUTE_ID) - .toString()); - if (bcontrol.getChildrenArray().size() > 0) { - list.addAll(getAllBControlNames(bcontrol.getChildrenArray())); - } - } - return list; - } - - public String getMaxIDString(String type) { - String newID = getMaxID(type, 0, getAllBControlIDs()); - getAllBControlIDs().add(newID); - return newID; - } - - // old method - private String getMaxID(String type, int count, List<String> allIDs) { - String newID = "control_" + count; - if (allIDs.contains(newID)) { - return getMaxID(type, (count + 1), allIDs); - } else { - return newID; - } - } - - // TODO: Reimplement me!!! - public boolean checkIfIdExists(String ID) { - // if (getVariableList().hasEntry(ID) == true) - // return true; - // if (getConstantList().hasEntry(ID) == true) - // return true; - return getAllBControlNames().contains(ID); - } - - public BControl getBControl(String ID) { - return getBControl(ID, getChildrenArray()); - } - - private BControl getBControl(String ID, List<BControl> children) { - for (BControl bcontrol : children) { - if (bcontrol.getID().equals(ID)) { - return bcontrol; - } - if (bcontrol.getChildrenArray().size() > 0) { - BControl childControl = getBControl(ID, - bcontrol.getChildrenArray()); - if (childControl != null) - return childControl; - } - } - return null; - } - - public BMotionRuler getRuler(int orientation) { - BMotionRuler result = null; - switch (orientation) { - case PositionConstants.NORTH: - result = topRuler; - break; - case PositionConstants.WEST: - result = leftRuler; - break; - } - return result; - } - - public BMotionRuler getTopRuler() { - return topRuler; - } - - public void setTopRuler(BMotionRuler topRuler) { - this.topRuler = topRuler; - } - - public BMotionRuler getLeftRuler() { - return leftRuler; - } - - public void setLeftRuler(BMotionRuler leftRuler) { - this.leftRuler = leftRuler; - } - - protected void createRulers() { - if (leftRuler == null) - leftRuler = new BMotionRuler(false); - if (topRuler == null) - topRuler = new BMotionRuler(true); - } - - public void setRulerVisibility(boolean newValue) { - rulersVisibility = newValue; - } - - public void setGridEnabled(boolean isEnabled) { - gridEnabled = isEnabled; - } - - public void setSnapToGeometry(boolean isEnabled) { - snapToGeometry = isEnabled; - } - - public boolean getRulerVisibility() { - return rulersVisibility; - } - - public boolean isGridEnabled() { - return gridEnabled; - } - - public boolean isSnapToGeometryEnabled() { - return snapToGeometry; - } - - public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { - return null; - } - - public void addErrorListener(IAddErrorListener listener) { - this.errorListener.add(listener); - } - - public void removeErrorListener(IAddErrorListener listener) { - this.errorListener.remove(listener); - } - - public void setSchedulerOperations( - ArrayList<PredicateOperation> schedulerOperations) { - this.schedulerOperations = schedulerOperations; - } - - public ArrayList<PredicateOperation> getSchedulerOperations() { - if (this.schedulerOperations == null) - this.schedulerOperations = new ArrayList<PredicateOperation>(); - return this.schedulerOperations; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - @Override - public String getType() { - return TYPE; - } - - @Override - protected void initAttributes() { - } - - @Override - public boolean canHaveChildren() { - return true; - } - -} +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.draw2d.PositionConstants; + +import de.be4.classicalb.core.parser.exceptions.BException; +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.ButtonGroupHelper; +import de.bmotionstudio.gef.editor.IAddErrorListener; +import de.bmotionstudio.gef.editor.internal.Animation; +import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; +import de.prob.core.command.ExecuteOperationCommand; +import de.prob.core.command.GetOperationByPredicateCommand; +import de.prob.core.domainobjects.Operation; +import de.prob.exceptions.ProBException; + +public class Visualization extends BControl { + + public static transient String TYPE = "de.bmotionstudio.gef.editor.text"; + + protected String bmachine, language, version; + + protected BMotionRuler leftRuler, topRuler; + + private boolean rulersVisibility, snapToGeometry, gridEnabled; + + private transient List<String> allBControlIDs; + + public List<String> getAllBControlIDs() { + if (allBControlIDs == null) + allBControlIDs = getAllBControlNames(); + return allBControlIDs; + } + + private transient Boolean isRunning; + + private transient Animation animation; + + private transient IFile projectFile; + + private transient ArrayList<IAddErrorListener> errorListener; + + private transient Thread operationSchedulerThread; + + private ArrayList<PredicateOperation> schedulerOperations; + + public Visualization(String bmachine, String language, String version) { + super(null); + setVisualization(this); + this.rulersVisibility = true; + this.bmachine = bmachine; + this.language = language; + this.version = version; + this.errorListener = new ArrayList<IAddErrorListener>(); + this.isRunning = false; + createRulers(); + ButtonGroupHelper.reset(); + } + + @Override + protected Object readResolve() { + super.readResolve(); + this.isRunning = false; + populateVisualization(this); + createRulers(); + this.errorListener = new ArrayList<IAddErrorListener>(); + ButtonGroupHelper.reset(); + // this.errorMessages = new ArrayList<ErrorMessage>(); + // setAttributeValue(AttributeConstants.ATTRIBUTE_ID, "surface", false); + return this; + } + + public void startOperationScheduler() { + + if (!getSchedulerOperations().isEmpty()) { + + operationSchedulerThread = new Thread(new Runnable() { + public void run() { + while (true) { + + for (PredicateOperation p : getSchedulerOperations()) { + + if (animation.getCurrentStateOperation(p + .getOperationName()) != null) { + + try { + + String fpredicate = "1=1"; + + if (p.getPredicate().length() > 0) { + fpredicate = p.getPredicate(); + } + + Operation op = GetOperationByPredicateCommand + .getOperation(animation + .getAnimator(), animation + .getState().getId(), p + .getOperationName(), + fpredicate); + ExecuteOperationCommand.executeOperation( + animation.getAnimator(), op); + + } catch (ProBException e) { + break; + } catch (BException e) { + break; + } + + } + + } + + try { + Thread.sleep(500); + } catch (InterruptedException e) { + break; + } + + } + } + }); + operationSchedulerThread.start(); + + } + + } + + public void stopOperationScheduler() { + if (operationSchedulerThread != null) + operationSchedulerThread.interrupt(); + } + + public void setIsRunning(Boolean bol) { + this.isRunning = bol; + } + + public Boolean isRunning() { + return isRunning; + } + + public IFile getProjectFile() { + return projectFile; + } + + public void setProjectFile(IFile pf) { + projectFile = pf; + } + + public String getMachineName() { + return this.bmachine; + } + + public void setMachineName(String machineName) { + this.bmachine = machineName; + } + + public String getLanguage() { + return this.language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public void setAnimation(Animation animation) { + this.animation = animation; + } + + public Animation getAnimation() { + return this.animation; + } + + public List<String> getAllBControlNames() { + return getAllBControlNames(getChildrenArray()); + } + + private List<String> getAllBControlNames(List<BControl> children) { + List<String> list = new ArrayList<String>(); + for (BControl bcontrol : children) { + list.add(bcontrol + .getAttributeValue(AttributeConstants.ATTRIBUTE_ID) + .toString()); + if (bcontrol.getChildrenArray().size() > 0) { + list.addAll(getAllBControlNames(bcontrol.getChildrenArray())); + } + } + return list; + } + + public String getMaxIDString(String type) { + String newID = getMaxID(type, 0, getAllBControlIDs()); + getAllBControlIDs().add(newID); + return newID; + } + + // old method + private String getMaxID(String type, int count, List<String> allIDs) { + String newID = "control_" + count; + if (allIDs.contains(newID)) { + return getMaxID(type, (count + 1), allIDs); + } else { + return newID; + } + } + + // TODO: Reimplement me!!! + public boolean checkIfIdExists(String ID) { + // if (getVariableList().hasEntry(ID) == true) + // return true; + // if (getConstantList().hasEntry(ID) == true) + // return true; + return getAllBControlNames().contains(ID); + } + + public BControl getBControl(String ID) { + return getBControl(ID, getChildrenArray()); + } + + private BControl getBControl(String ID, List<BControl> children) { + for (BControl bcontrol : children) { + if (bcontrol.getID().equals(ID)) { + return bcontrol; + } + if (bcontrol.getChildrenArray().size() > 0) { + BControl childControl = getBControl(ID, + bcontrol.getChildrenArray()); + if (childControl != null) + return childControl; + } + } + return null; + } + + public BMotionRuler getRuler(int orientation) { + BMotionRuler result = null; + switch (orientation) { + case PositionConstants.NORTH: + result = topRuler; + break; + case PositionConstants.WEST: + result = leftRuler; + break; + } + return result; + } + + public BMotionRuler getTopRuler() { + return topRuler; + } + + public void setTopRuler(BMotionRuler topRuler) { + this.topRuler = topRuler; + } + + public BMotionRuler getLeftRuler() { + return leftRuler; + } + + public void setLeftRuler(BMotionRuler leftRuler) { + this.leftRuler = leftRuler; + } + + protected void createRulers() { + if (leftRuler == null) + leftRuler = new BMotionRuler(false); + if (topRuler == null) + topRuler = new BMotionRuler(true); + } + + public void setRulerVisibility(boolean newValue) { + rulersVisibility = newValue; + } + + public void setGridEnabled(boolean isEnabled) { + gridEnabled = isEnabled; + } + + public void setSnapToGeometry(boolean isEnabled) { + snapToGeometry = isEnabled; + } + + public boolean getRulerVisibility() { + return rulersVisibility; + } + + public boolean isGridEnabled() { + return gridEnabled; + } + + public boolean isSnapToGeometryEnabled() { + return snapToGeometry; + } + + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + return null; + } + + public void addErrorListener(IAddErrorListener listener) { + this.errorListener.add(listener); + } + + public void removeErrorListener(IAddErrorListener listener) { + this.errorListener.remove(listener); + } + + public void setSchedulerOperations( + ArrayList<PredicateOperation> schedulerOperations) { + this.schedulerOperations = schedulerOperations; + } + + public ArrayList<PredicateOperation> getSchedulerOperations() { + if (this.schedulerOperations == null) + this.schedulerOperations = new ArrayList<PredicateOperation>(); + return this.schedulerOperations; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String getType() { + return TYPE; + } + + @Override + protected void initAttributes() { + } + + @Override + public boolean canHaveChildren() { + return true; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java index 8bf29b1c02cd753f7c47e624616fd1bb31e1995b..91e73bff97e9777486da75c13b95de080b142937 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java @@ -1,343 +1,343 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.part; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map.Entry; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.draw2d.ButtonModel; -import org.eclipse.draw2d.ChangeEvent; -import org.eclipse.draw2d.ChangeListener; -import org.eclipse.draw2d.ChopboxAnchor; -import org.eclipse.draw2d.ConnectionAnchor; -import org.eclipse.draw2d.Figure; -import org.eclipse.draw2d.FlowLayout; -import org.eclipse.draw2d.IFigure; -import org.eclipse.gef.ConnectionEditPart; -import org.eclipse.gef.NodeEditPart; -import org.eclipse.gef.Request; -import org.eclipse.gef.RequestConstants; -import org.eclipse.gef.editparts.AbstractGraphicalEditPart; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; - -import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; -import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; -import de.bmotionstudio.gef.editor.library.AbstractLibraryCommand; -import de.bmotionstudio.gef.editor.library.AttributeRequest; -import de.bmotionstudio.gef.editor.model.BConnection; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.Visualization; -import de.bmotionstudio.gef.editor.observer.IObserverListener; -import de.bmotionstudio.gef.editor.observer.Observer; - -public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart - implements PropertyChangeListener, IObserverListener, IAdaptable, - NodeEditPart { - - private final Cursor cursorHover = new Cursor(Display.getCurrent(), - SWT.CURSOR_HAND); - - protected ConnectionAnchor anchor; - - private ChangeListener changeListener = new ChangeListener() { - @Override - public void handleStateChanged(ChangeEvent event) { - if (getCastedModel().hasEvent(AttributeConstants.EVENT_MOUSECLICK)) { - if (event.getPropertyName().equals( - ButtonModel.MOUSEOVER_PROPERTY)) - getFigure().setCursor(cursorHover); - if (event.getPropertyName() - .equals(ButtonModel.PRESSED_PROPERTY)) { - AbstractBMotionFigure f = (AbstractBMotionFigure) getFigure(); - if (f.getModel().isPressed()) - executeEvent(AttributeConstants.EVENT_MOUSECLICK); - } - } - } - }; - - private String[] layoutAttributes = { BControl.PROPERTY_LAYOUT, - BControl.PROPERTY_LOCATION, AttributeConstants.ATTRIBUTE_X, - AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, - AttributeConstants.ATTRIBUTE_HEIGHT }; - - public void activate() { - if (!isActive()) { - super.activate(); - ((BControl) getModel()).addPropertyChangeListener(this); - ((BControl) getModel()).addObserverListener(this); - if (getFigure() instanceof AbstractBMotionFigure) { - AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); - if (isRunning()) - af.addChangeListener(changeListener); - af.activateFigure(); - } - } - } - - public void deactivate() { - if (isActive()) { - super.deactivate(); - ((BControl) getModel()).removePropertyChangeListener(this); - ((BControl) getModel()).removeObserverListener(this); - if (getFigure() instanceof AbstractBMotionFigure) { - AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); - if (isRunning()) - af.removeChangeListener(changeListener); - af.deactivateFigure(); - } - } - } - - protected abstract IFigure createEditFigure(); - - @Override - protected void createEditPolicies() { - if (isRunning()) - prepareRunPolicies(); - else - prepareEditPolicies(); - } - - protected abstract void prepareEditPolicies(); - - protected abstract void prepareRunPolicies(); - - protected Boolean isRunning() { - return ((BControl) getModel()).getVisualization().isRunning(); - } - - @Override - protected IFigure createFigure() { - final IFigure figure = createEditFigure(); - IFigure toolTipFigure = getToolTip(); - if (toolTipFigure != null) - figure.setToolTip(toolTipFigure); - if (!isRunning()) { - if (figure instanceof AbstractBMotionFigure) { - ((AbstractBMotionFigure) figure).setEnabled(false); - } - } - return figure; - } - - @Override - public void performRequest(Request req) { - if (!isRunning()) { - if (req.getType().equals(RequestConstants.REQ_OPEN)) { - try { - IWorkbenchPage page = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); - page.showView(IPageLayout.ID_PROP_SHEET); - } catch (PartInitException e) { - e.printStackTrace(); - } - } - } - } - - @Override - protected void refreshVisuals() { - IFigure figure = getFigure(); - BControl model = (BControl) getModel(); - for (Entry<String, AbstractAttribute> e : model.getAttributes() - .entrySet()) { - PropertyChangeEvent evt = new PropertyChangeEvent(model, - e.getKey(), null, e.getValue().getValue()); - refreshEditFigure(figure, model, evt); - } - refreshEditLayout(figure, model); - } - - public abstract void refreshEditFigure(IFigure figure, BControl model, - PropertyChangeEvent pEvent); - - protected void refreshEditLayout(IFigure figure, BControl control) { - if (!(control instanceof Visualization)) { - if (getFigure().getParent() != null) - getFigure().getParent().setConstraint((IFigure) figure, - control.getLayout()); - getFigure().setPreferredSize(control.getDimension()); - } - } - - @Override - public void propertyChange(final PropertyChangeEvent evt) { - final IFigure figure = (IFigure) getFigure(); - final BControl model = (BControl) getModel(); - String propName = evt.getPropertyName(); - - if (BControl.SOURCE_CONNECTIONS_PROP.equals(propName)) { - refreshSourceConnections(); - } else if (BControl.TARGET_CONNECTIONS_PROP.equals(propName)) { - refreshTargetConnections(); - } - if (propName.equals(BControl.PROPERTY_ADD) - || propName.equals(BControl.PROPERTY_REMOVE)) { - refreshChildren(); - } else if (Arrays.asList(layoutAttributes).contains(propName)) { - // Layout attribute - if (isRunning()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - refreshEditLayout(figure, model); - } - }); - } else { - refreshEditLayout(figure, model); - } - } else { - - // Custom attribute - if (isRunning()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - refreshEditFigure(figure, model, evt); - } - }); - } else { - refreshEditFigure(figure, model, evt); - } - } - } - - public List<BControl> getModelChildren() { - return new ArrayList<BControl>(); - } - - public void executeEvent(String event) { - getCastedModel().executeEvent(event); - } - - protected IFigure getToolTip() { - - Figure fig = new Figure(); - fig.setLayoutManager(new FlowLayout()); - - Collection<Observer> observerList = ((BControl) getModel()) - .getObservers().values(); - for (Observer observer : observerList) { - IFigure observerFigure = observer.getToolTip((BControl) getModel()); - if (observerFigure != null) { - fig.add(observerFigure); - } - } - - return fig; - - } - - @Override - public void addedObserver(BControl control, Observer observer) { - // Update Tooltip - getFigure().setToolTip(getToolTip()); - } - - @Override - public void removedObserver(BControl control) { - - } - - public AbstractLibraryCommand getLibraryCommand(AttributeRequest request) { - return null; - } - - protected BControl getCastedModel() { - return (BControl) getModel(); - } - - protected ConnectionAnchor getConnectionAnchor() { - if (anchor == null) { - anchor = new ChopboxAnchor(getFigure()); - } - return anchor; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections - * () - */ - protected List<BConnection> getModelSourceConnections() { - return getCastedModel().getSourceConnections(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections - * () - */ - protected List<BConnection> getModelTargetConnections() { - return getCastedModel().getTargetConnections(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef - * .ConnectionEditPart) - */ - public ConnectionAnchor getSourceConnectionAnchor( - ConnectionEditPart connection) { - return getConnectionAnchor(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef - * .Request) - */ - public ConnectionAnchor getSourceConnectionAnchor(Request request) { - return getConnectionAnchor(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef - * .ConnectionEditPart) - */ - public ConnectionAnchor getTargetConnectionAnchor( - ConnectionEditPart connection) { - return getConnectionAnchor(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef - * .Request) - */ - public ConnectionAnchor getTargetConnectionAnchor(Request request) { - return getConnectionAnchor(); - } - -} +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.part; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; +import org.eclipse.draw2d.ChopboxAnchor; +import org.eclipse.draw2d.ConnectionAnchor; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.FlowLayout; +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.NodeEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; +import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; +import de.bmotionstudio.gef.editor.library.AbstractLibraryCommand; +import de.bmotionstudio.gef.editor.library.AttributeRequest; +import de.bmotionstudio.gef.editor.model.BConnection; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.Visualization; +import de.bmotionstudio.gef.editor.observer.IObserverListener; +import de.bmotionstudio.gef.editor.observer.Observer; + +public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart + implements PropertyChangeListener, IObserverListener, IAdaptable, + NodeEditPart { + + private final Cursor cursorHover = new Cursor(Display.getCurrent(), + SWT.CURSOR_HAND); + + protected ConnectionAnchor anchor; + + private ChangeListener changeListener = new ChangeListener() { + @Override + public void handleStateChanged(ChangeEvent event) { + if (getCastedModel().hasEvent(AttributeConstants.EVENT_MOUSECLICK)) { + if (event.getPropertyName().equals( + ButtonModel.MOUSEOVER_PROPERTY)) + getFigure().setCursor(cursorHover); + } + if (event.getPropertyName() + .equals(ButtonModel.PRESSED_PROPERTY)) { + AbstractBMotionFigure f = (AbstractBMotionFigure) getFigure(); + if (f.getModel().isPressed()) + executeEvent(AttributeConstants.EVENT_MOUSECLICK); + } + } + }; + + private String[] layoutAttributes = { BControl.PROPERTY_LAYOUT, + BControl.PROPERTY_LOCATION, AttributeConstants.ATTRIBUTE_X, + AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, + AttributeConstants.ATTRIBUTE_HEIGHT }; + + public void activate() { + if (!isActive()) { + super.activate(); + ((BControl) getModel()).addPropertyChangeListener(this); + ((BControl) getModel()).addObserverListener(this); + if (getFigure() instanceof AbstractBMotionFigure) { + AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); + if (isRunning()) + af.addChangeListener(changeListener); + af.activateFigure(); + } + } + } + + public void deactivate() { + if (isActive()) { + super.deactivate(); + ((BControl) getModel()).removePropertyChangeListener(this); + ((BControl) getModel()).removeObserverListener(this); + if (getFigure() instanceof AbstractBMotionFigure) { + AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); + if (isRunning()) + af.removeChangeListener(changeListener); + af.deactivateFigure(); + } + } + } + + protected abstract IFigure createEditFigure(); + + @Override + protected void createEditPolicies() { + if (isRunning()) + prepareRunPolicies(); + else + prepareEditPolicies(); + } + + protected abstract void prepareEditPolicies(); + + protected abstract void prepareRunPolicies(); + + protected Boolean isRunning() { + return ((BControl) getModel()).getVisualization().isRunning(); + } + + @Override + protected IFigure createFigure() { + final IFigure figure = createEditFigure(); + IFigure toolTipFigure = getToolTip(); + if (toolTipFigure != null) + figure.setToolTip(toolTipFigure); + if (!isRunning()) { + if (figure instanceof AbstractBMotionFigure) { + ((AbstractBMotionFigure) figure).setEnabled(false); + } + } + return figure; + } + + @Override + public void performRequest(Request req) { + if (!isRunning()) { + if (req.getType().equals(RequestConstants.REQ_OPEN)) { + try { + IWorkbenchPage page = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + page.showView(IPageLayout.ID_PROP_SHEET); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } + } + + @Override + protected void refreshVisuals() { + IFigure figure = getFigure(); + BControl model = (BControl) getModel(); + for (Entry<String, AbstractAttribute> e : model.getAttributes() + .entrySet()) { + PropertyChangeEvent evt = new PropertyChangeEvent(model, + e.getKey(), null, e.getValue().getValue()); + refreshEditFigure(figure, model, evt); + } + refreshEditLayout(figure, model); + } + + public abstract void refreshEditFigure(IFigure figure, BControl model, + PropertyChangeEvent pEvent); + + protected void refreshEditLayout(IFigure figure, BControl control) { + if (!(control instanceof Visualization)) { + if (getFigure().getParent() != null) + getFigure().getParent().setConstraint((IFigure) figure, + control.getLayout()); + getFigure().setPreferredSize(control.getDimension()); + } + } + + @Override + public void propertyChange(final PropertyChangeEvent evt) { + final IFigure figure = (IFigure) getFigure(); + final BControl model = (BControl) getModel(); + String propName = evt.getPropertyName(); + + if (BControl.SOURCE_CONNECTIONS_PROP.equals(propName)) { + refreshSourceConnections(); + } else if (BControl.TARGET_CONNECTIONS_PROP.equals(propName)) { + refreshTargetConnections(); + } + if (propName.equals(BControl.PROPERTY_ADD) + || propName.equals(BControl.PROPERTY_REMOVE)) { + refreshChildren(); + } else if (Arrays.asList(layoutAttributes).contains(propName)) { + // Layout attribute + if (isRunning()) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + refreshEditLayout(figure, model); + } + }); + } else { + refreshEditLayout(figure, model); + } + } else { + + // Custom attribute + if (isRunning()) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + refreshEditFigure(figure, model, evt); + } + }); + } else { + refreshEditFigure(figure, model, evt); + } + } + } + + public List<BControl> getModelChildren() { + return new ArrayList<BControl>(); + } + + public void executeEvent(String event) { + getCastedModel().executeEvent(event); + } + + protected IFigure getToolTip() { + + Figure fig = new Figure(); + fig.setLayoutManager(new FlowLayout()); + + Collection<Observer> observerList = ((BControl) getModel()) + .getObservers().values(); + for (Observer observer : observerList) { + IFigure observerFigure = observer.getToolTip((BControl) getModel()); + if (observerFigure != null) { + fig.add(observerFigure); + } + } + + return fig; + + } + + @Override + public void addedObserver(BControl control, Observer observer) { + // Update Tooltip + getFigure().setToolTip(getToolTip()); + } + + @Override + public void removedObserver(BControl control) { + + } + + public AbstractLibraryCommand getLibraryCommand(AttributeRequest request) { + return null; + } + + protected BControl getCastedModel() { + return (BControl) getModel(); + } + + protected ConnectionAnchor getConnectionAnchor() { + if (anchor == null) { + anchor = new ChopboxAnchor(getFigure()); + } + return anchor; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections + * () + */ + protected List<BConnection> getModelSourceConnections() { + return getCastedModel().getSourceConnections(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections + * () + */ + protected List<BConnection> getModelTargetConnections() { + return getCastedModel().getTargetConnections(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef + * .ConnectionEditPart) + */ + public ConnectionAnchor getSourceConnectionAnchor( + ConnectionEditPart connection) { + return getConnectionAnchor(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef + * .Request) + */ + public ConnectionAnchor getSourceConnectionAnchor(Request request) { + return getConnectionAnchor(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef + * .ConnectionEditPart) + */ + public ConnectionAnchor getTargetConnectionAnchor( + ConnectionEditPart connection) { + return getConnectionAnchor(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef + * .Request) + */ + public ConnectionAnchor getTargetConnectionAnchor(Request request) { + return getConnectionAnchor(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BCheckboxPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BCheckboxPart.java index a5e6b73978208d8d607bb74dbbaa969e22d3938a..a0efb30c21906df461032231558d23d546573821 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BCheckboxPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BCheckboxPart.java @@ -8,6 +8,9 @@ package de.bmotionstudio.gef.editor.part; import java.beans.PropertyChangeEvent; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; @@ -24,11 +27,58 @@ import de.bmotionstudio.gef.editor.editpolicy.AppDeletePolicy; import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy; import de.bmotionstudio.gef.editor.editpolicy.CustomDirectEditPolicy; import de.bmotionstudio.gef.editor.editpolicy.RenamePolicy; +import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; import de.bmotionstudio.gef.editor.figure.CheckboxFigure; import de.bmotionstudio.gef.editor.model.BControl; public class BCheckboxPart extends AppAbstractEditPart { + private ChangeListener changeListener = new ChangeListener() { + @Override + public void handleStateChanged(ChangeEvent event) { + + if (event.getPropertyName().equals(ButtonModel.PRESSED_PROPERTY)) { + + BControl control = (BControl) getModel(); + + // Recheck observer after click + control.getVisualization().getAnimation().checkObserver(); + + if (Boolean.valueOf(control.getAttributeValue( + AttributeConstants.ATTRIBUTE_CHECKED).toString())) { + control.setAttributeValue( + AttributeConstants.ATTRIBUTE_CHECKED, false); + } else { + control.setAttributeValue( + AttributeConstants.ATTRIBUTE_CHECKED, true); + } + + } + + } + + }; + + @Override + public void activate() { + super.activate(); + if (isRunning()) { + if (getFigure() instanceof AbstractBMotionFigure) + ((AbstractBMotionFigure) getFigure()) + .addChangeListener(changeListener); + } + } + + @Override + public void deactivate() { + if (isRunning()) { + if (getFigure() instanceof AbstractBMotionFigure) + ((AbstractBMotionFigure) getFigure()) + .removeChangeListener(changeListener); + } + super.deactivate(); + } + @Override protected IFigure createEditFigure() { CheckboxFigure fig = new CheckboxFigure(); @@ -71,6 +121,10 @@ public class BCheckboxPart extends AppAbstractEditPart { .getDefault(), rgbText)); } + if (aID.equals(AttributeConstants.ATTRIBUTE_ENABLED)) + ((CheckboxFigure) figure).setBtEnabled(Boolean.valueOf(value + .toString())); + } @Override diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BRadioButtonPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BRadioButtonPart.java index 21c60a92a8a0d2c76e17e8db8ce6d7140d264153..f4ad340be62284ad1c6ce9d3a390393c3160e08a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BRadioButtonPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BRadioButtonPart.java @@ -7,7 +7,11 @@ package de.bmotionstudio.gef.editor.part; import java.beans.PropertyChangeEvent; +import java.util.Collection; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; @@ -24,11 +28,63 @@ import de.bmotionstudio.gef.editor.editpolicy.AppDeletePolicy; import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy; import de.bmotionstudio.gef.editor.editpolicy.CustomDirectEditPolicy; import de.bmotionstudio.gef.editor.editpolicy.RenamePolicy; +import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; import de.bmotionstudio.gef.editor.figure.RadioButtonFigure; import de.bmotionstudio.gef.editor.model.BControl; public class BRadioButtonPart extends AppAbstractEditPart { + private ChangeListener changeListener = new ChangeListener() { + @Override + public void handleStateChanged(ChangeEvent event) { + + if (event.getPropertyName().equals(ButtonModel.PRESSED_PROPERTY)) { + + BControl control = (BControl) getModel(); + + // Recheck observer after click + control.getVisualization().getAnimation().checkObserver(); + + // Set correct image of Radiobutton + String btgroupid = control.getAttributeValue( + AttributeConstants.ATTRIBUTE_BUTTONGROUP).toString(); + if (!btgroupid.trim().equals("")) { + Collection<BControl> btGroup = ButtonGroupHelper + .getButtonGroup(btgroupid); + for (BControl c : btGroup) { + c.setAttributeValue( + AttributeConstants.ATTRIBUTE_CHECKED, false); + } + } + control.setAttributeValue(AttributeConstants.ATTRIBUTE_CHECKED, + true); + + } + + } + + }; + + @Override + public void activate() { + super.activate(); + if (isRunning()) { + if (getFigure() instanceof AbstractBMotionFigure) + ((AbstractBMotionFigure) getFigure()) + .addChangeListener(changeListener); + } + } + + @Override + public void deactivate() { + if (isRunning()) { + if (getFigure() instanceof AbstractBMotionFigure) + ((AbstractBMotionFigure) getFigure()) + .removeChangeListener(changeListener); + } + super.deactivate(); + } + @Override protected IFigure createEditFigure() { RadioButtonFigure fig = new RadioButtonFigure(); @@ -78,6 +134,10 @@ public class BRadioButtonPart extends AppAbstractEditPart { } } + if (aID.equals(AttributeConstants.ATTRIBUTE_ENABLED)) + ((RadioButtonFigure) figure).setBtEnabled(Boolean.valueOf(value + .toString())); + } @Override