|
|
|
|
Re: Undo [message #894092 is a reply to message #893940] |
Fri, 06 July 2012 15:22 |
Miriam Baran Messages: 16 Registered: May 2012 |
Junior Member |
|
|
here my add Methode of the a connection (there are different ones, but one will do, as it is always the same problem).
/**
* {@inheritDoc}
*/
@Override
public PictogramElement add(IAddContext context) {
IAddConnectionContext addConContext = (IAddConnectionContext) context;
// TODO: Domain object
Rule addedDomainObject = (Rule) context.getNewObject();
ISprayStyle style = new RuleStyle();
ISprayConnection connection = new SimpleArrowShape(getFeatureProvider());
Connection result = (Connection) connection.getConnection(getDiagram(), style, addConContext.getSourceAnchor(), addConContext.getTargetAnchor());
// create link and wire it
peService.setPropertyValue(result, PROPERTY_MODEL_TYPE, CorePackage.Literals.RULE.getName());
link(result, addedDomainObject);
for (ConnectionDecorator conDecorator : result.getConnectionDecorators()) {
link(conDecorator, addedDomainObject);
}
setDoneChanges(true);
updatePictogramElement(result);
/*
* My add:
* add false connections to enable collapse/expand
*/
CustomContext ccontext = new CustomContext();
PictogramElement[] pea = new PictogramElement[2];
pea[0] = addConContext.getSourceAnchor().getParent();
pea[1] = addConContext.getTargetAnchor().getParent();
ccontext.setPictogramElements(pea);
ccontext.putProperty("type", "rule");
ICustomFeature[] cfs = getFeatureProvider().getCustomFeatures(ccontext);
for(ICustomFeature cf : cfs){
if(cf instanceof MyCreateFalseConnectionsFeature){
if(cf.canExecute(ccontext)){
cf.execute(ccontext);
}
}
}
return result;
}
and here is how the connection is created (getConnection Method of DottedArrowShape)
@Override
public Connection getConnection(final Diagram diagram, final ISprayStyle sprayStyle, final Anchor startAnchor, final Anchor endAnchor) {
final Connection newConnection = peCreateService.createFreeFormConnection(diagram);
newConnection.setStart(startAnchor);
newConnection.setEnd(endAnchor);
final Polyline polyline = gaService.createPolyline(newConnection);
polyline.setStyle(sprayStyle.getStyle(diagram));
// Define general layout of connection
polyline.setLineStyle(LineStyle.DASH);
// Set the Placings of the connection
{
ConnectionDecorator decorator = peCreateService.createConnectionDecorator(newConnection, false, 1.0, true);
List<Point> pointList = new ArrayList<Point>();
pointList.add(gaService.createPoint(-10, 10, 0, 0));
pointList.add(gaService.createPoint(0, 0, 0, 0));
pointList.add(gaService.createPoint(-10, -10, 0, 0));
Polyline element = gaService.createPolyline(decorator, pointList);
ISprayStyle style = sprayStyle;
element.setStyle(style.getStyle(diagram));
}
return newConnection;
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02113 seconds