Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Adding buttons to the elements
Adding buttons to the elements [message #853762] Mon, 23 April 2012 10:00 Go to next message
eni bundo is currently offline eni bundoFriend
Messages: 7
Registered: March 2012
Junior Member
Hello,

I want to add a button to some of my elements (the squares/figures of class A.), that when clicked will create a special Node (class B), and will link A to B using an already defined connection between the two.

The idea is :
- click
+- create node
+- create link

and all this will be done automatically.

Can you give me a hint on how to do this?

Thanks in advance
Re: Adding buttons to the elements [message #853807 is a reply to message #853762] Mon, 23 April 2012 10:56 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi Eni,

do you want to have a button added to the buttons that appear if you hover over a model element? This is not very hard to realize if you are interested into that.

Cheers,

Ralph
Re: Adding buttons to the elements [message #853880 is a reply to message #853807] Mon, 23 April 2012 12:29 Go to previous messageGo to next message
eni bundo is currently offline eni bundoFriend
Messages: 7
Registered: March 2012
Junior Member
Hi Ralph,

When I started thinking about the UI side of the project the buttons were going to be visible all the time.

Now that you're telling me the 2nd way is easier, I might as well just make them visible when the mouse hovers for the sake of time, and I will later on try to make them visible the whole time, or just add the same button in the Properties view of the Element.

How can I achieve what you mentioned Ralph? Also, how do I 'automatize' the creation of the other node and the link?

Thanks

Eni
Re: Adding buttons to the elements [message #853889 is a reply to message #853880] Mon, 23 April 2012 12:37 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

can you provide a picture which shows where the buttton shall be visible? Shall it be visible on the selection of the element?

Ralph
Re: Adding buttons to the elements [message #853904 is a reply to message #853889] Mon, 23 April 2012 12:56 Go to previous messageGo to next message
eni bundo is currently offline eni bundoFriend
Messages: 7
Registered: March 2012
Junior Member
Hello Ralph,

It doesn't really matter,

It can be inside the selection
index.php/fa/8035/0/

Or even outside
index.php/fa/8036/0/

If it's inside, I'd like it to be positioned on the "top-left" corner instead of just the top (like the image).

Anyways, as I said before, as long as it's visible and clickable it's OK Smile

Thanks

[Updated on: Mon, 23 April 2012 12:57]

Report message to a moderator

Re: Adding buttons to the elements [message #853958 is a reply to message #853904] Mon, 23 April 2012 14:04 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

For a pop up you need to do the following:

Create a class inherited from PopupBarEditPolicy and overwrite the fillPopupBarDescriptorsMethod:

@Override
protected void fillPopupBarDescriptors() {
 super.fillPopupBarDescriptors();

 AbstractPopupBarTool tool = null;

 ImageDescriptor imageDescriptor = null;
 Image image = null;

 tool = new XXXPopupBarTool(getHost(), null);
	
 imageDescriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "/icons/tool.gif");
 image = imageDescriptor.createImage();
			
 addPopupBarDescriptor(null, image, tool, "ToolTip");
}			


Create a class XXXPopupTollBarTool inherited from AbstractPopupBarTool with the followinf methods overriden

public XXXPopupBarTool(EditPart epHost, CreateRequest theRequest) {
 super(epHost, theRequest);
}

@Override
protected Request createTargetRequest() {
 return new RequestForThisTool();
}

@Override
protected Command getCommand() {
 return new CommandForThisTool();
}



Now you need to install your editpolicy into the editpart


/**
* @generated
*/
protected void createDefaultEditPolicies() {

 //Generated code before...


  removeEditPolicy(EditPolicyRoles.POPUPBAR_ROLE);
  installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new YourPopupBarEditPolicy());
}


That's all.

Ralph
Re: Adding buttons to the elements [message #854882 is a reply to message #853958] Tue, 24 April 2012 10:19 Go to previous messageGo to next message
eni bundo is currently offline eni bundoFriend
Messages: 7
Registered: March 2012
Junior Member
Hello Ralph,

Thanks for your response.

I still have something unclear though. I'm not sure of how to code the CommandForThisTool and RequestForThisTool classes. I understand they have to extend the Command and Request and I understand I'll have to use CreateRequest for creating the new element and CreateConnectionRequest for creating the new connection between 'this' element and the newly created one. But all this abstractions of GMF make it difficult for me to wrap my head around this whole thing.

Could you please hint me with another code snippet or example?

Edit:
also there's a problem with this line
imageDescriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "/icons/tool.gif");

seems like Eclipse can't recognize the Activator.imageDescriptorFromPlugin(String, String); even though I imported org.eclipse.core.internal.content.Activator; (I tried importing other Activators just in case I wasn't chosing the right one, but the same problem continues).

Edit2:
According to some code I browsed online, should that line be more like this:
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PI_APP, "open.gif");


Thanks,

Eni

[Updated on: Tue, 24 April 2012 13:08]

Report message to a moderator

Re: Adding buttons to the elements [message #856082 is a reply to message #854882] Wed, 25 April 2012 10:56 Go to previous message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

to implement the tool I do the following:

public IntrospectPopupBarTool(EditPart epHost, CreateRequest theRequest) {
 super(epHost, theRequest);
}

@Override
protected Request createTargetRequest() {
 ChangePropertyValueRequest req = new ChangePropertyValueRequest("XXXX", "XXX");
 return req;
}

@Override
protected Command getCommand() {
 return new XXXCommand((IGraphicalEditPart)getHost());
}


I do not use the ChangePropertyValueRequest in my command I just create anyone to implement this abstract method. On getCommand I return my custom command. It is implemented like this:
private IGraphicalEditPart host = null;
	
/**
 * 
 * @param host Element to introspect
 */
public IntrospectCommand(IGraphicalEditPart host){
 this.host = host;
}

@Override
public void execute() {
 super.execute();
		
 Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
 MessageBox m = new MessageBox(shell);
 m.setMessage("Hello World");
 m.open();
}


You can place whatever code you want in the execute method.

Michael Golubev postest this code a view days ago to create new model element in the way the palette does:

List types = Collections.singletonList(ActivityElementTypes.Action_2001);
CreateUnspecifiedTypeRequest gefRequest = new CreateUnspecifiedTypeRequest(types, PreferencesHint.USE_DEFAULTS);
gefRequest.setLocation(...);
gefRequest.setSize(...);
EditPart containerEP = .... //find EP that should host the new element, DiagramEditPart for top-level elements.
Command gefCommand = containerEP.getCommand(gefRequest);
if (gefCommand.canExecute()) {
   //execute 
}


Ralph
Previous Topic:generating xml-structured file beside the generated xmi file
Next Topic:Exception while generating the code
Goto Forum:
  


Current Time: Thu Apr 25 09:57:28 GMT 2024

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

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

Back to the top