[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] Getting the cursor position in the current editor

Hi ,

I am making some application in Java in which I have to get the cursor position or a mouseclick position in the current active editor... I created a very small code to start with

public class MouseTest {

public static void main(String[] args) {

System.out.println(PlatformUI.isWorkbenchRunning());
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor();
if (editor instanceof ITextEditor) {
ISelectionProvider selectionProvider = ((ITextEditor)editor).getSelectionProvider();
ISelection selection = selectionProvider.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)selection;
int offset = textSelection.getOffset(); // etc.
}
}
System.out.println( "hi --");
}
}


But when I run this application I get an error
Exception in thread "main" java.lang.IllegalStateException: Workbench has not been created yet.