Jump to: navigation, search

Eclipsepedia talk:Tips and Tricks

Revision as of 23:19, 24 February 2008 by Agramirez.exist.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

FAQ How do I open an editor programmatically in Eclipse 3.3?

First of all, this works on eclipse 3.3.0. I haven't tried the codes on the other versions of eclipse.


            import java.io.File;

            import org.eclipse.core.filesystem.EFS;
            import org.eclipse.core.filesystem.IFileStore;

            import org.eclipse.ui.PartInitException;
            import org.eclipse.ui.IWorkbenchPage;
            import org.eclipse.ui.PlatformUI;
            import org.eclipse.ui.ide.IDE;

            ...



            File fileToOpen = new File( textField.getText() );

            if ( fileToOpen.exists() && fileToOpen.isFile() )
            {
                IFileStore fileStore = EFS.getLocalFileSystem().getStore( fileToOpen.toURI() );

                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                try
                {
                    IDE.openEditorOnFileStore( page, fileStore );

                }
                catch ( PartInitException e )
                {
                    //Create your error handler codes here
                }
            }
            else
            {
                //You may do something if the file is not a file and the file does not exist
            }


See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.