[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| [pde-dev] Selection Text doesn't work !!! | 
Hi, 
 
I need to select text and insert text in all the editors. 
While I can do the same when I open a file with text editor. The same doesn't work when i open it with XML Editor.
 
I have a ActionDelegate subclass that has the following code in the run method:
 
 
  // get the opened document  
  IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage().getActiveEditor();
  IEditorSite site = part.getEditorSite
();
  TextFileDocumentProvider docProvider = new TextFileDocumentProvider();
  try {
    docProvider.connect(part.getEditorInput());
  } catch (CoreException e) {
   e.printStackTrace();
  }
  IDocument doc = docProvider.getDocument(part.getEditorInput());
 
// get the cursor position/selected area in the editor
 
 ISelection selection = site.getSelectionProvider().getSelection();
  
   try {
    // get the selected text
   String selectedText = ((ITextSelection)selection).getText();
    System.out.println(" Selected text : " + selectedText);
    // insert a text
   start = ((ITextSelection)selection).getOffset();
   doc.replace(start, 0, "init section #1 starts here .... ends here");
   } catch (BadLocationException exp) {
      e.printStackTrace();
   }
 
 
selectedText is null when its XML Editor. Even though the XML editor displays the xml file as set of characters like a text editor, why i cannot acheive the functionality ?
 
Please help me ASAP.
 
Thanks