1

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!

AndrejK
  • 11
  • 3

2 Answers2

2

How can i get a List which contains all Elements from the Diagram?

Diagram is a ContainerShape, you can call getChildren() to retrieve all shapes

add some Elements to the Diagram without drag and drop them from the palette.

Is the object already created, inside the EMF model, and you only want it to add its graphical counterpart to the diagram? If so, you need to instantiate and execute yourself your corresponding XXXAddFeature class.

Elsewhere (more probable, if you want to mimic some drag-n-drop from the palette), you must call the proper XXXCreateFeature, which will add ("create", in Graphiti parlance) the element to the model (typically, the create body will at the end invoke addGraphicalRepresentation() which will also add the corresponding graphical element to the diagram by calling, internally the appropiate XXXAddFeature).

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • thank you for the answer! i was thinking nobody will answer me, in the meantime i solved this problems. It was really difficult at beginning where/how i should approach but at the end it was easy. but maybe you can help my with another question about "Graphiti as RCP"? http://stackoverflow.com/questions/16686964/graphiti-as-rcp – AndrejK May 22 '13 at 13:58
  • Yes, Graphiti has a small community, and the documentation is rather anemic. BTW: if you know the answer for a question you asked here, you are encouraged to answer it yourself. The purpose of this site is not to help individual/isolated problems, but to build a knowledge base than can help other people. – leonbloy May 22 '13 at 14:03
0

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);
                          }
                      }
                  }
              }
          }
AndrejK
  • 11
  • 3