2

I create eclipse plugin (button), which insert some text into active open file. I inspirate http://wiki.eclipse.org/FAQ_How_do_I_insert_text_in_the_active_text_editor%3F

public class PasteTextAction implements IWorkbenchWindowActionDelegate {

  private IWorkbenchWindow window;

  public void run(IAction aAction) {

    IWorkbenchPage page = window.getActivePage();
    IEditorPart part = page.getActiveEditor();
    if (!(part instanceof AbstractTextEditor))
      return;
    ITextEditor editor = (ITextEditor) part;
    IDocumentProvider dp = editor.getDocumentProvider();
    IDocument doc = dp.getDocument(editor.getEditorInput());

    try {
      int offset = doc.getLineOffset(doc.getNumberOfLines() - 4);
      doc.replace(offset, 0, "pasteText\n");
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }

  public void selectionChanged(IAction aAction, ISelection aSelection) {

  }

  public void dispose() {

  }

  public void init(IWorkbenchWindow aWindow) {
    window = aWindow;
  }

}

It works great.

But I have problem with readonly file or file under ClearCase version control system. It paste text into editor, but it doesn't try set file writable or doesn't paste it if file can't set writable. (It doesn't open CheckOut window for ClearCase file).

How can I set file writable programmatically?

kubedan
  • 616
  • 2
  • 7
  • 26

1 Answers1

1

Note that any java solution in your Eclipse plugin would only work for a snapshot view.
(provided you have the right Java version)

If you are in a dynamic view, a setWritable(true); will not work.
You will have to execute a cleartool checkout -nc filePath.


The OP kubedan comments:

I use snapshot view.
Maybe I don't want set file writable, because setWritable(true); hijack the file (I don't want hijack the file).
I want open CheckOut window. The same behavior if I paste text from clipboard.

There is no easy way to display the native ClearCase "Checkout" dialog box.
You would have to recreate it (managing the UCM activity as well is you are using UCM web view), as the ClearCase plugin does in Eclipse:

enter image description here

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I use snapshot view. Mayby I dont want set file writable, because `setWritable(true);` hijack the file (I dont want hijack the file). I want open CheckOut window. The same behavior if I paste text from clipboard. – kubedan Jan 29 '13 at 11:21
  • @kubedan not sure it can be done from an Eclipse without having to recreate the checkout dialog box. See my edit. – VonC Jan 29 '13 at 12:37
  • Is in eclipse some (openfile) listener which can I call in my plugin ? Than eclipse create CheckOut window itself. I would like simulate same situation like I paste text by Ctrl+V. – kubedan Jan 29 '13 at 14:21