Java Code Examples for org.eclipse.ui.IWorkbenchPage#openEditor()

The following examples show how to use org.eclipse.ui.IWorkbenchPage#openEditor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GWTProjectPropertyPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void reopenWithGWTJavaEditor(IEditorReference[] openEditors) {
  IWorkbenchPage page = JavaPlugin.getActivePage();

  for (IEditorReference editorRef : openEditors) {
    try {
      IEditorPart editor = editorRef.getEditor(false);
      IEditorInput input = editorRef.getEditorInput();

      // Close the editor, prompting the user to save if document is dirty
      if (page.closeEditor(editor, true)) {
        // Re-open the .java file in the GWT Java Editor
        IEditorPart gwtEditor = page.openEditor(input, GWTJavaEditor.EDITOR_ID);

        // Save the file from the new editor if the Java editor's
        // auto-format-on-save action screwed up the JSNI formatting
        gwtEditor.doSave(null);
      }
    } catch (PartInitException e) {
      GWTPluginLog.logError(e, "Could not open GWT Java editor on {0}", editorRef.getTitleToolTip());
    }
  }
}
 
Example 2
Source File: GeometryEclipseFormWidget.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This operation displays the {@link ReflectivityFormEditor} instead of the
 * standard ICEFormEditor.
 */
@Override
public void display() {

	// Local Declarations
	IWorkbenchPage page = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage();

	// Create the ICEFormInput for the ReflectivityFormBuilder.
	ICEFormInput = new ICEFormInput(widgetForm);

	try {
		// Use the workbench to open the editor with our input.
		IEditorPart formEditor = page.openEditor(ICEFormInput,
				GeometryFormEditor.ID);
		// Set this editor reference so that listeners can be registered
		// later.
		ICEFormEditor = (ICEFormEditor) formEditor;

	} catch (PartInitException e) {
		// Dump the stacktrace if something happens.
		e.printStackTrace();
	}

	return;
}
 
Example 3
Source File: UIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Opens an editor in current workbench window
 * 
 * @param editorId
 * @param input
 * @return the created or reopened IEditorPart
 * @throws PartInitException
 */
public static IEditorPart openEditorUnchecked(String editorId, IEditorInput input, boolean activate) throws PartInitException {
	final IWorkbenchPage activePage = getActivePage();
	if (activePage != null) {
		final IEditorPart openEditor = activePage.openEditor(input, editorId, activate);

		// Trigger re-evaluation of the handler enablement state by
		// cycling the activepage. Cycling the active page causes an
		// event to be fired inside the selection service.
		// During this time, there will be no active page!
		getActiveWindow().setActivePage(null);
		getActiveWindow().setActivePage(activePage);

		return openEditor;
	}
	return null;
}
 
Example 4
Source File: ReadCamelProcess.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRun() {
    final IRepositoryNode node = (IRepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    CamelProcessItem processItem = (CamelProcessItem) node.getObject().getProperty().getItem();

    IWorkbenchPage page = getActivePage();

    try {
        CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, true, null, true);
        checkUnLoadedNodeForProcess(fileEditorInput);
        IEditorPart editorPart = page.findEditor(fileEditorInput);

        if (editorPart == null) {
            fileEditorInput.setRepositoryNode(node);
            page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, true);
        } else {
            page.activate(editorPart);
        }
    } catch (PartInitException | PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
 
Example 5
Source File: OpenEditorAction.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (inputFile == null) {
		return;
	}
	IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
	IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
	try {
		IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile),
				COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
		if (selectedRegion != null) {
			((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
		}
	} catch (PartInitException partInitException) {
		throw new WrappedRuntimeException(partInitException);
	}

}
 
Example 6
Source File: ModulaSearchResultPage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected void showMatch( Match match, int currentOffset
                        , int currentLength, boolean activate 
                        ) throws PartInitException 
{
    if (match instanceof ModulaSymbolMatch) {
        try {
            ModulaSymbolMatch em = (ModulaSymbolMatch)match;
            IFile f = em.getFile();
            IWorkbenchPage page = WorkbenchUtils.getActivePage();
            IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(f.getName());
            IEditorPart ep = page.openEditor(new FileEditorInput(f), desc.getId());
            ITextEditor te = (ITextEditor)ep;
            Control ctr = (Control)te.getAdapter(Control.class);
            ctr.setFocus();
            te.selectAndReveal(em.getOffset(), em.getLength());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 7
Source File: ReflectivityEclipseFormWidget.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This operation displays the {@link ReflectivityFormEditor} instead of the
 * standard ICEFormEditor.
 */
@Override
public void display() {

	// Local Declarations
	IWorkbenchPage page = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage();

	// Create the ICEFormInput for the ReflectivityFormBuilder.
	ICEFormInput = new ICEFormInput(widgetForm);

	try {
		// Use the workbench to open the editor with our input.
		IEditorPart formEditor = page.openEditor(ICEFormInput,
				ReflectivityFormEditor.ID);
		// Set this editor reference so that listeners can be registered
		// later.
		ICEFormEditor = (ICEFormEditor) formEditor;

	} catch (PartInitException e) {
		// Dump the stacktrace if something happens.
		e.printStackTrace();
	}

	return;
}
 
Example 8
Source File: EditorUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void openEditor( Object adaptable, File target,
		String editorId ) throws PartInitException
{
	IWorkbench workbench = PlatformUI.getWorkbench( );
	IWorkbenchWindow window = workbench == null ? null
			: workbench.getActiveWorkbenchWindow( );

	IWorkbenchPage page = window == null ? null : window.getActivePage( );

	if ( page != null )
	{
		IEditorInput input = null;
		Object adapter = Platform.getAdapterManager( )
				.getAdapter( adaptable, IPathEditorInputFactory.class );

		if ( adapter instanceof IPathEditorInputFactory )
		{
			input = ( (IPathEditorInputFactory) adapter ).create( new Path( target.getAbsolutePath( ) ) );
			IFile file = (IFile) input.getAdapter( IFile.class );
			if ( file != null )
			{
				try
				{
					file.refreshLocal( IResource.DEPTH_INFINITE, null );
				}
				catch ( CoreException e )
				{
					// do nothing now
				}
			}
		}

		if ( input == null )
		{
			input = new ReportEditorInput( target );
		}

		page.openEditor( input, editorId, true );
	}
}
 
Example 9
Source File: TestUtils.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens an external editor on an IEditorInput containing the file having filePath
 * @param editorInput
 * @param filePath
 * @throws PartInitException
 */
public static IEditorPart openExternalEditor(IEditorInput editorInput, String filePath) throws PartInitException {
	//TODO Maybe this method could be improved by omitting filepath which comes from editorInput, but "how?" should be defined here
	final IWorkbenchPage page = getPage();
	IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(filePath);
	if (desc == null) desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(filePath+".txt");
	return page.openEditor(editorInput, desc.getId());
}
 
Example 10
Source File: ProcessNavigatorActionProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public void run() {
	if (myDiagram == null || myDiagram.eResource() == null) {
		return;
	}

	IEditorInput editorInput = getEditorInput(myDiagram);
	IWorkbenchPage page = myViewerSite.getPage();
	try {
		page.openEditor(editorInput, ProcessDiagramEditor.ID);
	} catch (PartInitException e) {
		ProcessDiagramEditorPlugin.getInstance().logError("Exception while openning diagram", e); //$NON-NLS-1$
	}
}
 
Example 11
Source File: UIInterpreterHelper.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Open in an editor the given file.
 * 
 * @param file
 * @throws PartInitException
 */
public static void openFile(IFile file) throws PartInitException {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
	if (desc != null) {
		page.openEditor(new FileEditorInput(file), desc.getId());
	}
}
 
Example 12
Source File: CoreEditorUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private static IEditorPart openInEditor(IEditorInput input,
		String editorID, boolean activate) throws CoreException {
	Assert.isNotNull(input);
	Assert.isNotNull(editorID);

	IWorkbenchPage p = WorkbenchUtils.getActivePage();
	if (p == null)
		ExceptionHelper.throwCoreException(IdeCorePlugin.PLUGIN_ID, "JavaEditorMessages.EditorUtility_no_active_WorkbenchPage"); //$NON-NLS-1$

	return p.openEditor(input, editorID, activate);
}
 
Example 13
Source File: EditorUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Open an editor anywhere on the file system using Eclipse's default editor registered for the given file.
 *
 * @param fileToOpen File to open
 * @note we must be in the UI thread for this method to work.
 * @return Editor opened or created
 */
public static IEditorPart openFile(File fileToOpen, boolean activate) {

    final IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        throw new RuntimeException("workbench cannot be null");
    }

    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        throw new RuntimeException(
                "activeWorkbenchWindow cannot be null (we have to be in a ui thread for this to work)");
    }

    IWorkbenchPage wp = activeWorkbenchWindow.getActivePage();

    final IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());

    try {
        if (activate) {
            // open the editor on the file
            return IDE.openEditorOnFileStore(wp, fileStore);
        }

        // Workaround when we don't want to activate (as there's no suitable API
        // in the core for that).
        IEditorInput input = getEditorInput(fileStore);
        String editorId = getEditorId(input, null);

        return wp.openEditor(input, editorId, activate);

    } catch (Exception e) {
        Log.log("Editor failed to open", e);
        return null;
    }
}
 
Example 14
Source File: OpenCamelExistVersionProcessWizard.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
@Override
protected void openAnotherVersion(RepositoryNode node, boolean readonly) {
    final Item item = node.getObject().getProperty().getItem();
    final IWorkbenchPage page = getActivePage();
    try {
        final RepositoryEditorInput fileEditorInput = getEditorInput(item, readonly, page);
        page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, readonly);
    } catch (Exception e) {
        MessageBoxExceptionHandler.process(e);
    }
}
 
Example 15
Source File: OpenDashboardHandler.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IWorkbenchPage page = window.getActivePage();
	try {
		hideIntroView();
		hideDashboards();
		PlatformUI.getWorkbench().showPerspective(J2EE_PERSPECTIVE_ID, window);
		page.openEditor(new NullEditorInput(), DASHBOARD_VIEW_ID);
	} catch (Exception e) {
		log.error("Cannot open dashboard", e);
	}
	return true;
}
 
Example 16
Source File: EditorHelper.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static void handleOpen ( final IWorkbenchPage page, final String connectionId, final String factoryId, final String configurationId )
{
    try
    {
        page.openEditor ( new ConfigurationEditorInput ( connectionId, factoryId, configurationId ), MultiConfigurationEditor.EDITOR_ID, true );
    }
    catch ( final PartInitException e )
    {
        StatusManager.getManager ().handle ( e.getStatus () );
    }
}
 
Example 17
Source File: CreateCamelProcess.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
protected final void openEditor(ProcessItem processItem) throws PersistenceException, PartInitException {
    // Set readonly to false since created job will always be editable.
    CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, false, true, false);

    IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(
            fileEditorInput.getItem().getProperty().getId(), false);
    fileEditorInput.setRepositoryNode(repositoryNode);

    IWorkbenchPage page = getActivePage();
    page.openEditor(fileEditorInput, getEditorId(), true);
    // // use project setting true
    // ProjectSettingManager.defaultUseProjectSetting(fileEditorInput.getLoadedProcess());
}
 
Example 18
Source File: OpenFileAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void run( )
{
	FileDialog dialog = new FileDialog( fWindow.getShell( ), SWT.OPEN
			| SWT.MULTI );
	dialog.setText( DesignerWorkbenchMessages.Dialog_openFile );
	dialog.setFilterExtensions( filterExtensions );
	dialog.setFilterPath( ResourcesPlugin.getWorkspace( )
			.getRoot( )
			.getProjectRelativePath( )
			.toOSString( ) );
	dialog.open( );
	String[] names = dialog.getFileNames( );

	if ( names != null )
	{
		String fFilterPath = dialog.getFilterPath( );

		int numberOfFilesNotFound = 0;
		StringBuffer notFound = new StringBuffer( );
		for ( int i = 0; i < names.length; i++ )
		{
			File file = new File( fFilterPath + File.separator + names[i] );
			if ( file.exists( ) )
			{
				IWorkbenchPage page = fWindow.getActivePage( );
				IEditorInput input = new ReportEditorInput( file );
				IEditorDescriptor editorDesc = getEditorDescriptor( input,
						OpenStrategy.activateOnOpen( ) );
				try
				{
					page.openEditor( input, editorDesc.getId( ) );
				}
				catch ( Exception e )
				{
					ExceptionUtil.handle( e );
				}
			}
			else
			{
				if ( ++numberOfFilesNotFound > 1 )
					notFound.append( '\n' );
				notFound.append( file.getName( ) );
			}
		}
		if ( numberOfFilesNotFound > 0 )
		{
			// String msgFmt= numberOfFilesNotFound == 1 ?
			// TextEditorMessages.OpenExternalFileAction_message_fileNotFound
			// :
			// TextEditorMessages.OpenExternalFileAction_message_filesNotFound;
			// String msg= MessageFormat.format(msgFmt, new Object[] {
			// notFound.toString() });
			// MessageDialog.openError(fWindow.getShell(),
			// TextEditorMessages.OpenExternalFileAction_title, msg);
		}
	}
}
 
Example 19
Source File: EditorOpener.java    From typescript.java with MIT License 4 votes vote down vote up
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException {
	IEditorInput input= new FileEditorInput(file);
	IEditorPart editor= page.findEditor(input);
	if (editor != null) {
		page.bringToTop(editor);
		if (activate) {
			page.activate(editor);
		}
		return editor;
	}
	IEditorReference reusedEditorRef= fReusedEditor;
	if (reusedEditorRef !=  null) {
		boolean isOpen= reusedEditorRef.getEditor(false) != null;
		boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
		if (canBeReused) {
			boolean showsSameInputType= reusedEditorRef.getId().equals(editorId);
			if (!showsSameInputType) {
				page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
				fReusedEditor= null;
			} else {
				editor= reusedEditorRef.getEditor(true);
				if (editor instanceof IReusableEditor) {
					((IReusableEditor) editor).setInput(input);
					page.bringToTop(editor);
					if (activate) {
						page.activate(editor);
					}
					return editor;
				}
			}
		}
	}
	editor= page.openEditor(input, editorId, activate);
	if (editor instanceof IReusableEditor) {
		IEditorReference reference= (IEditorReference) page.getReference(editor);
		fReusedEditor= reference;
	} else {
		fReusedEditor= null;
	}
	return editor;
}
 
Example 20
Source File: MassOpenHandler.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private void openEditor(IFile file) throws PartInitException {
	final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
	page.openEditor(new FileEditorInput(file), desc.getId());
}