Skip to content
Snippets Groups Projects
Commit d7445ef4 authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

added resize feautre for table cells and columns

parent ceff72de
No related branches found
No related tags found
No related merge requests found
Showing with 283 additions and 70 deletions
......@@ -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();
......
......@@ -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;
......@@ -30,15 +34,16 @@ import de.prob.logging.Logger;
public final class EventBHelper {
public static ISCMachineRoot getCorrespondingFile(IFile file,
private static FormulaFactory formularFactory = FormulaFactory.getDefault();
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,28 +169,44 @@ 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();
ISCInternalContext[] seenContexts = machineRoot
.getSCSeenContexts();
for (ISCInternalContext context : seenContexts) {
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);
}
}
} catch (RodinDBException e) {
String message = "Rodin DB Exception while getting constants: "
+ e.getLocalizedMessage();
......@@ -194,6 +216,8 @@ public final class EventBHelper {
}
return tmpSet;
}
}
......@@ -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 Type type;
public MachineContentObject(String label) {
this.setLabel(label);
......@@ -29,4 +32,12 @@ public class MachineContentObject extends BindingObject {
return this.label;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}
......@@ -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(
......
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment