Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » custom content provider not automatically activated
custom content provider not automatically activated [message #325760] Tue, 26 February 2008 14:48 Go to next message
Andreas Pakulat is currently offline Andreas PakulatFriend
Messages: 127
Registered: July 2009
Senior Member
Hi,

I've got a relatively simple custom content provider for a CommonNavigator
view. The provider itself seems to work quite fine, but I can't seem to
find out why it displays the content only after I've disabled and
re-enabled the content provider under the Customize View dialog. After the
re-enabling I see the two nodes, but not when initially showing the view.

Any ideas?

Andreas

The content provider code is as follows and its just bound to a plain
CommonNavigator view.

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.progress.UIJob;

public class MyTreeContentProvider implements ITreeContentProvider,
IResourceChangeListener, IResourceDeltaVisitor
{

private String root;
private String[] childs = { "foo", "bar" };

private StructuredViewer viewer;

public MyTreeContentProvider()
{
System.err.println("content tree provider");
System.out.println( "Using squish content provider" );
ResourcesPlugin.getWorkspace().addResourceChangeListener( this,
IResourceChangeEvent.POST_CHANGE );
}

@Override
public Object[] getChildren( Object parentElement )
{
// TODO Auto-generated method stub
System.err.println( "TreeProvider.getChildren:" +
parentElement+"|"+parentElement.getClass() );
if ( parentElement instanceof String ) {
return new String[0];
} else {
return childs;
}
}

@Override
public Object getParent( Object element )
{
// TODO Auto-generated method stub
if( element.equals( childs[0] ) || element.equals( childs[1] ) )
return root;
System.err.println( "TreeProvider.getParent" + element
+"|"+element.getClass() );
return null;
}

@Override
public boolean hasChildren( Object element )
{
// TODO Auto-generated method stub
System.err.println( "TreeProvider.hasChildren:"+element+"|"+
element.getClass() );
return getChildren( element ).length > 0;
}

@Override
public Object[] getElements( Object inputElement )
{
// TODO Auto-generated method stub
System.err.println( "TreeProvider.getElements:" +
inputElement+"|"+inputElement.getClass() );
return getChildren( inputElement );
}

@Override
public void dispose()
{
System.err.println( "TreeProvider.dispose" );
ResourcesPlugin.getWorkspace().removeResourceChangeListener( this );
// TODO Auto-generated method stub

}

@Override
public void inputChanged( Viewer aviewer, Object oldInput, Object
newInput )
{
System.err.println( "TreeProvider.inputChanged" );
viewer = (StructuredViewer)aviewer;
// TODO Auto-generated method stub

}

/*
* (non-Javadoc)
*
*/
public void resourceChanged( IResourceChangeEvent event )
{
System.out.println("TreeProvider.resourceChagned");
IResourceDelta delta = event.getDelta();
try {
delta.accept( this );
} catch ( CoreException e ) {
e.printStackTrace();
}
}

/*
* (non-Javadoc)
*
*/
public boolean visit( IResourceDelta delta )
{
IResource source = delta.getResource();
System.out.println("TreeProvider.visit:"+source.getType() );
switch ( source.getType() ) {
case IResource.FOLDER:
System.err.println("folder change");
final IFolder f = (IFolder)source;
System.err.println("updating view");
new UIJob("Update Properties Model in CommonViewer") {
public IStatus runInUIThread(IProgressMonitor monitor) {
if (viewer != null
&& !viewer.getControl().isDisposed()) {
System.err.println("refreshing viewer for
project");
viewer.refresh(f);
}
return Status.OK_STATUS;
}
}.schedule();

case IResource.ROOT:
System.err.println("root change:");
final IResource root = (IResource)source;
System.err.println("updating view");
new UIJob("Update Properties Model in CommonViewer") {
public IStatus runInUIThread(IProgressMonitor monitor) {
if (viewer != null
&& !viewer.getControl().isDisposed()) {
System.err.println("refreshing viewer for
project");
viewer.refresh(root);
}
return Status.OK_STATUS;
}
}.schedule();

case IResource.PROJECT:
System.err.println("project change");
final IProject project = (IProject)source;
System.err.println("updating view");
new UIJob("Update Properties Model in CommonViewer") {
public IStatus runInUIThread(IProgressMonitor monitor) {
if (viewer != null
&& !viewer.getControl().isDisposed()) {
System.err.println("refreshing viewer for
project");
viewer.refresh(project);
}
return Status.OK_STATUS;
}
}.schedule();
return false;
case IResource.FILE:
System.err.println("got file");
final IFile file = (IFile) source;
// if (PROPERTIES_EXT.equals(file.getFileExtension())) {
// updateModel(file);
new UIJob("Update Properties Model in CommonViewer") {
public IStatus runInUIThread(IProgressMonitor monitor)
{
if (viewer != null
&& !viewer.getControl().isDisposed()) {
System.err.println("refreshing viewer for
file");
viewer.refresh(file);
}
return Status.OK_STATUS;
}
}.schedule();
// }
return false;
default:
System.err.println("unknown change");
}
return true;
}
}
Re: custom content provider not automatically activated [message #325777 is a reply to message #325760] Tue, 26 February 2008 19:20 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
Hi,

The content provider must be set before that viewer call setInput method.
Is this?


Cheers,
Xiangya
Andreas Pakulat 写道:
> Hi,
>
> I've got a relatively simple custom content provider for a CommonNavigator
> view. The provider itself seems to work quite fine, but I can't seem to
> find out why it displays the content only after I've disabled and
> re-enabled the content provider under the Customize View dialog. After the
> re-enabling I see the two nodes, but not when initially showing the view.
>
> Any ideas?
>
> Andreas
>
> The content provider code is as follows and its just bound to a plain
> CommonNavigator view.
>
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IFolder;
> import org.eclipse.core.resources.IProject;
> import org.eclipse.core.resources.IResource;
> import org.eclipse.core.resources.IResourceChangeEvent;
> import org.eclipse.core.resources.IResourceChangeListener;
> import org.eclipse.core.resources.IResourceDelta;
> import org.eclipse.core.resources.IResourceDeltaVisitor;
> import org.eclipse.core.resources.ResourcesPlugin;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.core.runtime.IStatus;
> import org.eclipse.core.runtime.Status;
> import org.eclipse.jface.viewers.ITreeContentProvider;
> import org.eclipse.jface.viewers.StructuredViewer;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.ui.progress.UIJob;
>
> public class MyTreeContentProvider implements ITreeContentProvider,
> IResourceChangeListener, IResourceDeltaVisitor
> {
>
> private String root;
> private String[] childs = { "foo", "bar" };
>
> private StructuredViewer viewer;
>
> public MyTreeContentProvider()
> {
> System.err.println("content tree provider");
> System.out.println( "Using squish content provider" );
> ResourcesPlugin.getWorkspace().addResourceChangeListener( this,
> IResourceChangeEvent.POST_CHANGE );
> }
>
> @Override
> public Object[] getChildren( Object parentElement )
> {
> // TODO Auto-generated method stub
> System.err.println( "TreeProvider.getChildren:" +
> parentElement+"|"+parentElement.getClass() );
> if ( parentElement instanceof String ) {
> return new String[0];
> } else {
> return childs;
> }
> }
>
> @Override
> public Object getParent( Object element )
> {
> // TODO Auto-generated method stub
> if( element.equals( childs[0] ) || element.equals( childs[1] ) )
> return root;
> System.err.println( "TreeProvider.getParent" + element
> +"|"+element.getClass() );
> return null;
> }
>
> @Override
> public boolean hasChildren( Object element )
> {
> // TODO Auto-generated method stub
> System.err.println( "TreeProvider.hasChildren:"+element+"|"+
> element.getClass() );
> return getChildren( element ).length > 0;
> }
>
> @Override
> public Object[] getElements( Object inputElement )
> {
> // TODO Auto-generated method stub
> System.err.println( "TreeProvider.getElements:" +
> inputElement+"|"+inputElement.getClass() );
> return getChildren( inputElement );
> }
>
> @Override
> public void dispose()
> {
> System.err.println( "TreeProvider.dispose" );
> ResourcesPlugin.getWorkspace().removeResourceChangeListener( this );
> // TODO Auto-generated method stub
>
> }
>
> @Override
> public void inputChanged( Viewer aviewer, Object oldInput, Object
> newInput )
> {
> System.err.println( "TreeProvider.inputChanged" );
> viewer = (StructuredViewer)aviewer;
> // TODO Auto-generated method stub
>
> }
>
> /*
> * (non-Javadoc)
> *
> */
> public void resourceChanged( IResourceChangeEvent event )
> {
> System.out.println("TreeProvider.resourceChagned");
> IResourceDelta delta = event.getDelta();
> try {
> delta.accept( this );
> } catch ( CoreException e ) {
> e.printStackTrace();
> }
> }
>
> /*
> * (non-Javadoc)
> *
> */
> public boolean visit( IResourceDelta delta )
> {
> IResource source = delta.getResource();
> System.out.println("TreeProvider.visit:"+source.getType() );
> switch ( source.getType() ) {
> case IResource.FOLDER:
> System.err.println("folder change");
> final IFolder f = (IFolder)source;
> System.err.println("updating view");
> new UIJob("Update Properties Model in CommonViewer") {
> public IStatus runInUIThread(IProgressMonitor monitor) {
> if (viewer != null
> && !viewer.getControl().isDisposed()) {
> System.err.println("refreshing viewer for
> project");
> viewer.refresh(f);
> }
> return Status.OK_STATUS;
> }
> }.schedule();
>
> case IResource.ROOT:
> System.err.println("root change:");
> final IResource root = (IResource)source;
> System.err.println("updating view");
> new UIJob("Update Properties Model in CommonViewer") {
> public IStatus runInUIThread(IProgressMonitor monitor) {
> if (viewer != null
> && !viewer.getControl().isDisposed()) {
> System.err.println("refreshing viewer for
> project");
> viewer.refresh(root);
> }
> return Status.OK_STATUS;
> }
> }.schedule();
>
> case IResource.PROJECT:
> System.err.println("project change");
> final IProject project = (IProject)source;
> System.err.println("updating view");
> new UIJob("Update Properties Model in CommonViewer") {
> public IStatus runInUIThread(IProgressMonitor monitor) {
> if (viewer != null
> && !viewer.getControl().isDisposed()) {
> System.err.println("refreshing viewer for
> project");
> viewer.refresh(project);
> }
> return Status.OK_STATUS;
> }
> }.schedule();
> return false;
> case IResource.FILE:
> System.err.println("got file");
> final IFile file = (IFile) source;
> // if (PROPERTIES_EXT.equals(file.getFileExtension())) {
> // updateModel(file);
> new UIJob("Update Properties Model in CommonViewer") {
> public IStatus runInUIThread(IProgressMonitor monitor)
> {
> if (viewer != null
> && !viewer.getControl().isDisposed()) {
> System.err.println("refreshing viewer for
> file");
> viewer.refresh(file);
> }
> return Status.OK_STATUS;
> }
> }.schedule();
> // }
> return false;
> default:
> System.err.println("unknown change");
> }
> return true;
> }
> }
>
Re: custom content provider not automatically activated [message #325778 is a reply to message #325777] Tue, 26 February 2008 19:35 Go to previous messageGo to next message
Andreas Pakulat is currently offline Andreas PakulatFriend
Messages: 127
Registered: July 2009
Senior Member
Qinxian wrote:

> Hi,
>
> The content provider must be set before that viewer call setInput method.
> Is this?

I don't do either, I just have the needed extension point declarations in my
plugin.xml.

org.eclipse.ui.navigator.CommonNavigator does seem to set at least the
filter and sorter before setting the input. I can't find any place where
the content provider is set though.

Andreas
Re: custom content provider not automatically activated [message #325784 is a reply to message #325778] Wed, 27 February 2008 03:20 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
Yes, It seems be setInput.
Do you checked activeByDefault attribute of navigatorContent be true?

Xiangya

Andreas Pakulat 写道:
> Qinxian wrote:
>
>> Hi,
>>
>> The content provider must be set before that viewer call setInput method.
>> Is this?
>
> I don't do either, I just have the needed extension point declarations in my
> plugin.xml.
>
> org.eclipse.ui.navigator.CommonNavigator does seem to set at least the
> filter and sorter before setting the input. I can't find any place where
> the content provider is set though.
>
> Andreas
Re: custom content provider not automatically activated [message #325806 is a reply to message #325784] Wed, 27 February 2008 16:52 Go to previous messageGo to next message
Andreas Pakulat is currently offline Andreas PakulatFriend
Messages: 127
Registered: July 2009
Senior Member
Qinxian wrote:

> Yes, It seems be setInput.
> Do you checked activeByDefault attribute of navigatorContent be true?

Yes thats set to true. Also the item has a checkmark in the Customize View..
dialog.

Maybe noteworthy: The content provider works on the project/folder/file
stuff from the workspace, just displays it a bit different. And the problem
is that after creating a new project it isn't shown until I disable and
re-enable the custom content provider.

Andreas
Re: custom content provider not automatically activated [message #325813 is a reply to message #325806] Thu, 28 February 2008 01:10 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
Hi,

Now It looks same as bug 156357: [CommonNavigator] Project Explorer does
not show contributed view menu actions unless opened on startup
https://bugs.eclipse.org/bugs/show_bug.cgi?id=156357

Which version yours?

Xiangya

Andreas Pakulat 写道:
> Qinxian wrote:
>
>> Yes, It seems be setInput.
>> Do you checked activeByDefault attribute of navigatorContent be true?
>
> Yes thats set to true. Also the item has a checkmark in the Customize View..
> dialog.
>
> Maybe noteworthy: The content provider works on the project/folder/file
> stuff from the workspace, just displays it a bit different. And the problem
> is that after creating a new project it isn't shown until I disable and
> re-enable the custom content provider.
>
> Andreas
Re: custom content provider not automatically activated [message #325856 is a reply to message #325813] Fri, 29 February 2008 08:32 Go to previous messageGo to next message
Andreas Pakulat is currently offline Andreas PakulatFriend
Messages: 127
Registered: July 2009
Senior Member
Qinxian wrote:

> Hi,
>
> Now It looks same as bug 156357: [CommonNavigator] Project Explorer does
> not show contributed view menu actions unless opened on startup
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=156357
>
> Which version yours?

I'm using:
org.eclipse.ui_3.3.1.M20070910-0800b.jar
org.eclipse.ui.navigator_3.3.2.M20071022-1600a.jar
org.eclipse.ui.navigator.resources_3.3.1.M20070831-2000.jar

so that should be fixed as far as I understand...

Andreas
Re: custom content provider not automatically activated [message #921719 is a reply to message #325856] Mon, 24 September 2012 11:21 Go to previous message
Maria Brown is currently offline Maria BrownFriend
Messages: 1
Registered: September 2012
Junior Member
LearnMax offers Custom Content Development, a custom courseware developed to meet the unique training development needs of the clients. It is an end to end training solution starting from content design and development enabling you to upgrade and enhance your training requirements.

Kochar Infotech Pvt Ltd
learnmax(dot)co(dot)in
Previous Topic:Shutdown process and builder with UI-Dependencies
Next Topic:Race conditions in AnnotationModel? Error annotations lost in Reconciler
Goto Forum:
  


Current Time: Sun Dec 21 04:05:59 GMT 2014

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

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