5
Bendpoints Gliederung RONModel anpassen RONModel anpassen ONArcFigure anpassen Commands erstellen ONArcBendPointEditPolicy erstellen ONArcBendPointEditPolicy erstellen ONArcEditPart anpassen RONModel anpassen RONModel anpassen EMF-Editor-Ansicht RONModel anpassen Ecore-Editor-Ansicht

Eclipse GEF Bendpoints Document

  • Upload
    -

  • View
    746

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Eclipse GEF Bendpoints Document

Bendpoints

Gliederung

RONModel anpassenRONModel anpassenONArcFigure anpassenCommands erstellenONArcBendPointEditPolicy erstellenONArcBendPointEditPolicy erstellenONArcEditPart anpassen

RONModel anpassenRONModel anpassenEMF-Editor-Ansicht

RONModel anpassenpEcore-Editor-Ansicht

Page 2: Eclipse GEF Bendpoints Document

RONModel anpassen RONModel anpassen

RONModel anpassen ONArcFigure anpassen

public ONArcFigure(Connection con) {public ONArcFigure(Connection con) {label = new Label("");setSourceAnchor(con.getSourceAnchor());...//BendpointConnectionRouter hinzufuegensetConnectionRouter(new(BendpointConnectionRouter());

}

Page 3: Eclipse GEF Bendpoints Document

Hilfsklasse AbstractBendPointCommandHilfsklasse AbstractBendPointCommandpublic abstract class AbstractBendpointCommand extends Command {

protected int index;protected Point location;protected ONArc onArc;protected BendPoint bendPoint;protected Dimension d1, d2;

protected Dimension getFirstRelativeDimension() {return d1; // relative Dimension zum source Node

}protected Dimension getSecondRelativeDimension() {

return d2; // relative Dimension zum target Node}}protected int getIndex() {

return index; // index von BendPoint }protected Point getLocation() {

return location;}

t t d ONA tONA () {protected ONArc getONArc() {return onArc; // ONArc zu dem BendPoint gehoert

}public void redo() {

execute();}public void setRelativeDimensions(Dimension dim1, Dimension dim2) {

d1 di 1 // R l ti Di i N dd1 = dim1; // Relative Dimension zum source Noded2 = dim2; // Relative Dimension zum target Node

}public void setIndex(int i) {

index = i; // setzt BendPoitIndex}public void setLocation(Point p) {

l tilocation = p;}public void setONArc(ONArc w) {

onArc = w;}public BendPoint getBendPoint() {

return bendPoint;}}

public void setBendPoint(BendPoint bendPoint) {this.bendPoint = bendPoint;

}}

Commands erstellenCommands erstellenpublic class CreateBendpointCommand extends AbstractBendpointCommand {

public void execute() {RonmodelFactory mfc = RONModelManager.getFactory();bendPoint = mfc.createBendPoint();//Speichern der relativen Position zum 1 Object//Speichern der relativen Position zum 1. ObjectbendPoint.getH().add(new

Integer(getFirstRelativeDimension().height));bendPoint.getW().add(new

Integer(getFirstRelativeDimension().width));Integer(getFirstRelativeDimension().width));

//Speichern der relativen Position zum 2. ObjectbendPoint.getH().add(new

Integer(getSecondRelativeDimension().height));Integer(getSecondRelativeDimension().height));bendPoint.getW().add(new

Integer(getSecondRelativeDimension().width));

//BendPoint hinzufügen//BendPoint hinzufügengetONArc().getBendPoints().add(getIndex(), bendPoint);

}

public void undo() {public void undo() {getONArc().getBendPoints().remove(bendPoint);

}}

Commands erstellenpublic class DeleteBendpointCommand

extends AbstractBendpointCommand {

public void execute() {bendPoint = (BendPoint) getONArc().getBendPoints().get(getIndex());getONArc().getBendPoints().remove(bendPoint);

}}

public void undo() {getONArc().getBendPoints().add(getIndex(), bendPoint);

}}

}

Commands erstellenpublic class MoveBendpointCommand extends AbstractBendpointCommand {p p p

public void execute() {RonmodelFactory mfc = RONModelManager.getFactory();//neuen BendPoint erzeugenBendPoint bp = mfc.createBendPoint();//setzt die relative Dimension zum source Object//setzt die relative Dimension zum source Objectbp.getH().add(new Integer(getFirstRelativeDimension().height));bp.getW().add(new Integer(getFirstRelativeDimension().width));// setzt die relative Dimension zum target Objectbp.getH().add(new Integer(getSecondRelativeDimension().height));bp.getW().add(new Integer(getSecondRelativeDimension().width));

//speichern von oldBendpointsetOldBendpoint((BendPoint) getONArc().getBendPoints().get(getIndex()));

//einfuegen von neuen Bendpoint mit neuen Position in ModelgetONArc().getBendPoints().set(getIndex(), bp);g () g () (g (), p);

}

protected BendPoint getOldBendpoint() {return bendPoint;

}

public void setOldBendpoint(BendPoint bp) {bendPoint = bp;

}

public void undo() {getONArc().getBendPoints().set(getIndex(), getOldBendpoint());

}}

Page 4: Eclipse GEF Bendpoints Document

ONArcBendPointEditPolicyONArcBendPointEditPolicy erstellen

public class ONArcBendPointEditPolicy extends BendpointEditPolicy {

protected Command getCreateBendpointCommand(BendpointRequest request) {AbstractBendpointCommand com = new CreateBendpointCommand();AbstractBendpointCommand com new CreateBendpointCommand();Point p = request.getLocation();Connection conn = getConnection();conn.translateToRelative(p);Point ref1 = conn.getSourceAnchor().getReferencePoint();Point ref1 conn.getSourceAnchor().getReferencePoint();Point ref2 = conn.getTargetAnchor().getReferencePoint();

conn.translateToRelative(ref1);conn.translateToRelative(ref2);conn.translateToRelative(ref2);

com.setRelativeDimensions(p.getDifference(ref1), p.getDifference(ref2));com.setONArc((ONArc) request.getSource().getModel());com.setIndex(request.getIndex());com.setIndex(request.getIndex());return com;

}

ONArcBendPointEditPolicyONArcBendPointEditPolicy erstellen

protected Command getDeleteBendpointCommand(BendpointRequest request) {{

AbstractBendpointCommand com = new DeleteBendpointCommand();Point p = request.getLocation();com setLocation(p);com.setLocation(p);com.setONArc((ONArc) request.getSource().getModel());com.setIndex(request.getIndex());return com;

}}

ONArcBendPointEditPolicyONArcBendPointEditPolicy erstellen

protected Command getMoveBendpointCommand(BendpointRequest request) {

MoveBendpointCommand com = new MoveBendpointCommand();Point p = request.getLocation();Connection conn = getConnection();

conn.translateToRelative(p);

com.setLocation(p);

Point ref1 = getConnection().getSourceAnchor().getReferencePoint();Point ref2 = getConnection().getTargetAnchor().getReferencePoint();

conn.translateToRelative(ref1);conn.translateToRelative(ref2);

com.setRelativeDimensions(p.getDifference(ref1), p.getDifference(ref2));com.setONArc((ONArc) request.getSource().getModel());com.setIndex(request.getIndex());

return com;}}

}

ONArcEditPart anpassenpublic class ONArcEditPart extends AbstractConnectionEditPart {...

protected void createEditPolicies() {protected void createEditPolicies() {

installEditPolicy( EditPolicy.CONNECTION_ENDPOINTS_ROLE, newONArcEndpointEditPolicy() );

installEditPolicy( EditPolicy.CONNECTION BENDPOINTS ROLE, newy y _ _ArcSelectionHandlesEditPolicy() );

installEditPolicy( EditPolicy.CONNECTION_BENDPOINTS_ROLE, newONArcBendPointEditPolicy());

installEditPolicy( EditPolicy.CONNECTION_ROLE, newONArcEditPolicy());

}}...

Page 5: Eclipse GEF Bendpoints Document

ONArcEditPart anpassenprivate void refreshBendpoints() {private void refreshBendpoints() {

List modelConstraint = getONArc().getBendPoints();List figureConstraint = new ArrayList();if (modelConstraint != null) {

for (int i = 0; i < modelConstraint.size(); i++) {BendPoint wbp = (BendPoint) modelConstraint.get(i);RelativeBendpoint rbp =new RelativeBendpoint(getConnectionFigure());new RelativeBendpoint(getConnectionFigure());Dimension first = new Dimension(

(Integer) wbp.getW().get(0),(Integer) wbp.getH().get(0));

Dimension second = new Dimension(Dimension second new Dimension((Integer) wbp.getW().get(1),(Integer) wbp.getH().get(1));

rbp.setRelativeDimensions(first, second);figureConstraint.add(rbp);gu eCo st a t.add( bp);

}getConnectionFigure().setRoutingConstraint(figureConstraint);}

}}

ONArcEditPart anpassen

protected void refreshVisuals() {super.refreshVisuals();ONA Fi A Fi (ONA Fi ) tC ti Fi ()ONArcFigure onArcFigure = (ONArcFigure)getConnectionFigure();onArcFigure.setWeight(getONArc().getWeight());refreshBendpoints();

}

ONArcEditPart anpassenprivate class ONArcAdapter implements Adapter {

...public void notifyChanged(Notification notification) {public void notifyChanged(Notification notification) {int featureId = notification.getFeatureID(RonmodelPackage.class);switch (featureId) {

case RonmodelPackage.ON_ARC__WEIGHT:refreshVisuals();refreshVisuals();break;

case RonmodelPackage.ON_ARC__BEND_POINTS :refreshBendpoints();break;break;

}}

Nach dem alles geklappt hat