Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Programatically invoke Editor(Create Editor window inside KeyListener)
Programatically invoke Editor [message #860648] Sat, 28 April 2012 02:12 Go to next message
Charles Tubbs is currently offline Charles Tubbs
Messages: 35
Registered: March 2012
Member
I want to use a KeyListener, in my TreeViewer, to invoke an Editor window, similar to what happens when you double-click a source file name in Eclipse's Package Explorer. Can anybody tell me how this is done?
Re: Programatically invoke Editor [message #867088 is a reply to message #860648] Tue, 01 May 2012 01:51 Go to previous messageGo to next message
Charles Tubbs is currently offline Charles Tubbs
Messages: 35
Registered: March 2012
Member
Just in case somebody else wants to know the answer to this question, I will describe what I did. I created my Editor Input and Action classes but DID NOT add the action to a menu. I inserted code similar to the following into my KeyListener:

IWorkbenchWindow window = getSite().getWorkbenchWindow();
Action action = new DiaAction();
action.init(window);
action.run();


The action's run method looks like this:

public void run() {
IWorkbenchPage page = window.getActivePage();
DiaInput input = new DiaInput(blank);
try {
page.openEditor(input, editorID);
} catch (PartInitException e) {
// handle error
}
}

I don't know if this is the correct way to do it, but it seems to work, so far.
Re: Programatically invoke Editor [message #868525 is a reply to message #867088] Wed, 02 May 2012 02:37 Go to previous message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi Charles,
open the editor via the WorkbenchWindow is OK. Personally I would solve this problem the Eclipse way by implementing a command, a handler and a binding.

In that case something like this would be appropriate.

<extension
         point="org.eclipse.ui.commands">
      <command
            id="testWsCall"
            name="testWsCall">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="testspringws.TestWsCallHandler"
            commandId="testWsCall">
         <enabledWhen>
              <with
                     variable="selection">
                  <iterate
                        ifEmpty="false"
                        operator="or">
                     <!-- put something resonable here -->
                     <instanceof
                           value="java.lang.Object">
                     </instanceof>
                  </iterate>
               </with>
           </enabledWhen>      
       </handler>
   </extension>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="testWsCall"
            contextId="org.eclipse.ui.contexts.window"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M1+O">
      </key>
   </extension>



The enabledWhen expression should have some resonable subexpressions that checks the current selection. That way you have a command that is decoupled from the viewer and can be used elsewhere in your application.

Regards
Thorsten
Previous Topic:p2 update on read-only file system
Next Topic:Add .exe in a View of RCP
Goto Forum:
  


Current Time: Wed Jul 30 13:25:29 EDT 2014

Powered by FUDForum. Page generated in 0.02433 seconds