org.eclipse.cdt.internal.ui.util
Class EditorUtility

java.lang.Object
  extended by org.eclipse.cdt.internal.ui.util.EditorUtility

public class EditorUtility
extends java.lang.Object


Field Summary
static java.lang.String DEFAULT_TEXT_EDITOR_ID
          The ID of the default text editor
 
Method Summary
static int findLocalizedModifier(java.lang.String token)
          Maps the localized modifier name to a code in the same manner as #findModifier.
static org.eclipse.cdt.core.model.ICElement getActiveEditorCInput()
          If the current active editor edits a c element return it, else return null
static java.lang.String getEditorID(org.eclipse.ui.IEditorInput input, java.lang.Object inputObject)
          Determine the editor id from the given editor input and optional input object.
static java.lang.String getEditorID(java.lang.String name)
          Determine the editor id from the given file name using the workspace-wide content-type definitions.
static org.eclipse.ui.IEditorInput getEditorInput(java.lang.Object input)
           
static org.eclipse.ui.IEditorInput getEditorInputForLocation(org.eclipse.core.runtime.IPath location, org.eclipse.cdt.core.model.ICElement context)
          Utility method to get an editor input for the given file system location.
static java.lang.String getModifierString(int stateMask)
          Returns the modifier string for the given SWT modifier modifier bits.
static org.eclipse.core.resources.IStorage getStorage(org.eclipse.cdt.core.model.IBinary bin)
           
static org.eclipse.core.resources.IStorage getStorage(org.eclipse.cdt.core.model.ITranslationUnit tu)
           
static org.eclipse.cdt.core.model.ITranslationUnit getWorkingCopy(org.eclipse.cdt.core.model.ITranslationUnit cu)
          Gets the working copy of an compilation unit opened in an editor
static boolean isLinked(org.eclipse.core.resources.IFile file)
           
static org.eclipse.ui.IEditorPart isOpenInEditor(java.lang.Object inputElement)
          Tests if a cu is currently shown in an editor
static org.eclipse.ui.IEditorPart openInEditor(org.eclipse.core.runtime.IPath location, org.eclipse.cdt.core.model.ICElement element)
          Utility method to open an editor for the given file system location using getEditorInputForLocation(IPath, ICElement) to create the editor input.
static org.eclipse.ui.IEditorPart openInEditor(java.lang.Object inputElement)
          Opens an editor for an element such as ICElement, IFile, or IStorage.
static org.eclipse.ui.IEditorPart openInEditor(java.lang.Object inputElement, boolean activate)
          Opens an editor for an element (ICElement, IFile, IStorage...)
static void revealInEditor(org.eclipse.ui.IEditorPart part, org.eclipse.cdt.core.model.ICElement element)
          Selects a C Element in an editor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEXT_EDITOR_ID

public static final java.lang.String DEFAULT_TEXT_EDITOR_ID
The ID of the default text editor

See Also:
Constant Field Values
Method Detail

isOpenInEditor

public static org.eclipse.ui.IEditorPart isOpenInEditor(java.lang.Object inputElement)
Tests if a cu is currently shown in an editor

Returns:
the IEditorPart if shown, null if element is not open in an editor

openInEditor

public static org.eclipse.ui.IEditorPart openInEditor(java.lang.Object inputElement)
                                               throws org.eclipse.cdt.core.model.CModelException,
                                                      org.eclipse.ui.PartInitException
Opens an editor for an element such as ICElement, IFile, or IStorage. The editor is activated by default.

Returns:
the IEditorPart or null if wrong element type or opening failed
Throws:
org.eclipse.cdt.core.model.CModelException
org.eclipse.ui.PartInitException

openInEditor

public static org.eclipse.ui.IEditorPart openInEditor(java.lang.Object inputElement,
                                                      boolean activate)
                                               throws org.eclipse.cdt.core.model.CModelException,
                                                      org.eclipse.ui.PartInitException
Opens an editor for an element (ICElement, IFile, IStorage...)

Returns:
the IEditorPart or null if wrong element type or opening failed
Throws:
org.eclipse.cdt.core.model.CModelException
org.eclipse.ui.PartInitException

revealInEditor

public static void revealInEditor(org.eclipse.ui.IEditorPart part,
                                  org.eclipse.cdt.core.model.ICElement element)
Selects a C Element in an editor


isLinked

public static boolean isLinked(org.eclipse.core.resources.IFile file)

getEditorInput

public static org.eclipse.ui.IEditorInput getEditorInput(java.lang.Object input)
                                                  throws org.eclipse.cdt.core.model.CModelException
Throws:
org.eclipse.cdt.core.model.CModelException

openInEditor

public static org.eclipse.ui.IEditorPart openInEditor(org.eclipse.core.runtime.IPath location,
                                                      org.eclipse.cdt.core.model.ICElement element)
                                               throws org.eclipse.ui.PartInitException
Utility method to open an editor for the given file system location using getEditorInputForLocation(IPath, ICElement) to create the editor input.

Parameters:
location - a file system location
element - an element related to the target file, may be null
Throws:
org.eclipse.ui.PartInitException

getEditorInputForLocation

public static org.eclipse.ui.IEditorInput getEditorInputForLocation(org.eclipse.core.runtime.IPath location,
                                                                    org.eclipse.cdt.core.model.ICElement context)
Utility method to get an editor input for the given file system location. If the location denotes a workspace file, a FileEditorInput is returned, otherwise, the input is an IStorageEditorInput assuming the location points to an existing file in the file system. The ICElement is used to determine the associated project in case the location can not be resolved to a workspace IFile.

Parameters:
location - a valid file system location
context - an element related to the target file, may be null
Returns:
an editor input

getActiveEditorCInput

public static org.eclipse.cdt.core.model.ICElement getActiveEditorCInput()
If the current active editor edits a c element return it, else return null


getWorkingCopy

public static org.eclipse.cdt.core.model.ITranslationUnit getWorkingCopy(org.eclipse.cdt.core.model.ITranslationUnit cu)
Gets the working copy of an compilation unit opened in an editor

Parameters:
cu - the original compilation unit (or another working copy)
Returns:
the working copy of the compilation unit, or null if not found

getEditorID

public static java.lang.String getEditorID(java.lang.String name)
Determine the editor id from the given file name using the workspace-wide content-type definitions.

Parameters:
name - the file name
Returns:
a valid editor id, never null

getEditorID

public static java.lang.String getEditorID(org.eclipse.ui.IEditorInput input,
                                           java.lang.Object inputObject)
Determine the editor id from the given editor input and optional input object. When a translation unit can be obtained, the project-specific content-type mechanism is used to determine the correct editor id. If that fails, the editor id is determined by file name and extension using the workspace-wide content-type definitions.

Parameters:
input - the editor input
inputObject - the input object (used to create the editor input) or null
Returns:
a valid editor id, never null

findLocalizedModifier

public static int findLocalizedModifier(java.lang.String token)
Maps the localized modifier name to a code in the same manner as #findModifier.

Returns:
the SWT modifier bit, or 0 if no match was found

getModifierString

public static java.lang.String getModifierString(int stateMask)
Returns the modifier string for the given SWT modifier modifier bits.

Parameters:
stateMask - the SWT modifier bits
Returns:
the modifier string
Since:
2.1.1

getStorage

public static org.eclipse.core.resources.IStorage getStorage(org.eclipse.cdt.core.model.IBinary bin)

getStorage

public static org.eclipse.core.resources.IStorage getStorage(org.eclipse.cdt.core.model.ITranslationUnit tu)