org.eclipse.ui.IWorkbenchPage#openEditor ( )源码实例Demo

下面列出了org.eclipse.ui.IWorkbenchPage#openEditor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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());
    }
  }
}
 
源代码2 项目: ice   文件: GeometryEclipseFormWidget.java
/**
 * 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;
}
 
源代码3 项目: tesb-studio-se   文件: ReadCamelProcess.java
@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);
    }
}
 
源代码4 项目: ice   文件: ReflectivityEclipseFormWidget.java
/**
 * 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;
}
 
源代码5 项目: xds-ide   文件: ModulaSearchResultPage.java
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();
        }
    }
}
 
源代码6 项目: xtext-xtend   文件: OpenEditorAction.java
@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);
	}

}
 
源代码7 项目: tlaplus   文件: UIHelper.java
/**
 * 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;
}
 
源代码8 项目: dawnsci   文件: TestUtils.java
/**
 * 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());
}
 
源代码9 项目: tesb-studio-se   文件: CreateCamelProcess.java
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());
}
 
源代码10 项目: neoscada   文件: EditorHelper.java
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 () );
    }
}
 
源代码11 项目: developer-studio   文件: OpenDashboardHandler.java
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;
}
 
@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);
    }
}
 
源代码13 项目: Pydev   文件: EditorUtils.java
/**
 * 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;
    }
}
 
源代码14 项目: xds-ide   文件: CoreEditorUtils.java
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);
}
 
源代码15 项目: typescript.java   文件: UIInterpreterHelper.java
/**
 * 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());
	}
}
 
/**
* @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$
	}
}
 
源代码17 项目: birt   文件: EditorUtil.java
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 );
	}
}
 
源代码18 项目: n4js   文件: MassOpenHandler.java
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());
}
 
源代码19 项目: birt   文件: OpenFileAction.java
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);
		}
	}
}
 
源代码20 项目: typescript.java   文件: EditorOpener.java
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;
}