diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java index 956819493c3a5554155a51cf5f936bd59fd19356..8aa9b37d2045776523ff961f947763692a15901d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java @@ -5,18 +5,29 @@ * */ package de.bmotionstudio.gef.editor.editpolicy; +import java.util.List; + import org.eclipse.draw2d.FlowLayout; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.draw2d.geometry.Translatable; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gef.editpolicies.FlowLayoutEditPolicy; +import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gef.requests.CreateRequest; import de.bmotionstudio.gef.editor.command.AddCommand; +import de.bmotionstudio.gef.editor.command.BControlChangeLayoutCommand; import de.bmotionstudio.gef.editor.command.ReorderPartCommand; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.BTable; @@ -25,6 +36,16 @@ import de.bmotionstudio.gef.editor.model.BTableColumn; public class BMotionStudioFlowEditPolicy extends FlowLayoutEditPolicy { + private static final Dimension PREFERRED_SIZE = new Dimension(-1, -1); + + /** + * Constant being used to indicate that upon creation (or during move) a + * size was not specified. + * + * @since 3.7 + */ + protected static final Dimension UNSPECIFIED_SIZE = new Dimension(); + @Override protected Command createAddCommand(EditPart child, EditPart after) { @@ -44,6 +65,165 @@ public class BMotionStudioFlowEditPolicy extends FlowLayoutEditPolicy { return null; } + @Override + public Command getCommand(Request request) { + if (REQ_RESIZE_CHILDREN.equals(request.getType())) + return getResizeChildrenCommand((ChangeBoundsRequest) request); + return super.getCommand(request); + } + + protected Command getResizeChildrenCommand(ChangeBoundsRequest request) { + CompoundCommand resize = new CompoundCommand(); + Command c; + GraphicalEditPart child; + List<?> children = request.getEditParts(); + for (int i = 0; i < children.size(); i++) { + child = (GraphicalEditPart) children.get(i); + c = createChangeConstraintCommand( + request, + child, + translateToModelConstraint(getConstraintFor(request, child))); + resize.add(c); + } + return resize.unwrap(); + } + + protected Command createChangeConstraintCommand( + ChangeBoundsRequest request, EditPart child, Object constraint) { + BControlChangeLayoutCommand cmd = new BControlChangeLayoutCommand(); + cmd.setModel(child.getModel()); + cmd.setConstraint((Rectangle) constraint); + return cmd; + } + + /** + * Generates a draw2d constraint object for the given + * <code>ChangeBoundsRequest</code> and child EditPart by delegating to + * {@link #getConstraintFor(Request, GraphicalEditPart, Rectangle)}. + * + * The rectangle being passed over to + * {@link #getConstraintFor(Request, GraphicalEditPart, Rectangle)} is + * calculated based on the child figure's current bounds and the + * ChangeBoundsRequest's move and resize deltas. It is made layout-relative + * by using {@link #translateFromAbsoluteToLayoutRelative(Translatable)} + * before calling + * {@link #getConstraintFor(Request, GraphicalEditPart, Rectangle)}. + * + * @param request + * the ChangeBoundsRequest + * @param child + * the child EditPart for which the constraint should be + * generated + * @return the draw2d constraint + */ + protected Object getConstraintFor(ChangeBoundsRequest request, + GraphicalEditPart child) { + Rectangle locationAndSize = new PrecisionRectangle(child.getFigure() + .getBounds()); + child.getFigure().translateToAbsolute(locationAndSize); + locationAndSize = request.getTransformedRectangle(locationAndSize); + translateFromAbsoluteToLayoutRelative(locationAndSize); + return getConstraintFor(request, child, locationAndSize); + } + + /** + * Responsible of generating a draw2d constraint for the given Rectangle, + * which represents the already transformed (layout-relative) position and + * size of the given Request. + * + * By default, this method delegates to {@link #getConstraintFor(Point)} or + * {@link #getConstraintFor(Rectangle)}, dependent on whether the size of + * the rectangle is an {@link #UNSPECIFIED_SIZE} or not. + * + * Subclasses may overwrite this method in case they need the request or the + * edit part (which will of course not be set during creation) to calculate + * a layout constraint for the request. + * + * @param rectangle + * the Rectangle relative to the {@link #getLayoutOrigin() layout + * origin} + * @return the constraint + * @since 3.7 + */ + protected Object getConstraintFor(Request request, GraphicalEditPart child, + Rectangle rectangle) { + if (UNSPECIFIED_SIZE.equals(rectangle.getSize())) { + return getConstraintFor(rectangle.getLocation()); + } + return getConstraintFor(rectangle); + } + + /** + * Generates a draw2d constraint for the given <code>CreateRequest</code> by + * delegating to + * {@link #getConstraintFor(Request, GraphicalEditPart, Rectangle)}. + * + * If the CreateRequest has a size, is used during size-on-drop creation, a + * Rectangle of the request's location and size is passed with the + * delegation. Otherwise, a rectangle with the request's location and an + * empty size (0,0) is passed over. + * <P> + * The CreateRequest's location is relative to the Viewer. The location is + * made layout-relative by using + * {@link #translateFromAbsoluteToLayoutRelative(Translatable)} before + * calling {@link #getConstraintFor(Request, GraphicalEditPart, Rectangle)}. + * + * @param request + * the CreateRequest + * @return a draw2d constraint + */ + protected Object getConstraintFor(CreateRequest request) { + Rectangle locationAndSize = null; + if (request.getSize() == null || request.getSize().isEmpty()) { + locationAndSize = new PrecisionRectangle(request.getLocation(), + UNSPECIFIED_SIZE); + } else { + locationAndSize = new PrecisionRectangle(request.getLocation(), + request.getSize()); + } + translateFromAbsoluteToLayoutRelative(locationAndSize); + return getConstraintFor(request, null, locationAndSize); + } + + /** + * Generates a draw2d constraint given a <code>Point</code>. This method is + * called during creation, when only a mouse location is available, as well + * as during move, in case no resizing is involved. + * + * @param point + * the Point relative to the {@link #getLayoutOrigin() layout + * origin} + * @return the constraint + */ + protected Object getConstraintFor(Point p) { + return new Rectangle(p, PREFERRED_SIZE); + } + + /** + * Generates a draw2d constraint given a <code>Rectangle</code>. This method + * is called during most operations. + * + * @param rect + * the Rectangle relative to the {@link #getLayoutOrigin() layout + * origin} + * @return the constraint + */ + protected Object getConstraintFor(Rectangle r) { + return new Rectangle(r); + } + + /** + * Converts a constraint from the format used by LayoutManagers, to the form + * stored in the model. + * + * @param figureConstraint + * the draw2d constraint + * @return the model constraint + */ + protected Object translateToModelConstraint(Object figureConstraint) { + return figureConstraint; + } + /** * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart) */ @@ -57,7 +237,6 @@ public class BMotionStudioFlowEditPolicy extends FlowLayoutEditPolicy { @Override protected Command createMoveChildCommand(EditPart child, EditPart after) { - BControl childModel = (BControl) child.getModel(); BControl parentModel = (BControl) getHost().getModel(); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/EventBHelper.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/EventBHelper.java index 8e38321cd1a05a202ef222c752bcd764c728ffc3..4fd4504a7ddb5e6a299050aa56703ae0875b9e47 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/EventBHelper.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/EventBHelper.java @@ -11,8 +11,8 @@ import java.util.Collections; import java.util.List; import org.eclipse.core.resources.IFile; -import org.eventb.core.IMachineRoot; import org.eventb.core.ISCConstant; +import org.eventb.core.ISCContextRoot; import org.eventb.core.ISCEvent; import org.eventb.core.ISCGuard; import org.eventb.core.ISCInternalContext; @@ -20,6 +20,10 @@ import org.eventb.core.ISCInvariant; import org.eventb.core.ISCMachineRoot; import org.eventb.core.ISCParameter; import org.eventb.core.ISCVariable; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.basis.ContextRoot; +import org.eventb.core.basis.EventBRoot; +import org.eventb.core.basis.MachineRoot; import org.rodinp.core.IRodinFile; import org.rodinp.core.IRodinProject; import org.rodinp.core.RodinCore; @@ -29,16 +33,17 @@ import de.bmotionstudio.gef.editor.model.Visualization; import de.prob.logging.Logger; public final class EventBHelper { + + private static FormulaFactory formularFactory = FormulaFactory.getDefault(); - public static ISCMachineRoot getCorrespondingFile(IFile file, + public static EventBRoot getCorrespondingFile(IFile file, String machineFileName) { IRodinProject rProject = RodinCore.valueOf(file.getProject()); - ISCMachineRoot machineRoot = null; + EventBRoot machineRoot = null; if (rProject != null) { IRodinFile rFile = rProject.getRodinFile(machineFileName); - if (rFile != null && rFile.getRoot() instanceof IMachineRoot) - machineRoot = ((IMachineRoot) rFile.getRoot()) - .getSCMachineRoot(); + if (rFile != null && rFile.getRoot() instanceof EventBRoot) + machineRoot = (EventBRoot) rFile.getRoot(); } return machineRoot; } @@ -50,9 +55,10 @@ public final class EventBHelper { if (visualization.getLanguage().equals("EventB")) { - ISCMachineRoot machineRoot = null; - machineRoot = getCorrespondingFile(visualization.getProjectFile(), + EventBRoot correspondingFile = getCorrespondingFile( + visualization.getProjectFile(), visualization.getMachineName()); + ISCMachineRoot machineRoot = correspondingFile.getSCMachineRoot(); if (machineRoot != null) { @@ -98,10 +104,9 @@ public final class EventBHelper { public static List<MachineContentObject> getVariables( Visualization visualization) { - ISCMachineRoot machineRoot = null; - - machineRoot = getCorrespondingFile(visualization.getProjectFile(), - visualization.getMachineName()); + EventBRoot correspondingFile = getCorrespondingFile( + visualization.getProjectFile(), visualization.getMachineName()); + ISCMachineRoot machineRoot = correspondingFile.getSCMachineRoot(); ISCVariable[] vars = null; ArrayList<MachineContentObject> tmpSet = new ArrayList<MachineContentObject>(); @@ -113,6 +118,7 @@ public final class EventBHelper { MachineContentObject machinevar = new MachineContentObject( var.getIdentifierString()); + machinevar.setType(var.getType(formularFactory)); tmpSet.add(machinevar); } @@ -131,10 +137,10 @@ public final class EventBHelper { public static List<MachineContentObject> getInvariants( Visualization visualization) { - ISCMachineRoot machineRoot = null; - - machineRoot = getCorrespondingFile(visualization.getProjectFile(), + EventBRoot correspondingFile = getCorrespondingFile( + visualization.getProjectFile(), visualization.getMachineName()); + ISCMachineRoot machineRoot = correspondingFile.getSCMachineRoot(); ISCInvariant[] invariants = null; ArrayList<MachineContentObject> tmpSet = new ArrayList<MachineContentObject>(); @@ -163,24 +169,40 @@ public final class EventBHelper { public static List<MachineContentObject> getConstants( Visualization visualization) { - ISCMachineRoot machineRoot = null; - - machineRoot = getCorrespondingFile(visualization.getProjectFile(), - visualization.getMachineName()); + EventBRoot correspondingFile = getCorrespondingFile( + visualization.getProjectFile(), visualization.getMachineName()); ArrayList<MachineContentObject> tmpSet = new ArrayList<MachineContentObject>(); - try { + if (correspondingFile instanceof MachineRoot) { + + ISCMachineRoot machineRoot = correspondingFile + .getSCMachineRoot(); - ISCInternalContext[] seenContexts = machineRoot.getSCSeenContexts(); - for (ISCInternalContext context : seenContexts) { + ISCInternalContext[] seenContexts = machineRoot + .getSCSeenContexts(); + for (ISCInternalContext context : seenContexts) { - for (ISCConstant constant : context.getSCConstants()) { + for (ISCConstant constant : context.getSCConstants()) { + MachineContentObject machineinv = new MachineContentObject( + constant.getIdentifierString()); + machineinv.setType(constant.getType(formularFactory)); + tmpSet.add(machineinv); + + } + + } + + } else if (correspondingFile instanceof ContextRoot) { + + ISCContextRoot contextRoot = correspondingFile + .getSCContextRoot(); + for (ISCConstant constant : contextRoot.getSCConstants()) { MachineContentObject machineinv = new MachineContentObject( constant.getIdentifierString()); + machineinv.setType(constant.getType(formularFactory)); tmpSet.add(machineinv); - } } @@ -194,6 +216,8 @@ public final class EventBHelper { } return tmpSet; + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/MachineContentObject.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/MachineContentObject.java index d032677402fc822500ba698ee4874eb6de46e371..e96ac7b06d2282ca95ac0713d56474ccc7a31b38 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/MachineContentObject.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/eventb/MachineContentObject.java @@ -6,12 +6,15 @@ package de.bmotionstudio.gef.editor.eventb; +import org.eventb.core.ast.Type; + import de.bmotionstudio.gef.editor.BindingObject; public class MachineContentObject extends BindingObject { - private String label; + private String label; + private Type type; public MachineContentObject(String label) { this.setLabel(label); @@ -27,6 +30,14 @@ public class MachineContentObject extends BindingObject { public String toString() { return this.label; - } + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java index 2dd8dd38e62e2d22abf9506745e0ff4ca0b62fc8..0ff983a25693e6393cbff7f955beabbbab333315 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java @@ -17,8 +17,8 @@ public class BTable extends BControl { super(visualization); - int numberOfColumns = 2; - int numberOfRows = 2; + int numberOfColumns = 1; + int numberOfRows = 1; CreateCommand cmd; for (int i = 0; i < numberOfColumns; i++) { @@ -49,7 +49,7 @@ public class BTable extends BControl { initAttribute(new BAttributeRows(1)); getAttributes().get(AttributeConstants.ATTRIBUTE_SIZE).setShow(false); getAttributes().get(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( - false); + true); getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable( false); getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH).setEditable( diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java index 587e2cdf6281cc14a709f88dd0bd30aa713dae02..8ee5ec9f47041b73c31888e1c1905af87a5284e0 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java @@ -32,8 +32,8 @@ public class BTableCell extends BControl { getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable( false); getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH).setEditable( - false); - getAttributes().get(AttributeConstants.ATTRIBUTE_SIZE).setShow(false); + true); + getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setShow(false); getAttributes().get(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( false); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java index ab26245d43bbb3d7019759dc228ce859ecf8974d..cf0f44bac80179efb6ec88333377fda412633c2c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java @@ -26,16 +26,10 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Text; -import org.eventb.core.ISCConstant; -import org.eventb.core.ISCInternalContext; -import org.eventb.core.ISCMachineRoot; -import org.eventb.core.ISCVariable; -import org.eventb.core.ast.FormulaFactory; import org.eventb.core.ast.PowerSetType; -import org.eventb.core.ast.Type; -import org.rodinp.core.RodinDBException; import de.bmotionstudio.gef.editor.eventb.EventBHelper; +import de.bmotionstudio.gef.editor.eventb.MachineContentObject; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.observer.ObserverWizard; @@ -93,38 +87,18 @@ public class WizardTableObserver extends ObserverWizard { ArrayList<String> relationList = new ArrayList<String>(); - try { - ISCMachineRoot machineRoot = EventBHelper.getCorrespondingFile( - getBControl().getVisualization().getProjectFile(), - getBControl().getVisualization().getMachineName()); - ISCVariable[] scVariables; - - scVariables = machineRoot.getSCVariables(); - for (ISCVariable var : scVariables) { - Type type = var.getType(FormulaFactory.getDefault()); - if (type instanceof PowerSetType) { - relationList.add(var.getElementName()); - } - } - - ISCInternalContext[] scSeenContexts = machineRoot - .getSCSeenContexts(); - for (ISCInternalContext ctx : scSeenContexts) { - - ISCConstant[] scConstants = ctx.getSCConstants(); - for (ISCConstant constant : scConstants) { - Type type = constant.getType(FormulaFactory - .getDefault()); - if (type instanceof PowerSetType) { - relationList.add(constant.getElementName()); - } - } - - } + java.util.List<MachineContentObject> constants = EventBHelper + .getConstants(getBControl().getVisualization()); + for (MachineContentObject mobj : constants) { + if (mobj.getType() instanceof PowerSetType) + relationList.add(mobj.getLabel()); + } - } catch (RodinDBException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + java.util.List<MachineContentObject> variables = EventBHelper + .getVariables(getBControl().getVisualization()); + for (MachineContentObject mobj : variables) { + if (mobj.getType() instanceof PowerSetType) + relationList.add(mobj.getLabel()); } final List list = new List(conRight, SWT.SINGLE | SWT.BORDER); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java index dba8ecf10865c8195fb1d48a36b55ac813c4d0e2..b82098acebf8e81157319b4af0bf0bedad386199 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java @@ -62,6 +62,18 @@ public class BTableCellPart extends AppAbstractEditPart { } + @Override + protected void refreshEditLayout(IFigure figure, BControl control) { + + // Set size of parent column + int width = control.getDimension().width; + control.getParent().setAttributeValue( + AttributeConstants.ATTRIBUTE_WIDTH, width); + + super.refreshEditLayout(figure, control); + + } + private void performDirectEdit() { new TextEditManager(this, new TextCellEditorLocator( (IFigure) getFigure())).show(); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java index 49cfccce4221d7aea645ef752e40062d925e844c..598b8feb8ae5ef3229c0f2369dbdf95bd015d66c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java @@ -67,12 +67,25 @@ public class BTableColumnPart extends AppAbstractEditPart { @Override protected void refreshEditLayout(IFigure figure, BControl control) { + + int width = control.getDimension().width; + + // Change width of all cells + List<BControl> cells = control.getChildrenArray(); + for (BControl cell : cells) { + cell.setAttributeValue(AttributeConstants.ATTRIBUTE_WIDTH, width, + true, true); + } + + // Notify parent table about change if (getParent() instanceof AppAbstractEditPart) { AppAbstractEditPart tablePart = (AppAbstractEditPart) getParent(); tablePart.refreshEditLayout(tablePart.getFigure(), control.getParent()); } + super.refreshEditLayout(figure, control); + } @Override