I have 2 questions, maybe somebody can give me an idea how i can do this
I've created new "testFeature" extended from AbstractCustomFeature and can call it in my Diagram. How can i get a List which contains all Elements from the Diagram?(i want to update their names and colors at start and later)
My second question is: I'm trying to add some Elements to the Diagram without drag and drop them from the palette.
For example i have some Elements saved in the Diagram and my "model say i miss 3 Elements in the Diagram". I want to write an Custom Feature, which draw/put missing Elements in the Graphiti Diagram with just one/two clicks, maybe i need to use Zest at this part? but at the beginning i just want to put few elements without drop them from the Palette, how can i do this?
Maybe somebody can give me direction?
Thanks for your help!
ok! here is my solution:
class testFeature extends AbstractCustomFeature {
//...
public void execute(ICustomContext context) {
Diagram diagram = getDiagram(); //get Diagram
EList<Shape> diagramChildren= diagram.getChildren();//get List with all Children's
Iterator<Shape> it = diagramChildren.iterator(); //Build iterator for this List
//go through all objects which are in the Diagram
while (it.hasNext()) {
Shape testObjekt = it.next();
PictogramElement pe = testObjekt.getGraphicsAlgorithm().getPictogramElement();
Object bo = getBusinessObjectForPictogramElement(pe);
//BUILD YOUR EMF & GRAPHITI projects together!!!!
//otherwise you get always false after editor restart
if (bo instanceof graphicElement) {
graphicElement sElement = (graphicElement)bo;
if(pe instanceof ContainerShape){
RoundedRectangle testR= (RoundedRectangle) pe.getGraphicsAlgorithm();
//testR is my RoundedRectangle like in help tutorial
//changes are possible here:
//...
ContainerShape cs = (ContainerShape) pe;
for (Shape shape : cs.getChildren()) {
//set Name
if (shape.getGraphicsAlgorithm() instanceof Text) {
Text text = (Text) shape.getGraphicsAlgorithm();
text.setValue("new name!");
}
//set Line color
if (shape.getGraphicsAlgorithm() instanceof Polyline) {
Polyline polyline = (Polyline)shape.getGraphicsAlgorithm();
polyline.setForeground(manageColor(myColorGreen));
polyline.setLineWidth(3);
}
}
}
}
}