Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Changing a Viewpart from a Menu item(User selects menu item -> update a view. How to do it ?)
Changing a Viewpart from a Menu item [message #696971] Fri, 15 July 2011 08:27 Go to next message
Daniel Santos is currently offline Daniel Santos
Messages: 2
Registered: July 2011
Junior Member
Hello,

I have a menu Item that when selected should change a view part's widget layout.
For now I am using the selection provider-selection listener pattern in a way
that I don't like very much.

In a class I have a static member that stores a reference to the menu command's
handler object. When I construct the command object I store it there. The menu command implements the ISelectionProvider interface.

In the view, on the createPartControl method I set the selection provider to the
command object I stored previously and register the view as a selection listener.
Like this :

public void createPartControl(Composite parent) {
...
getSite().setSelectionProvider(Application.getLoadTxFileCmdObj());
getSite().getPage().addSelectionListener(this);
...


The problem is that the view part is doing the selection provider addition code.
I would prefer to do it on the menu command class. But there is no method that
is run at initialization after all objects are constructed.

Is there a standard way to make this communication happen between a menu command and a view ?

Thanks for your reply
Re: Changing a Viewpart from a Menu item [message #698052 is a reply to message #696971] Mon, 18 July 2011 17:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Usually you would just find the view in your handler's execute(ExecutionEvent) method, no?

If you work against the active view, something like:

IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part instanceof MyView) {
    ((MyView)part).updateView();
}


If you need to find your view, you could use something like:

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IViewReference ref = window.getActivePage().findViewReference(MyView.ID);
if (ref != null && ref.getPart(false)!=null) {
    ((MyView)ref.getPart(false)).updateView();
}


PW


Re: Changing a Viewpart from a Menu item [message #698093 is a reply to message #698052] Mon, 18 July 2011 18:47 Go to previous messageGo to next message
Daniel Santos is currently offline Daniel Santos
Messages: 2
Registered: July 2011
Junior Member
What you are saying seems like the most direct way of doing the view update. But that way is synchronous. Wouldn't the user interface block until the view was finished updating ?
I used the provider-listener pattern because I thought that the update would be asynchronous, so that the application can continue responding while the update is being done.

Daniel
Re: Changing a Viewpart from a Menu item [message #698418 is a reply to message #698093] Tue, 19 July 2011 12:53 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Those selection notifications are done in the UI thread, so it would be just as blocking.

If you have a long-running operation, try the Jobs framework:
http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html

if (part instanceof MyView) {
    Job job = new Job("viewUpdate") {
        public IStatus run(IProgressMonitor monitor) {
            ((MyView)part).updateView(monitor);
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}


then you have to make sure if you update an UI, you use a UIJob or display.asyncExec(*) to post it back to the UI thread.

PW


Previous Topic:Add a listener to ViewPart title or title image?
Next Topic:How to override plugin_customization.ini from a fragment
Goto Forum:
  


Current Time: Thu Oct 30 23:52:03 GMT 2014

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

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