📄 eclipsemecoreplugin.java
字号:
* This directory will automatically be added to the emulator classpath when
* running midlets from source.
*
* @return
*/
public static String getResourcesDirectoryName() {
return getDefault().getPluginPreferences().getString(PREF_RESOURCES_DIR);
}
/**
* Create a component specification for the specified configuration
* element
* @param element
* @return
* @throws CoreException
*/
private static LibrarySpecification createComponentSpecification(IConfigurationElement element)
throws CoreException
{
String id = element.getAttribute("id");
String name = element.getAttribute("name");
String versionString = element.getAttribute("version");
Version version = new Version(versionString);
LibrarySpecification specification = new LibrarySpecification();
specification.setIdentifier(id);
specification.setName(name);
specification.setVersion(version);
return specification;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* Get the verified output directory name the user has
* specified in the preferences.
*
* @return
*/
public static String getVerifiedOutputDirectoryName() {
return getDefault().getPluginPreferences().getString(PREF_VERIFIED_DIR);
}
/**
* Log the specified message.
*/
public static void log(int severity, String message) {
log(severity, message, null);
}
/**
* Log the specified exception.
*/
public static void log(int severity, Throwable throwable) {
log(severity, throwable.getMessage(), throwable);
}
/**
* Log the specified message and exception
*/
public static void log(int severity, String message, Throwable throwable) {
if (message == null) message = throwable.getMessage();
if (message == null) message = "No Message";
EclipseMECorePlugin plugin = EclipseMECorePlugin.getDefault();
String id = IEclipseMECoreConstants.PLUGIN_ID;
Status status =
new Status(severity, id, IStatus.OK, message, throwable);
plugin.getLog().log(status);
}
/**
* Creates a new status object for our plugin. The created status has no children.
*
* @param severity the severity; one of <code>OK</code>,
* <code>ERROR</code>, <code>INFO</code>, or <code>WARNING</code>
* @param code the plug-in-specific status code, or <code>OK</code>
* @param message a human-readable message, localized to the
* current locale
*/
public static IStatus newStatus(int severity, int code, String message)
{
return newStatus(severity, code, message, null);
}
/**
* Creates a new status object for our plugin. The created status has no children.
*
* @param severity the severity; one of <code>OK</code>,
* <code>ERROR</code>, <code>INFO</code>, or <code>WARNING</code>
* @param code the plug-in-specific status code, or <code>OK</code>
* @param message a human-readable message, localized to the
* current locale
* @param exception a low-level exception, or <code>null</code> if not
* applicable
*/
public static IStatus newStatus(int severity, int code, String message, Throwable exception)
{
return new Status(severity, PLUGIN_ID, code, message, exception);
}
/**
* Recursively set the resources in the specified container and all resources
* within that container as derived.
*
* @param container
* @throws CoreException
*/
public static void setResourcesAsDerived(IContainer container)
throws CoreException
{
if (container.exists()) {
// Mark this folder first...
container.setDerived(true);
// Recursively handle the members of the directory
IResource[] resources = container.members();
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
if (resource instanceof IContainer) {
setResourcesAsDerived((IContainer) resource);
} else {
resource.setDerived(true);
}
}
}
}
/**
* Attempt to prompt on a status object. If prompting fails,
* a CoreException will be thrown.
*
* @param status
* @param source
* @return
* @throws CoreException
*/
public static Object statusPrompt(IStatus status, Object source)
throws CoreException
{
Object result = null;
IStatusHandler prompterStatus =
DebugPlugin.getDefault().getStatusHandler(PROMPTER_STATUS);
if (prompterStatus == null) {
// if there is no handler, throw the exception
throw new CoreException(status);
} else {
result = prompterStatus.handleStatus(status, source);
}
return result;
}
/**
* Throw a new CoreException wrapped around the specified
* exception.
*
* @param severity
* @param code
* @param exception
* @throws CoreException
*/
public static void throwCoreException(
int severity,
int code,
Throwable exception)
throws CoreException
{
// Make sure we create a valid status object
String message = null;
if (exception != null) {
message = exception.getMessage();
}
if (message == null) message = "[No Message]";
IStatus status = new Status(
severity,
IEclipseMECoreConstants.PLUGIN_ID,
code,
message,
exception);
throw new CoreException(status);
}
/**
* Throw a new CoreException wrapped around the specified
* String.
*
* @param severity
* @param code
* @param message
* @throws CoreException
*/
public static void throwCoreException(
int severity,
int code,
String message)
throws CoreException
{
if (message == null) message = "[No Message]";
IStatus status = new Status(
severity,
IEclipseMECoreConstants.PLUGIN_ID,
code,
message,
null);
throw new CoreException(status);
}
/**
* Returns the plugin's resource bundle,
*
* @uml.property name="resourceBundle"
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
// Install the preprocessor source mapper
SourceMapperAccess.setSourceMapper(new PreprocessedSourceMapper());
// Do version to version migration
(new MigrationJob()).schedule(5000L);
}
/**
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
/**
* Execute the necessary migration steps.
*
* @param monitor
* @throws CoreException
*/
private void doMigration(IProgressMonitor monitor)
throws CoreException
{
ResourcesPlugin.getWorkspace().run(new PreprocessedProjectMigrationRunnable(), monitor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -