|
|
|
|
|
Re: Adding buttons to the elements [message #853958 is a reply to message #853904] |
Mon, 23 April 2012 14:04 |
Ralph Gerbig 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 |
eni bundo 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03171 seconds