本文整理了Java中org.eclipse.core.runtime.Plugin
类的一些代码示例,展示了Plugin
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Plugin
类的具体详情如下:
包路径:org.eclipse.core.runtime.Plugin
类名称:Plugin
[英]The abstract superclass of all plug-in runtime class implementations. A plug-in subclasses this class and overrides the appropriate life cycle methods in order to react to the life cycle requests automatically issued by the platform. For compatibility reasons, the methods called for those life cycle events vary, please see the "Constructors and life cycle methods" section below.
Conceptually, the plug-in runtime class represents the entire plug-in rather than an implementation of any one particular extension the plug-in declares. A plug-in is not required to explicitly specify a plug-in runtime class; if none is specified, the plug-in will be given a default plug-in runtime object that ignores all life cycle requests (it still provides access to the corresponding plug-in descriptor).
In the case of more complex plug-ins, it may be desirable to define a concrete subclass of Plugin
. However, just subclassing Plugin
is not sufficient. The name of the class must be explicitly configured in the plug-in's manifest (plugin.xml
) file with the class attribute of the <plugin>
element markup.
Instances of plug-in runtime classes are automatically created by the platform in the course of plug-in activation. For compatibility reasons, the constructor used to create plug-in instances varies, please see the "Constructors and life cycle methods" section below.
The concept of bundles underlies plug-ins. However it is safe to regard plug-ins and bundles as synonyms.
Clients must never explicitly instantiate a plug-in runtime class.
A typical implementation pattern for plug-in runtime classes is to provide a static convenience method to gain access to a plug-in's runtime object. This way, code in other parts of the plug-in implementation without direct access to the plug-in runtime object can easily obtain a reference to it, and thence to any plug-in-wide resources recorded on it. An example for Eclipse 3.0 follows:
package myplugin;
public class MyPluginClass extends Plugin {
private static MyPluginClass instance;
public static MyPluginClass getInstance() { return instance; }
public void MyPluginClass() {
super();
instance = this;
// ... other initialization
}
// ... other methods
}
In the above example, a call to MyPluginClass.getInstance()
will always return an initialized instance of MyPluginClass
.
Constructors and life cycle methods
If the plugin.xml of a plug-in indicates <?eclipse version="3.0"?> and its prerequisite list includes org.eclipse.core.runtime
, the default constructor of the plug-in class is used and #start(BundleContext) and #stop(BundleContext) are called as life cycle methods.
The #Plugin(IPluginDescriptor) constructor was called only for plug-ins which explicitly require the org.eclipse.core.runtime.compatibility plug-in. It is not called anymore as Eclipse 4.6 removed this plug-in.
If the plugin.xml of your plug-in does not indicate <?eclipse version="3.0"?> it is therefore not a 3.0 plug-in. Consequently the #Plugin(IPluginDescriptor) is used and #startup() and #shutdown() are called as life cycle methods.
Since Eclipse 3.0 APIs of the Plugin class can be called only when the Plugin is in an active state, i.e., after it was started up and before it is shutdown. In particular, it means that Plugin APIs should not be called from overrides of #Plugin().
[中]所有插件运行时类实现的抽象超类。插件子类化这个类并重写适当的生命周期方法,以便对平台自动发出的生命周期请求做出反应。出于兼容性原因,为这些生命周期事件调用的方法各不相同,请参阅下面的“构造函数和生命周期方法”部分。
从概念上讲,插件运行时类代表整个插件,而不是插件声明的任何一个特定扩展的实现。插件不需要显式指定插件运行时类;如果未指定,插件将获得一个默认插件运行时对象,该对象将忽略所有生命周期请求(它仍然提供对相应插件描述符的访问)。
对于更复杂的插件,可能需要定义一个具体的子类Plugin
。然而,仅仅子类化Plugin
是不够的。必须使用<plugin>
元素标记的class属性在插件的清单(plugin.xml
)文件中显式配置类的名称。
插件运行时类的实例由平台在插件激活过程中自动创建。出于兼容性原因,用于创建插件实例的构造函数各不相同,请参阅下面的“构造函数和生命周期方法”部分。
捆绑包的概念是插件的基础。然而,将插件和捆绑包视为同义词是安全的。
客户端决不能显式实例化插件运行时类。
插件运行时类的一种典型实现模式是提供一种静态方便的方法来访问插件的运行时对象。这样,插件实现的其他部分中的代码在不直接访问插件运行时对象的情况下,就可以很容易地获得对它的引用,从而获得对其上记录的任何插件范围的资源的引用。Eclipse 3.0的一个示例如下:
package myplugin;
public class MyPluginClass extends Plugin {
private static MyPluginClass instance;
public static MyPluginClass getInstance() { return instance; }
public void MyPluginClass() {
super();
instance = this;
// ... other initialization
}
// ... other methods
}
在上述示例中,对MyPluginClass.getInstance()
的调用将始终返回MyPluginClass
的初始化实例。
构造函数和生命周期方法
如果是插件。插件的xml表示<?eclipse version=“3.0”>它的先决条件列表包括[$6$],使用插件类的默认构造函数,#start(BundleContext)和#stop(BundleContext)被称为生命周期方法。
#Plugin(IPluginDescriptor)构造函数仅为明确需要org的插件调用。日食果心运行时。兼容性插件。由于Eclipse4.6删除了这个插件,所以不再调用它。
如果是插件。插件的xml不表示<?eclipse version=“3.0”>因此,它不是3.0插件。因此,使用了#插件(IPluginDescriptor),而#startup()和#shutdown()被称为生命周期方法。
因为只有当插件处于活动状态时,即启动后和关闭前,才能调用插件类的Eclipse 3.0 API。特别是,这意味着不应该从#Plugin()的覆盖中调用插件API。
代码示例来源:origin: org.eclipse.core/runtime
@Override
public void start(BundleContext runtimeContext) throws Exception {
PlatformActivator.context = runtimeContext;
InternalPlatform.getDefault().start(runtimeContext);
startAppContainer();
InternalPlatform.getDefault().setRuntimeInstance(this);
super.start(runtimeContext);
}
代码示例来源:origin: org.eclipse.core/runtime
/**
* Returns a string representation of the plug-in, suitable
* for debugging purposes only.
*/
@Override
public String toString() {
Bundle myBundle = getBundle();
if (myBundle == null)
return ""; //$NON-NLS-1$
String name = myBundle.getSymbolicName();
return name == null ? new Long(myBundle.getBundleId()).toString() : name;
}
代码示例来源:origin: org.eclipse.core/runtime
getPluginPreferences();
代码示例来源:origin: org.eclipse.core/runtime
/**
* Returns the plug-in descriptor for this plug-in runtime object.
*
* @return the plug-in descriptor for this plug-in runtime object
* @deprecated
* <code>IPluginDescriptor</code> was refactored in Eclipse 3.0.
* The <code>getDescriptor()</code> method may only be called by plug-ins
* which explicitly require the org.eclipse.core.runtime.compatibility plug-in.
* See the comments on {@link IPluginDescriptor} and its methods for details.
*/
@Deprecated
public final IPluginDescriptor getDescriptor() {
if (descriptor != null)
return descriptor;
return initializeDescriptor(getBundle().getSymbolicName());
}
代码示例来源:origin: org.eclipse.core/runtime
/**
* Returns whether this plug-in is in debug mode.
* By default plug-ins are not in debug mode. A plug-in can put itself
* into debug mode or the user can set an execution option to do so.
* <p>
* Note that the plug-in's debug flag is initialized when the
* plug-in is started. The result of calling this method before the plug-in
* has started is unspecified.
* </p>
*
* @return whether this plug-in is in debug mode
* XXX deprecate use the service and cache as needed
*/
public boolean isDebugging() {
Bundle debugBundle = getBundle();
if (debugBundle == null)
return debug;
String key = debugBundle.getSymbolicName() + "/debug"; //$NON-NLS-1$
// first check if platform debugging is enabled
final DebugOptions debugOptions = getDebugOptions();
if (debugOptions == null)
return debug;
// if platform debugging is enabled, check to see if this plugin is enabled for debugging
return debugOptions.isDebugEnabled() ? InternalPlatform.getDefault().getBooleanOption(key, false) : false;
}
代码示例来源:origin: angelozerr/angularjs-eclipse
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
public static void log(IStatus status) {
Plugin plugin = JavaCore.getPlugin();
if (plugin == null) {
System.err.println(status.toString());
} else {
plugin.getLog().log(status);
}
}
代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.core
/**
* Convenience method for handling generic exceptions.
*
* @param exception
* @param errorMessage
*/
public static void handleException(final Plugin plugin, final Throwable exception, final String errorMessage) {
final MultiStatus errorStatus = getServiceInfo(plugin.getBundle(), exception);
final IStatus status = new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), IStatus.ERROR, errorMessage, exception);
errorStatus.add(status);
plugin.getLog().log(status);
}
代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core
synchronized void setIndexState(int state) {
if (DEBUG) {
System.out.println("JSPIndexManager setting index state to: " + state2String(state)); //$NON-NLS-1$
}
Plugin jspModelPlugin = JSPCorePlugin.getDefault();
jspModelPlugin.getPluginPreferences().setValue(PKEY_INDEX_STATE, state);
jspModelPlugin.savePluginPreferences();
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.ide/org.eclipse.scada.configuration.world.lib
@Override
public void stop ( final BundleContext context ) throws Exception
{
plugin = null;
super.stop ( context );
}
代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core
public static void log(IStatus status) {
Plugin plugin = JavaCore.getPlugin();
if (plugin == null) {
System.err.println(status.toString());
} else {
plugin.getLog().log(status);
}
}
代码示例来源:origin: org.eclipse.core/runtime
/**
* Sets whether this plug-in is in debug mode.
* By default plug-ins are not in debug mode. A plug-in can put itself
* into debug mode or the user can set a debug option to do so.
* <p>
* Note that the plug-in's debug flag is initialized when the
* plug-in is started. The result of calling this method before the plug-in
* has started is unspecified.
* </p>
*
* @param value whether or not this plug-in is in debug mode
* XXX deprecate use the service and cache as needed
*/
public void setDebugging(boolean value) {
Bundle debugBundle = getBundle();
if (debugBundle == null) {
this.debug = value;
return;
}
String key = debugBundle.getSymbolicName() + "/debug"; //$NON-NLS-1$
final DebugOptions options = getDebugOptions();
if (options == null)
this.debug = value;
else {
if (!options.isDebugEnabled())
options.setDebugEnabled(true);
options.setOption(key, value ? Boolean.TRUE.toString() : Boolean.FALSE.toString());
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.expressions
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
fBundleContext= context;
}
代码示例来源:origin: com.reprezen.rapidml/com.reprezen.rapidml
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
代码示例来源:origin: org.eclipse.core/runtime
/**
* Returns a URL for the given path. Returns <code>null</code> if the URL
* could not be computed or created.
*
* @param path path relative to plug-in installation location
* @return a URL for the given path or <code>null</code>
* @deprecated use {@link FileLocator#find(Bundle, IPath, Map)}
*/
@Deprecated
public final URL find(IPath path) {
return FileLocator.find(getBundle(), path, null);
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
public static void log(IStatus status) {
JavaCore.getPlugin().getLog().log(status);
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
/**
* Returns the Java Core plug-in preferences.
*
* @return the Java Core plug-in preferences
* @since 3.7
*/
public static org.eclipse.core.runtime.Preferences getJavaCorePluginPreferences() {
return JavaCore.getPlugin().getPluginPreferences();
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.ide/org.eclipse.scada.configuration.world.lib
@Override
public void start ( final BundleContext context ) throws Exception
{
super.start ( context );
plugin = this;
}
代码示例来源:origin: org.eclipse/org.eclipse.contribution.xref.core
/**
* This method is called when the plug-in is stopped
*
* 3.0 compatible
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
}
代码示例来源:origin: org.eclipse.core/runtime
/**
* Returns the DebugOptions instance
*
* @since 3.5
* @return Either the DebugOptions instance or <code>null</code> if this plug-in does not have a bundle
*/
private DebugOptions getDebugOptions() {
Bundle debugBundle = getBundle();
if (debugBundle == null)
return null;
if (debugTracker == null) {
BundleContext context = debugBundle.getBundleContext();
if (context == null)
return null;
debugTracker = new ServiceTracker<DebugOptions,DebugOptions>(context, DebugOptions.class.getName(), null);
debugTracker.open();
}
return this.debugTracker.getService();
}
内容来源于网络,如有侵权,请联系作者删除!