Home » Eclipse Projects » Eclipse Platform » [howto] Invoke a view programmatically?
[howto] Invoke a view programmatically? [message #29960] |
Tue, 13 May 2003 14:41  |
Eclipse User |
|
|
|
Hi,
I have written an Extension Point for a View and implemented a class
"MyView" derived from ViewPart. I have implemented the methods
"createPartControl" and
"setFocus". The view works just fine if I activate it via the menu
("Window/ShowView/Java/MyView").
But how can I activate it programmatically? I have looked into the source
of the jdt.junit plugin (since my view deals with different VM's, too) and
(I think I) followed their example. That is, I have written a class
"MyPlugin" which extends AbstractUIPlugin. In this class, I call a
"getActiveWorkbenchWindow().getActivePage().showView(<id of my view>);",
however "getActiveWorkbenchWindow()" returns null... And I cannot see,
why. In the plugin.xml file, I specified the correct plugin-class (i.e. I
specified the fully qualified name of MyPlugin).
Do I have to "register" my plugin somewhere? To I have to tell Eclipse
that "I am a View"? What did I forget to do?
Do you have any ideas?
Thanks for your help,
Philipp
|
|
|
Re: [howto] Invoke a view programmatically? [message #29968 is a reply to message #29960] |
Tue, 13 May 2003 15:31   |
Eclipse User |
|
|
|
Sorry, just found it:
the "getActiveWorkbenchWindow().getActivePage().showView(...)" method must
be called from a different (new) display thread...
Now it works...
Philipp
> Hi,
> I have written an Extension Point for a View and implemented a class
> "MyView" derived from ViewPart. I have implemented the methods
> "createPartControl" and
> "setFocus". The view works just fine if I activate it via the menu
> ("Window/ShowView/Java/MyView").
> But how can I activate it programmatically? I have looked into the source
> of the jdt.junit plugin (since my view deals with different VM's, too) and
> (I think I) followed their example. That is, I have written a class
> "MyPlugin" which extends AbstractUIPlugin. In this class, I call a
> "getActiveWorkbenchWindow().getActivePage().showView(<id of my view>);",
> however "getActiveWorkbenchWindow()" returns null... And I cannot see,
> why. In the plugin.xml file, I specified the correct plugin-class (i.e. I
> specified the fully qualified name of MyPlugin).
> Do I have to "register" my plugin somewhere? To I have to tell Eclipse
> that "I am a View"? What did I forget to do?
> Do you have any ideas?
> Thanks for your help,
> Philipp
|
|
|
Re: [howto] Invoke a view programmatically? [message #31651 is a reply to message #29968] |
Wed, 14 May 2003 11:03   |
Eclipse User |
|
|
|
Originally posted by: simon.ibm.oti.lab
You should avoid using getActionWorkbenchWindow(). It can and will return
null in some situations. I do not understand what you mean by "called from a
different (new) display thread". Are you creating a new Display?
Can you provide use with the use case for showing the view programmatically?
For instance, is it the case where you have a menu action, and if the user
runs this action you want to open the view? Or you want your view visible in
a given perspective X when perspective X is open?
Simon :-)
"Philipp Bouillon" <Philipp.Bouillon@t-online.de> wrote in message
news:b9rh64$fg2$1@rogue.oti.com...
> Sorry, just found it:
>
> the "getActiveWorkbenchWindow().getActivePage().showView(...)" method must
> be called from a different (new) display thread...
>
> Now it works...
> Philipp
>
> > Hi,
> > I have written an Extension Point for a View and implemented a class
> > "MyView" derived from ViewPart. I have implemented the methods
> > "createPartControl" and
> > "setFocus". The view works just fine if I activate it via the menu
> > ("Window/ShowView/Java/MyView").
> > But how can I activate it programmatically? I have looked into the
source
> > of the jdt.junit plugin (since my view deals with different VM's, too)
and
> > (I think I) followed their example. That is, I have written a class
> > "MyPlugin" which extends AbstractUIPlugin. In this class, I call a
> > "getActiveWorkbenchWindow().getActivePage().showView(<id of my view>);",
> > however "getActiveWorkbenchWindow()" returns null... And I cannot see,
> > why. In the plugin.xml file, I specified the correct plugin-class (i.e.
I
> > specified the fully qualified name of MyPlugin).
>
> > Do I have to "register" my plugin somewhere? To I have to tell Eclipse
> > that "I am a View"? What did I forget to do?
> > Do you have any ideas?
>
> > Thanks for your help,
> > Philipp
>
>
>
>
|
|
|
Re: [howto] Invoke a view programmatically? [message #36987 is a reply to message #31651] |
Sun, 18 May 2003 16:39   |
Eclipse User |
|
|
|
Sorry for the late reply, but I did not notice your post until now.
I am checking the return value of "getActiveWorkbenchWindow" -- so far, it
never returned null... But if it does, I "simply" do not show my view.
However, I have seen this method of diplaying a view by looking at the
code of the jdt.junit plugin.
All I am trying is to open a view at a certain point during the execution
of my plugin. Say, a user runs a JUnit test. One test fails. I do some
analysis. And I'd like to show the progress of the analysis in a separate
view (very similar to the JUnit view). So, I assume that a Java
perspective (or Java Browsing or Debugging, or whatever) is already open,
and all I'd like to do, is to show my view on top of the package explorer.
What I meant by "called from a different (new) display thread" was simply
that I had to make the call as a new Runnable object:
display.syncExec(new Runnable() {
public void run() {
listeningView = MyPlugin.getDefault().connectMyView();
});
and this works fine for me -- did I overlook anything?
Thanks for your advice,
Philipp
> You should avoid using getActionWorkbenchWindow(). It can and will return
> null in some situations. I do not understand what you mean by "called from a
> different (new) display thread". Are you creating a new Display?
> Can you provide use with the use case for showing the view programmatically?
> For instance, is it the case where you have a menu action, and if the user
> runs this action you want to open the view? Or you want your view visible in
> a given perspective X when perspective X is open?
> Simon :-)
> "Philipp Bouillon" <Philipp.Bouillon@t-online.de> wrote in message
> news:b9rh64$fg2$1@rogue.oti.com...
> > Sorry, just found it:
> >
> > the "getActiveWorkbenchWindow().getActivePage().showView(...)" method must
> > be called from a different (new) display thread...
> >
> > Now it works...
> > Philipp
> >
> > > Hi,
> > > I have written an Extension Point for a View and implemented a class
> > > "MyView" derived from ViewPart. I have implemented the methods
> > > "createPartControl" and
> > > "setFocus". The view works just fine if I activate it via the menu
> > > ("Window/ShowView/Java/MyView").
> > > But how can I activate it programmatically? I have looked into the
> source
> > > of the jdt.junit plugin (since my view deals with different VM's, too)
> and
> > > (I think I) followed their example. That is, I have written a class
> > > "MyPlugin" which extends AbstractUIPlugin. In this class, I call a
> > > "getActiveWorkbenchWindow().getActivePage().showView(<id of my view>);",
> > > however "getActiveWorkbenchWindow()" returns null... And I cannot see,
> > > why. In the plugin.xml file, I specified the correct plugin-class (i.e.
> I
> > > specified the fully qualified name of MyPlugin).
> >
> > > Do I have to "register" my plugin somewhere? To I have to tell Eclipse
> > > that "I am a View"? What did I forget to do?
> > > Do you have any ideas?
> >
> > > Thanks for your help,
> > > Philipp
> >
> >
> >
> >
|
|
| |
Re: [howto] Invoke a view programmatically? [message #46068 is a reply to message #40447] |
Fri, 23 May 2003 11:01  |
Eclipse User |
|
|
|
Aaaaahh... Yes. That sounds good. Thanks for the information. My code
seems to be a lot cleaner now ;-)).
Thanks,
Philipp
> "Philipp Bouillon" <Philipp.Bouillon@t-online.de> wrote in message
> news:ba8r2s$uvc$1@rogue.oti.com...
> > Sorry for the late reply, but I did not notice your post until now.
> > I am checking the return value of "getActiveWorkbenchWindow" -- so far, it
> > never returned null... But if it does, I "simply" do not show my view.
> > However, I have seen this method of diplaying a view by looking at the
> > code of the jdt.junit plugin.
> Does not mean they are doing it right ;-)
> You want to open a view at a point in the execution of your plugin. What
> started that long running execution in your plugin? Was it an action? If so,
> it should have enough context for you to determine what the window is. Then
> past that along to show any views you need to (still using the syncExec call
> since it seems this long running operation is in the background thread)
> Simon :-)
|
|
|
Goto Forum:
Current Time: Tue Sep 02 19:02:42 EDT 2025
Powered by FUDForum. Page generated in 0.03879 seconds
|