org.eclipse.ui.IEditorSite Java Examples

The following examples show how to use org.eclipse.ui.IEditorSite. 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: ServiceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
Example #2
Source File: XLIFFEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 启动编辑器。
 * 
 * @param site
 *            the site
 * @param input
 *            the input
 * @throws PartInitException
 *             the part init exception
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);
	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);
}
 
Example #3
Source File: UIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Tries to set the given message on the workbench's status line. This is a
 * best effort method which fails to set the status line if there is no
 * active editor present from where the statuslinemanager can be looked up.
 * 
 * @param msg
 *            The message to be shown on the status line
 */
public static void setStatusLineMessage(final String msg) {
	IStatusLineManager statusLineManager = null;
	ISelectionProvider selectionService = null;

	// First try to get the StatusLineManager from the IViewPart and only
	// resort back to the editor if a view isn't active right now.
	final IWorkbenchPart workbenchPart = getActiveWindow().getActivePage().getActivePart();
	if (workbenchPart instanceof IViewPart) {
		final IViewPart viewPart = (IViewPart) workbenchPart;
		statusLineManager = viewPart.getViewSite().getActionBars().getStatusLineManager();
		selectionService = viewPart.getViewSite().getSelectionProvider();
	} else if (getActiveEditor() != null) {
		final IEditorSite editorSite = getActiveEditor().getEditorSite();
		statusLineManager = editorSite.getActionBars().getStatusLineManager();
		selectionService = editorSite.getSelectionProvider();
	}

	if (statusLineManager != null && selectionService != null) {
		statusLineManager.setMessage(msg);
		selectionService.addSelectionChangedListener(new StatusLineMessageEraser(statusLineManager,
				selectionService));
	}
}
 
Example #4
Source File: EdgeMatcherEditor.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  setSite(site);
  setInput(input);
  // only accept a file as input.
  if (input instanceof IFileEditorInput) {
    // get the URI
    IFileEditorInput fileInput = (IFileEditorInput) input;
    file = fileInput.getFile();

    EdgeMatcherDocXmlPersist persist = EdgeMatcherDocXmlPersist.build(true);
    matcherInfo = persist.load(file.getRawLocationURI());

    setPartName(buildPartName());
    setDirtyState(false);
    return;
  }

  // Something unexpected
  throw new PartInitException(
      "Input for editor is not suitable for the RelationSetDescriptorEditor");
}
 
Example #5
Source File: RemapEditor.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  super.init(site, input);

  if (input instanceof IFileEditorInput) {
    try {
      taskFile = ((IFileEditorInput) input).getFile();
      RemapTaskDocXmlPersist persist = RemapTaskDocXmlPersist.build(true);

      migrationTask = loadMigrationTask(persist);
      this.setPartName(migrationTask.getName());
    } catch (IOException errIo) {
      String msg = MessageFormat.format(
          "Unable to load migration task from {0}", taskFile.getFullPath());
      throw new PartInitException(msg, errIo);
    }
  }
}
 
Example #6
Source File: HDSEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init ( final IEditorSite site, final IEditorInput input ) throws PartInitException
{
    setSite ( site );
    setInput ( input );

    final IFileEditorInput fileInput = AdapterHelper.adapt ( input, IFileEditorInput.class );
    if ( fileInput != null )
    {
        this.loader = new FileLoader ( fileInput );
        setContentDescription ( fileInput.getName () );
        setPartName ( fileInput.getName () );
    }

    if ( this.loader == null )
    {
        throw new PartInitException ( "Invalid editor input. Unable to load data" );
    }
}
 
Example #7
Source File: ModelEditor.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
		throws PartInitException {
	super.init(site, input);
	log.trace("open " + modelClass.getSimpleName() + " editor {}", input);
	ModelEditorInput i = (ModelEditorInput) input;
	setPartName(input.getName());
	setTitleImage(Images.get(i.getDescriptor()));
	try {
		dao = Daos.base(Database.get(), modelClass);
		model = dao.getForId(i.getDescriptor().id);
		loadComments(i.getDescriptor().type,
				i.getDescriptor().refId);
		eventBus.register(this);
	} catch (Exception e) {
		log.error("failed to load " + modelClass.getSimpleName()
				+ " from editor input", e);
	}
}
 
Example #8
Source File: AbstractFXEditor.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void init(final IEditorSite site, final IEditorInput input)
		throws PartInitException {
	setInput(input);
	setSite(site);

	createActions();

	dirtyStateProvider = createDirtyStateProvider();
	if (dirtyStateProvider != null) {
		dirtyStateNotifier = new ChangeListener<Boolean>() {
			@Override
			public void changed(
					ObservableValue<? extends Boolean> observable,
					Boolean oldValue, Boolean newValue) {
				AbstractFXEditor.this.firePropertyChange(PROP_DIRTY);
			}
		};
		dirtyStateProvider.dirtyProperty().addListener(dirtyStateNotifier);
	}
}
 
Example #9
Source File: XtextEditorErrorTickUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
	IEditorSite site = null != editor ? editor.getEditorSite() : null;
	if (site != null) {
		if (!monitor.isCanceled() && editor != null) {
			if (titleImage != null && !titleImage.isDisposed()) {
				editor.updatedTitleImage(titleImage);
				titleImage = null;
			} else if (titleImageDescription != null) {
				Image image = imageHelper.getImage(titleImageDescription);
				if (editor.getTitleImage() != image) {
					editor.updatedTitleImage(image);
				}
				titleImageDescription = null;
			}
		}
	}
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	return Status.OK_STATUS;
}
 
Example #10
Source File: BibtexEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The <code>MultiPageEditorExample</code> implementation of this method
 * checks that the input is an instance of <code>IFileEditorInput</code>.
 */
@Override
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
	if (!(editorInput instanceof DocumentStorageEditorInput)) {
		PartInitException pie = new PartInitException("Invalid Input: Must be DocumentStorageEditorInput");
		pie.printStackTrace();
		throw pie;
	}
	super.init(site, editorInput);
	setPartName(editorInput.getName());
	site.getPage().addPartListener(partListener);
	extractDocument(editorInput);
	getActionBarContributor().setActiveEditor(BibtexEditor.this);
	setSelection(getSelection());
	ModelRegistryPlugin.getModelRegistry().setActiveDocument(document);
}
 
Example #11
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (log.isDebugEnabled())
		log.debug("init:" + input);
	if (!input.exists()) {
		// Set site to prevent issues when disposing this editor
		setSite(site);
		throw new PartInitException("Input doesn't exist");
	}

	// do document provider setup
	setDocumentProvider(documentProvider.get());

	// source viewer setup
	setSourceViewerConfiguration(sourceViewerConfiguration);

	sourceViewerConfiguration.setEditor(this);
	
	// Bug 464591 all editor presentation settings (font/color) handled here are in the InstanceScope only
	setPreferenceStore(preferenceStoreAccess.getPreferenceStore());

	// NOTE: Outline CANNOT be initialized here, since we do not have access
	// to the source viewer yet (it will be created later).

	super.init(site, input);
}
 
Example #12
Source File: MetainformationEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	
	//to avoid errors, close editor, when project is not open
	//use case : project deleted
	if(!getProjectFromIEditorPart(this).isOpen()) {
		this.getEditorSite().getPage().closeEditor(this, false);
	}

	// initialize whole project
	unloadDocumentResources();
	initializeWholeProject(getProjectFromIEditorPart(this));

	// set filename as displayed tab name
	activeFilePath = ((IFileEditorInput) input).getFile().getLocation();
	String pathString = activeFilePath.toOSString();
	this.setPartName(pathString.substring(pathString.lastIndexOf(File.separator) + 1));

	activeFilePath = ((IFileEditorInput) input).getFile().getLocation();
}
 
Example #13
Source File: DefaultMergeViewer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected SourceViewerConfiguration createSourceViewerConfiguration(SourceViewer sourceViewer,
		IEditorInput editorInput) {
	SourceViewerConfiguration sourceViewerConfiguration = null;
	if (editorInput != null && getEditor(sourceViewer) != null) {
		DefaultMergeEditor mergeEditor = getEditor(sourceViewer);
		sourceViewerConfiguration = mergeEditor.getXtextSourceViewerConfiguration();
		try {
			mergeEditor.init((IEditorSite) mergeEditor.getSite(), editorInput);
			mergeEditor.createActions();
		} catch (PartInitException partInitException) {
			throw new WrappedException(partInitException);
		}
	} else {
		sourceViewerConfiguration = sourceViewerConfigurationProvider.get();
	}
	return sourceViewerConfiguration;
}
 
Example #14
Source File: ImageViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
	// we need either an IStorage or an input that can return an ImageData
	if (!(input instanceof IStorageEditorInput) && input.getAdapter(ImageData.class) == null) {
		throw new PartInitException("Unable to read input: " + input); //$NON-NLS-1$
	}
	setSite(site);
	setInput(input, false);
}
 
Example #15
Source File: StyledTextSelectionListener.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IActionBars saveDiagramActions() {
	final StatechartDiagramActionbarContributor contributor = (StatechartDiagramActionbarContributor) ((IEditorSite) site)
			.getActionBarContributor();
	copyAction = contributor.getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId());
	cutAction = contributor.getActionBars().getGlobalActionHandler(ActionFactory.CUT.getId());
	pasteAction = contributor.getActionBars().getGlobalActionHandler(ActionFactory.PASTE.getId());
	selectAllAction = contributor.getActionBars().getGlobalActionHandler(ActionFactory.SELECT_ALL.getId());
	printAction = contributor.getActionBars().getGlobalActionHandler(ActionFactory.PRINT.getId());
	return contributor.getActionBars();
}
 
Example #16
Source File: RelationSetDescriptorEditor.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  setSite(site);
  setInput(input);
  // only accept a file as input.
  if (input instanceof IFileEditorInput) {
    // get the URI
    IFileEditorInput fileInput = (IFileEditorInput) input;
    file = fileInput.getFile();

    RelationSetDescriptorXmlPersist persist =
        RelationSetDescriptorXmlPersist.build(true);
    relSetInfo = persist.load(file.getRawLocationURI());

    relRepo = new RelationSetDescrRepo(relSetInfo.getModel().getRelations());
    relRepo.setRelationSet(relSetInfo.getInfo());

    setPartName(buildPartName());
    setDirtyState(false);
    return;
  }

  // Something unexpected
  throw new PartInitException(
      "Input for editor is not suitable for the RelationSetDescriptorEditor");
}
 
Example #17
Source File: ReportPreviewEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void init( IEditorSite site, IEditorInput input )
		throws PartInitException
{
	super.setSite( site );

	setInput( input );
}
 
Example #18
Source File: ReportScriptFormPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void init( IEditorSite site, IEditorInput input )
		throws PartInitException
{
	super.init( site, input );
	jsEditor = createJSEditor( );
	jsEditor.init( site, input );
}
 
Example #19
Source File: EipEditor.java    From eip-designer with Apache License 2.0 5 votes vote down vote up
/**
   * This is called during startup.
   * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
   * @generated
   */
@Override
public void init(IEditorSite site, IEditorInput editorInput) {
     setSite(site);
     setInputWithNotify(editorInput);
     setPartName(editorInput.getName());
     site.setSelectionProvider(this);
     site.getPage().addPartListener(partListener);
     ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
  }
 
Example #20
Source File: APICloudWizardEditor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
		throws PartInitException {
	setSite(site);
	setInput(input);
	initInfo();
}
 
Example #21
Source File: ERDiagramMultiPageEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void init(IEditorSite site, IEditorInput input)
		throws PartInitException {
	super.init(site, input);
	this.fElementStateListener = new ERDiagramElementStateListener(this);
}
 
Example #22
Source File: BibtexOverviewEditor.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The <code>MultiPageEditorExample</code> implementation of this method
 * checks that the input is an instance of <code>IFileEditorInput</code>.
 */
@Override
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
	super.init(site, editorInput);
	this.setPartName(name);
	init = false;
}
 
Example #23
Source File: FindOccurrencesInFileAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new <code>FindOccurrencesInFileAction</code>. The action
 * requires that the selection provided by the site's selection provider is of type
 * <code>IStructuredSelection</code>.
 *
 * @param site the site providing context information for this action
 * @since 3.1
 */
public FindOccurrencesInFileAction(IWorkbenchSite site) {
	super(site);

	if (site instanceof IViewSite)
		fActionBars= ((IViewSite)site).getActionBars();
	else if (site instanceof IEditorSite)
		fActionBars= ((IEditorSite)site).getActionBars();
	else if (site instanceof IPageSite)
		fActionBars= ((IPageSite)site).getActionBars();

	setText(SearchMessages.Search_FindOccurrencesInFile_label);
	setToolTipText(SearchMessages.Search_FindOccurrencesInFile_tooltip);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_OCCURRENCES_IN_FILE_ACTION);
}
 
Example #24
Source File: NLSKeyHyperlinkDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
	ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
	if (region == null || textEditor == null)
		return null;

	IEditorSite site= textEditor.getEditorSite();
	if (site == null)
		return null;

	ITypeRoot javaElement= getInputJavaElement(textEditor);
	if (javaElement == null)
		return null;

	CompilationUnit ast= SharedASTProvider.getAST(javaElement, SharedASTProvider.WAIT_NO, null);
	if (ast == null)
		return null;

	ASTNode node= NodeFinder.perform(ast, region.getOffset(), 1);
	if (!(node instanceof StringLiteral)  && !(node instanceof SimpleName))
		return null;

	if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY)
		return null;

	IRegion nlsKeyRegion= new Region(node.getStartPosition(), node.getLength());
	AccessorClassReference ref= NLSHintHelper.getAccessorClassReference(ast, nlsKeyRegion);
	if (ref == null)
		return null;
	String keyName= null;
	if (node instanceof StringLiteral) {
		keyName= ((StringLiteral)node).getLiteralValue();
	} else {
		keyName= ((SimpleName)node).getIdentifier();
	}
	if (keyName != null)
		return new IHyperlink[] {new NLSKeyHyperlink(nlsKeyRegion, keyName, ref, textEditor)};

	return null;
}
 
Example #25
Source File: WelcomePageEditorPart.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (!(input instanceof WelcomePageEditorInput)) {
		Logger.logError("The editor input is not valid for the welcome page: " + input.getClass()); //$NON-NLS-1$
       	throw new PartInitException(Messages.WelcomePageEditorCreateError);
	}
	
	setSite(site);
       setInput(input);
       
       setPartName(Messages.WelcomePageEditorPartName);
       
       CodewindUIPlugin.getUpdateHandler().addUpdateListener(this);
}
 
Example #26
Source File: LinkingPropertiesPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
		throws PartInitException {
	super.init(site, input);
	SimpleEditorInput in = (SimpleEditorInput) input;
	props = Cache.getAppCache().remove(
			in.id, LinkingProperties.class);
}
 
Example #27
Source File: NodeListEditor.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  setSite(site);
  setInput(input);
  initFromInput(input);
}
 
Example #28
Source File: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
  casDocumentProvider =
          CasDocumentProviderFactory.instance().getDocumentProvider(input);
  
  setDocumentProvider(new TextDocumentProvider(casDocumentProvider));

  super.init(site, input);
}
 
Example #29
Source File: RCPMultiPageReportEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void init( IEditorSite site, IEditorInput input )
		throws PartInitException
{
	super.init( site, input );
	getSite( ).getWorkbenchWindow( )
			.getPartService( )
			.addPartListener( this );
}
 
Example #30
Source File: AnalyzeEditor.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput iInput)
		throws PartInitException {
	super.init(site, iInput);
	ResultEditorInput inp = (ResultEditorInput) iInput;
	result = Cache.getAppCache().remove(inp.resultKey, FullResult.class);
	if (inp.dqResultKey != null) {
		dqResult = Cache.getAppCache().remove(
				inp.dqResultKey, DQResult.class);
	}
	setup = Cache.getAppCache().remove(inp.setupKey, CalculationSetup.class);
	ProductSystem system = setup.productSystem;
	String name = M.AnalysisResultOf + " " + system.name;
	setPartName(name);
}