Home » Eclipse Projects » Eclipse Platform » Team Decorators not displaying in TreeView
|
Re: Team Decorators not displaying in TreeView [message #176363 is a reply to message #176314] |
Tue, 06 January 2004 21:21 |
Eclipse User |
|
|
|
Originally posted by: Michael_Valenta.oti.com
Mike,
You need to use a special lable provider that UI provides. It can be
obtained using the following snipet:
WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()
It you want to customize the behavior of your label provider, you can
create a custom label provider that delegates to the above label
provider to get the decorated image.
Michael
Mike Winston wrote:
> Win2000, E2.1
>
> I am created a TreeView for a new perspective. It took a while to figure
> out, but I finally got the Team menu to show up in my Popup Context Menu.
> I still can't get the decorators to show up though. I do have them
> enabled through the preference window (they work in the resource
> perspective). I have created a LabelProvider to go with my TreeView so I
> can have the icons to go along with my tree.
>
> Everything I have read says that CVS should just take care of this, but
> there must be some trick to getting it to work with a new TreeViewer.
>
> Can anyone please help or send some documentation on how to do this???
>
> Thanks,
> Mike Winston
>
>
|
|
|
Re: Team Decorators not displaying in TreeView [message #176436 is a reply to message #176363] |
Tue, 06 January 2004 23:51 |
Mike Winston Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Thanks for the quick response, but still a little lost. What do you mean
by "delegate"?? Are you saying I should extend WorkbenchLabelProvider, or
should it be used in the LabelProvider. If you do just use it in
LabelProvider, then where/how do you implement this??
I do want to create a custom label provider, so I have a class that looks
like:
public class AdaLabelProvider extends LabelProvider {
public AdaLabelProvider() {
super();
}
/*
* @see ILabelProvider#getImage(Object)
*/
public Image getImage(Object element) {
MarkElement me = (MarkElement) element;
ImageDescriptor descriptor = getDescriptor(me);
//obtain the cached image corresponding to the descriptor
Image image = (Image)imageCache.get(descriptor);
if (image == null) {
image = descriptor.createImage();
imageCache.put(descriptor, image); // cache the image for efficiency,
sice we'll have many elements use the same image
}
return image;
}
public ImageDescriptor getDescriptor(MarkElement me) {
// returns the ImageDescriptor depending on the type attribute of the
MarkElement objects
ImageDescriptor descriptor = null;
if ((me.getMarkElementType()).equals("file") && me.getResource()!=null
&& hasValidExtension((IFile)me.getResource()))
descriptor = AdaPlugin.getImageDescriptor("FileImage.gif");
}
if(descriptor==null) // get image from system
descriptor = ((new
TempLabelProvider()).getTempAdapter(me.getResource())).getIm ageDescriptor(me.getResource());
if(descriptor==null)
descriptor = AdaPlugin.getImageDescriptor("Others.gif"); // our default
image
return descriptor;
}
/*
* @see ILabelProvider#getText(Object)
*/
public String getText(Object element) {
return ((MarkElement)element).getLabel() +
((MarkElement)element).getLabelAddition();
}
class TempLabelProvider extends WorkbenchLabelProvider {
public IWorkbenchAdapter getTempAdapter(Object o) {
return super.getAdapter(o);
}
}
public void dispose() {
for (Iterator i = imageCache.values().iterator(); i.hasNext();) {
((Image) i.next()).dispose();
}
imageCache.clear();
}
protected RuntimeException unknownElement(Object element) {
return new RuntimeException("Unknown type of element in tree of type " +
element.getClass().getName());
}
}
Michael Valenta wrote:
> Mike,
> You need to use a special lable provider that UI provides. It can be
> obtained using the following snipet:
> WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()
> It you want to customize the behavior of your label provider, you can
> create a custom label provider that delegates to the above label
> provider to get the decorated image.
> Michael
> Mike Winston wrote:
> > Win2000, E2.1
> >
> > I am created a TreeView for a new perspective. It took a while to figure
> > out, but I finally got the Team menu to show up in my Popup Context Menu.
> > I still can't get the decorators to show up though. I do have them
> > enabled through the preference window (they work in the resource
> > perspective). I have created a LabelProvider to go with my TreeView so I
> > can have the icons to go along with my tree.
> >
> > Everything I have read says that CVS should just take care of this, but
> > there must be some trick to getting it to work with a new TreeViewer.
> >
> > Can anyone please help or send some documentation on how to do this???
> >
> > Thanks,
> > Mike Winston
> >
> >
|
|
|
Re: Team Decorators not displaying in TreeView [message #176489 is a reply to message #176436] |
Wed, 07 January 2004 01:32 |
Mike Winston Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Okay, so I did some more playing and here is what I came up with:
treeViewer.setLabelProvider(new
DecoratingLabelProvider(myCustomLabelProvider,
((DecoratingLabelProvider)WorkbenchLabelProvider.getDecorati ngWorkbenchLabelProvider()).getLabelDecorator()));
So far this is mostly working. It has added the decorators to my tree,
but it has added them to all the branches, not just the file name. I am
looking at the PDE navigator and there are decorators on the file name,
but not as you go down into the tree. I would like this same thing to
happen. How do you specify where to stop??? Or am I totally doing this
wrong???
Mike Winston wrote:
> Thanks for the quick response, but still a little lost. What do you mean
> by "delegate"?? Are you saying I should extend WorkbenchLabelProvider, or
> should it be used in the LabelProvider. If you do just use it in
> LabelProvider, then where/how do you implement this??
> I do want to create a custom label provider, so I have a class that looks
> like:
> public class AdaLabelProvider extends LabelProvider {
> public AdaLabelProvider() {
> super();
> }
> /*
> * @see ILabelProvider#getImage(Object)
> */
> public Image getImage(Object element) {
> MarkElement me = (MarkElement) element;
> ImageDescriptor descriptor = getDescriptor(me);
> //obtain the cached image corresponding to the descriptor
> Image image = (Image)imageCache.get(descriptor);
> if (image == null) {
> image = descriptor.createImage();
> imageCache.put(descriptor, image); // cache the image for efficiency,
> sice we'll have many elements use the same image
> }
> return image;
> }
> public ImageDescriptor getDescriptor(MarkElement me) {
> // returns the ImageDescriptor depending on the type attribute of the
> MarkElement objects
> ImageDescriptor descriptor = null;
> if ((me.getMarkElementType()).equals("file") && me.getResource()!=null
> && hasValidExtension((IFile)me.getResource()))
> descriptor = AdaPlugin.getImageDescriptor("FileImage.gif");
> }
> if(descriptor==null) // get image from system
> descriptor = ((new
>
TempLabelProvider()).getTempAdapter(me.getResource())).getIm ageDescriptor(me.getResource());
> if(descriptor==null)
> descriptor = AdaPlugin.getImageDescriptor("Others.gif"); // our default
> image
> return descriptor;
> }
> /*
> * @see ILabelProvider#getText(Object)
> */
> public String getText(Object element) {
> return ((MarkElement)element).getLabel() +
> ((MarkElement)element).getLabelAddition();
> }
> class TempLabelProvider extends WorkbenchLabelProvider {
> public IWorkbenchAdapter getTempAdapter(Object o) {
> return super.getAdapter(o);
> }
> }
> public void dispose() {
> for (Iterator i = imageCache.values().iterator(); i.hasNext();) {
> ((Image) i.next()).dispose();
> }
> imageCache.clear();
> }
> protected RuntimeException unknownElement(Object element) {
> return new RuntimeException("Unknown type of element in tree of type " +
> element.getClass().getName());
> }
> }
> Michael Valenta wrote:
> > Mike,
> > You need to use a special lable provider that UI provides. It can be
> > obtained using the following snipet:
> > WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()
> > It you want to customize the behavior of your label provider, you can
> > create a custom label provider that delegates to the above label
> > provider to get the decorated image.
> > Michael
> > Mike Winston wrote:
> > > Win2000, E2.1
> > >
> > > I am created a TreeView for a new perspective. It took a while to figure
> > > out, but I finally got the Team menu to show up in my Popup Context
Menu.
> > > I still can't get the decorators to show up though. I do have them
> > > enabled through the preference window (they work in the resource
> > > perspective). I have created a LabelProvider to go with my TreeView so I
> > > can have the icons to go along with my tree.
> > >
> > > Everything I have read says that CVS should just take care of this, but
> > > there must be some trick to getting it to work with a new TreeViewer.
> > >
> > > Can anyone please help or send some documentation on how to do this???
> > >
> > > Thanks,
> > > Mike Winston
> > >
> > >
|
|
|
Re: Team Decorators not displaying in TreeView [message #176745 is a reply to message #176489] |
Wed, 07 January 2004 14:36 |
Eclipse User |
|
|
|
Originally posted by: Michael_Valenta.oti.com
Mike,
I don't think what you have is quite right. It looks like it will do
double decoration (which may not cause a visual problem but will do
twice the work). Have a look at the DecoratingJavaLabelProvider (in the
project org.eclipse.jdt.ui). It subclasses DecoratingJavaLabelProvider
in order to customize the label provider.
The PDE Navigator? Do you mean the Package Explorer? I believe the
package explorer uses the DecoratingJavaLabelProvider so this should
give you hints about what your seeing. I'm not sure if this is the
prblem but basically, the Eclipse label decorator will decorate anything
that adapts to an IResource.
Hope this helps,
Michael
Mike Winston wrote:
> Okay, so I did some more playing and here is what I came up with:
>
> treeViewer.setLabelProvider(new
> DecoratingLabelProvider(myCustomLabelProvider,
> ((DecoratingLabelProvider)WorkbenchLabelProvider.getDecorati ngWorkbenchLabelProvider()).getLabelDecorator()));
>
> So far this is mostly working. It has added the decorators to my tree,
> but it has added them to all the branches, not just the file name. I am
> looking at the PDE navigator and there are decorators on the file name,
> but not as you go down into the tree. I would like this same thing to
> happen. How do you specify where to stop??? Or am I totally doing this
> wrong???
>
> Mike Winston wrote:
>
>
>>Thanks for the quick response, but still a little lost. What do you mean
>>by "delegate"?? Are you saying I should extend WorkbenchLabelProvider, or
>>should it be used in the LabelProvider. If you do just use it in
>>LabelProvider, then where/how do you implement this??
>>
>
>>I do want to create a custom label provider, so I have a class that looks
>>like:
>>public class AdaLabelProvider extends LabelProvider {
>>
>
>> public AdaLabelProvider() {
>> super();
>> }
>>
>
>> /*
>> * @see ILabelProvider#getImage(Object)
>> */
>> public Image getImage(Object element) {
>>
>
>> MarkElement me = (MarkElement) element;
>> ImageDescriptor descriptor = getDescriptor(me);
>> //obtain the cached image corresponding to the descriptor
>> Image image = (Image)imageCache.get(descriptor);
>> if (image == null) {
>> image = descriptor.createImage();
>> imageCache.put(descriptor, image); // cache the image for efficiency,
>>sice we'll have many elements use the same image
>> }
>> return image;
>> }
>>
>
>> public ImageDescriptor getDescriptor(MarkElement me) {
>>
>
>> // returns the ImageDescriptor depending on the type attribute of the
>>MarkElement objects
>> ImageDescriptor descriptor = null;
>>
>
>> if ((me.getMarkElementType()).equals("file") && me.getResource()!=null
>>&& hasValidExtension((IFile)me.getResource()))
>> descriptor = AdaPlugin.getImageDescriptor("FileImage.gif");
>>
>
>> }
>> if(descriptor==null) // get image from system
>> descriptor = ((new
>>
>>
> TempLabelProvider()).getTempAdapter(me.getResource())).getIm ageDescriptor(me.getResource());
>
>> if(descriptor==null)
>> descriptor = AdaPlugin.getImageDescriptor("Others.gif"); // our default
>>image
>>
>
>> return descriptor;
>> }
>> /*
>> * @see ILabelProvider#getText(Object)
>> */
>>
>
>> public String getText(Object element) {
>> return ((MarkElement)element).getLabel() +
>>((MarkElement)element).getLabelAddition();
>> }
>>
>
>> class TempLabelProvider extends WorkbenchLabelProvider {
>>
>
>> public IWorkbenchAdapter getTempAdapter(Object o) {
>> return super.getAdapter(o);
>> }
>>
>
>> }
>>
>
>> public void dispose() {
>> for (Iterator i = imageCache.values().iterator(); i.hasNext();) {
>> ((Image) i.next()).dispose();
>> }
>> imageCache.clear();
>> }
>>
>
>> protected RuntimeException unknownElement(Object element) {
>> return new RuntimeException("Unknown type of element in tree of type " +
>>element.getClass().getName());
>> }
>>}
>>
>
>
>>Michael Valenta wrote:
>>
>
>>>Mike,
>>>
>
>>>You need to use a special lable provider that UI provides. It can be
>>>obtained using the following snipet:
>>>
>
>>> WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()
>>>
>
>>>It you want to customize the behavior of your label provider, you can
>>>create a custom label provider that delegates to the above label
>>>provider to get the decorated image.
>>>
>
>>>Michael
>>>
>
>>>Mike Winston wrote:
>>>
>
>>>>Win2000, E2.1
>>>>
>>>>I am created a TreeView for a new perspective. It took a while to figure
>>>>out, but I finally got the Team menu to show up in my Popup Context
>>>>
> Menu.
>
>>>>I still can't get the decorators to show up though. I do have them
>>>>enabled through the preference window (they work in the resource
>>>>perspective). I have created a LabelProvider to go with my TreeView so I
>>>>can have the icons to go along with my tree.
>>>>
>>>>Everything I have read says that CVS should just take care of this, but
>>>>there must be some trick to getting it to work with a new TreeViewer.
>>>>
>>>>Can anyone please help or send some documentation on how to do this???
>>>>
>>>>Thanks,
>>>>Mike Winston
>>>>
>>>>
>>>>
>
>
|
|
|
Goto Forum:
Current Time: Sun Dec 22 01:31:59 GMT 2024
Powered by FUDForum. Page generated in 0.04443 seconds
|