Customizing Context Menu (remove standard features) [message #714467] |
Wed, 10 August 2011 15:08 |
Christian B Messages: 68 Registered: August 2011 |
Member |
|
|
Hi,
I just finished the tutorial parts for Context Buttons and Context menus. It is possible to remove standard features of the Context Buttons. (e.g. just by not adding the remove button)
setGenericContextButtons(data, pe, CONTEXT_BUTTON_DELETE |
CONTEXT_BUTTON_UPDATE);
But i found no way to remove standard features of the context menu, if i dont need them.
How to remove the "Remove" - feature from the context menu?
[Updated on: Wed, 10 August 2011 15:10] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Customizing Context Menu (remove standard features) [message #720417 is a reply to message #720239] |
Tue, 30 August 2011 14:41 |
Hernan Gonzalez Messages: 188 Registered: October 2010 Location: Buenos Aires, Argentina |
Senior Member |
|
|
I agree that a separation between "user facing and internal features is requested", or at least some conceptual clarification.
I wasn't confortable with the proposed solution, because I saw that getFeatureProvider().getRemoveFeature()) is called in several places, and I feared that it would return null during some operation inside the Delete operation.
Instead, I did something much simpler and cleaner (though it's still hackish), I provided the Delete feature with an extended feature provider
public class MyFeatureProvider extends DefaultFeatureProvider {
...
@Override
public IRemoveFeature getRemoveFeature(IRemoveContext context) {
return null; // remove disabled for the UI
}
protected IRemoveFeature getRemoveFeatureEnabled(IRemoveContext context) {
return super.getRemoveFeature(context); // used where we enable remove (deleting...)
}
@Override
public IDeleteFeature getDeleteFeature(IDeleteContext context) {
return new MyDeleteFeature(this);
}
}
public class MyFeatureProviderWithRemove extends MyFeatureProvider {
public MyFeatureProviderWithRemove(IDiagramTypeProvider dtp) {
super(dtp);
}
@Override
public IRemoveFeature getRemoveFeature(IRemoveContext context) {
return super.getRemoveFeatureEnabled(context);
}
}
public class MyDeleteFeature extends DefaultDeleteFeature {
public MyDeleteFeature(IFeatureProvider fp) {
super(new MyFeatureProviderWithRemove(fp.getDiagramTypeProvider()));
}
}
It seems to work ok.
[Updated on: Tue, 30 August 2011 14:42] Report message to a moderator
|
|
|
Re: Customizing Context Menu (remove standard features) [message #1015708 is a reply to message #720417] |
Fri, 01 March 2013 20:50 |
Johnny Qin Messages: 40 Registered: April 2012 |
Member |
|
|
Here's my solution to not adding "Remove" to context menu. "Delete" is still there, so this fix does meet my needs.
public class MyFeatureProvider extends DefaultFeatureProvider {
...
@Override
public IRemoveFeature getRemoveFeature(IRemoveContext context) {
/**
* return <code>NULL</code> will disable Remove action but at the same time disable Delete action, because delete uses remove.
*/
return new DefaultRemoveFeature(this) {
/*
* (non-Javadoc)
* @see org.eclipse.graphiti.features.impl.AbstractFeature#isAvailable(org.eclipse.graphiti.features.context.IContext)
*/
@Override
public boolean isAvailable(IContext context) {
return false;
}
};
}
}
[Updated on: Fri, 01 March 2013 20:50] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04581 seconds