Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Getting the name of a class when right clicking
Getting the name of a class when right clicking [message #645277] Thu, 16 December 2010 12:26 Go to next message
Haffi is currently offline HaffiFriend
Messages: 39
Registered: November 2010
Member
Hi,

I've added a context menu entry in Eclipse when right clicking an object (maybe a class) and then an action is run. I get a selection array into the run method in the action but I've no idea on how to get the name of the class, what I get is an object of the type ClassEditPart. Does anyone have an idea on how to get the name of the object in question?
Re: Getting the name of a class when right clicking [message #646365 is a reply to message #645277] Thu, 23 December 2010 14:39 Go to previous messageGo to next message
Haffi is currently offline HaffiFriend
Messages: 39
Registered: November 2010
Member
I've been digging around and haven't found a solution yet. Does anyone know if there's any way to get an object of type ClassImpl from an object of type ClassEditPart?
Re: Getting the name of a class when right clicking [message #646919 is a reply to message #646365] Mon, 03 January 2011 07:32 Go to previous messageGo to next message
Wojciech Trocki is currently offline Wojciech TrockiFriend
Messages: 64
Registered: May 2010
Member
So.. i don't have solution but I know how to search for it.
I think that ClassImpl is object representing model and class edit part is a class representing view. As I know this class have public method getUmlElement(). Try to view this class or dig in debugger.

>> I've added a context menu entry in Eclipse when right clicking an object
How you did this?

Re: Getting the name of a class when right clicking [message #647249 is a reply to message #646919] Wed, 05 January 2011 12:11 Go to previous message
Haffi is currently offline HaffiFriend
Messages: 39
Registered: November 2010
Member
Hi, thanks for your reply. I eventually found out how to do this with this code (so many lines for such a simple task!):
GraphicalEditPart editPart = (GraphicalEditPart) selections[0];
ShapeImpl item = (ShapeImpl) editPart.getModel();
EObject obj = item.getElement();
EStructuralFeature namefeature = obj.eClass().getEStructuralFeature("name");
String name = (String) obj.eGet(namefeature);


You mentioned the context menu, I added it with this code to the plugin.xml:
   <extension point = "org.eclipse.ui.popupMenus">
      <viewerContribution
        id="<path to action>"
        targetID="org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
	    <action id="<action id>"
	       label="<label>"
	       menubarPath="additions"
           definitionId="<id>"
	       class="<path to class>">	
	    </action>
       </viewerContribution>
	 </extension> 


I now have a new problem to address, that is how to find the path to the file which was right-clicked. It seems that every simple task has to be very complicated when working with plugins in Eclipse. I will add a new thread on it though.
Previous Topic:Question about the HelloWorld-Tutorial
Next Topic:XText Documentation
Goto Forum:
  


Current Time: Fri Apr 26 10:25:56 GMT 2024

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

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

Back to the top