Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Dynamic "Refreshing" of Palette on Object Selection
Dynamic "Refreshing" of Palette on Object Selection [message #1274415] Fri, 21 March 2014 12:43 Go to next message
Sudharshan Ravi is currently offline Sudharshan RaviFriend
Messages: 12
Registered: March 2014
Junior Member
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 #1276254 is a reply to message #1274415] Mon, 24 March 2014 09:51 Go to previous messageGo to next message
Sudharshan Ravi is currently offline Sudharshan RaviFriend
Messages: 12
Registered: March 2014
Junior Member
To those who are interested, I managed to find a solution for this.

I override the function getSingleClickFeature() (or getDoubleClickFeature()). Use the context I get here to retrieve the Business Object from the Pictogram element. I manually refresh the palette by calling refreshPalette() in the implementation of the SingleClickFeature class.

So each time I click on a object in the diagram, I refresh the palette with new entries based on the object selected as I wanted to.

If anyone has a better/easier way to do this please let me know. Smile

[Updated on: Mon, 24 March 2014 11:06]

Report message to a moderator

Re: Dynamic "Refreshing" of Palette on Object Selection [message #1276268 is a reply to message #1274415] Mon, 24 March 2014 10:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi,

currently, the palette is rather static, meaning it is created once at
editor startup (there also refresh is called). Without going into the
details of that long ago written code, I'm not even sure if the palette
implementation would allow for dynamically adding/removing stuff...

Michael
Re: Dynamic "Refreshing" of Palette on Object Selection [message #1276272 is a reply to message #1276254] Mon, 24 March 2014 10:16 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
That kind of overtook my answer...

Great that you found that possibility and shared the solution here.

Thanks,
Michael
Re: Dynamic "Refreshing" of Palette on Object Selection [message #1277680 is a reply to message #1274415] Wed, 26 March 2014 10:01 Go to previous message
Sudharshan Ravi is currently offline Sudharshan RaviFriend
Messages: 12
Registered: March 2014
Junior Member
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 10:04]

Report message to a moderator

Previous Topic:Adding features dynamically
Next Topic:Width of polyline doesn't reflect on the diagram
Goto Forum:
  


Current Time: Fri Apr 26 08:09:19 GMT 2024

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

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

Back to the top