Eclipse/プラグイン開発のTIPS集/プログレスモニタを使う
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
#topicpath
----
**概要 [#x1642ddb]
たとえば検索など、時間のかかる処理をするときはダイアログ...
-org.eclipse.jface.operation.IRunnableWithProgressの実装...
-org.eclipse.jface.dialogs.ProgressMonitorDialogをインス...
-ProgressMonitorDialog#run(true,true,IRunnableWithProgres...
とすればダイアログ上で、時間のかかる処理が実行されます。
***やってみる [#kae5c2f2]
具体的に見ると、以下のような感じです。
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWi...
Shell shell = window.getShell();
// プログレスバーを使う
ProgressMonitorDialog dialog = new ProgressMonitorDialog...
SearchWithProgress searchThread = new SearchWithProgress...
try {
dialog.run(true, true, searchThread);
} catch (InvocationTargetException e) {
logger.error(e);
// 処理中に何らかの例外が発生したときの処理
} catch (InterruptedException e) {
// キャンセルされたときの処理
logger.info("キャンセルされました");
logger.info(e);
}
ダイアログを作って、ビジネスロジックを作って、ダイアログ...
:InterruptedException| ユーザがダイアログ上のキャンセルボ...
:InvocationTargetException| それ以外の例外が発行されたと...
となっています。
では実際にIRunnableWithProgress を見てみると、
private class SearchWithProgress
implements IRunnableWithProgress {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedExc...
monitor.beginTask("「" + text + "」でGoogleを検索中....
try {
monitor.subTask("スペルチェック");
monitor.worked(1);
なんか処理
monitor.worked(3);
if (monitor.isCanceled()) {
throw new InterruptedException("Cancel has been ...
}
monitor.subTask("検索中");
なんか処理
monitor.worked(3);
//検索終了
if (monitor.isCanceled()) {
throw new InterruptedException("Cancel has been ...
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.worked(10);
処理終わり
monitor.done();
}
}
てな感じになっています。
:monitor.beginTask("「" + text + "」でGoogleを検索中...",...
:monitor.subTask("スペルチェック");|サブタスク名を記述し...
:monitor.worked(1);|進捗率を記述します。
:monitor.done();|処理が全て完了したときに記述します。
:if (monitor.isCanceled())|ユーザがキャンセルをクリックし...
#ref(dialog.png)
なんか、アプリぽっくなってきました。
次はあこがれの(?)「[[バックグラウンドで実行>Eclipse/プラ...
----
この記事は
#vote(おもしろかった[12],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
#topicpath
----
**概要 [#x1642ddb]
たとえば検索など、時間のかかる処理をするときはダイアログ...
-org.eclipse.jface.operation.IRunnableWithProgressの実装...
-org.eclipse.jface.dialogs.ProgressMonitorDialogをインス...
-ProgressMonitorDialog#run(true,true,IRunnableWithProgres...
とすればダイアログ上で、時間のかかる処理が実行されます。
***やってみる [#kae5c2f2]
具体的に見ると、以下のような感じです。
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWi...
Shell shell = window.getShell();
// プログレスバーを使う
ProgressMonitorDialog dialog = new ProgressMonitorDialog...
SearchWithProgress searchThread = new SearchWithProgress...
try {
dialog.run(true, true, searchThread);
} catch (InvocationTargetException e) {
logger.error(e);
// 処理中に何らかの例外が発生したときの処理
} catch (InterruptedException e) {
// キャンセルされたときの処理
logger.info("キャンセルされました");
logger.info(e);
}
ダイアログを作って、ビジネスロジックを作って、ダイアログ...
:InterruptedException| ユーザがダイアログ上のキャンセルボ...
:InvocationTargetException| それ以外の例外が発行されたと...
となっています。
では実際にIRunnableWithProgress を見てみると、
private class SearchWithProgress
implements IRunnableWithProgress {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedExc...
monitor.beginTask("「" + text + "」でGoogleを検索中....
try {
monitor.subTask("スペルチェック");
monitor.worked(1);
なんか処理
monitor.worked(3);
if (monitor.isCanceled()) {
throw new InterruptedException("Cancel has been ...
}
monitor.subTask("検索中");
なんか処理
monitor.worked(3);
//検索終了
if (monitor.isCanceled()) {
throw new InterruptedException("Cancel has been ...
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.worked(10);
処理終わり
monitor.done();
}
}
てな感じになっています。
:monitor.beginTask("「" + text + "」でGoogleを検索中...",...
:monitor.subTask("スペルチェック");|サブタスク名を記述し...
:monitor.worked(1);|進捗率を記述します。
:monitor.done();|処理が全て完了したときに記述します。
:if (monitor.isCanceled())|ユーザがキャンセルをクリックし...
#ref(dialog.png)
なんか、アプリぽっくなってきました。
次はあこがれの(?)「[[バックグラウンドで実行>Eclipse/プラ...
----
この記事は
#vote(おもしろかった[12],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: