Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » My plugin TextEditor is never created
My plugin TextEditor is never created [message #530856] Sat, 01 May 2010 22:44 Go to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
I have a plugin that implements a syntax highlighting text editor for a small programming language. In the debugger, I can open a file with my file extension and observe my partitioner and partition scanner being created, the partitioner is connected to the document, the input file is scanned and properly divided into the specified partitions (comments, strings, and everything else is the default partition for code). When it is finished, the source program is displayed in what looks like a default TextEditor. Breakpoints in my extension of TextEditor were never hit, including in the constructor. Hence, my syntax highlighting is never invoked, etc.

The extension in my plugin.xml is as follows:

   <extension
         point="org.eclipse.ui.editors">
         <editor
            name="T Language Editor"
            extensions="t"
            icon="icons/sample.gif"
            contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
            class="com.acme.t.editors.TEditor"
            id="com.acme.t.editors.TEditor"/>
   </extension>


In the com.acme.t.editors package is the file TEditor.java, with the class definition and constructor:

public class TEditor extends TextEditor {

   private ColorCache colorCache;
   private TEditConfiguration editConfiguration;

   public TEditor()
   {
      super();

      IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
      colorCache = new ColorCache();

      editConfiguration = new TEditConfiguration(colorCache, this,  preferences);

      setSourceViewerConfiguration(editConfiguration);
      setDocumentProvider(new TDocumentProvider());

      // enable standard vertical ruler
      setRangeIndicator(new DefaultRangeIndicator());
   }


Any ideas why my TEditor() constructor is never reached in the debugger? Does anyone know where I should set a breakpoint in Eclipse code to see it create the TextEditor that it is creating?

Thanks for any help.

Re: My plugin TextEditor is never created [message #531057 is a reply to message #530856] Mon, 03 May 2010 14:28 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2308
Registered: July 2009
Senior Member
Are you sure it's trying to open your editor? Does anything change if
you choose your editor from the file's Open With... context menu?

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: My plugin TextEditor is never created [message #531161 is a reply to message #531057] Mon, 03 May 2010 23:39 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
The Open With ... only has Notepad as a choice. My plugin is not a choice.

Re: My plugin TextEditor is never created [message #531163 is a reply to message #531057] Mon, 03 May 2010 23:44 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
Also, I cannot set up a File Association in Eclipse for my file extension, because my plugin is not one of the Editor choices. Of course, I have set up file associations in my plugin.xml file, as seen in my original post above for the editor extension point, and also for the document provider and the content type, as seen below:

<!-- document provider (even for the external files) -->
   <extension point="org.eclipse.ui.editors.documentProviders">
      <provider
            class="org.eclipse.ui.editors.text.TextFileDocumentProvider"
            inputTypes="org.eclipse.ui.IStorageEditorInput"
            id="org.eclipse.ui.editors.text.StorageDocumentProvider"/>
      <provider
            class="com.acme.t.editors.TDocumentProvider"
            id="com.acme.t.editors.TDocumentProvider"
            extensions=".t"/>
   </extension>
   <extension
         id = "TDocumentSetupParticipant"
         point = "org.eclipse.core.filebuffers.documentSetup">
      <participant
            class="com.acme.t.editors.TDocumentSetupParticipant"
            extensions="t"/>
   </extension>

<!-- T file content type, so that it is treated as text -->
  <extension point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            file-extensions="t"
            name="T Source File"
            id="tfile"
            base-type="org.eclipse.core.runtime.text"/>
   </extension>
   

Re: My plugin TextEditor is never created [message #531279 is a reply to message #530856] Tue, 04 May 2010 12:23 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Is anything in your log? either run with -consoleLog or look in your
<runtime-workspace>/.metadata/.log

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: My plugin TextEditor is never created [message #531289 is a reply to message #531279] Tue, 04 May 2010 12:55 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
Nothing has appeared in the log file for several days now except for brief mentions that usage data is being reported to eclipse.org (because I turned on usage data reporting when I installed Eclipse).

I see my breakpoints in my partitioner being hit when I open the file. I did a small amount of editing today to see what would happen when I deleted the last letter of a keyword, replaced it with a letter that makes it no longer be a keyword, then changed it back to being the keyword. The partitioner breakpoints were hit after each edit as it re-scanned the file. But it still never hit any breakpoints in my editor, and hence still never did any syntax highlighting.
Re: My plugin TextEditor is never created [message #531297 is a reply to message #531279] Tue, 04 May 2010 13:15 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
Does anyone know where in Eclipse it decides to create a particular text editor, so that I could set a breakpoint? Then I could see why it is creating a default editor instead of creating my editor.

Thanks,

Re: My plugin TextEditor is never created [message #531743 is a reply to message #531297] Thu, 06 May 2010 01:51 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
I have been setting breakpoints earlier and earlier in the Eclipse code. I keep seeing the editorId String "org.eclipse.ui.editors.DefaultTextEditor" passed as arguments, so I keep going back to an earlier spot.

Now, I am in org.eclipse.ui.internal.ReopenEditorMenu.java. The last method is called open() and looks like this:


  private void open(EditorHistoryItem item) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            try {
                String itemName = item.getName();
                if (!item.isRestored()) {
                    item.restoreState();
                }
                IEditorInput input = item.getInput();
                IEditorDescriptor desc = item.getDescriptor();
                if (input == null || desc == null) {
                    String title = WorkbenchMessages.OpenRecent_errorTitle;
                    String msg = NLS.bind(WorkbenchMessages.OpenRecent_unableToOpen,  itemName ); 
                    MessageDialog.openWarning(window.getShell(), title, msg);
                    history.remove(item);
                } else {
                    page.openEditor(input, desc.getId());
                }
            } catch (PartInitException e2) {
                String title = WorkbenchMessages.OpenRecent_errorTitle;
                MessageDialog.openWarning(window.getShell(), title, e2
                        .getMessage());
                history.remove(item);
            }
        }
    }



The 5th line of code:

String itemName = item.getName();

produces the name of the input source text file I just opened, "foo.t"

The 10th line of code:

IEditorDescriptor desc = item.getDescriptor();

produces a descriptor for the file foo.t, which already has the org.eclipse.ui.editors.DefaultTextEditor class filled in, with null for the editor name, etc.

So, despite the plugin.xml editor extension point that I showed earlier in this thread, Eclipse has associated my file with the default editor VERY early in the process.

If anyone knows where in the Eclipse code it would associate this file name with an editor descriptor, I will set breakpoints there. Otherwise, I will keep trying to trace backwards on my own.

Thanks.
Re: My plugin TextEditor is never created [message #531744 is a reply to message #531743] Thu, 06 May 2010 01:55 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
The above code is called from an event loop run from the workbench. I would suppose that the lazy loading of the plugin means that the plugin is not loaded until the file extension associated with it is seen. Is that right?

In which case, I guess that Eclipse processes the plugin.xml files for all the installed plugins, NOT lazily, to build a map associating file extensions with plugins, else it would not know what to do in this event loop when a file with my file extension is opened. Is that how it works?

So, it must be VERY early in Eclipse startup where my problem occurs, in which the plugin.xml is not processed properly to associate my editor with my file extension.

Any hints are appreciated. Getting very desperate here.
Re: My plugin TextEditor is never created [message #531746 is a reply to message #531744] Thu, 06 May 2010 02:04 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
One more desperate idea: Would it be possible to detach and close the default editor from within my partitioner, then open my own editor and attach it to the document?

The second part seems to be described here:

http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programm atically%3F

Not sure if it is possible to do things in this order (already existing partitioner creates TextEditor).

Not sure how to detach and close the default text editor, either.
Re: My plugin TextEditor is never created [message #531884 is a reply to message #531746] Thu, 06 May 2010 13:19 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

There's 2 possible things going on

1) if you ever opened one of your files with the text editor before,
eclipse remembers. The easy way to disprove that is to create a new
file for your file extension and try and open that.

2) don't use double-click to open. Instead, write a little command to
open your specific test file. For example:


public Object execute(ExecutionEvent event) {
IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject("testOpen ");
IFile file = project.getFile("open.t");
IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
.getActiveWorkbenchWindow(event);
activeWorkbenchWindow.getActivePage().openEditor(
new FileEditorInput(file), "your.editor.id");
return null;
}

This bypasses the system trying to guess your editor and simply opens it.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: My plugin TextEditor is never created [message #531907 is a reply to message #531884] Thu, 06 May 2010 13:59 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
Thanks for the reply.

I tried a new file with my file extension, and I get the same behavior. Very early in Eclipse code, it has decided to associate the DefaultTextEditor with my file.

I open the files using File->Open File. When I do this, it eventually opens my partitioner, which is also associated with the file extension. But this is after the point in time when it should have opened an editor for the same file extension.

The code you posted is a great idea, but where do I put it? My plug-in is really just an editor and a partitioner, with a document provider. As far as I know, my plug-in is not executing until I do the File->File Open, at which point Eclipse will create my partitioner due to the file extension. Should I have the user invoke the plug-in, then have it prompt for a file name, and then open the file using the code you provided?

I am not familiar with the code structure for a plug-in that gets invoked by the user. This is my first plug-in, and it has only been invoked by Eclipse due to the file open event.

Thanks for any advice.
Re: My plugin TextEditor is never created [message #531941 is a reply to message #531907] Thu, 06 May 2010 14:44 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
To make sure my question is clear: If a user ran my plug-in without opening a file first, where would the plug-in start executing, given that it is just an editor, a partitioner, and a document provider?
Re: My plugin TextEditor is never created [message #531998 is a reply to message #531907] Thu, 06 May 2010 17:48 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The code I offered is not the generic solution, simply a debugging step.
Create org.eclipse.ui.commands with the "Hello World Command" template.

You need to hard-code the project/filename so you know what gets opened.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: My plugin TextEditor is never created [message #531999 is a reply to message #531941] Thu, 06 May 2010 17:49 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Clark wrote:
> To make sure my question is clear: If a user ran my plug-in without
> opening a file first, where would the plug-in start executing, given
> that it is just an editor, a partitioner, and a document provider?
>

A plugin is not started until something causes a class to be loaded (in
the common case). If you provide an editor, your plugin is not started
until the user first opens your editor. The plugin.xml is read before
starting the plugin, that that's what makes your editor available to the
system.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: My plugin TextEditor is never created [message #532164 is a reply to message #531999] Fri, 07 May 2010 11:45 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
I have made some progress using the code you posted. I modified it to permit opening a file from a FileDialog. I am successfully opening files and creating my editor and passing the file to the editor. I can see the file being partitioned (as was always the case) and the file opens in a window.

Problem: Still no syntax highlighting. I can see my presentation reconciler being created, and three damager-repairers being created and attached to it (for my three partitions: comments, strings, and code (default)). But the scanners are apparently never used. In the scanner classes, I overrode the nextToken() methods to do nothing but call super.nextToken() just so I could set breakpoints and see if the nextToken() method (of RuleBasedScanner) is ever called. It is not. Who is supposed to be calling the scanners in the presentation reconciler to scan the partitions?

Here is the setup of my presentation reconciler:


  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {

        if (reconciler == null) {
            reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(TPartitions.T_PARTITION_TYPE);

            DefaultDamagerRepairer dr;

            // DefaultDamagerRepairer implements both IPresentationDamager, IPresentationRepairer
            // IPresentationDamager::getDamageRegion does not scan, just
            // returns the intersection of document event, and partition region
            // IPresentationRepairer::createPresentation scans
            // gets each token, and sets text attributes according to token

            // We need to cover all the content types from FastTPartitionScanner
            // Comments have uniform color
            commentScanner = new TColoredScanner(colorCache, new RGB(0, 192, 0), SWT.NORMAL);
            dr = new DefaultDamagerRepairer(commentScanner);
            reconciler.setDamager(dr, TPartitions.T_COMMENT);
            reconciler.setRepairer(dr, TPartitions.T_COMMENT);

            // Strings have uniform color
            stringScanner = new TColoredScanner(colorCache, new RGB(0, 0, 192), SWT.NORMAL);
            dr = new DefaultDamagerRepairer(stringScanner);
            reconciler.setDamager(dr, TPartitions.T_STRING);
            reconciler.setRepairer(dr, TPartitions.T_STRING);

            // Default content is code, we need syntax highlighting
            codeScanner = new TCodeScanner(colorCache);
            dr = new DefaultDamagerRepairer(codeScanner);
            reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
        }

        return reconciler;
    }



Note the comment (code was imitated from the PyDev project): the createPresentation() method in the repairer is the one that will use my scanners to do the syntax highlighting. However, breakpoints indicate that we never hit createPresentation(). I think this is because of the original problem: Eclipse is not calling my code due to the extension points set up in my plugin.xml. Rather, my editor is now being created in my own code that handles the new command.

As a result, I am thinking of calling the repairer's createPresentation() method directly from my partition scanner. The partition scanner IS called by Eclipse every time a single character of the file is changed during editing. I think I have to force the calling of my syntax highlighting scanners via IPresentationReconciler::createPresentation() because Eclipse does not invoke my editor via my editor extension point.

Not sure how I will ever get beyond this work-around approach, however. Any feedback is appreciated.
Re: My plugin TextEditor is never created [message #532197 is a reply to message #532164] Fri, 07 May 2010 13:52 Go to previous messageGo to next message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
Big current problem: Given a document and the editor for that document, I can get the repairer that I set up, and then I can call createPresentation() using that repairer, but the color does not change on the screen. I am doing the simplest case (applying the color green to the comment regions).

After I call createPresentation() do I have to do something else? Or is it hopeless to try to bypass the normal workings of Eclipse so much?

Thanks for any help. Eclipse has been a living hell so far.
Re: My plugin TextEditor is never created [message #532211 is a reply to message #532197] Fri, 07 May 2010 14:28 Go to previous message
Clark  is currently offline Clark
Messages: 21
Registered: April 2010
Junior Member
I have stepped through the DefaultDamagerRepairer::createPresentation() method and observed it correctly getting the green color for comments (RGB(0, 192, 0)) and calling addRange() for the range of the comment. addRange() sets up a StyleRange (again with the correct green color) and calls addStyleRange in the presentation. All that does is add the range to some range collection.

This makes me think that createPresentation() is not the ultimate action I need to take. Do I have to tell the viewer to update the presentation on the screen somehow?
Previous Topic:Handling Cut/Copy/Paste
Next Topic:unmet dependencies on installing PDT [SOLVED]
Goto Forum:
  


Current Time: Wed Oct 22 15:33:22 GMT 2014

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

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