Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » getContextButtonPad is not running feature
getContextButtonPad is not running feature [message #849008] Wed, 18 April 2012 16:01 Go to next message
Josef Pohl is currently offline Josef Pohl
Messages: 82
Registered: January 2012
Member
Hi there,

I am trying to associate a Custom Feature with a context button on the ContexButtonPad. I seem to have two issues that I am not sure how to trouble shoot.

The first, and less troubling, is that the icon (which is registered through an image provider, hopefully correctly) is not showing up, but the location has a gray square instead. I have the image provider and registered the extensions in the plugin.xml. Is there anything else that I am missing?

The second issue is that the CustomFeature I registered with the button is not firing when I click on it.

The CustomFeature does actually work from the context menu derived from a right click on the GA.

I was modeling this code (below) partially on the instance from the sketch tool example. The tutorial shows examples for adding drag and drop features and collapse features (the latter with help of a createCollapseContextButton method). But there is nothing about adding a domain specific context button that is not one of these features.

The item I was not sure about is adding the feature to the button so I just did it in the constructor. Is this correct?

Thanks, as always!
Joe


	@Override
	public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) {
		IContextButtonPadData data = super.getContextButtonPad(context);
		PictogramElement pe = context.getPictogramElement();
		
		setGenericContextButtons(data, pe, CONTEXT_BUTTON_DELETE | CONTEXT_BUTTON_UPDATE);
		
		// setting behavior
		
		// behavior is defined in EgsndiagramBrowserFeature
	
		ContextButtonEntry button;
		
		CustomContext cc = new CustomContext(new PictogramElement[] {pe});
		ICustomFeature[] cf = getFeatureProvider().getCustomFeatures(cc);
		for (int i = 0; i < cf.length; i++){
			ICustomFeature iCF = cf[i];
			if (iCF instanceof EgsndiagramBrowserFeature) {
				button =  new ContextButtonEntry(iCF, context);
				button.setText("View Referenced Document");
				button.setDescription("Launch a browser to view referenced document");
				button.setIconId(EgsnImageProvider.IMG_DOCUMENT);
				data.getDomainSpecificContextButtons().add(button);
			}
		}
		
		return data;
	}
Re: getContextButtonPad is not running feature [message #850818 is a reply to message #849008] Fri, 20 April 2012 07:04 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1583
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, looks good so far what I can say without debugging. Is the feature
enabled (canExecute) ?

Michael
Re: getContextButtonPad is not running feature [message #850996 is a reply to message #850818] Fri, 20 April 2012 10:41 Go to previous messageGo to next message
Josef Pohl is currently offline Josef Pohl
Messages: 82
Registered: January 2012
Member
Hi there,

I meant to note in my original post that the feature works great from the context menu (right click on the GA). Not exactly sure why it is not working here.
I am also not sure if it is two problems or just one that is masking another.

I will continue to play with it when I get the chance and report back but if anyone has any ideas I would appreciate it.

Thanks,
Joe

Re: getContextButtonPad is not running feature [message #851081 is a reply to message #850996] Fri, 20 April 2012 12:20 Go to previous messageGo to next message
Brian Fitzpatrick is currently offline Brian Fitzpatrick
Messages: 495
Registered: July 2009
Senior Member
Hey Joe,

I'm having a similar problem. The canExecute is never being fired on my custom feature. But I am using getGenericContextButtons instead of getDomainSpecificContextButtons. The only difference seems to be where the button appears on the button bar. And like you, my custom action works great from the popup menu but won't fire from the button bar.

		CustomContext cc = new CustomContext(new PictogramElement[] { pe });
		ICustomFeature[] cf = getFeatureProvider().getCustomFeatures(cc);
		for (int i = 0; i < cf.length; i++) {
			ICustomFeature iCustomFeature = cf[i];
			if (iCustomFeature instanceof SCADiagramCustomPromoteServiceFeature) {
				ContextButtonEntry button = new ContextButtonEntry(iCustomFeature, context);
				data.getGenericContextButtons().add(button);
				break;
			}
		}


--Fitz
Re: getContextButtonPad is not running feature [message #854059 is a reply to message #851081] Mon, 23 April 2012 12:09 Go to previous messageGo to next message
Josef Pohl is currently offline Josef Pohl
Messages: 82
Registered: January 2012
Member
Hi Brian,
Unfortunately no solution yet. I was wondering though, are you having a similar issue with the image icon display? Trying to narrow down how many issues I really have here.

Thanks,
Joe
Re: getContextButtonPad is not running feature [message #854819 is a reply to message #854059] Tue, 24 April 2012 04:58 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1583
Registered: July 2009
Location: Walldorf, Germany
Senior Member
After a second closer look I noticed what's wrong: you need to pass the
CustomContext (cc) to the ContextButtonEntry instead of the original
context. The reason is that the CustomFeature will only work on
CustomContexts and otherwise silently ignore calls, which is the source of
confusion.

I have create https://bugs.eclipse.org/bugs/show_bug.cgi?id=377475, because
I stumbled over an issue in the execute of CustomFeatures and will expand
this bug to adapt canExecute as well so that clients get feedback on wrong
calls.

Michael
Re: getContextButtonPad is not running feature [message #855478 is a reply to message #854819] Tue, 24 April 2012 17:30 Go to previous message
Josef Pohl is currently offline Josef Pohl
Messages: 82
Registered: January 2012
Member
Thanks Michael,
That did the trick. Looking back I am not sure where, or why, I did that. But it appears Brian did a similar thing as well.

I resolved the image display thing as well. The icon I had in there was 128 x 128 not 16 x 16.
The bug report will be useful.
Thanks,
Joe
Previous Topic:Layering of figures
Next Topic:Make FigureCanvas Larger
Goto Forum:
  


Current Time: Fri Aug 22 07:49:00 EDT 2014

Powered by FUDForum. Page generated in 0.01719 seconds