Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Lost in a maze.(I do not really understand the logic behind Views/Editors/Commands)
Lost in a maze. [message #499762] Mon, 23 November 2009 20:23 Go to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 416
Registered: September 2009
Senior Member
Hi,
sorry to pester You all again.
I am trying to write my first "real" RCP app and I'm more than a bit lost.
I found a lot of good tutorials around (I'm especially fond of Lars Vogella's ones), but I still do not understand how to find my way around.

Current example:
I have an app that processes an XML data file.

I have two views (ViewPart) that relay on it.

The first one (Book) actually owns the XML (in a org.w3c.DOM.Document) and displays the Book structure in a TreeView widget.
This TreeView is also a SelectionProvider.

The second view (Scene) is a ISelectionListener displays the details of the selected part of the book by hooking to The first one events.

The ISelection transports a node reference in the XML tree and I can retrieve all Information I need.

Up to this point the things are relatively clear and clean.
Scene uses what I believe is a correct way to hook to the selection:
		getSite().getPage().addSelectionListener(Book.ID, this);
Is this acceptable?

After this things simply fall apart:
I have a Command defined to Open a file.
The Command has a handler
public class OpenHandler extends AbstractHandler
that is responsible for displaying a nice FileDialog, then I need to communicate to Book the new file selection and have it open & parse the file.
The nearest thing to a working code I have is:
        IWorkbenchWindow ww = HandlerUtil.getActiveWorkbenchWindow(event);
        IWorkbench w = ww.getWorkbench();
        IWorkbenchPart wp = w.get
        if (wp instanceof Book) {
		Book b = (Book) wp;
		b.setFile(file);
	}
which is not good enough beacuse it will not work if I do not have the Book view selected.
I also tried doing the reverse: Have the OpenHandler completely handle the file operations, but I didn't find a way to reach the handler from the View: I tried something like:
	ICommandService cs = (ICommandService)getSite().getPage().getWorkbenchWindow().getService(ICommandService.class);
	Command cmd = cs.getCommand(OpenHandler.ID);
	cmd.addCommandListener(this);
	IHandler ih = cmd.getHandler();
	AbstractHandler ah = (AbstractHandler)ih;
	OpenHandler oh = (OpenHandler)ah;
	oh.getFile();
which does not work because ah is not my AbstractHandler, but a HandlerProxy which holds the reference I need in a private (handler) member.

Similar problems I have in Scene to retrieve the name of the input file from Book.

I currently solved the problem in a very ugly way: since I have a single instance of the Book View I declared a static member holding the reference to the singleton and I retrieve from there the instance I need.

I strongly suspect there are better methods.
Can someone point me in the right direction?
I do apologize for the length of the post, but I wanted to make clear where I'm lost.

Thanks in Advance
Mauro
Re: Lost in a maze. [message #499918 is a reply to message #499762] Tue, 24 November 2009 09:21 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Mauro Condarelli wrote on Mon, 23 November 2009 20:23

Up to this point the things are relatively clear and clean.
Scene uses what I believe is a correct way to hook to the selection:
		getSite().getPage().addSelectionListener(Book.ID, this);
Is this acceptable?\



It would be better to use:

ISelectionService s = getSite().getService(ISelectionService.class);
s.addSelectionListener(Book.ID, this);


This has the advantage that when your part is disposed, you don't have to worry about removing the selection listener (it gets cleaned up automatically).

Quote:


        IWorkbenchWindow ww = HandlerUtil.getActiveWorkbenchWindow(event);
        IWorkbench w = ww.getWorkbench();
        IWorkbenchPart wp = w.get
        if (wp instanceof Book) {
		Book b = (Book) wp;
		b.setFile(file);
	}




from the workbench window, I would go:

IWorkbenchPage page = ww.getActivePage();
Book part = (Book)page.findView(Book.ID);


You can put safeguards around that code, but basically look for your part by ID (or part reference, although in an RCP app that might not be as important).

PW



Previous Topic:Best Update Strategy
Next Topic:changing a viewPart name
Goto Forum:
  


Current Time: Wed Jul 30 05:24:14 EDT 2014

Powered by FUDForum. Page generated in 0.01952 seconds