Dynamic "Refreshing" of Palette on Object Selection [message #1274415] |
Fri, 21 March 2014 08:43  |
Eclipse User |
|
|
|
Hello,
As stated in the Title, I want the palette to automatically refresh itself (call the refreshPalette() method and from there the getPalette() method) when I select an object in the diagram. If there are no objects in the diagram (i.e. a new diagram) then a list of the allowed objects should be shown, not all the available objects.
For example, If I have selected Object A in the diagram. The palette should then refresh and show me the children of A that can be created and remove all other irrelevant objects from the palette list.
I have extended the DefaultToolBehaviorProvider class and edited in the getPalette() to customize my palette entries but I do not know how often the palette is actually refreshed. Is it only at start or is it refreshed more often ?
When I traced the call hierarchy of the refreshPalette() I found that it was called in setCurrentToolBehaviorIndex(int) method in the Class AbstractDiagramTypeProvider.
Can anyone give me some pointers to accomplish this?
|
|
|
|
|
|
Re: Dynamic "Refreshing" of Palette on Object Selection [message #1277680 is a reply to message #1274415] |
Wed, 26 March 2014 06:01  |
Eclipse User |
|
|
|
A Quick Update on this.
The solution I presented earlier is not the best way to go about the Palette refresh because the getSingleClickFeature() requires the object to first be selected and then the click to be done. So basically two clicks on an object with a pause in between which is not intuitive behavior.
Another problem with this was that Graphiti seems to think that hovering over an object is same as selection? Thus if I have selected an object and hover my mouse over another, then the palette is refreshed on the object that my mouse is hovering over instead of the object selected.
I found instead that the method selectionChanged() worked much better because it responds on selection of the object, not a click after or mouse hover position.
public class MyEditor extends DiagramEditor{
@Override
protected DiagramBehavior createDiagramBehavior() {
return new GuideDiagramBehavior(this);
}
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
if (!sel.isEmpty()
&& sel.getFirstElement() instanceof GraphitiShapeEditPart) {
GraphitiShapeEditPart ep = (GraphitiShapeEditPart) sel.getFirstElement();
if (ep.getPictogramElement() instanceof PictogramElement) {
PictogramElement pe = ep.getPictogramElement();
XmleditorToolBehaviorProvider.setPictogramElement(pe);
getDiagramBehavior().refreshPalette();
}
}
}
}
}
Thus on object selection, the palette is refreshed with new entries based on the object. Hovering over another object does not refresh the palette as before.
I override the selectionChanged() method in my class MyEditor which extends DiagramEditor. I send the pictogram element that is selected to MyToolBehaviorProvider which then does the necessary work required to appropriately refresh the palette based on the pictogram element selected.
If anyone has further questions about my implementation, feel free to ask.
[Updated on: Wed, 26 March 2014 06:04] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.07284 seconds