public final class IDE extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
IDE.Preferences
Preferences defined by the IDE workbench.
|
static interface |
IDE.SharedImages
Standard shared images defined by the IDE.
|
Modifier and Type | Field and Description |
---|---|
static String |
EDITOR_ID_ATTR
An optional attribute within a workspace marker (
IMarker )
which identifies the preferred editor type to be opened. |
static QualifiedName |
EDITOR_KEY
The persistent property key used on IFile resources to contain the
preferred editor ID to use.
|
static String |
RESOURCE_PERSPECTIVE_ID
The resource based perspective identifier.
|
Modifier and Type | Method and Description |
---|---|
static List |
computeSelectedResources(IStructuredSelection originalSelection)
Extracts and returns the
IResource s in the given
selection or the resource objects they adapts to. |
static IContentType |
getContentType(IFile file)
Return the content type for the given file.
|
static IEditorDescriptor |
getDefaultEditor(IFile file)
Returns the default editor for a given file.
|
static IEditorDescriptor |
getDefaultEditor(IFile file,
boolean determineContentType)
Returns the default editor for a given file.
|
static IEditorDescriptor |
getEditorDescriptor(IFile file)
Returns an editor descriptor appropriate for opening the given file
resource.
|
static IEditorDescriptor |
getEditorDescriptor(IFile file,
boolean determineContentType)
Returns an editor descriptor appropriate for opening the given file
resource.
|
static IEditorDescriptor |
getEditorDescriptor(String name)
Returns an editor descriptor appropriate for opening a file resource with
the given name.
|
static IEditorDescriptor |
getEditorDescriptor(String name,
boolean inferContentType)
Returns an editor descriptor appropriate for opening a file resource with
the given name.
|
static IMarkerHelpRegistry |
getMarkerHelpRegistry()
Returns the marker help registry for the workbench.
|
static void |
gotoMarker(IEditorPart editor,
IMarker marker)
Sets the cursor and selection state for the given editor to reveal the
position of the given marker.
|
static IContentType |
guessContentType(IFile file)
Guess at the content type of the given file based on the filename.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IEditorInput input,
String editorId)
Opens an editor on the given object.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IEditorInput input,
String editorId,
boolean activate)
Opens an editor on the given object.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IFile input)
Opens an editor on the given file resource.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IFile input,
boolean activate)
Opens an editor on the given file resource.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IFile input,
boolean activate,
boolean determineContentType)
Opens an editor on the given file resource.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IFile input,
String editorId)
Opens an editor on the given file resource.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IFile input,
String editorId,
boolean activate)
Opens an editor on the given file resource.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IMarker marker)
Opens an editor on the file resource of the given marker.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
IMarker marker,
boolean activate)
Opens an editor on the file resource of the given marker.
|
static IEditorPart |
openEditor(IWorkbenchPage page,
URI uri,
String editorId,
boolean activate)
Opens an editor on the given IFileStore object.
|
static IEditorPart |
openEditorOnFileStore(IWorkbenchPage page,
IFileStore fileStore)
Opens an editor on the given IFileStore object.
|
static IEditorReference[] |
openEditors(IWorkbenchPage page,
IFile[] inputs)
Opens editors on given file resources.
|
static IEditorPart |
openInternalEditorOnFileStore(IWorkbenchPage page,
IFileStore fileStore)
Opens an internal editor on the given IFileStore object.
|
static IEditorDescriptor |
overrideDefaultEditorAssociation(IEditorInput editorInput,
IContentType contentType,
IEditorDescriptor editorDescriptor)
Applies the
org.eclipse.ui.ide.editorAssociationOverride extensions to the given
input. |
static IEditorDescriptor[] |
overrideEditorAssociations(IEditorInput editorInput,
IContentType contentType,
IEditorDescriptor[] editorDescriptors)
Applies the
org.eclipse.ui.ide.editorAssociationOverride extensions to the given
input. |
static IEditorDescriptor[] |
overrideEditorAssociations(String fileName,
IContentType contentType,
IEditorDescriptor[] editorDescriptors)
Applies the
org.eclipse.ui.ide.editorAssociationOverride extensions to the given
input. |
static boolean |
promptToConfirm(Shell shell,
String title,
String message,
IResourceDelta delta,
String[] ignoreModelProviderIds,
boolean syncExec)
Prompt the user to inform them of the possible side effects of an
operation on resources.
|
static void |
registerAdapters()
Register workbench adapters programmatically.
|
static boolean |
saveAllEditors(IResource[] resourceRoots,
boolean confirm)
Save all dirty editors in the workbench whose editor input is a child
resource of one of the
IResource 's provided. |
static void |
setDefaultEditor(IFile file,
String editorID)
Sets the default editor id for a given file.
|
public static final QualifiedName EDITOR_KEY
Example of retrieving the persisted editor id:
IFile file = ...
IEditorDescriptor editorDesc = null;
try {
String editorID = file.getPersistentProperty(EDITOR_KEY);
if (editorID != null) {
editorDesc = editorReg.findEditor(editorID);
}
} catch (CoreException e) {
// handle problem accessing persistent property here
}
Example of persisting the editor id:
IFile file = ...
try {
file.setPersistentProperty(EDITOR_KEY, editorDesc.getId());
} catch (CoreException e) {
// handle problem setting persistent property here
}
public static final String EDITOR_ID_ATTR
IMarker
)
which identifies the preferred editor type to be opened.public static final String RESOURCE_PERSPECTIVE_ID
public static IMarkerHelpRegistry getMarkerHelpRegistry()
public static void gotoMarker(IEditorPart editor, IMarker marker)
IGotoMarker
interface (either
directly or via IAdaptable.getAdapter
), this has no
effect.editor
- the editormarker
- the markerpublic static IEditorPart openEditor(IWorkbenchPage page, IEditorInput input, String editorId) throws PartInitException
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openedinput
- the editor inputeditorId
- the id of the editor extension to usenull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
public static IEditorPart openEditor(IWorkbenchPage page, URI uri, String editorId, boolean activate) throws PartInitException
Unlike the other openEditor
methods, this one can be used
to open files that reside outside the workspace resource set.
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openeduri
- the URI of the file store representing the file to openeditorId
- the id of the editor extension to useactivate
- if true
the editor will be activated openednull
if an external editor wasPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
,
EFS.getStore(URI)
public static IEditorPart openEditor(IWorkbenchPage page, IEditorInput input, String editorId, boolean activate) throws PartInitException
If the page already has an editor open on the target object then that
editor is brought to front; otherwise, a new editor is opened. If
activate == true
the editor will be activated.
page
- the page in which the editor will be openedinput
- the editor inputeditorId
- the id of the editor extension to useactivate
- if true
the editor will be activatednull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String,
boolean)
public static IEditorPart openEditor(IWorkbenchPage page, IFile input, boolean activate) throws PartInitException
If the page already has an editor open on the target object then that
editor is brought to front; otherwise, a new editor is opened. If
activate == true
the editor will be activated.
page
- the page in which the editor will be openedinput
- the editor inputactivate
- if true
the editor will be activatednull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(org.eclipse.ui.IEditorInput,
String, boolean)
public static IEditorPart openEditor(IWorkbenchPage page, IFile input, boolean activate, boolean determineContentType) throws PartInitException
determineContentType
is
true
.
If the page already has an editor open on the target object then that
editor is brought to front; otherwise, a new editor is opened. If
activate == true
the editor will be activated.
page
- the page in which the editor will be openedinput
- the editor inputactivate
- if true
the editor will be activateddetermineContentType
- attempt to resolve the content type for this filenull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(org.eclipse.ui.IEditorInput,
String, boolean)
public static IEditorPart openEditor(IWorkbenchPage page, IFile input) throws PartInitException
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openedinput
- the editor inputnull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
public static IEditorPart openEditor(IWorkbenchPage page, IFile input, String editorId) throws PartInitException
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openedinput
- the editor inputeditorId
- the id of the editor extension to usenull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
public static IEditorPart openEditor(IWorkbenchPage page, IFile input, String editorId, boolean activate) throws PartInitException
If the page already has an editor open on the target object then that
editor is brought to front; otherwise, a new editor is opened. If
activate == true
the editor will be activated.
page
- the page in which the editor will be openedinput
- the editor inputeditorId
- the id of the editor extension to useactivate
- if true
the editor will be activatednull
if an external editor was
openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String,
boolean)
public static IEditorDescriptor getEditorDescriptor(IFile file) throws PartInitException
The editor descriptor is determined using a multi-step process. This method will attempt to resolve the editor based on content-type bindings as well as traditional name/extension bindings.
IResource
is consulted for a persistent property named
IDE.EDITOR_KEY
containing the preferred editor id to be
used.IEditorRegistry.getDefaultEditor(String)
.file
- the filePartInitException
- if no editor can be foundpublic static IEditorDescriptor getEditorDescriptor(IFile file, boolean determineContentType) throws PartInitException
The editor descriptor is determined using a multi-step process. This
method will attempt to resolve the editor based on content-type bindings
as well as traditional name/extension bindings if
determineContentType
is true
.
IResource
is consulted for a persistent property named
IDE.EDITOR_KEY
containing the preferred editor id to be
used.IEditorRegistry.getDefaultEditor(String)
.file
- the filedetermineContentType
- query the content type system for the content type of the filePartInitException
- if no editor can be foundpublic static IEditorDescriptor overrideDefaultEditorAssociation(IEditorInput editorInput, IContentType contentType, IEditorDescriptor editorDescriptor)
org.eclipse.ui.ide.editorAssociationOverride
extensions to the given
input.
Note: It is recommended to get the descriptor for the default editor by
calling getDefaultEditor(IFile, boolean)
. This method here should only be used if
this is not possible for whatever reason.
editorInput
- the editor input for the editorcontentType
- the content type of the input or null
if not availableeditorDescriptor
- the current association for the given input or null
if
nonenull
if none.
Can be editorDescriptor
.IEditorAssociationOverride.overrideDefaultEditor(IEditorInput, IContentType,
IEditorDescriptor)
public static IEditorDescriptor[] overrideEditorAssociations(IEditorInput editorInput, IContentType contentType, IEditorDescriptor[] editorDescriptors)
org.eclipse.ui.ide.editorAssociationOverride
extensions to the given
input.editorInput
- the editor input for the editorcontentType
- the content type of the input or null
if not availableeditorDescriptors
- the current association for the given inputeditorDescriptors
. The order is not relevant.IEditorAssociationOverride.overrideEditors(IEditorInput, IContentType,
IEditorDescriptor[])
public static IEditorDescriptor[] overrideEditorAssociations(String fileName, IContentType contentType, IEditorDescriptor[] editorDescriptors)
org.eclipse.ui.ide.editorAssociationOverride
extensions to the given
input.fileName
- the name of the file for which to choose the editorcontentType
- the content type of the input or null
if not availableeditorDescriptors
- the current association for the given inputeditorDescriptors
. The order is not relevant.IEditorAssociationOverride.overrideEditors(IEditorInput, IContentType,
IEditorDescriptor[])
public static IEditorDescriptor getEditorDescriptor(String name) throws PartInitException
The editor descriptor is determined using a multi-step process. This method will attempt to infer content type from the file name.
IEditorRegistry.getDefaultEditor(String)
.name
- the file namePartInitException
- if no editor can be foundpublic static IEditorDescriptor getEditorDescriptor(String name, boolean inferContentType) throws PartInitException
The editor descriptor is determined using a multi-step process. This
method will attempt to infer the content type of the file if
inferContentType
is true
.
IEditorRegistry.getDefaultEditor(String)
.name
- the file nameinferContentType
- attempt to infer the content type from the file name if this
is true
PartInitException
- if no editor can be foundpublic static IEditorPart openEditor(IWorkbenchPage page, IMarker marker) throws PartInitException
If this page already has an editor open on the marker resource file that editor is brought to front; otherwise, a new editor is opened.The cursor and selection state of the editor are then updated from information recorded in the marker.
If the marker contains an EDITOR_ID_ATTR
attribute the
attribute value will be used to determine the editor type to be opened.
If not, the registered editor for the marker resource file will be used.
page
- the workbench page to open the editor inmarker
- the marker to opennull
not possiblePartInitException
- if the editor could not be initializedopenEditor(org.eclipse.ui.IWorkbenchPage,
org.eclipse.core.resources.IMarker, boolean)
public static IEditorPart openEditor(IWorkbenchPage page, IMarker marker, boolean activate) throws PartInitException
If this page already has an editor open on the marker resource file that
editor is brought to front; otherwise, a new editor is opened. If
activate == true
the editor will be activated. The cursor
and selection state of the editor are then updated from information
recorded in the marker.
If the marker contains an EDITOR_ID_ATTR
attribute the
attribute value will be used to determine the editor type to be opened.
If not, the registered editor for the marker resource file will be used.
page
- the workbench page to open the editor inmarker
- the marker to openactivate
- if true
the editor will be activatednull
not possiblePartInitException
- if the editor could not be initializedpublic static IEditorPart openEditorOnFileStore(IWorkbenchPage page, IFileStore fileStore) throws PartInitException
Unlike the other openEditor
methods, this one
can be used to open files that reside outside the workspace
resource set.
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openedfileStore
- the IFileStore representing the file to opennull
if an external editor was openedPartInitException
- if the editor could not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
public static IEditorPart openInternalEditorOnFileStore(IWorkbenchPage page, IFileStore fileStore) throws PartInitException
Unlike the other openEditor
methods, this one can be used to
open files that reside outside the workspace resource set.
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.
page
- the page in which the editor will be openedfileStore
- the IFileStore representing the file to opennull
if an external editor was
openedPartInitException
- if no internal editor can be found or if the editor could
not be initializedIWorkbenchPage.openEditor(IEditorInput, String)
public static boolean saveAllEditors(IResource[] resourceRoots, boolean confirm)
IResource
's provided. Opens a
dialog to prompt the user if confirm
is true. Return true
if successful. Return false if the user has canceled the command.resourceRoots
- the resource roots under which editor input should
be saved, other will be left dirtyconfirm
- true
to ask the user before saving unsaved
changes (recommended), and false
to save
unsaved changes without askingtrue
if the command succeeded, and
false
if the operation was canceled by the user or
an error occurred while savingpublic static void setDefaultEditor(IFile file, String editorID)
getDefaultEditor(IFile)
.file
- the fileeditorID
- the editor idpublic static IEditorDescriptor getDefaultEditor(IFile file)
A default editor id may be registered for a specific file using
setDefaultEditor
. If the given file has a registered
default editor id the default editor will derived from it. If not, the
default editor is determined by taking the file name for the file and
obtaining the default editor for that name.
file
- the filenull
if
not foundpublic static IEditorDescriptor getDefaultEditor(IFile file, boolean determineContentType)
determineContentType
is
true
.
A default editor id may be registered for a specific file using
setDefaultEditor
. If the given file has a registered
default editor id the default editor will derived from it. If not, the
default editor is determined by taking the file name for the file and
obtaining the default editor for that name.
file
- the filedetermineContentType
- determine the content type for the given filenull
if
not foundpublic static List computeSelectedResources(IStructuredSelection originalSelection)
IResource
s in the given
selection or the resource objects they adapts to.originalSelection
- the original selection, possibly emptyIResource
),
possibly emptypublic static IContentType getContentType(IFile file)
file
- the file to testnull
if it cannot be
determined.public static IContentType guessContentType(IFile file)
file
- the file to testnull
if it cannot be
determined.public static boolean promptToConfirm(Shell shell, String title, String message, IResourceDelta delta, String[] ignoreModelProviderIds, boolean syncExec)
shell
- the shell to parent the prompt dialogtitle
- the title of the dialogmessage
- the message for the dialogdelta
- a delta built using an
IResourceChangeDescriptionFactory
ignoreModelProviderIds
- model providers to be ignoredsyncExec
- prompt in a sync exec (required when called from a non-UI
thread)public static void registerAdapters()
Note: this method should only be called once, in your application's WorkbenchAdvisor#initialize(IWorkbenchConfigurer) method.
public static IEditorReference[] openEditors(IWorkbenchPage page, IFile[] inputs) throws MultiPartInitException
If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened. The editor created for the first input will be activated.
page
- the page in which the editor will be openedinputs
- the inputs for the editorsMultiPartInitException
- if at least one of the editors could not be initialized
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.