Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/eclipse/jdt/actions/GotoOffsetAction.java


1   /*
2    * Created on Apr 27, 2003
3    */
4   package com.port80.eclipse.jdt.actions;
5   
6   import org.eclipse.jface.action.IAction;
7   import org.eclipse.jface.dialogs.InputDialog;
8   import org.eclipse.jface.text.IDocument;
9   import org.eclipse.jface.text.TextSelection;
10  import org.eclipse.jface.viewers.ISelection;
11  import org.eclipse.jface.window.Window;
12  import org.eclipse.ui.IEditorActionDelegate;
13  import org.eclipse.ui.IEditorPart;
14  import org.eclipse.ui.IWorkbenchWindow;
15  import org.eclipse.ui.IWorkbenchWindowActionDelegate;
16  import org.eclipse.ui.texteditor.StatusTextEditor;
17  
18  import com.port80.eclipse.jdt.JdtPlugin;
19  
20  /**
21   * Goto character offset in active editor.
22   * @author chrisl
23   */
24  public class GotoOffsetAction implements IWorkbenchWindowActionDelegate, IEditorActionDelegate {
25  
26    ////////////////////////////////////////////////////////////////////////
27  
28    private static final String NAME = "GotoOffsetAction";
29    private static final String ID = "com.port80.eclipse.jdt.actions.GotoOffsetAction";
30    private static final boolean DEBUG = true;
31  
32    ////////////////////////////////////////////////////////////////////////
33  
34    public GotoOffsetAction() {
35      super();
36    }
37  
38    ////////////////////////////////////////////////////////////////////////
39  
40    public void run(IAction action) {
41      Object part = JdtPlugin.getActiveWorkbenchWindow().getActivePage().getActivePart();
42      if (DEBUG)
43        System.err.println(NAME + ".run(): " + part);
44      if (part instanceof StatusTextEditor) {
45        StatusTextEditor editor = (StatusTextEditor) part;
46        IDocument doc=editor.getDocumentProvider().getDocument(editor.getEditorInput());
47        int len=doc.getLength();
48        ISelection selection=editor.getSelectionProvider().getSelection();
49        String init="";
50        if(selection instanceof TextSelection) {
51          init=""+((TextSelection)selection).getOffset();
52        }
53        InputDialog dialog =
54          new InputDialog(
55            JdtPlugin.getActiveWorkbenchShell(),
56            "Goto offset",
57            "Enter offset (0-"+len+") :",
58            init,
59            null);
60        if (dialog.open() != Window.OK)
61          return;
62        String value = dialog.getValue();
63        try {
64          int offset = Integer.parseInt(value);
65          editor.selectAndReveal(offset, 0);
66        } catch (NumberFormatException e) {
67          JdtPlugin.log("value=" + value, e);
68        }
69      }
70    }
71  
72    public void dispose() {
73    }
74  
75    public void init(IWorkbenchWindow window) {
76    }
77  
78    public void selectionChanged(IAction action, ISelection selection) {
79    }
80  
81    ////////////////////////////////////////////////////////////////////////
82  
83    /*
84     * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
85     */
86    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
87    }
88  
89    ////////////////////////////////////////////////////////////////////////
90  
91  }