下面列出了怎么用org.eclipse.ui.IEditorSite的API类实例代码及写法,或者点击链接到github查看源代码。
@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" );
}
}
/**
* 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);
}
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;
}
@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);
}
@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;
}
@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);
}
}
@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);
}
}
/**
* 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));
}
}
/**
* 启动编辑器。
*
* @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);
}
@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");
}
@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);
}
}
}
/**
* 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);
}
@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();
}
@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);
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
ApplicationOverviewEditorInput appInput = null;
if (input instanceof ApplicationOverviewEditorInput) {
appInput = (ApplicationOverviewEditorInput)input;
if ((appInput.connectionId == null && appInput.connectionUri == null) || appInput.projectID == null) {
Logger.logError("Invalid editor input for application overview. Connection id/uri or project id is null." + input.getClass()); //$NON-NLS-1$
throw new PartInitException(NLS.bind(Messages.AppOverviewEditorCreateError, input));
}
} else {
Logger.logError("The editor input is not valid for the application overview: " + input.getClass()); //$NON-NLS-1$
throw new PartInitException(NLS.bind(Messages.AppOverviewEditorCreateError, input));
}
setSite(site);
setInput(input);
// Support old mementos by defaulting to local connection
appName = appInput.projectName;
connectionId = appInput.connectionId;
if (connectionId == null) {
connectionId = LocalConnection.DEFAULT_ID;
}
connectionName = appInput.connectionName;
if (connectionName == null) {
connectionName = LocalConnection.DEFAULT_NAME;
}
projectId = appInput.projectID;
setPartName(NLS.bind(Messages.AppOverviewEditorPartName, new String[] {appName, connectionName}));
CodewindUIPlugin.getUpdateHandler().addUpdateListener(this);
}
/**
* Records the file open operation when the editor is instantiated.
* @param site the editor site
* @param input the editor input
* @exception PartInitException if this editor was not initialized successfully
*/
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
if (historyManager == null) {
historyManager = HistoryManager.getInstance();
historyManager.start(this);
historyManager.recordFileOpenOperation(getInputFile(), getSourceCode());
}
}
public void init( IEditorSite site, IEditorInput input )
throws PartInitException
{
setSite( site );
setInput( input );
scriptEditor.init( site, input );
}
/**
* This is called during startup.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public void init ( final IEditorSite site, final IEditorInput editorInput )
{
setSite ( site );
setInputWithNotify ( editorInput );
setPartName ( editorInput.getName () );
site.setSelectionProvider ( this );
site.getPage ().addPartListener ( this.partListener );
ResourcesPlugin.getWorkspace ().addResourceChangeListener (
this.resourceChangeListener, IResourceChangeEvent.POST_CHANGE );
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
if (!(input instanceof TaskEditorInput)) {
throw new RuntimeException("Wrong input");
}
this.input = (TaskEditorInput) input;
setSite(site);
setInput(input);
todo = TaskService.getInstance().getTaskById(this.input.getId());
setPartName("Todo ID: " + todo.getId());
}
@Override
public void init ( final IEditorSite site, final IEditorInput input ) throws PartInitException
{
try
{
setPartName ( input.toString () );
setSite ( site );
setInput ( input );
}
catch ( final Exception e )
{
throw new PartInitException ( "Failed to initialize editor", e );
}
}
private void hookContextMenu ( final IEditorSite editorSite )
{
final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown ( true );
menuMgr.addMenuListener ( new IMenuListener () {
@Override
public void menuAboutToShow ( final IMenuManager manager )
{
fillContextMenu ( manager );
}
} );
final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
this.viewer.getControl ().setMenu ( menu );
editorSite.registerContextMenu ( menuMgr, this.viewer );
}
@Override
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);
cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);
hookListener();
}
@Override
public void init ( final IEditorSite site, final IEditorInput input ) throws PartInitException
{
setPartName ( input.toString () );
setSite ( site );
try
{
setInput ( input );
}
catch ( final Exception e )
{
throw new PartInitException ( "Failed to initialize editor", e );
}
}
@Override
public void init ( final IEditorSite site, final IEditorInput input ) throws PartInitException
{
setPartName ( input.toString () );
setSite ( site );
try
{
setInput ( input );
}
catch ( final Exception e )
{
throw new PartInitException ( "Failed to initialize editor", e );
}
}
private void hookContextMenu ( final IEditorSite editorSite )
{
final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown ( true );
menuMgr.addMenuListener ( new IMenuListener () {
@Override
public void menuAboutToShow ( final IMenuManager manager )
{
fillContextMenu ( manager );
}
} );
final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
this.viewer.getControl ().setMenu ( menu );
editorSite.registerContextMenu ( menuMgr, this.viewer );
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setEditDomain(new DefaultEditDomain(this));
if (input instanceof GraphicalEditorInput) {
GraphicalEditorInput modelInput = (GraphicalEditorInput) input;
if (modelInput.getDescriptor() != null) {
setPartName(Labels.name(modelInput.getDescriptor()));
}
}
super.init(site, input);
}
/**
* 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 );
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
super.init(site, input);
Process p = getModel();
if (p.documentation == null)
p.documentation = new ProcessDocumentation();
evalFormulas();
parameterSupport = new ParameterChangeSupport();
parameterSupport.onEvaluation(this::evalFormulas);
}
/**
* 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 );
}
/**
* 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 );
}