Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Getting the Position of an Editor(How to get the absolute Position of an Editor)
Getting the Position of an Editor [message #1016674] Thu, 07 March 2013 05:33 Go to next message
Mark Geiger is currently offline Mark Geiger
Messages: 2
Registered: March 2013
Junior Member
I tried several things, but sadly none of them seem to work how i need it to.

        final IWorkbenchPart activePart = PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow().getActivePage().getActivePart();
        WorkflowEditor editor = (WorkflowEditor) activePart;      
        GraphicalViewer viewer = editor.getViewer();
        FigureCanvas figure = ((FigureCanvas) viewer.getControl());

        figure.getBounds().x
        figure.getViewport().getClientArea().x
        figure.getShell().getBounds().x
        figure.getLocation().x


all of these returns just give me the position of the application itself or just 0.

But what i figured out, when i add a MouseListener to the "figure", the MouseEvents give me the Positions i need.
        figure.addMouseMoveListener(new MouseMoveListener() {   
            @Override
            public void mouseMove(MouseEvent arg0) {
                // TODO Auto-generated method stub
                offsetx = MouseInfo.getPointerInfo().getLocation().x - arg0.x;
                offsety = MouseInfo.getPointerInfo().getLocation().y - arg0.y;
                
            }
        });


I need a way to get these informations. Is it possible to get the informations the MouseEvent has, without using an EventListener?
Re: Getting the Position of an Editor [message #1016915 is a reply to message #1016674] Fri, 08 March 2013 03:14 Go to previous messageGo to next message
karthykeyan Palanisamy is currently offline karthykeyan Palanisamy
Messages: 4
Registered: May 2010
Location: Bangalore
Junior Member

From a TextEditor, you can get the document, document provider, and selection. That will give you access to the current cursor offset.

ITextEditor editor = (ITextEditor) editorPart
.getAdapter(ITextEditor.class);
IDocumentProvider provider = editor.getDocumentProvider();
IDocument document = provider.getDocument(editorPart
.getEditorInput());
ITextSelection textSelection = (ITextSelection) editorPart
.getSite().getSelectionProvider().getSelection();
int offset = textSelection.getOffset();
int lineNumber = document.getLineOfOffset(offset);

IDocument provides other methods to get the starts of lines (you can calculate the column from that).

I got this for one of the forum...


Thanks and Regards
Karthikeyan
Re: Getting the Position of an Editor [message #1017277 is a reply to message #1016674] Mon, 11 March 2013 08:57 Go to previous message
Mark Geiger is currently offline Mark Geiger
Messages: 2
Registered: March 2013
Junior Member
Thanks for your help. But I think you misunderstood me, What I need is not the current Cursor Position.

The thing with the mouseListener is just a super ugly workaround that does "work", because arg0.x hast the relative position of the cursor to the Editor and MouseInfo gets me the relative position to the whole application. Subtracting the 2 values gives me what i need: the relative position of the Editor to the Application.

The Editor is not a TextEditor so your suggestion doesnt work for me.

Thanks.
Previous Topic:Transfer Crashes Application
Next Topic:Change the DaD feedback on the pointer
Goto Forum:
  


Current Time: Tue Sep 02 15:06:25 EDT 2014

Powered by FUDForum. Page generated in 0.01579 seconds