Eclipse/プラグイン開発のTIPS集/プラグインクラスに定義しておきたいメソッド
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
**プラグインクラスに定義しておきたいメソッド [#wffd52d9]
○○Pluginなど、プラグインクラスにはそのプラグインでやりた...
***UI依存しないCoreなプラグインの場合 [#a496e8f5]
org.eclipse.core.runtime.Pluginを継承する、UI依存しないプ...
public static void log(String message, Exception e) {
IStatus status = new Status(IStatus.ERROR, getPlugin...
IStatus.OK, message, e);
getDefault().getLog().log(status);
}
public static void log(String message) {
log(message, null);
}
public static void log(Exception e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
String message = stringWriter.getBuffer().toString();
log(message, e);
}
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
***UI依存するプラグインの場合 [#f86377bb]
org.eclipse.ui.plugin.AbstractUIPluginを継承するUI依存す...
以下のコードは、org.eclipse.update.internal.ui.UpdateUI ...
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
public static void logException(Throwable e) {
logException(e, true);
}
public static void logException(Throwable e, boolean sho...
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetExcepti...
}
IStatus status = null;
if (e instanceof CoreException) {
status = ((CoreException) e).getStatus();
} else {
String message = e.getMessage();
if (message == null)
message = e.toString();
status = new Status(IStatus.ERROR, getPluginId(), IS...
message, e);
}
log(status, showErrorDialog);
}
public static void log(IStatus status, boolean showError...
Bundle bundle = Platform.getBundle("org.eclipse.update...
Platform.getLog(bundle).log(status);
if (Display.getCurrent() == null || !showErrorDialog)
return;
if (status.getSeverity() != IStatus.INFO) {
ErrorDialog.openError(getActiveWorkbenchShell(), nul...
} else {
MessageDialog.openInformation(getActiveWorkbenchShel...
}
}
/**
* Returns the standard display to be used. The method f...
* thread calling this method has an associated disaply....
* is returned. Otherwise the method returns the default...
*/
public static Display getStandardDisplay() {
Display display;
display = Display.getCurrent();
if (display == null)
display = Display.getDefault();
return display;
}
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
return window != null ? window.getShell() : getStandar...
.getActiveShell();
}
public static IWorkbenchWindow getActiveWorkbenchWindow(...
return getDefault().getWorkbench().getActiveWorkbenchW...
}
----
この記事は
#vote(おもしろかった[5],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
**プラグインクラスに定義しておきたいメソッド [#wffd52d9]
○○Pluginなど、プラグインクラスにはそのプラグインでやりた...
***UI依存しないCoreなプラグインの場合 [#a496e8f5]
org.eclipse.core.runtime.Pluginを継承する、UI依存しないプ...
public static void log(String message, Exception e) {
IStatus status = new Status(IStatus.ERROR, getPlugin...
IStatus.OK, message, e);
getDefault().getLog().log(status);
}
public static void log(String message) {
log(message, null);
}
public static void log(Exception e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
String message = stringWriter.getBuffer().toString();
log(message, e);
}
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
***UI依存するプラグインの場合 [#f86377bb]
org.eclipse.ui.plugin.AbstractUIPluginを継承するUI依存す...
以下のコードは、org.eclipse.update.internal.ui.UpdateUI ...
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
public static void logException(Throwable e) {
logException(e, true);
}
public static void logException(Throwable e, boolean sho...
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetExcepti...
}
IStatus status = null;
if (e instanceof CoreException) {
status = ((CoreException) e).getStatus();
} else {
String message = e.getMessage();
if (message == null)
message = e.toString();
status = new Status(IStatus.ERROR, getPluginId(), IS...
message, e);
}
log(status, showErrorDialog);
}
public static void log(IStatus status, boolean showError...
Bundle bundle = Platform.getBundle("org.eclipse.update...
Platform.getLog(bundle).log(status);
if (Display.getCurrent() == null || !showErrorDialog)
return;
if (status.getSeverity() != IStatus.INFO) {
ErrorDialog.openError(getActiveWorkbenchShell(), nul...
} else {
MessageDialog.openInformation(getActiveWorkbenchShel...
}
}
/**
* Returns the standard display to be used. The method f...
* thread calling this method has an associated disaply....
* is returned. Otherwise the method returns the default...
*/
public static Display getStandardDisplay() {
Display display;
display = Display.getCurrent();
if (display == null)
display = Display.getDefault();
return display;
}
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
return window != null ? window.getShell() : getStandar...
.getActiveShell();
}
public static IWorkbenchWindow getActiveWorkbenchWindow(...
return getDefault().getWorkbench().getActiveWorkbenchW...
}
----
この記事は
#vote(おもしろかった[5],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: