Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » CustomFeature's create & get all Elements
CustomFeature's create & get all Elements [message #1052810] Tue, 30 April 2013 15:01 Go to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
Hello!

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!

Andrej K.

Re: CustomFeature's create & get all Elements [message #1053488 is a reply to message #1052810] Mon, 06 May 2013 08:54 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Andrej,

what exactly do you mean with "all Elements from the Diagram"? In case you
are talking about the Graphiti pictogram elements, you can simply retrieve
the sahpes contained directly in the diagram by calling getChildren on the
diagram instance. In case one of the returned shapes is a ContainerShape it
might again have children.

In order to add objects via drag&drop you can simply use an add feature that
adds the object representation to the diagram. Depending on where you drag
from, you might need to add an additional drag target listener to the
editor. The tutorial implements adding EClasses from the project explorer.
Have you seen that?

Michael
Re: CustomFeature's create & get all Elements [message #1058217 is a reply to message #1053488] Mon, 13 May 2013 09:14 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
I mean i want to get all Elements which are in the Diagram, so i can change their Names/Labels, Colors and maybe their Image/Icon at start or later during the editing

public class testFeature extends AbstractCustomFeature {
...
 public void execute(ICustomContext context) {
    	  Diagram diagram = getDiagram();
          EList<Shape> diagramChildren= diagram.getChildren();
          
          Iterator<Shape> it = diagramChildren.iterator();
          while (it.hasNext()) {
        	  Shape testObjekt= it.next();
                  Object bo = getBusinessObjectForPictogramElement(testObjekt);
        	  
        	  if (bo instanceof Task) {//dont work
                      Task eClass = (Task) bo;//dont work
        		  
        	      eClass.setName(stringFromModel);
        	      eClass.setColor(colorFromModel);  
        		  
        	  }
          }
 }
}

I'm trying that in this code and i can get a count of all Elements which are in the Diagram, but i have no Idea how i can get/change their Names

If i run this (without "if()") i get this exception:
java.lang.ClassCastException: 
de.model.prozesse.impl.TaskImpl cannot be cast to de.model.prozesse.Task


i think its because i put "Shape" Element instead of "PictogramElement" in getBusinessObjectForPictogramElement, i have no Idea how i can solve this
Can you give me a Nudge, how i should go ahead?


(Sorry for the late answer, i was ill)
Re: CustomFeature's create &amp;amp; get all Elements [message #1058237 is a reply to message #1058217] Mon, 13 May 2013 10:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Andrej,

your coding looks perfectly fine. I assume there is something wrong with
your EMF model. Does TaskImpl implement Task?

Michael
Re: CustomFeature's create &amp;amp; get all Elements [message #1058263 is a reply to message #1058237] Mon, 13 May 2013 12:10 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
Hello,
yes it does, i looked into Example from Vogella to build/generate my EMF model/classes
http://www.vogella.com/articles/EclipseEMF/article.html

i think i know how to change the Name (code from "updatefeature" helps)... don't know if it works for Colors & Icons/pictures later.

Now i can change the Names of Elements but, problem is the condition of my IF is true just for Objects i created after the load. Objects/Elements which where created saved and loaded became not realized

for example i load my Diagram and have Object_1 and Object_2
then i add Object_3 and Object_4
(all 4 Objects are Tasks)
then I execute my testFeature and get all 4 Objects, but just Object_3 and 4 go into my IF Order and i can change the Names of them

How it could be?Why the IF Order don't realize loaded Elements?What I'm missing`?


Andrej
Re: CustomFeature's create &amp;amp; get all Elements [message #1058281 is a reply to message #1058263] Mon, 13 May 2013 12:58 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
need to correct me, it happens after Rerun/Compiling, if I Save, Close and load Diagram ->it works fine
But why it doesn't works after Compiling?
Re: CustomFeature's create &amp;amp; get all Elements [message #1059681 is a reply to message #1058281] Tue, 21 May 2013 08:13 Go to previous message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
I've solved this problem by putting together my EMF and Graphiti projects
and i can get all Elements from Diagram
Previous Topic:Loading/Saving Diagrams
Next Topic:Architecture of Graphiti Diagram Editor
Goto Forum:
  


Current Time: Fri Apr 19 17:04:46 GMT 2024

Powered by FUDForum. Page generated in 0.01358 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top