Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Each Editor part to uniquely track navigator state
Each Editor part to uniquely track navigator state [message #1104942] Mon, 09 September 2013 06:10 Go to next message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
Using E4.2.2 I would like to have each editor view part track the explorer view part only while each particular editor is in focus(and store the tree state when the editor looses focus).

This is similar to the Edclise IDE when the package view is linked with editor view parts. Each editor 'knowing' which item in the package tree was selected for that editor view part.

One difference is that I have a CheckboxTreeViewer in the 'explorer' view part and will have one or many items selected in the tree, with each separate editor having widgets on screen relating to the treeviwer state at the time that particular editor instance was in focus.

Currently I have dynamic part descriptor which references an editor part and I can create multiple editor parts using a handler with the following code:

MPart part = partService.createPart("com.test.myeditor");
List<MPartStack> stacks = modelService.findElements(application, null,
MPartStack.class, null);
stacks.get(2).getChildren().add(part);
//where '2' is the editor location in the partstack

What I am struggling with is how to have each editor view part store or reference a snapshot of the explorer view parts tree state.

using:
@Inject
@Optional
private void getNotified(@UIEventTopic(TreeNodeEventConstants.TREE_DATAS_DATA_SELECTED) String s) is OK for updating all the instances of the editor view part, but I only want to update the part that is currently in focus.

As there is no @LostFocus in e4.2.2 I can't take a snapshot of the tree, and set a flag not to update the editor part when the tree view is modified while another instance of the editor part is being viewd.

Bit of a long winded explanation.., am I missing something? Does anyone know how to do this?
Re: Each Editor part to uniquely track navigator state [message #1104968 is a reply to message #1104942] Mon, 09 September 2013 06:58 Go to previous messageGo to next message
Andrzej Szczepanski is currently offline Andrzej SzczepanskiFriend
Messages: 16
Registered: May 2013
Junior Member
What about having a condition in your getNotified() method that checks whether this MPart (which you can have injected, for example as field or constructor argument) is "active", and if it isn't - returns immediately?

There are methods of MPart (isOnTop, isVisible) and EPartService (isPartVisible(MPart), getActivePart()), that may be of use to you (yeah I can't remember what they all do so you've got to check it yourself). As the last resort, you can check it through part stack:
mpart.getParent().getSelectedElement() == mpart ?

A little observation: when user clicks on tree viewer in your 'Explorer' part and changes the selection, doesn't he also change focus to the 'Explorer' part?
If so, tracking focus would be of no use anyway.


Re: Each Editor part to uniquely track navigator state [message #1105190 is a reply to message #1104968] Mon, 09 September 2013 13:40 Go to previous messageGo to next message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
Thanks Andrzej,

I added a test in the getNotified() method inside my part POJO, one way I found to do this is using .hasCode() (which seems like a bit of a hack):

MPart testpart = (MPart)stacks.get(2).getSelectedElement();
int testHashCode = testpart.getObject().hashCode();
int thisHashCode = this.hashCode();
if (testHashCode == thisHashCode){
//then I have the correct instance
}

I note that .getSelectedElement() on the MPartStack keeps its state when the part has lost focus which is fortunate Smile

I can now isolate the non selected editor parts from updating based on tree selection.

Cheers

Don

Re: Each Editor part to uniquely track navigator state [message #1105502 is a reply to message #1105190] Tue, 10 September 2013 00:11 Go to previous messageGo to next message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
NB I will remember to replace .hashCode() test with 'if (testpart.getObject() == this)' going forward.

On L. Vogella's Eclipse Patform Servives tutorial, there is a reference to 'In its @PostConstruct method the implementation class can get the MPart injected and access its persisted state.' which sounds promising, just need to work out how exactly to do this.


Re: Each Editor part to uniquely track navigator state [message #1105671 is a reply to message #1104942] Tue, 10 September 2013 06:27 Go to previous messageGo to next message
Andrzej Szczepanski is currently offline Andrzej SzczepanskiFriend
Messages: 16
Registered: May 2013
Junior Member
I'm glad it worked for you.

You can inject "this" MPart instance either as field or method argument in your POJO class contribution (you probably know this already). Persisted state access is straightforward: MPart::getPersistedState().

 @PostConstruct
 public void postConstruct(MPart part) {
      Map<String, String> ps = part.getPersistedState();
      (...)
}


The method returns map with String keys and values. Values put in this map will be persisted (sic!) and available even after application restart.
Re: Each Editor part to uniquely track navigator state [message #1107014 is a reply to message #1105671] Wed, 11 September 2013 21:49 Go to previous message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
Thanks Andrzej, thats clear now.

To note:
Above I was using a 'magic number' in (MPart)stacks.get(2).getSelectedElement() above to get the relevant editor MPart to modify based on CheckboxTreeViewer selection.
The problem with this is the user can drag the editor MPart to any stack and the above would return the wrong MPart or null.
To fix this I will give each MPart a UID on creation ((ObjectType)part.getObject()).setId(UID) then and store the id in a 'editor MPart' placeholder in the eclipse context on each parts @Focus.

Another possible solution would be to prevent drag and drop of MParts outside their stack - I have seen somewhere a mention of global disable of dnd - does anyone know if it is possible to allow dnd within a Part Stack only?
Previous Topic:change handled tool item label
Next Topic:Removing Dynamic Menu Contributions
Goto Forum:
  


Current Time: Thu Mar 28 08:27:26 GMT 2024

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

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

Back to the top