Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to manage the parts
How to manage the parts [message #1027823] Wed, 27 March 2013 13:02 Go to next message
Aljoscha Steffens is currently offline Aljoscha SteffensFriend
Messages: 302
Registered: November 2012
Senior Member
Hi,
I'm troubeling with this since several month so maybe there is a better way of how to do it. So what I want to achieve is actually quite simple:
Just as in the Eclpise IDE I have a treeViewer with a couple of different Objects in it. Those Objects (some containing text, some tables, some other stuff), can be displayed in parts. If I double click on a object, there should be a check if the object is already beeing displayed. If not, a part will be created for it, if yes the part is put to top. Just as in Eclipse IDE.

This is how I did it so far:
public void displayMyObject(MyObject myObject) {

		MPartStack stack = (MPartStack) modelService.find(
				"myParts.partstack.editors", app);

		if (objectIsOpen(myObject.getID(), stack))
			return;


		MInputPart part = MBasicFactory.INSTANCE.createInputPart();
		part.setContributionURI("bundleclass://ui.parts.MyObjectEditor");
		stack.getChildren().add(part);
		partService.showPart(part, PartState.ACTIVATE);


		((MyObjectEditor) part.getObject()).setViewerContent(myObject);
	}




	private boolean objectIsOpen(UUID iD, MPartStack stack) {
		Iterator<MStackElement> iter = stack.getChildren().iterator();
		while (iter.hasNext()) {
			
			Object obj = iter.next();
			if (obj instanceof MInputPart) {
				MInputPart part = (MInputPart) obj;
				if (part.getObject() instanceof MyObjectEditor) {
					MyObjectEditor viewer = (MyObjectEditor) part.getObject();
					if (viewer.getDisplayedItemId().equals(iD)) {
						partService.showPart(part, PartState.ACTIVATE);
						return true;
					}
				}
			}
		}

		return false;
	}


So.. I think this is mostly self-explaning, except that each of my objects has an ID which can be optained from the displaying part. (-> If there is a part which displays that ID, the part is put to top. If not a new one is beeing created)

It all works fine except from when I (re)start the application.
http://www.imgbox.de/users/public/images/iMgJ7DDrSF.jpg
All the tabs that were there when I closed the application are beeing created again. Thats fine. But only if I click ob each part seperatly the content of the tab is beeing loaded. So before that, they don't have an ID which means, I can't check if the object is already beeing displayed.

So... Is this a wrong approach? Is there a way to let rcp handle the parts?

Re: How to manage the parts [message #1029244 is a reply to message #1027823] Fri, 29 March 2013 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Aljoscha, you're going about this the wrong way.

In the 3.x APIs, you'd open an editor on an IEditorInput. In your case, your IEditorInput would just be your object's UUID.

You can, and should, use a similar approach in E4: although we don't have IEditorInputs, you can pass information in via the persisted-state and transient-state maps on the MPart. So rather than futz about trying to get your party's contribution element to be instantiated so that you can instruct it to show a particular object, configure its MPart so that the necessary information is available once the contribution class is instantiated.

Or put another way: your MPart's contribution defines the UI behaviour and UI representation. If your part is never shown, then no UI representation Is needed and so your contribution need never be instantiated. You want to ensure that when it is instantiated, it has the details of what to show from its MPart. No orchestration needed.

Brian.
Re: How to manage the parts [message #1031986 is a reply to message #1027823] Tue, 02 April 2013 12:42 Go to previous message
Aljoscha Steffens is currently offline Aljoscha SteffensFriend
Messages: 302
Registered: November 2012
Senior Member
Okay, that sounds reasonable.
So right now I don't create new parts when I display an object but call showPart(..) if it has been opened at some point.
Still, there is one thing left:
There is no way to really save an Object in the MPart right? getTransientData(..) just saves the Object until the application is closed. The only thing I can use to get the content of the part is getPersistentData(..). So I need to store information (like the UUID of the object) and somehow retrieve the content of the Object with this ID right?

So I tried to send an event (containing the Objects UUID) to another class, which then searches for the corresponding Object. Then it searches for part which sent the event (also via the Id) and sets the parts content.
Well this is what should happen. Actually when I found the part (via Id) part.getObject() returns null.

Am I on the right track?
Thanks for your help Smile

edit:
Okay. I found a workaround (I dont think that this is the normal approach):
After I found the part that corresponds to the Id, I put the Object in the TransientData.In the part I then use the TransientData to display the content

eventBroker.send(EventConstants.UPDATE_EDITOR, map);

//----In another class the Object is put into the TransientData---
			
document.set((String) part.getTransientData().get("content"));


Still there is one problem left, but this is probably wrong anyway, right?

[Updated on: Tue, 02 April 2013 13:02]

Report message to a moderator

Previous Topic:Shortcut problems in 2nd editor
Next Topic:simple text field widget does not work
Goto Forum:
  


Current Time: Thu Mar 28 11:55:54 GMT 2024

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

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

Back to the top