com.aptana.ide.core.ui
Class CoreUIUtils

java.lang.Object
  extended by com.aptana.ide.core.ui.CoreUIUtils

public final class CoreUIUtils
extends java.lang.Object

Functions useful for retrieving interesting information for plug-ins and the environment, but tailored to UI-related functions

Author:
Ingo Muschenetz

Field Summary
static boolean inEclipse32orHigher
          Are we in Eclipse 3.2?
static java.lang.String LICENSED_UPDATE_SITE_HOST_NAME
          LICENSED_UPDATE_SITE_HOST_NAME
static boolean runningOnMac
          runningOnMac
static boolean runningOnWindows
          runningOnWindows
static java.lang.String URL_SEPARATOR
          Separates URL segments
 
Method Summary
static java.lang.String appendProtocol(java.lang.String path)
          Appends the file:// protocol, if none found
static void attachSaveListener(IVirtualFile file, java.io.File f, org.eclipse.ui.IEditorPart editorPart)
          Watches the local file for changes and saves them back to the IVirtualFile when the editor is saved
static org.eclipse.ui.IEditorInput createJavaFileEditorInput(java.io.File file)
          Creates a new JavaFileEditorInput
static org.eclipse.ui.IEditorInput createNonExistingFileEditorInput(java.io.File file, java.lang.String fileName)
          Creates a new NonExistingFileEditorInput
static boolean editVirtualFileManagerProperties(IVirtualFileManager vfm)
          editVirtualFileManagerProperties
static void fixConnection(IVirtualFileManager manager)
          Presents a dialog allow the user to "fix" a connection
static org.eclipse.ui.IEditorPart getActiveEditor()
          Returns the IEditorPart for the current editor
static java.lang.String getActiveEditorURI()
          Returns the URI for the current editor (effectively the file path transformed into file://)
static java.net.URL getBundlePathAsFile(java.net.URI url)
          Converts a URI with a bundle name in it to a entry ID.
static java.io.File getConfigurationDirectory()
          Returns a file handle to the folder links to osgi.configuration.area.
static java.lang.String getEncryptedProValue()
          Gets the encrypted pro value
static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(java.lang.String pluginId, java.lang.String imageFilePath)
          Retrieves the image descriptor associated with resource from the image descriptor registry.
static java.lang.String[] getOpenEditorPaths()
          getOpenEditorPaths
static java.lang.String getPathFromEditorInput(org.eclipse.ui.IEditorInput input)
          Returns the current path to the source file from an editor input.
static java.lang.String getPathFromURI(java.lang.String sourceURI)
          Gets the file path from a URI
static org.eclipse.core.runtime.IPath getPathOfIFileLocation(org.eclipse.core.resources.IFile file)
           
static java.io.File getPluginFile(org.eclipse.core.runtime.Plugin plugin)
          Retrieves the location of the plug-in
static java.lang.String getPluginLocation(org.eclipse.core.runtime.Plugin plugin)
          Retrieves the location of the plug-in
static java.net.URL getResolvedURL(org.osgi.framework.Bundle b, java.lang.String fullPath)
          Returns the URL as a local URL
static java.lang.String getStringOfIFileLocation(org.eclipse.core.resources.IFile file)
          Calls IFile.getLocation if it exists and uses an Eclipse internal mechanism if the file is deleted.
static java.lang.String getURI(java.io.File file)
          Returns a URI from a file
static java.lang.String getURI(java.io.File file, boolean urlEncode)
          Returns a URI from a file
static java.lang.String getURI(org.eclipse.ui.IEditorInput input)
          Returns a valid URI from the passed in editor input.
static java.lang.String getURI(org.eclipse.ui.IEditorPart editor)
          Returns the URI for the current editor (effectively the file path transformed into file://)
static java.lang.String getURI(org.eclipse.core.runtime.IPath path)
          getURI
static java.lang.String getURI(java.lang.String path)
          Returns a valid URI from the passed in path.
static java.lang.String getUserName()
          Gets the user's name from preferences or the system, whichever is defined
static org.eclipse.ui.IWorkbenchPart getViewInternal(java.lang.String id, java.lang.String secondaryId)
          getViewInternal
static org.eclipse.ui.IWorkbenchPart[] getViewsInternal(java.lang.String id)
          Gets all views with the primary part id, and any secondary part id
static org.eclipse.ui.IWorkbenchPart[] getViewsInternal(java.lang.String id, java.lang.String secondaryId)
          getViewInternal
static java.lang.String getWorkspaceDirectory()
          getWorkspaceDirectory
static boolean isFeatureEnabled(java.lang.String featureId)
          Returns true if a feature with this id is enabled
static boolean isFeatureInstalled(java.lang.String featureId)
          Returns true if a feature with this id is enabled
static boolean isInstalledAsPlugin()
          Are we installed as a plugin into Eclipse?
static boolean isURI(java.lang.String path)
          Does the current path contain a protocol?
static java.lang.String joinURI(java.lang.String uriPrefix, java.lang.String uriSuffix)
          joinURI
static java.lang.String joinURI(java.net.URL url, java.lang.String uriSuffix)
          joinURI
static java.lang.String joinUrlPath(java.lang.String[] segments)
          Joins the URL from segments
static void logAndDialogError(org.eclipse.swt.widgets.Shell shell, org.eclipse.core.runtime.Plugin plugin, java.lang.String title, java.lang.String message)
          Logs an error
static void logAndDialogError(org.eclipse.swt.widgets.Shell shell, org.eclipse.core.runtime.Plugin plugin, java.lang.String title, java.lang.String message, java.lang.Throwable th)
          Logs an error
static void openBrowserURL(java.lang.String browserUrl)
          Opens the url in an external browser according to the browser returned from IWorkbenchBrowserSupport.getExternalBrowser().
static void openBrowserURLWithAllInfo(java.lang.String browserUrl, boolean startWithQuestionMark, java.lang.String from)
          Opens a browser url with all the added info
static void openBrowserURLWithInfo(java.lang.String browserUrl, boolean startWithQuestionMark, java.lang.String from)
          Opens a browser url with added info
static void openFileInEditor(IVirtualFile file, org.eclipse.ui.IEditorDescriptor editorDesc)
          openFileInEditor
static void placeDialogInScreenCenter(org.eclipse.swt.widgets.Shell parent, org.eclipse.swt.widgets.Shell shell)
          Puts the respective dialog in the center of the screen
static void registerFileExtension(java.lang.String editorID, java.lang.String filename, java.lang.String extension)
          registerFileExtension
static java.net.URI replaceBundleNameWithId(java.net.URI url)
          Converts a URI with a bundle name in it to a entry ID.
static java.lang.String resolveBundleUrl(java.lang.String stringUrl)
           
static java.io.File saveRemoteFileAsLocal(IVirtualFile file)
          Saves a remote file as a local file
static void showError(java.lang.String message, java.lang.Exception e)
           
static void showError(java.lang.String message, java.lang.Exception e, boolean log)
           
static void showMessage(java.lang.String message)
           
static java.lang.String[] splitUrlPath(java.lang.String urlPath)
          Splits the URL into segments
static java.net.URL trimURLSegments(java.net.URL url, int segments)
          Trims the specified # of segments from the end of the URL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LICENSED_UPDATE_SITE_HOST_NAME

public static final java.lang.String LICENSED_UPDATE_SITE_HOST_NAME
LICENSED_UPDATE_SITE_HOST_NAME

See Also:
Constant Field Values

runningOnMac

public static boolean runningOnMac
runningOnMac


runningOnWindows

public static boolean runningOnWindows
runningOnWindows


inEclipse32orHigher

public static boolean inEclipse32orHigher
Are we in Eclipse 3.2?


URL_SEPARATOR

public static java.lang.String URL_SEPARATOR
Separates URL segments

Method Detail

getImageDescriptor

public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(java.lang.String pluginId,
                                                                            java.lang.String imageFilePath)
Retrieves the image descriptor associated with resource from the image descriptor registry. If the image descriptor cannot be retrieved, attempt to find and load the image descriptor at the location specified in resource.

Parameters:
pluginId - the Id of the plug-in to grab the image from
imageFilePath - the image descriptor to retrieve
Returns:
The image descriptor associated with resource or the default "missing" image descriptor if one could not be found

placeDialogInScreenCenter

public static void placeDialogInScreenCenter(org.eclipse.swt.widgets.Shell parent,
                                             org.eclipse.swt.widgets.Shell shell)
Puts the respective dialog in the center of the screen

Parameters:
parent -
shell -

getPluginLocation

public static java.lang.String getPluginLocation(org.eclipse.core.runtime.Plugin plugin)
Retrieves the location of the plug-in

Parameters:
plugin - The plug-in to search
Returns:
The string plug-in value

getPluginFile

public static java.io.File getPluginFile(org.eclipse.core.runtime.Plugin plugin)
Retrieves the location of the plug-in

Parameters:
plugin - The plug-in to search
Returns:
The file plug-in value

getWorkspaceDirectory

public static java.lang.String getWorkspaceDirectory()
getWorkspaceDirectory

Returns:
File

getStringOfIFileLocation

public static java.lang.String getStringOfIFileLocation(org.eclipse.core.resources.IFile file)
Calls IFile.getLocation if it exists and uses an Eclipse internal mechanism if the file is deleted. Look at the implementation of IFile.getLocation to see why this is necessary. Basically getLocation() returns null if the enclosing project doesn't exist so this allows the location of a deleted file to be found.

Parameters:
file -
Returns:
- Absolute OS string of file location

getPathOfIFileLocation

public static org.eclipse.core.runtime.IPath getPathOfIFileLocation(org.eclipse.core.resources.IFile file)
Parameters:
file -
Returns:
- path of IFile
See Also:
getStringOfIFileLocation(IFile file)

getPathFromEditorInput

public static java.lang.String getPathFromEditorInput(org.eclipse.ui.IEditorInput input)
Returns the current path to the source file from an editor input.

Parameters:
input - the editor input
Returns:
the path, or null if not found

appendProtocol

public static java.lang.String appendProtocol(java.lang.String path)
Appends the file:// protocol, if none found

Parameters:
path -
Returns:
String

getURI

public static java.lang.String getURI(java.io.File file)
Returns a URI from a file

Parameters:
file - the file to pull from
Returns:
the string path to the file

getURI

public static java.lang.String getURI(java.io.File file,
                                      boolean urlEncode)
Returns a URI from a file

Parameters:
file - the file to pull from
urlEncode - do we url encode the file name
Returns:
the string path to the file

getURI

public static java.lang.String getURI(org.eclipse.core.runtime.IPath path)
getURI

Parameters:
path -
Returns:
String

getURI

public static java.lang.String getURI(org.eclipse.ui.IEditorInput input)
Returns a valid URI from the passed in editor input. This assumed that the editor input represents a file on disk

Parameters:
input -
Returns:
String

isURI

public static boolean isURI(java.lang.String path)
Does the current path contain a protocol?

Parameters:
path -
Returns:
String

getURI

public static java.lang.String getURI(java.lang.String path)
Returns a valid URI from the passed in path. If the current path contains a protocol (i.e. file://), it just returns the path unchanged

Parameters:
path -
Returns:
String

getURI

public static java.lang.String getURI(org.eclipse.ui.IEditorPart editor)
Returns the URI for the current editor (effectively the file path transformed into file://)

Parameters:
editor -
Returns:
String

getActiveEditor

public static org.eclipse.ui.IEditorPart getActiveEditor()
Returns the IEditorPart for the current editor

Returns:
IEditorPart

getActiveEditorURI

public static java.lang.String getActiveEditorURI()
Returns the URI for the current editor (effectively the file path transformed into file://)

Returns:
String

getOpenEditorPaths

public static java.lang.String[] getOpenEditorPaths()
getOpenEditorPaths

Returns:
String[]

getViewInternal

public static org.eclipse.ui.IWorkbenchPart getViewInternal(java.lang.String id,
                                                            java.lang.String secondaryId)
getViewInternal

Parameters:
id -
secondaryId -
Returns:
IWorkbenchPart

getViewsInternal

public static org.eclipse.ui.IWorkbenchPart[] getViewsInternal(java.lang.String id)
Gets all views with the primary part id, and any secondary part id

Parameters:
id -
Returns:
IWorkbenchPart

getViewsInternal

public static org.eclipse.ui.IWorkbenchPart[] getViewsInternal(java.lang.String id,
                                                               java.lang.String secondaryId)
getViewInternal

Parameters:
id -
secondaryId -
Returns:
IWorkbenchPart

getPathFromURI

public static java.lang.String getPathFromURI(java.lang.String sourceURI)
Gets the file path from a URI

Parameters:
sourceURI - the source URI
Returns:
the URI converted to a path (removed file:// from the beginning)

getUserName

public static java.lang.String getUserName()
Gets the user's name from preferences or the system, whichever is defined

Returns:
String

logAndDialogError

public static void logAndDialogError(org.eclipse.swt.widgets.Shell shell,
                                     org.eclipse.core.runtime.Plugin plugin,
                                     java.lang.String title,
                                     java.lang.String message)
Logs an error

Parameters:
shell -
plugin -
title - the title of the dialog
message - the message to log

logAndDialogError

public static void logAndDialogError(org.eclipse.swt.widgets.Shell shell,
                                     org.eclipse.core.runtime.Plugin plugin,
                                     java.lang.String title,
                                     java.lang.String message,
                                     java.lang.Throwable th)
Logs an error

Parameters:
shell -
plugin -
title - the title of the dialog
message - the message to log
th -

createJavaFileEditorInput

public static org.eclipse.ui.IEditorInput createJavaFileEditorInput(java.io.File file)
Creates a new JavaFileEditorInput

Parameters:
file -
Returns:
IEditorInput

createNonExistingFileEditorInput

public static org.eclipse.ui.IEditorInput createNonExistingFileEditorInput(java.io.File file,
                                                                           java.lang.String fileName)
Creates a new NonExistingFileEditorInput

Parameters:
file -
fileName -
Returns:
IEditorInput

joinURI

public static java.lang.String joinURI(java.net.URL url,
                                       java.lang.String uriSuffix)
joinURI

Parameters:
url -
uriSuffix -
Returns:
String

joinURI

public static java.lang.String joinURI(java.lang.String uriPrefix,
                                       java.lang.String uriSuffix)
joinURI

Parameters:
uriPrefix -
uriSuffix -
Returns:
String

trimURLSegments

public static java.net.URL trimURLSegments(java.net.URL url,
                                           int segments)
Trims the specified # of segments from the end of the URL

Parameters:
url -
segments -
Returns:
URL

splitUrlPath

public static java.lang.String[] splitUrlPath(java.lang.String urlPath)
Splits the URL into segments

Parameters:
urlPath -
Returns:
an array of strings

joinUrlPath

public static java.lang.String joinUrlPath(java.lang.String[] segments)
Joins the URL from segments

Parameters:
segments -
Returns:
an joined array

registerFileExtension

public static void registerFileExtension(java.lang.String editorID,
                                         java.lang.String filename,
                                         java.lang.String extension)
registerFileExtension

Parameters:
editorID -
filename - The name of the file to associate with the given editor ID. Use * if any file for the given extension will work
extension - The file extensions without the leading '.' to associate with the given editor ID

replaceBundleNameWithId

public static java.net.URI replaceBundleNameWithId(java.net.URI url)
Converts a URI with a bundle name in it to a entry ID.

Parameters:
url -
Returns:
URI

getBundlePathAsFile

public static java.net.URL getBundlePathAsFile(java.net.URI url)
Converts a URI with a bundle name in it to a entry ID.

Parameters:
url -
Returns:
URI

getResolvedURL

public static java.net.URL getResolvedURL(org.osgi.framework.Bundle b,
                                          java.lang.String fullPath)
Returns the URL as a local URL

Parameters:
b -
fullPath -
Returns:
the resolved url

getConfigurationDirectory

public static java.io.File getConfigurationDirectory()
Returns a file handle to the folder links to osgi.configuration.area.

Returns:
A reference to the configuration directory on disk

resolveBundleUrl

public static java.lang.String resolveBundleUrl(java.lang.String stringUrl)
Parameters:
stringUrl -
Returns:
string of resolved url

openFileInEditor

public static void openFileInEditor(IVirtualFile file,
                                    org.eclipse.ui.IEditorDescriptor editorDesc)
openFileInEditor

Parameters:
file -
editorDesc -

attachSaveListener

public static void attachSaveListener(IVirtualFile file,
                                      java.io.File f,
                                      org.eclipse.ui.IEditorPart editorPart)
Watches the local file for changes and saves them back to the IVirtualFile when the editor is saved

Parameters:
file -
f -
editorPart -

saveRemoteFileAsLocal

public static java.io.File saveRemoteFileAsLocal(IVirtualFile file)
Saves a remote file as a local file

Parameters:
file -
Returns:
File

fixConnection

public static void fixConnection(IVirtualFileManager manager)
Presents a dialog allow the user to "fix" a connection

Parameters:
manager -

editVirtualFileManagerProperties

public static boolean editVirtualFileManagerProperties(IVirtualFileManager vfm)
editVirtualFileManagerProperties

Parameters:
vfm -
Returns:
boolean

showError

public static void showError(java.lang.String message,
                             java.lang.Exception e)
Parameters:
message -
e -

showError

public static void showError(java.lang.String message,
                             java.lang.Exception e,
                             boolean log)
Parameters:
message -
e -
log -

showMessage

public static void showMessage(java.lang.String message)
Parameters:
message -

isInstalledAsPlugin

public static boolean isInstalledAsPlugin()
Are we installed as a plugin into Eclipse?

Returns:
true if plugin, false otherwise

openBrowserURLWithInfo

public static void openBrowserURLWithInfo(java.lang.String browserUrl,
                                          boolean startWithQuestionMark,
                                          java.lang.String from)
Opens a browser url with added info

Parameters:
browserUrl - - base url that will be directly appened with ? plus info
startWithQuestionMark - - true to append a ?, false to start appending with &
from - - location triggering

openBrowserURLWithAllInfo

public static void openBrowserURLWithAllInfo(java.lang.String browserUrl,
                                             boolean startWithQuestionMark,
                                             java.lang.String from)
Opens a browser url with all the added info

Parameters:
browserUrl - - base url that will be directly appened with ? plus ALL info
startWithQuestionMark - - true to append a ?, false to start appending with &
from - - location triggering

getEncryptedProValue

public static java.lang.String getEncryptedProValue()
Gets the encrypted pro value

Returns:
- pro value

openBrowserURL

public static void openBrowserURL(java.lang.String browserUrl)
Opens the url in an external browser according to the browser returned from IWorkbenchBrowserSupport.getExternalBrowser(). Will not throw exceptions that occur during the opening

Parameters:
browserUrl - - url to open

isFeatureEnabled

public static boolean isFeatureEnabled(java.lang.String featureId)
Returns true if a feature with this id is enabled

Parameters:
featureId -
Returns:
true if enabled, false otherwise

isFeatureInstalled

public static boolean isFeatureInstalled(java.lang.String featureId)
Returns true if a feature with this id is enabled

Parameters:
featureId -
Returns:
true if enabled, false otherwise