Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » getting objects from diagarm file
getting objects from diagarm file [message #655727] Tue, 22 February 2011 13:35 Go to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
hi i am using gmf for my graphical editor

i want to get the object in the diagarm file using the diagram file object. how is that possible

can you please give the code snippet

the below is my function

i want to an specific object and its attribute

TestCase is an object in my diagram file/ecore model that contains other objects

i want to get the name of testcase object





public String getTestCaseName(ExecutionEvent event)
{

ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)currentSelection;
if (!ss.isEmpty()) {
Object so = ss.getFirstElement();

if (so instanceof EditPart) {
Object m = ((EditPart)so).getModel();
if (m instanceof EObject) {
EObject eo=(EObject)m;
DiagramImpl di=(DiagramImpl)eo;
Diagram d=di.basicGetDiagram();



}

}
}
}

return null;


}
}


please reply
Re: getting objects from diagarm file [message #655728 is a reply to message #655727] Tue, 22 February 2011 13:45 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi,

You can either create an EMF ResourceSet and a EMF Resource for your your file and use getContents()[0] on your resource file to get the top-level model element. Or you can use the OffscreenEditPartFactory to load your file with an offscreen GMF editor and then manipulate it with GMF APIs.

HTH,

--
Mickael Istria -- BonitaSoft S.A.
http://www.bonitasoft.com/products/BPM_download.php
Re: getting objects from diagarm file [message #655750 is a reply to message #655728] Tue, 22 February 2011 14:50 Go to previous messageGo to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Hi mickeal

Thanks for u r reply.

i have tried the following but in vain. can u give the snippet?

public String getDiagramFile(ExecutionEvent event)
{

ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)currentSelection;
if (!ss.isEmpty()) {
Object so = ss.getFirstElement();

if (so instanceof EditPart) {
Object m = ((EditPart)so).getModel();
if (m instanceof EObject) {
EObject eo=(EObject)m;
DiagramImpl di=(DiagramImpl)eo;
Diagram d=di.basicGetDiagram();
ResourceSet resourceSet = new ResourceSetImpl();
URI file=((EObject)m).eResource().getURI();
Resource modelResource=resourceSet.getResource(file, true);
List<EObject> ls=modelResource.getContents();
List<EObject> lm=ls.get(0).eContents();
NodeImpl ni=(NodeImpl) lm.get(0);
Node n=ni;
return (String) n.eGet(MistPackage.Literals.TEST_CASE__NAME);

}

}
}
}
Re: getting objects from diagarm file [message #655827 is a reply to message #655750] Tue, 22 February 2011 18:26 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

to get the root object of when having a EObject you can use EcoreUtil.getRootContainer(EObject);

Maybe this solves your problem.

Ralph
Re: getting objects from diagarm file [message #655829 is a reply to message #655750] Tue, 22 February 2011 18:28 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

thank you very much! I used the "required Plugin identifiers" approach Smile I did put code for this in my genmodel to generator model transformation.

Thanks!!

Ralph
Re: getting objects from diagarm file [message #655921 is a reply to message #655829] Wed, 23 February 2011 10:31 Go to previous message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Hi
Thanks all. i found solution for my problem

Thanks ralph Smile

public String getTestCaseName(ExecutionEvent event)
{
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)currentSelection;
if (!ss.isEmpty()) {
Object so = ss.getFirstElement();

if (so instanceof EditPart) {
Object m = ((EditPart)so).getModel();
if (m instanceof EObject) {
EObject eo=(EObject)m;
EObject root=EcoreUtil.getRootContainer(eo);
List<EObject> lot=root.eContents();
for(int i=0;i<lot.size();i++)
{
EObject temp=lot.get(i);
if (temp instanceof NodeImpl) {
NodeImpl node = (NodeImpl) temp;
EObject element = node.getElement();
System.out.println(element.toString());
if(element instanceof StartBlockImpl)
{
System.out.println("hurrai");
StartBlockImpl sb=(StartBlockImpl)element;
EObject tc=sb.eContainer();
if(tc instanceof TestCaseImpl)
{
TestCaseImpl tcl=(TestCaseImpl)tc;
return tcl.getName()+".mist";
}
}
}
}


}

}
}
}

return null;


}
}
Previous Topic:Remove all actions except GMF's from tool bar
Next Topic:Aggregation as a link
Goto Forum:
  


Current Time: Fri Mar 29 05:59:49 GMT 2024

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

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

Back to the top