1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.model;
|
12
|
|
13
|
import java.lang.reflect.InvocationTargetException;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.commands.ExecutionException;
|
17
|
import org.eclipse.core.commands.operations.IOperationHistory;
|
18
|
import org.eclipse.core.runtime.IAdaptable;
|
19
|
import org.eclipse.core.runtime.ILog;
|
20
|
import org.eclipse.core.runtime.IProgressMonitor;
|
21
|
import org.eclipse.core.runtime.IStatus;
|
22
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
23
|
import org.eclipse.core.runtime.OperationCanceledException;
|
24
|
import org.eclipse.core.runtime.Status;
|
25
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
26
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
27
|
import org.eclipse.jface.action.IStatusLineManager;
|
28
|
import org.eclipse.jface.dialogs.MessageDialog;
|
29
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
30
|
import org.eclipse.jface.resource.ColorRegistry;
|
31
|
import org.eclipse.jface.resource.FontRegistry;
|
32
|
import org.eclipse.jface.window.ApplicationWindow;
|
33
|
import org.eclipse.swt.graphics.Color;
|
34
|
import org.eclipse.swt.graphics.Font;
|
35
|
import org.eclipse.swt.widgets.Shell;
|
36
|
import org.eclipse.ui.IEditorPart;
|
37
|
import org.eclipse.ui.IViewPart;
|
38
|
import org.eclipse.ui.IViewReference;
|
39
|
import org.eclipse.ui.IWorkbench;
|
40
|
import org.eclipse.ui.IWorkbenchPage;
|
41
|
import org.eclipse.ui.IWorkbenchPart;
|
42
|
import org.eclipse.ui.PartInitException;
|
43
|
import org.eclipse.ui.PlatformUI;
|
44
|
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
|
45
|
import org.eclipse.ui.part.EditorPart;
|
46
|
import org.eclipse.ui.progress.IProgressService;
|
47
|
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
|
48
|
import org.eclipse.ui.themes.ITheme;
|
49
|
import org.eclipse.ui.themes.IThemeManager;
|
50
|
|
51
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
52
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
53
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
54
|
import eu.etaxonomy.taxeditor.store.singlesource.widget.DisplayProxy;
|
55
|
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
|
56
|
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
|
57
|
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
|
58
|
|
59
|
/**
|
60
|
* <p>
|
61
|
* Abstract AbstractUtility class.
|
62
|
* </p>
|
63
|
*
|
64
|
* @author n.hoffmann
|
65
|
* @created 11.05.2009
|
66
|
* @version 1.0
|
67
|
*/
|
68
|
public abstract class AbstractUtility {
|
69
|
|
70
|
/** Constant <code>statusLineManager</code> */
|
71
|
protected static IStatusLineManager statusLineManager;
|
72
|
|
73
|
/**
|
74
|
* <p>
|
75
|
* closeAll
|
76
|
* </p>
|
77
|
*
|
78
|
* @return a boolean.
|
79
|
*/
|
80
|
public static boolean closeAll() {
|
81
|
return getActivePage().closeAllEditors(true);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Close the given editor.
|
86
|
*
|
87
|
* @param editor
|
88
|
* The <tt>MultipageTaxonEditor</tt> to close.
|
89
|
* @return <tt>true</tt> on success
|
90
|
*/
|
91
|
public static boolean close(EditorPart editor) {
|
92
|
return getActivePage().closeEditor(editor, true);
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* <p>
|
97
|
* getShell
|
98
|
* </p>
|
99
|
*
|
100
|
* @return a {@link org.eclipse.swt.widgets.Shell} object.
|
101
|
*/
|
102
|
public static Shell getShell() {
|
103
|
|
104
|
return TaxeditorStorePlugin.getDefault().getWorkbench()
|
105
|
.getActiveWorkbenchWindow().getShell();
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* <p>
|
110
|
* getActivePage
|
111
|
* </p>
|
112
|
*
|
113
|
* @return a {@link org.eclipse.ui.IWorkbenchPage} object.
|
114
|
*/
|
115
|
public static IWorkbenchPage getActivePage() {
|
116
|
|
117
|
return TaxeditorStorePlugin.getDefault().getWorkbench()
|
118
|
.getActiveWorkbenchWindow().getActivePage();
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* <p>
|
123
|
* getActivePart
|
124
|
* </p>
|
125
|
*
|
126
|
* @return a {@link org.eclipse.ui.IWorkbenchPart} object.
|
127
|
*/
|
128
|
public static IWorkbenchPart getActivePart() {
|
129
|
return getActivePage() != null ? getActivePage().getActivePart() : null;
|
130
|
}
|
131
|
|
132
|
public static IWorkbench getWorkbench() {
|
133
|
return TaxeditorStorePlugin.getDefault().getWorkbench();
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* <p>
|
138
|
* getWorkbenchWindow
|
139
|
* </p>
|
140
|
*
|
141
|
* @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
|
142
|
*/
|
143
|
public static ApplicationWindow getWorkbenchWindow() {
|
144
|
if (getWorkbench().getWorkbenchWindowCount() > 1) {
|
145
|
throw new IllegalStateException("More than one workbench window");
|
146
|
}
|
147
|
return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* <p>
|
152
|
* showView
|
153
|
* </p>
|
154
|
*
|
155
|
* @param id
|
156
|
* a {@link java.lang.String} object.
|
157
|
* @return a {@link org.eclipse.ui.IViewPart} object.
|
158
|
*/
|
159
|
public static IViewPart showView(String id) {
|
160
|
try {
|
161
|
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
162
|
.getActivePage()
|
163
|
.showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
|
164
|
} catch (PartInitException e) {
|
165
|
errorDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
|
166
|
return null;
|
167
|
}
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* <p>
|
172
|
* hideView
|
173
|
* </p>
|
174
|
*
|
175
|
* @param view
|
176
|
* a {@link org.eclipse.ui.IViewPart} object.
|
177
|
*/
|
178
|
public static void hideView(IViewPart view) {
|
179
|
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
180
|
.hideView(view);
|
181
|
}
|
182
|
|
183
|
/**
|
184
|
* <p>
|
185
|
* getView
|
186
|
* </p>
|
187
|
*
|
188
|
* @param id
|
189
|
* a {@link java.lang.String} object.
|
190
|
* @param restore
|
191
|
* a boolean.
|
192
|
* @return a {@link org.eclipse.ui.IViewPart} object.
|
193
|
*/
|
194
|
public static IViewPart getView(String id, boolean restore) {
|
195
|
IViewReference[] references = PlatformUI.getWorkbench()
|
196
|
.getActiveWorkbenchWindow().getActivePage().getViewReferences();
|
197
|
for (IViewReference reference : references) {
|
198
|
if (reference.getId().equals(id)) {
|
199
|
return reference.getView(restore);
|
200
|
}
|
201
|
}
|
202
|
return null;
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* <p>
|
207
|
* getService
|
208
|
* </p>
|
209
|
*
|
210
|
* @param api
|
211
|
* a {@link java.lang.Class} object.
|
212
|
* @return a {@link java.lang.Object} object.
|
213
|
*/
|
214
|
public static Object getService(Class api) {
|
215
|
return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* <p>
|
220
|
* getCurrentTheme
|
221
|
* </p>
|
222
|
*
|
223
|
* @return a {@link org.eclipse.ui.themes.ITheme} object.
|
224
|
*/
|
225
|
public static ITheme getCurrentTheme() {
|
226
|
IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
|
227
|
.getWorkbench().getThemeManager();
|
228
|
return themeManager.getCurrentTheme();
|
229
|
}
|
230
|
|
231
|
/**
|
232
|
* Fonts registered to the plugin may be obtained with the Eclipse themeing
|
233
|
* functionality. Thus fonts are chooseable by the user via
|
234
|
* Preferences->General->Appearance->Colors and Fonts
|
235
|
*
|
236
|
* @return the FontRegistry for the current theme
|
237
|
*/
|
238
|
public static FontRegistry getFontRegistry() {
|
239
|
return getCurrentTheme().getFontRegistry();
|
240
|
}
|
241
|
|
242
|
/**
|
243
|
* <p>
|
244
|
* getFont
|
245
|
* </p>
|
246
|
*
|
247
|
* @param symbolicName
|
248
|
* a {@link java.lang.String} object.
|
249
|
* @return a {@link org.eclipse.swt.graphics.Font} object.
|
250
|
*/
|
251
|
public static Font getFont(String symbolicName) {
|
252
|
return getFontRegistry().get(symbolicName);
|
253
|
}
|
254
|
|
255
|
/**
|
256
|
* Color registered to the plugin may be obtained with the Eclipse themeing
|
257
|
* functionality. Thus colors are editable by the user via
|
258
|
* Preferences->General->Appearance->Colors and Fonts
|
259
|
*
|
260
|
* @return the ColorRegistry for the current theme
|
261
|
*/
|
262
|
public static ColorRegistry getColorRegistry() {
|
263
|
return getCurrentTheme().getColorRegistry();
|
264
|
}
|
265
|
|
266
|
/**
|
267
|
* <p>
|
268
|
* getColor
|
269
|
* </p>
|
270
|
*
|
271
|
* @param symbolicName
|
272
|
* a {@link java.lang.String} object.
|
273
|
* @return a {@link org.eclipse.swt.graphics.Color} object.
|
274
|
*/
|
275
|
public static Color getColor(String symbolicName) {
|
276
|
return getColorRegistry().get(symbolicName);
|
277
|
}
|
278
|
|
279
|
/**
|
280
|
* Open a message box that informs the user about unimplemented
|
281
|
* functionality. This method is for developer convenience.
|
282
|
*
|
283
|
* @param source
|
284
|
* a {@link java.lang.Object} object.
|
285
|
*/
|
286
|
public static void notImplementedMessage(Object source) {
|
287
|
warningDialog("Not yet implemented", source,
|
288
|
"This functionality is not yet implemented.");
|
289
|
}
|
290
|
|
291
|
/**
|
292
|
* <p>
|
293
|
* informationDialog
|
294
|
* </p>
|
295
|
*
|
296
|
* @param title
|
297
|
* a {@link java.lang.String} object.
|
298
|
* @param message
|
299
|
* a {@link java.lang.String} object.
|
300
|
*/
|
301
|
public static void informationDialog(final String title,
|
302
|
final String message) {
|
303
|
DisplayProxy.getDefault().asyncExec(new Runnable() {
|
304
|
|
305
|
public void run() {
|
306
|
MessageDialog.openInformation(getShell(), title, message);
|
307
|
}
|
308
|
});
|
309
|
}
|
310
|
|
311
|
/**
|
312
|
* <p>
|
313
|
* warningDialog
|
314
|
* </p>
|
315
|
*
|
316
|
* @param title
|
317
|
* The dialogs title
|
318
|
* @param source
|
319
|
* The object where the warning was generated (used by log4j)
|
320
|
* @param message
|
321
|
* An informative String to be presented to the user
|
322
|
*/
|
323
|
public static void warningDialog(final String title, final Object source,
|
324
|
final String message) {
|
325
|
DisplayProxy.getDefault().asyncExec(new Runnable() {
|
326
|
|
327
|
public void run() {
|
328
|
MessageDialog.openWarning(getShell(), title, message);
|
329
|
Class<? extends Object> clazz = source != null ? source
|
330
|
.getClass() : AbstractUtility.class;
|
331
|
warn(clazz, message);
|
332
|
}
|
333
|
});
|
334
|
}
|
335
|
|
336
|
/**
|
337
|
* <p>
|
338
|
* errorDialog
|
339
|
* </p>
|
340
|
*
|
341
|
* @param title
|
342
|
* The dialogs title
|
343
|
* @param source
|
344
|
* The object where the warning was generated (used by log4j)
|
345
|
* @param message
|
346
|
* An informative String to be presented to the user
|
347
|
* @param title
|
348
|
* The dialogs title
|
349
|
* @param t
|
350
|
* a Throwable if one exists or null
|
351
|
*/
|
352
|
public static void errorDialog(final String title, final Object source,
|
353
|
final String message, final Throwable t) {
|
354
|
DisplayProxy.getDefault().asyncExec(new Runnable() {
|
355
|
|
356
|
public void run() {
|
357
|
MessageDialog.openError(getShell(), title, message + getCauseRecursively(t));
|
358
|
Class<? extends Object> clazz = source != null ? source
|
359
|
.getClass() : this.getClass();
|
360
|
error(clazz, message, t);
|
361
|
}
|
362
|
|
363
|
private String getCauseRecursively(Throwable t) {
|
364
|
if(t == null){
|
365
|
return null;
|
366
|
}
|
367
|
|
368
|
if(t.getCause() != null){
|
369
|
return getCauseRecursively(t.getCause());
|
370
|
}else{
|
371
|
return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
|
372
|
}
|
373
|
|
374
|
}
|
375
|
});
|
376
|
}
|
377
|
|
378
|
/**
|
379
|
* <p>
|
380
|
* errorDialog
|
381
|
* </p>
|
382
|
*
|
383
|
* @param title
|
384
|
* a {@link java.lang.String} object.
|
385
|
* @param source
|
386
|
* a {@link java.lang.Object} object.
|
387
|
* @param status
|
388
|
* a {@link org.eclipse.core.runtime.IStatus} object.
|
389
|
*/
|
390
|
public static void errorDialog(final String title, final Object source,
|
391
|
final IStatus status) {
|
392
|
DisplayProxy.getDefault().asyncExec(new Runnable() {
|
393
|
|
394
|
public void run() {
|
395
|
MessageDialog.openError(getShell(), title, status.getMessage());
|
396
|
Class<? extends Object> clazz = source != null ? source
|
397
|
.getClass() : this.getClass();
|
398
|
error(clazz, status.getMessage(), status.getException());
|
399
|
}
|
400
|
});
|
401
|
}
|
402
|
|
403
|
/**
|
404
|
* <p>
|
405
|
* confirmDialog
|
406
|
* </p>
|
407
|
*
|
408
|
* @param title
|
409
|
* a {@link java.lang.String} object.
|
410
|
* @param message
|
411
|
* a {@link java.lang.String} object.
|
412
|
* @return a boolean.
|
413
|
*/
|
414
|
public static boolean confirmDialog(String title, String message) {
|
415
|
return MessageDialog.openQuestion(getShell(), title, message);
|
416
|
}
|
417
|
|
418
|
/**
|
419
|
* <p>
|
420
|
* executeOperation
|
421
|
* </p>
|
422
|
*
|
423
|
* @param operation
|
424
|
* a
|
425
|
* {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation}
|
426
|
* object.
|
427
|
* @return a {@link org.eclipse.core.runtime.IStatus} object.
|
428
|
*/
|
429
|
public static IStatus executeOperation(final AbstractPostOperation operation) {
|
430
|
if (getOperationHistory() == null) {
|
431
|
throw new IllegalArgumentException(
|
432
|
"There is no operation history for this context");
|
433
|
}
|
434
|
|
435
|
final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
|
436
|
.getUIInfoAdapter(getShell());
|
437
|
|
438
|
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
439
|
|
440
|
public void run(IProgressMonitor monitor)
|
441
|
throws InvocationTargetException, InterruptedException {
|
442
|
monitor.beginTask(operation.getLabel(), 100);
|
443
|
IStatus status = Status.CANCEL_STATUS;
|
444
|
try {
|
445
|
operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
|
446
|
status = getOperationHistory().execute(operation, monitor,
|
447
|
uiInfoAdapter);
|
448
|
} catch (ExecutionException e) {
|
449
|
errorDialog("Error executing operation", getClass(), String.format("An error occured while executing %s.", operation.getLabel()), e);
|
450
|
} finally {
|
451
|
monitor.done();
|
452
|
}
|
453
|
|
454
|
String statusString = status.equals(Status.OK_STATUS) ? "completed"
|
455
|
: "cancelled";
|
456
|
setStatusLine(operation.getLabel() + " " + statusString + ".");
|
457
|
|
458
|
}
|
459
|
};
|
460
|
|
461
|
try {
|
462
|
runInUI(runnable, null);
|
463
|
} catch (Exception e) {
|
464
|
errorDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
|
465
|
}
|
466
|
|
467
|
// // Start the main progress monitor.
|
468
|
// IProgressMonitor newMonitor =
|
469
|
// startMainMonitor(getMonitor(),operation.getLabel(), 100);
|
470
|
//
|
471
|
// // Check whether operation was canceled and do some steps.
|
472
|
// workedChecked(newMonitor, 10);
|
473
|
//
|
474
|
// try {
|
475
|
// IStatus status = getOperationHistory().execute(operation, newMonitor,
|
476
|
// WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
|
477
|
//
|
478
|
// // Check whether operation was canceled and do some steps.
|
479
|
// workedChecked(newMonitor, 30);
|
480
|
//
|
481
|
// String statusString = status.equals(Status.OK_STATUS) ? "completed" :
|
482
|
// "cancelled";
|
483
|
// setStatusLine(operation.getLabel() + " " + statusString + ".");
|
484
|
//
|
485
|
// return status;
|
486
|
// } catch (ExecutionException e) {
|
487
|
// logger.error("Error executing operation: " + operation.getLabel(),
|
488
|
// e);
|
489
|
// errorDialog("Error executing operation: " + operation.getLabel(),
|
490
|
// "Please refer to the error log.");
|
491
|
// }
|
492
|
// finally {
|
493
|
//
|
494
|
// // Stop the progress monitor.
|
495
|
// newMonitor.done();
|
496
|
// }
|
497
|
|
498
|
IPostOperationEnabled postOperationEnabled = operation
|
499
|
.getPostOperationEnabled();
|
500
|
if (postOperationEnabled != null) {
|
501
|
postOperationEnabled.onComplete();
|
502
|
}
|
503
|
return Status.OK_STATUS;
|
504
|
}
|
505
|
|
506
|
/**
|
507
|
* <p>
|
508
|
* getOperationHistory
|
509
|
* </p>
|
510
|
*
|
511
|
* @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
|
512
|
* object.
|
513
|
*/
|
514
|
public static IOperationHistory getOperationHistory() {
|
515
|
return getWorkbench().getOperationSupport().getOperationHistory();
|
516
|
}
|
517
|
|
518
|
/**
|
519
|
* <p>
|
520
|
* setStatusLine
|
521
|
* </p>
|
522
|
*
|
523
|
* @param message
|
524
|
* a {@link java.lang.String} object.
|
525
|
*/
|
526
|
public static void setStatusLine(final String message) {
|
527
|
DisplayProxy.getDefault().asyncExec(new Runnable() {
|
528
|
|
529
|
public void run() {
|
530
|
statusLineManager.setMessage(message);
|
531
|
}
|
532
|
|
533
|
});
|
534
|
|
535
|
}
|
536
|
|
537
|
/**
|
538
|
* <p>
|
539
|
* getMonitor
|
540
|
* </p>
|
541
|
*
|
542
|
* @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
|
543
|
*/
|
544
|
public static IProgressMonitor getMonitor() {
|
545
|
statusLineManager.setCancelEnabled(false);
|
546
|
return statusLineManager.getProgressMonitor();
|
547
|
}
|
548
|
|
549
|
/**
|
550
|
* Starts either the given {@link IProgressMonitor} if it's not
|
551
|
* <code>null</code> or a new {@link NullProgressMonitor}.
|
552
|
*
|
553
|
* @param progressMonitor
|
554
|
* The {@link IProgressMonitor} or <code>null</code> if no
|
555
|
* progress should be reported.
|
556
|
* @param taskName
|
557
|
* The name of the main task.
|
558
|
* @param steps
|
559
|
* The number of steps this task is subdivided into.
|
560
|
* @return The {@link IProgressMonitor}.
|
561
|
*/
|
562
|
public static IProgressMonitor startMainMonitor(
|
563
|
IProgressMonitor progressMonitor, String taskName, int steps) {
|
564
|
IProgressMonitor newMonitor = progressMonitor;
|
565
|
if (newMonitor == null) {
|
566
|
newMonitor = new NullProgressMonitor();
|
567
|
}
|
568
|
newMonitor.beginTask(taskName == null ? "" : taskName, steps);
|
569
|
newMonitor.subTask(" ");
|
570
|
return newMonitor;
|
571
|
}
|
572
|
|
573
|
/**
|
574
|
* Creates a {@link SubProgressMonitor} if the given
|
575
|
* {@link IProgressMonitor} is not <code>null</code> and not a
|
576
|
* {@link NullProgressMonitor}.
|
577
|
*
|
578
|
* @param progressMonitor
|
579
|
* The parent {@link IProgressMonitor} of the
|
580
|
* {@link SubProgressMonitor} to be created.
|
581
|
* @param ticks
|
582
|
* The number of steps this subtask is subdivided into. Must be a
|
583
|
* positive number and must not be
|
584
|
* {@link IProgressMonitor#UNKNOWN}.
|
585
|
* @return The {@link IProgressMonitor}.
|
586
|
*/
|
587
|
public static IProgressMonitor getSubProgressMonitor(
|
588
|
IProgressMonitor progressMonitor, int ticks) {
|
589
|
if (progressMonitor == null) {
|
590
|
return new NullProgressMonitor();
|
591
|
}
|
592
|
if (progressMonitor instanceof NullProgressMonitor) {
|
593
|
return progressMonitor;
|
594
|
}
|
595
|
|
596
|
return new SubProgressMonitor(progressMonitor, ticks);
|
597
|
}
|
598
|
|
599
|
/**
|
600
|
* Checks whether the user canceled this operation. If not canceled, the
|
601
|
* given number of steps are declared as done.
|
602
|
*
|
603
|
* @param newMonitor
|
604
|
* a {@link org.eclipse.core.runtime.IProgressMonitor} object.
|
605
|
* @param steps
|
606
|
* a int.
|
607
|
*/
|
608
|
public static void workedChecked(IProgressMonitor newMonitor, int steps) {
|
609
|
// In case the progress monitor was canceled throw an exception.
|
610
|
if (newMonitor.isCanceled()) {
|
611
|
throw new OperationCanceledException();
|
612
|
}
|
613
|
// Otherwise declare this step as done.
|
614
|
newMonitor.worked(steps);
|
615
|
}
|
616
|
|
617
|
/**
|
618
|
* Present a progress dialog to the user. This dialog will block the UI
|
619
|
*
|
620
|
* @param runnable
|
621
|
* an implementation of {@link IRunnableWithProgress}
|
622
|
* @throws java.lang.InterruptedException
|
623
|
* if any.
|
624
|
* @throws java.lang.reflect.InvocationTargetException
|
625
|
* if any.
|
626
|
*/
|
627
|
public static void busyCursorWhile(IRunnableWithProgress runnable)
|
628
|
throws InvocationTargetException, InterruptedException {
|
629
|
getProgressService().busyCursorWhile(runnable);
|
630
|
}
|
631
|
|
632
|
/**
|
633
|
* <p>
|
634
|
* runInUI
|
635
|
* </p>
|
636
|
*
|
637
|
* @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
|
638
|
* @param runnable
|
639
|
* a {@link org.eclipse.jface.operation.IRunnableWithProgress}
|
640
|
* object.
|
641
|
* @param rule
|
642
|
* a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
|
643
|
* object.
|
644
|
* @throws java.lang.reflect.InvocationTargetException
|
645
|
* if any.
|
646
|
* @throws java.lang.InterruptedException
|
647
|
* if any.
|
648
|
*/
|
649
|
public static void runInUI(IRunnableWithProgress runnable,
|
650
|
ISchedulingRule rule) throws InvocationTargetException,
|
651
|
InterruptedException {
|
652
|
getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
|
653
|
}
|
654
|
|
655
|
/**
|
656
|
* <p>
|
657
|
* run
|
658
|
* </p>
|
659
|
*
|
660
|
* @param fork
|
661
|
* a boolean.
|
662
|
* @param cancelable
|
663
|
* a boolean.
|
664
|
* @param runnable
|
665
|
* a {@link org.eclipse.jface.operation.IRunnableWithProgress}
|
666
|
* object.
|
667
|
* @throws java.lang.reflect.InvocationTargetException
|
668
|
* if any.
|
669
|
* @throws java.lang.InterruptedException
|
670
|
* if any.
|
671
|
*/
|
672
|
public static void run(boolean fork, boolean cancelable,
|
673
|
IRunnableWithProgress runnable) throws InvocationTargetException,
|
674
|
InterruptedException {
|
675
|
getProgressService().run(fork, cancelable, runnable);
|
676
|
}
|
677
|
|
678
|
/**
|
679
|
* <p>
|
680
|
* getProgressService
|
681
|
* </p>
|
682
|
*
|
683
|
* @return a {@link org.eclipse.ui.progress.IProgressService} object.
|
684
|
*/
|
685
|
public static IProgressService getProgressService() {
|
686
|
IWorkbench workbench = PlatformUI.getWorkbench();
|
687
|
return workbench.getProgressService();
|
688
|
}
|
689
|
|
690
|
/**
|
691
|
* <p>
|
692
|
* getProgressService2
|
693
|
* </p>
|
694
|
*
|
695
|
* @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
|
696
|
* object.
|
697
|
*/
|
698
|
public static IWorkbenchSiteProgressService getProgressService2() {
|
699
|
return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
|
700
|
}
|
701
|
|
702
|
/**
|
703
|
* <p>
|
704
|
* info
|
705
|
* </p>
|
706
|
*
|
707
|
* @param message
|
708
|
* a {@link java.lang.String} object.
|
709
|
*/
|
710
|
public static void info(String message) {
|
711
|
IStatus status = new Status(IStatus.INFO, getPluginId(), message);
|
712
|
info(status);
|
713
|
}
|
714
|
|
715
|
/**
|
716
|
* <p>
|
717
|
* info
|
718
|
* </p>
|
719
|
*
|
720
|
* @param status
|
721
|
* a {@link org.eclipse.core.runtime.IStatus} object.
|
722
|
*/
|
723
|
public static void info(IStatus status) {
|
724
|
log(status);
|
725
|
}
|
726
|
|
727
|
/**
|
728
|
* <p>
|
729
|
* warn
|
730
|
* </p>
|
731
|
*
|
732
|
* @param source
|
733
|
* a {@link java.lang.Class} object.
|
734
|
* @param message
|
735
|
* a {@link java.lang.String} object.
|
736
|
*/
|
737
|
public static void warn(Class source, String message) {
|
738
|
IStatus status = new Status(IStatus.WARNING, getPluginId(), message);
|
739
|
getLog4JLogger(source).warn(message);
|
740
|
log(status);
|
741
|
}
|
742
|
|
743
|
public static void warn(Class source, Throwable t) {
|
744
|
IStatus status = new Status(IStatus.WARNING, getPluginId(), t.getMessage(), t);
|
745
|
getLog4JLogger(source).warn(t);
|
746
|
log(status);
|
747
|
}
|
748
|
|
749
|
/**
|
750
|
* <p>
|
751
|
* error
|
752
|
* </p>
|
753
|
*
|
754
|
* @param source
|
755
|
* a {@link java.lang.Class} object.
|
756
|
* @param t
|
757
|
* a {@link java.lang.Throwable} object.
|
758
|
*/
|
759
|
public static void error(Class source, Throwable t) {
|
760
|
error(source.getClass(), t.getMessage(), t);
|
761
|
}
|
762
|
|
763
|
/**
|
764
|
* <p>
|
765
|
* error
|
766
|
* </p>
|
767
|
*
|
768
|
* @param source
|
769
|
* a {@link java.lang.Class} object.
|
770
|
* @param message
|
771
|
* a {@link java.lang.String} object.
|
772
|
* @param t
|
773
|
* a {@link java.lang.Throwable} object.
|
774
|
*/
|
775
|
public static void error(Class source, String message, Throwable t) {
|
776
|
IStatus status = new Status(IStatus.ERROR, getPluginId(), message, t);
|
777
|
error(source, status);
|
778
|
}
|
779
|
|
780
|
/**
|
781
|
* <p>
|
782
|
* error
|
783
|
* </p>
|
784
|
*
|
785
|
* @param source
|
786
|
* a {@link java.lang.Class} object.
|
787
|
* @param status
|
788
|
* a {@link org.eclipse.core.runtime.IStatus} object.
|
789
|
*/
|
790
|
public static void error(Class source, IStatus status) {
|
791
|
getLog4JLogger(source)
|
792
|
.error(status.getMessage(), status.getException());
|
793
|
log(status);
|
794
|
}
|
795
|
|
796
|
/**
|
797
|
* <p>
|
798
|
* getLog4JLogger
|
799
|
* </p>
|
800
|
*
|
801
|
* @param clazz
|
802
|
* a {@link java.lang.Class} object.
|
803
|
* @return a {@link org.apache.log4j.Logger} object.
|
804
|
*/
|
805
|
public static Logger getLog4JLogger(Class clazz) {
|
806
|
return Logger.getLogger(clazz);
|
807
|
}
|
808
|
|
809
|
/**
|
810
|
* @see {@link ILog#log(IStatus)}
|
811
|
*
|
812
|
* @param status
|
813
|
*/
|
814
|
private static void log(IStatus status) {
|
815
|
TaxeditorStorePlugin.getDefault().getLog().log(status);
|
816
|
}
|
817
|
|
818
|
/**
|
819
|
* <p>
|
820
|
* getPluginId
|
821
|
* </p>
|
822
|
*
|
823
|
* @return a {@link java.lang.String} object.
|
824
|
*/
|
825
|
protected static String getPluginId() {
|
826
|
return "eu.taxeditor";
|
827
|
}
|
828
|
|
829
|
/**
|
830
|
* <p>
|
831
|
* getActiveEditor
|
832
|
* </p>
|
833
|
*
|
834
|
* @return a {@link org.eclipse.ui.IEditorPart} object.
|
835
|
*/
|
836
|
public static IEditorPart getActiveEditor() {
|
837
|
return getActivePage() != null ? getActivePage().getActiveEditor()
|
838
|
: null;
|
839
|
}
|
840
|
|
841
|
/**
|
842
|
* <p>
|
843
|
* getDetailsView
|
844
|
* </p>
|
845
|
*
|
846
|
* @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
|
847
|
* object.
|
848
|
*/
|
849
|
public static DetailsViewPart getDetailsView() {
|
850
|
return (DetailsViewPart) getView(DetailsViewPart.ID, false);
|
851
|
}
|
852
|
|
853
|
/**
|
854
|
* <p>
|
855
|
* refreshDetailsViewer
|
856
|
* </p>
|
857
|
*/
|
858
|
public static void refreshDetailsViewer() {
|
859
|
if (getDetailsView() != null) {
|
860
|
((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
|
861
|
}
|
862
|
}
|
863
|
|
864
|
/**
|
865
|
* <p>
|
866
|
* reflowDetailsViewer
|
867
|
* </p>
|
868
|
*/
|
869
|
public static void reflowDetailsViewer() {
|
870
|
if (getDetailsView() != null) {
|
871
|
((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
|
872
|
}
|
873
|
}
|
874
|
|
875
|
public static SupplementalDataViewPart getSupplementalDataView() {
|
876
|
return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
|
877
|
false);
|
878
|
}
|
879
|
|
880
|
public static void reflowSupplementalViewer() {
|
881
|
if (getSupplementalDataView() != null) {
|
882
|
((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
|
883
|
.reflow();
|
884
|
}
|
885
|
}
|
886
|
}
|