Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » Help required on setting editor icon from code
icon5.gif  Help required on setting editor icon from code [message #636123] Fri, 29 October 2010 12:14 Go to next message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Hi,

Is it possible to identify and set the icons of the editor from code? This is my usecase. I have an editor that supports different file extensions. Behavior is same for all the editors but I would like to show different icons for the editor based on the file extension. Currently, I specify the icon required in "plugin.xml" in the "org.eclipse.ui.editors"'s extension.
As of now, I have created different editors that points to same class, only difference being icon and file extension.
If it is possible to set the icon from code, then I can have a single editor for all the file extensions.

Is such a thing is possible or is this a stupid idea??

Thanks,
Daisy.
Re: Help required on setting editor icon from code [message #636616 is a reply to message #636123] Tue, 02 November 2010 09:00 Go to previous messageGo to next message
David Largeteau is currently offline David LargeteauFriend
Messages: 35
Registered: July 2009
Location: Bordeaux - France
Member
daisydale85@yahoo.com a écrit :
> Hi,
>
> Is it possible to identify and set the icons of the editor from code?
> This is my usecase. I have an editor that supports different file
> extensions. Behavior is same for all the editors but I would like to
> show different icons for the editor based on the file extension.
> Currently, I specify the icon required in "plugin.xml" in the
> "org.eclipse.ui.editors"'s extension. As of now, I have created
> different editors that points to same class, only difference being icon
> and file extension. If it is possible to set the icon from code, then I
> can have a single editor for all the file extensions.
> Is such a thing is possible or is this a stupid idea??
>
> Thanks,
> Daisy.

Hi,

Take a look at setTitleImage(Image titleImage) method in WorkbenchPart
class (call it from your ScriptEditor based class).

David
Re: Help required on setting editor icon from code [message #636663 is a reply to message #636616] Tue, 02 November 2010 11:47 Go to previous messageGo to next message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Thank you, David. That does the trick. I can update the title image of the editor based on extension.

So I would like to proceed to the next step.
Is it possible to update the image of the file in "Project Explorer" also? Currently, it is displaying the icon of default editor. Icon change is getting reflected only in the editor view.
Also, is it possible to show the icon associated with the extension in "Open With" option which we get on right clicking on the file from "Project Explorer" as well as in "Window->Prefernces->General->Editors->File Associations"?

Thanks again,
Daisy.
Re: Help required on setting editor icon from code [message #636665 is a reply to message #636663] Tue, 02 November 2010 12:03 Go to previous messageGo to next message
David Largeteau is currently offline David LargeteauFriend
Messages: 35
Registered: July 2009
Location: Bordeaux - France
Member
daisydale85@yahoo.com a écrit :
> Thank you, David. That does the trick. I can update the title image of
> the editor based on extension.
>
> So I would like to proceed to the next step.
> Is it possible to update the image of the file in "Project Explorer"
> also? Currently, it is displaying the icon of default editor. Icon
> change is getting reflected only in the editor view. Also, is it
> possible to show the icon associated with the extension in "Open With"
> option which we get on right clicking on the file from "Project
> Explorer" as well as in "Window->Prefernces->General->Editors->File
> Associations"?
>
> Thanks again,
> Daisy.

Take a look at org.eclipse.dltk.ui.modelLabelProvider extension point.
Create a LabelProvider based class and extend getImage(Object element)
method. I think it should help you doing what you want to do.

David
Re: Help required on setting editor icon from code [message #636668 is a reply to message #636665] Tue, 02 November 2010 12:25 Go to previous messageGo to next message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Thank you again, David..
I'll try that.

Thanks,
Daisy.
Re: Help required on setting editor icon from code [message #636905 is a reply to message #636123] Wed, 03 November 2010 10:04 Go to previous messageGo to next message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Hi David,

I was able to change the icons in "Script Explorer" using "org.eclipse.dltk.ui.modelLabelProvider". But it was not getting reflected in Project Explorer as well as in Package Explorer. Hence I tried using "org.eclipse.ui.decorators" by giving it as given below.

<extension point="org.eclipse.ui.decorators"> 
	<decorator 
	    id="sample.ui.editor.DemoDecorator" 
	    label="Sample Decorator" 
	    state="true" 	    
	    class= "sample.ui.editor.DemoDecorator"	    
	    adaptable="true"> 	  
	    <enablement>
            <and>
            	<objectClass name="org.eclipse.core.resources.IFile"/>
	     <objectState
                   name="projectNature"
                   value="sample.core.nature">
             </objectState>
               </and>
         </enablement>	    
	  </decorator> 
</extension>


This is working though I am not sure whether this is the right method to do. Can we make the changes in ProjectExplorer and PackageExplorer using "org.eclipse.dltk.ui.modelLabelProvider" itself? This was how I gave the extension point.
<extension
          point="org.eclipse.dltk.ui.modelLabelProvider">
       <modelLabelProvider
             class="sample.ui.editor.CELabelProvider"
             id="sample.ui.SampleLabelProvider"
             language="sample.core.nature">
       </modelLabelProvider>
    </extension>


Is there anything wrong in this?

Also, one more issue.. I am using setTitleImage as you suggested for changing the title image. But here, I am getting one issue. If I am closing eclipse without closing all my files, next time, when I open, correct title image will be set only for the file which has focus. For rest of the opened files, it will be displaying the default image. I know that this is because we are setting the title image from editor. Only when the files get focus, their title image will get updated. Is there any way to solve this?

Thanks in advance,
Daisy.
Re: Help required on setting editor icon from code [message #637112 is a reply to message #636905] Thu, 04 November 2010 09:02 Go to previous messageGo to next message
David Largeteau is currently offline David LargeteauFriend
Messages: 35
Registered: July 2009
Location: Bordeaux - France
Member
daisydale85@yahoo.com a écrit :
> Hi David,
>
> I was able to change the icons in "Script Explorer" using
> "org.eclipse.dltk.ui.modelLabelProvider". But it was not getting
> reflected in Project Explorer as well as in Package Explorer. Hence I
> tried using "org.eclipse.ui.decorators" by giving it as given below.
>
> <extension point="org.eclipse.ui.decorators"> <decorator
> id="sample.ui.editor.DemoDecorator" label="Sample Decorator"
> state="true" class=
> "sample.ui.editor.DemoDecorator" adaptable="true">
> <enablement>
> <and>
> <objectClass name="org.eclipse.core.resources.IFile"/>
> <objectState
> name="projectNature"
> value="sample.core.nature">
> </objectState>
> </and>
> </enablement> </decorator> </extension>
>
> This is working though I am not sure whether this is the right method to
> do. Can we make the changes in ProjectExplorer and PackageExplorer using
> "org.eclipse.dltk.ui.modelLabelProvider" itself? This was how I gave the
> extension point.
> <extension
> point="org.eclipse.dltk.ui.modelLabelProvider">
> <modelLabelProvider
> class="sample.ui.editor.CELabelProvider"
> id="sample.ui.SampleLabelProvider"
> language="sample.core.nature">
> </modelLabelProvider>
> </extension>
>
> Is there anything wrong in this?
>
> Also, one more issue.. I am using setTitleImage as you suggested for
> changing the title image. But here, I am getting one issue. If I am
> closing eclipse without closing all my files, next time, when I open,
> correct title image will be set only for the file which has focus. For
> rest of the opened files, it will be displaying the default image. I
> know that this is because we are setting the title image from editor.
> Only when the files get focus, their title image will get updated. Is
> there any way to solve this?
>
> Thanks in advance,
> Daisy.

Hi Daisy,

I just noticed that I have the same problems :-(
I will see what I can do to solve them.

David
Re: Help required on setting editor icon from code [message #637158 is a reply to message #637112] Thu, 04 November 2010 12:18 Go to previous messageGo to next message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Hi David,

I was able to update the icons in PackageExplorer view and ProjectExplorer view using "org.eclipse.ui.decorators" and it is working though I am not sure whether it is a good method.

Following items are also there in my wishlist
1) See how title image can be set from some other place other than editor.
2) Remove icon set for the editor's name given in "Open With" option (I want the entry similar to that of the "Default Editor" option, i.e, without icon.)
3) Remove icon of my custom editor associated with the file extension in "Window"->"Preferences"->"General"->"Editors"->"File Associations"

Will keep posted if there is any progress..

Thanks,
Daisy.
Re: Help required on setting editor icon from code [message #640190 is a reply to message #637158] Fri, 19 November 2010 13:23 Go to previous messageGo to next message
David Largeteau is currently offline David LargeteauFriend
Messages: 35
Registered: July 2009
Location: Bordeaux - France
Member
daisydale85@yahoo.com a écrit :
> Hi David,
>
> I was able to update the icons in PackageExplorer view and
> ProjectExplorer view using "org.eclipse.ui.decorators" and it is working
> though I am not sure whether it is a good method.
>
> Following items are also there in my wishlist
> 1) See how title image can be set from some other place other than editor.
> 2) Remove icon set for the editor's name given in "Open With" option (I
> want the entry similar to that of the "Default Editor" option, i.e,
> without icon.)
> 3) Remove icon of my custom editor associated with the file extension in
> "Window"->"Preferences"->"General"->"Editors"->"File Associations"
>
> Will keep posted if there is any progress..
>
> Thanks, Daisy.

Hi Daisy,

I have solved my problems by adding as many org.eclipse.ui.editors
extension points as different extension I want to manage, and put the
right image in the extension point definition.

Probably not required for you, but I also :
- have modified my script editor class to be an abstract class (I don't
want it to be used directly).
- have added editor classes that extend the abstract editor class above.
In these classes, I have put a method returning specific editor image
(called from abstract editor), and other specific stuff.

That's work fine, both with unopened editor (tabbed), and in package
explorer (and in navigator view).

David
Re: Help required on setting editor icon from code [message #640485 is a reply to message #640190] Mon, 22 November 2010 10:08 Go to previous message
daisydale85 is currently offline daisydale85Friend
Messages: 38
Registered: August 2010
Member
Hi David,

Thank you for the reply. I tried the diffenent editors option itself initially. But since there wasnt any difference other than the icon among these editors, I wanted to remove this multiple editor option and replace it with a single editor. I was trying some other options as well (using decorators extension) but it wasnt a complete success. You can see my queries regarding the issues faced when I tried that way in this link ( http://www.eclipse.org/forums/index.php?t=msg&th=199906& amp;start=0&S=32bf90ecf1c92747f6226ff518e9cec3).

Once again, thank you for the update.
Regards,
Daisy.
Previous Topic:Tutorial for parser development
Next Topic:Find LocalVariable references not posible in Project Scope
Goto Forum:
  


Current Time: Sun Oct 06 16:44:50 GMT 2024

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

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

Back to the top