私はEclipseプラグインを持っていて、このプラグイン内で特定のアクションを実行したいのですが、Eclipseアプリケーションが開かれた後です。
オーバーライドしてやってみました
public void postWindowCreate()
しかし、アプリケーションを起動すると、この関数の中に入ることができないようです
何か案は ?
私はEclipseプラグインを持っていて、このプラグイン内で特定のアクションを実行したいのですが、Eclipseアプリケーションが開かれた後です。
オーバーライドしてやってみました
public void postWindowCreate()
しかし、アプリケーションを起動すると、この関数の中に入ることができないようです
何か案は ?
e4を使用していますか?次に、次のリンクが役立つ場合があります:http ://www.eclipse.org/forums/index.php/m/886197/
編集:
OK、独自のアプリケーションを定義しますか?
あなたが必要とするものによって提供される方法はorg.eclipse.ui.application.WorkbenchWindowAdvisor
ありますか?(例preWindowOpen()
、、、、、... preWindowShellClose()
)postWindowRestore()
postWindowCreate()
その機能も必要だったので、次のようにします。
3つのクラスが必要です。1つはorg.eclipse.equinox.app.IApplication
MyAppなどを実装し、もう1つはorg.eclipse.ui.application.WorkbenchAdvisor
MyAdvisorなどを拡張し、もう1つはorg.eclipse.ui.application.WorkbenchWindowAdvisor
MyWindowAdvisorなどを拡張します。
次に、MyAppで、おそらく次のようなものを呼び出します
PlatformUI.createAndRunWorkbench(display, new MyAdvisor());
実際にワークベンチを開始し、独自のを提供する場所WorkbenchWindowAdvisor
。MyAdvisorでは、以下を上書きする必要があります。
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new MyWindowAdvisor(configurer);
}
を提供しますWorkbenchWindowAdvisor
。クラスMyWindowAdvisor
では、最終的に適切な関数をオーバーライドできます。
@Override
public void postWindowOpen() {
//TODO
}
もちろん、これを機能させるには適切なアプリケーションを実行する必要があります;)さて、これらのイベントを処理するための任意のプラグインを提供するために、拡張ポイントを定義できます。
まず、聞きたい「イベント」を定義するインターフェースが必要です。例:
public interface IWorkbenchWindowAdvisorHook
{
/**
* Performs arbitrary actions before the window is opened.
* <p>
* This method is called before the window's controls have been created.
* Clients must not call this method directly (although super calls are okay).
* The default implementation does nothing. Subclasses may override.
* Typical clients will use the window configurer to tweak the
* workbench window in an application-specific way; however, filling the
* window's menu bar, tool bar, and status line must be done in
* {@link ActionBarAdvisor#fillActionBars}, which is called immediately
* after this method is called.
* </p>
*/
void preWindowOpen();
/**
* Performs arbitrary actions as the window's shell is being closed
* directly, and possibly veto the close.
* <p>
* This method is called from a ShellListener associated with the window,
* for example when the user clicks the window's close button. It is not
* called when the window is being closed for other reasons, such as if the
* user exits the workbench via the {@link ActionFactory#QUIT} action.
* Clients must not call this method directly (although super calls are
* okay). If this method returns <code>false</code>, then the user's
* request to close the shell is ignored. This gives the workbench advisor
* an opportunity to query the user and/or veto the closing of a window
* under some circumstances.
* </p>
*
* @return <code>true</code> to allow the window to close, and
* <code>false</code> to prevent the window from closing
* @see org.eclipse.ui.IWorkbenchWindow#close
* @see WorkbenchAdvisor#preShutdown()
*/
public boolean preWindowShellClose();
/**
* Performs arbitrary actions after the window has been restored,
* but before it is opened.
* <p>
* This method is called after a previously-saved window has been
* recreated. This method is not called when a new window is created from
* scratch. This method is never called when a workbench is started for the
* very first time, or when workbench state is not saved or restored.
* Clients must not call this method directly (although super calls are okay).
* The default implementation does nothing. Subclasses may override.
* It is okay to call <code>IWorkbench.close()</code> from this method.
* </p>
*
* @exception WorkbenchException thrown if there are any errors to report
* from post-restoration of the window
*/
void postWindowRestore() throws WorkbenchException;
/**
* Performs arbitrary actions after the window has been created (possibly
* after being restored), but has not yet been opened.
* <p>
* This method is called after the window has been created from scratch,
* or when it has been restored from a previously-saved window. In the latter case,
* this method is called after <code>postWindowRestore</code>.
* Clients must not call this method directly (although super calls are okay).
* The default implementation does nothing. Subclasses may override.
* </p>
*/
void postWindowCreate();
/**
* Performs arbitrary actions after the window has been opened (possibly
* after being restored).
* <p>
* This method is called after the window has been opened. This method is
* called after the window has been created from scratch, or when
* it has been restored from a previously-saved window.
* Clients must not call this method directly (although super calls are okay).
* The default implementation does nothing. Subclasses may override.
* </p>
*/
void postWindowOpen();
/**
* Performs arbitrary actions after the window is closed.
* <p>
* This method is called after the window's controls have been disposed.
* Clients must not call this method directly (although super calls are
* okay). The default implementation does nothing. Subclasses may override.
* </p>
*/
void postWindowClose();
}
次に、拡張ポイントスキーマ(すべての「YOUR-xxx」を独自のパッケージ/プラグイン名と名前空間に置き換えます):
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="***YOUR-NAMESPACE***" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="***YOUR-PLUGIN***" id="workbenchWindowHook" name="***YOUR-PACKAGE***.workbenchWindowHook"/>
</appInfo>
<documentation>
An extension to actively hook into the WorkbenchWindowAdvisor's pre/post methods from other plug-ins.
This is primarily intended for plug-ins that are optional or restricted to some specific products.
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="class" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="class">
<annotation>
<documentation>
The hook class implementing IWorkbenchWindowAdvisorHook.
</documentation>
</annotation>
<complexType>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
The hook class implementing IWorkbenchWindowAdvisorHook.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":***YOUR-PACKAGE***.IWorkbenchWindowAdvisorHook"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
</documentation>
</annotation>
</schema>
次に、MyWindowAdvisorで、拡張機能への参照を保持する必要があります
// the reference list
private List<IWorkbenchWindowAdvisorHook> hooks = new ArrayList<IWorkbenchWindowAdvisorHook>();
拡張機能をロード/初期化する
//code for initializing the extensions, must be called in the constructor
private void initExtensions()
{
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
IWorkbenchWindowAdvisorHook.ID);
for(IConfigurationElement element : config)
{
try
{
final Object o = element.createExecutableExtension("name"); //$NON-NLS-1$
if(o instanceof IWorkbenchWindowAdvisorHook)
{
hooks.add((IWorkbenchWindowAdvisorHook)o);
}
}
catch(CoreException e)
{
e.printStackTrace();
}
}
}
そして、各「イベント」関数で、拡張機能のメソッドを呼び出します。
// example method preWindowOpen()
public void preWindowOpen()
{
for(IWorkbenchWindowAdvisorHook hook : hooks)
{
try
{
hook.preWindowOpen();
}
catch(Throwable t)
{
CorePlugin.logDefaultError(t);
}
}
}
最後のステップは、これらのワークベンチウィンドウイベントをリッスンする必要がある各プラグインに拡張機能とクラスを提供することです。