Home » Eclipse Projects » Rich Client Platform (RCP) » Content not displayed with Common Navigator
Content not displayed with Common Navigator [message #453167] |
Mon, 24 July 2006 06:01  |
Eclipse User |
|
|
|
Hi,
I've been trying to implement a navigator view using documentation found
here
:http://scribbledideas.blogspot.com/2006/05/building-common- navigator-based-viewer_22.html.
I followed the different steps, and I created navigatorContent extension
and added a ITreeContentProvider. When i debug my code i see that
ContentProvider.getElements() method is called and I return a small arrays
of ebjects. BUT, nothing is displayed in the tree. Also it seems that the
LabelProvider is not called for the object i returned in content provider.
May be i'm wrong with triggerPoint or possibleChildren extensions, i don't
really know how to setup them as i setup the
viewerContentBinding.contentExtension.isRoot to true.
Any ideas or suggestions are welcome.
|
|
| | | | | | | | | | | | |
Re: Content not displayed with Common Navigator [message #454254 is a reply to message #454249] |
Wed, 23 August 2006 05:46   |
Eclipse User |
|
|
|
Hi,
I followd what your recommended an exported my application to a standalone
product.
As you may have seen on bug comment list (comment #21), I've tried two
versions of getDefaultPageInput().
When I use the one which returns ResourcesPlugin.getWorkspace().getRoot();
, i get the following error in .log :
!SESSION 2006-08-23 11:26:34.531
-----------------------------------------------
eclipse.buildId=unknown
java.version=1.5.0_07
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fr_FR
Command-line arguments: -os win32 -ws win32 -arch x86
!ENTRY org.eclipse.ui 4 4 2006-08-23 11:27:04.845
!MESSAGE Unable to save page input: R/, because it does not adapt to
IPersistableElement
When i try with the version which return my dummy NavigatorRoot, i get
quite the same:
!SESSION 2006-08-23 11:33:04.953
-----------------------------------------------
eclipse.buildId=unknown
java.version=1.5.0_07
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fr_FR
Command-line arguments: -os win32 -ws win32 -arch x86
!ENTRY org.eclipse.ui 4 4 2006-08-23 11:33:31.100
!MESSAGE Unable to save page input:
org.escapek.client.ui.repository.navigator.NavigatorRoot@2bfdff, because
it does not adapt to IPersistableElement
So, could it be that CommonNavigator can't persist neither my own root
neither the root he gets from ResourcesPlugin.getWorkspace().getRoot(),
because both are not IPersistableElement ? It would explain why further
starts (with a non-clean workspace) give a null inputElement because it
couldn't restore root state.
Now i'll try to implement IPersitableElement into my NavigatorRoot. Do you
have any code sample of a root element you use ?
Thanks,
Nico.
|
|
|
Re: Content not displayed with Common Navigator [message #454255 is a reply to message #454254] |
Wed, 23 August 2006 06:17   |
Eclipse User |
|
|
|
Ok, I think that i'm on the way .... ;)
I use the following getDefaultPageInput(), which return my dummy root.
public IAdaptable getDefaultPageInput()
{
IAdaptable root = new NavigatorRoot();
return root;
}
public class NavigatorRoot implements IAdaptable, IPersistableElement,
IElementFactory
{
public NavigatorRoot()
{ }
public Object getAdapter(Class adapter)
{
if(adapter == IPersistableElement.class)
return this;
return null;
}
public String getFactoryId()
{
return this.getClass().getCanonicalName();
}
public void saveState(IMemento memento)
{
// TODO Auto-generated method stub
return;
}
public IAdaptable createElement(IMemento memento)
{
return new NavigatorRoot();
}
}
In fact , I'just added IPersistableElement, and IElementFactory. This is
yet a bit messy, but by using this code, everything works fine !!!!
I can see more clearer now; but this makes me say that there may be a
problem when using ResourcesPlugin.getWorkspace().getRoot() to
getInitialInput, as the result seems to be not persistable.
|
|
| | | | |
Re: Content not displayed with Common Navigator [message #455242 is a reply to message #455233] |
Tue, 19 September 2006 05:32   |
Eclipse User |
|
|
|
Geri,
can you keep me in the loop, I'm struggeling at the same point :-(
Regards
Martin
"Geri Broser" <gerold.broser@easyklick.com> schrieb im Newsbeitrag
news:eemmr7$vlc$1@utils.eclipse.org...
>> Nico,
>>
>> I followed your discussion with great interest. Unfortunately the CN in
>> my RCP (still) doesn't display anything when I try your code:
>>
>> getDefaultPageInput() is called
>> getAdapter() is called with IWorkbenchAdapter as argument --> is
>> obviously not an IPersistableElement.class --> null is returned --> end
>> of the story
>> getFactoryID() is not called
>> createElement() is not called
>
> Is there _tested_, _really_ working sample code available somewhere? ( not
> just suggestions or shoulds or coulds ) After one week of googling,
> blogging, newsreading, trying, failing, trying again, failing again I'm
> rather desperate.
|
|
| | |
Re: Content not displayed with Common Navigator [message #455266 is a reply to message #455260] |
Tue, 19 September 2006 10:24   |
Eclipse User |
|
|
|
hi geri,
> The argument adapter to getAdapter(Class adapter) is still an
> org.eclipse.ui.model.IWorkbenchAdapter which IS NOT extended
> (=subinterfaced) by org.eclipse.core.runtime.IAdaptable (according to
> Eclipse v3.2 API doc ).
correct. nor by 'NavigatorRoot' eighter, of course.
> Hence, comparing an IWorkbenchAdapter (adapter) with an IAdaptable
> (NavigatorRoot), java.lang.Class.isAssignableFrom has no other choice
> than returning false ( according to Java 1.5.0 API doc ).
actually, the getAdapter method compares the argument to 'NavigatorRoot',
but you are right - because 'NavigatorRoot' implements 'IAdaptable' it
compares to 'IAdaptable' too.
and you are also right, that the method returns null for IWorkbenchAdapter
- but this is irrelevant for showing content.
> Or are there still knots in my brains?
1. we want to provide content at the cnf root level.
2. the cnf always takes the defaultPageInput as its root.
3. the common way to set the defaultPageInput (the default is the
WorkspaceRoot) is by overriding 'public IAdaptable getDefaultPageInput()'.
4. we create our own type (NavigatorRoot) to be able to compare
(instanceof) to something we know.
5. the reason for implementing 'IAdaptable' is, that only then we are able
to return our type through 'getDefaultPageInput()'.
it is a convention to react on the class' own type when querying for an
adapter.
6. by extension point declaration we hook our content to NavigatorRoot
(instanceof) and do the steps desribed at Michael D. Elder's blog in our
context.
works fine.
> P.S.: Can you tell us of which type is the argument Class adapter when
> you run/debug your code as a RCP?
the argument in my application is of the type
'org.eclipse.ui.model.IWorkbenchAdapter'.
it is not relevant, what or who queries our type for an adapter. you don't
have to care about it. it is not possible and it makes no sence to fulfill
any possible type-queries within our NavigatorRoot. it reacts on its own
type and returns null otherwise because we don't have got related objects
for our context.
it is very common in an extendable system to ask objects for adapters of
any type. the requested type belongs to the caller's context. for instance
the caller wants to know, wheter there is a new object opened or set,
which it can handle. in our case: it can't handle our object (because it
returns no adapter for the requested type). you can find more information
about the desing pattern 'Adapter' in the gang of four's design pattern
book.
what is positive for your application is, that your type made it to the
defaultPageInput. otherwise your getAdapter() method wouldn't be called or
you got a NullPointerException. nothing else matters.
now declare your content providers and label providers as your model and
context require. this can be tricky too, sometimes.
regards
sebastian
|
|
| | | | |
Re: Content not displayed with Common Navigator [message #457484 is a reply to message #454255] |
Wed, 01 November 2006 10:55   |
Eclipse User |
|
|
|
Originally posted by: alex.levato.ca
Just a followup for anyone else using the Common Navigator in an RCP
environment.
The root of the problem stems from the fact that the
CommonNavigator.getInitialInput() retrieves the initial input for the
viewer from the page's initial input.
It then uses the initial input object to check against the trigger points
in your extension plug in ( to see if your content provider can provide
children for this type ). However, IF the initial input is null, then your
extension plugin can never provide trigger points ( and neither will any
other extension ) because the code in
NavigatorContentDescriptor.isTriggerPoint() will return false if the input
is null.
So, what does this mean to an RCP implementor:
In your RCP, your workbench advisor SHOULD derive from the
WorkbenchAdvisor class ( rather than the IDEWorkbenchAdvisor, which is an
internal class and hence should not be subclassed. More on this later ) .
However, the default workbench advisor does not implement
getDefaultInput() ( it returns null ). So, if you do not override
getDefaultInput in your workbench advisor, your content will never be
displayed in the common navigator ( because of the behavior of the
isTriggerPoint() code above ).
Ok. So now you implement getDefaultInput in your advisor. If you simply
return the WorkspaceRoot, your navigator will work the first time you
start your app ( since there is no workspace metadata saved, the code will
ask your advisor for the default input object). However, the next time you
start the app, eclipse will try to restore from the workspace metadata
saved when it shuts down, and since WorkspaceRoot does not implement
IPersistable, your input from the previous session was not persisted. And
so, the restore code will try to read the input from the metadata and
return null.... And now your navigator does not work anymore (because the
input is null).
Therefore, you need to return an object from getDefaultInput() which is
persistable. This is what the previous poster has done. However, there is
still one piece of the puzzle. For eclipse to restore an object which was
persisted to saved data, it needs a factory to build the new object from
the metadata info. This is why you need to implement your "default input"
object as implementing IElementFactory ( or any other class you want to
use). Finally, you have to define an extension to the
org.eclipse.ui.elementFactories extension point an point it at your
factory so that eclipse can lookup your factory and restore your default
input object.
And now everything should work.
|
|
|
Re: Content not displayed with Common Navigator [message #459190 is a reply to message #457484] |
Tue, 28 November 2006 17:46   |
Eclipse User |
|
|
|
Alex,
thank you for the great write-up. I'd like to ask two more questions. In my
scenario I'd like to use CNF to provide the projects and provide the layer
below that myself, not bound to files or folders. I'm already struggeling on
the first point:
1) How does the standard ResourceNavigator provide the workbench contents if
it doesn't fit IPersistable- does even the IDE already subclass it?
2) The ResourcesPlugin is provided by org.eclipse.ui.ide instead of
org.eclipse.ui.navigator. This leads to using CNF requiring IDE, which adds
large size to the final RCP app and, even worse, java projects, wizards and
the like that is hard to get rid of- is it possible to use CNF in RCP apps
without relying on the IDE?
Thanks for your great support,
Andreas
"Alex Levato" <alex@levato.ca> wrote in message
news:6822c82feda362ee9e4191c20fb9ab12$1@www.eclipse.org...
> Just a followup for anyone else using the Common Navigator in an RCP
> environment.
>
> The root of the problem stems from the fact that the
> CommonNavigator.getInitialInput() retrieves the initial input for the
> viewer from the page's initial input.
> It then uses the initial input object to check against the trigger points
> in your extension plug in ( to see if your content provider can provide
> children for this type ). However, IF the initial input is null, then your
> extension plugin can never provide trigger points ( and neither will any
> other extension ) because the code in
> NavigatorContentDescriptor.isTriggerPoint() will return false if the input
> is null.
>
> So, what does this mean to an RCP implementor:
>
> In your RCP, your workbench advisor SHOULD derive from the
> WorkbenchAdvisor class ( rather than the IDEWorkbenchAdvisor, which is an
> internal class and hence should not be subclassed. More on this later ) .
> However, the default workbench advisor does not implement
> getDefaultInput() ( it returns null ). So, if you do not override
> getDefaultInput in your workbench advisor, your content will never be
> displayed in the common navigator ( because of the behavior of the
> isTriggerPoint() code above ).
>
> Ok. So now you implement getDefaultInput in your advisor. If you simply
> return the WorkspaceRoot, your navigator will work the first time you
> start your app ( since there is no workspace metadata saved, the code will
> ask your advisor for the default input object). However, the next time you
> start the app, eclipse will try to restore from the workspace metadata
> saved when it shuts down, and since WorkspaceRoot does not implement
> IPersistable, your input from the previous session was not persisted. And
> so, the restore code will try to read the input from the metadata and
> return null.... And now your navigator does not work anymore (because the
> input is null).
>
> Therefore, you need to return an object from getDefaultInput() which is
> persistable. This is what the previous poster has done. However, there is
> still one piece of the puzzle. For eclipse to restore an object which was
> persisted to saved data, it needs a factory to build the new object from
> the metadata info. This is why you need to implement your "default input"
> object as implementing IElementFactory ( or any other class you want to
> use). Finally, you have to define an extension to the
> org.eclipse.ui.elementFactories extension point an point it at your
> factory so that eclipse can lookup your factory and restore your default
> input object.
>
> And now everything should work.
|
|
| | | | | | | |
Re: Content not displayed with Common Navigator [message #459836 is a reply to message #455504] |
Thu, 07 December 2006 11:24   |
Eclipse User |
|
|
|
Nico, Sebastian, Geri,
still not entirely working for me. I've followed all steps described (wrote
the whole thing up under Eclipse Common Navigator Framework in RCP
Applications at http://www.cpuidle.de/blog/?p=48).
The RCP app does now run and the logfile stays clean, no exceptions.
Unfortunately, no projects are displayed either. I did somehow get it
working once but can't reproduce it. The difference ist that when
..metadata\.plugins\org.eclipse.core.resources\.projects is filled on
startup, the projects are found and new ones can be created. If I remove the
..plugins directory and restart, the naviagor stays empty, even when
refreshing the workspace.
Any idea how to initialize the workspace?
Thanks for your help,
Andreas
"Geri Broser" <gerold.broser@easyklick.com> wrote in message
news:efde71$2p0$1@utils.eclipse.org...
> Thx for the comprehensive info, which took a while to digest.
>
> Finally I managed it working. The main task was ...
>
> public void preStartup() {
> WorkbenchAdapterBuilder.registerAdapters();
> }
>
> ... in ApplicationWorkbenchAdvisor, where WorkbenchAdapterBuilder resides
> in org.eclipse.ui.internal.ide.model. Which is not mentioned in the API
> doc due to its internal nature.
>
> Thx a lot for all your assistance.
|
|
| | |
Goto Forum:
Current Time: Sat Mar 22 00:01:04 EDT 2025
Powered by FUDForum. Page generated in 0.05482 seconds
|