Project

General

Profile

Download (22.1 KB) Statistics
| Branch: | Tag: | Revision:
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.Display;
36
import org.eclipse.swt.widgets.Shell;
37
import org.eclipse.ui.IEditorPart;
38
import org.eclipse.ui.IViewPart;
39
import org.eclipse.ui.IViewReference;
40
import org.eclipse.ui.IWorkbench;
41
import org.eclipse.ui.IWorkbenchPage;
42
import org.eclipse.ui.IWorkbenchPart;
43
import org.eclipse.ui.PartInitException;
44
import org.eclipse.ui.PlatformUI;
45
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
46
import org.eclipse.ui.part.EditorPart;
47
import org.eclipse.ui.progress.IProgressService;
48
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
49
import org.eclipse.ui.themes.ITheme;
50
import org.eclipse.ui.themes.IThemeManager;
51

    
52
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
53
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
54
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
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
			error(AbstractUtility.class, "Could not open view: " + id, e);
166
			throw new RuntimeException(e);
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
		Display.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
		Display.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
		Display.getDefault().asyncExec(new Runnable() {
355

    
356
			public void run() {
357
				MessageDialog.openError(getShell(), title, message);
358
				Class<? extends Object> clazz = source != null ? source
359
						.getClass() : this.getClass();
360
				error(clazz, message, t);
361
			}
362
		});
363
	}
364

    
365
	/**
366
	 * <p>
367
	 * errorDialog
368
	 * </p>
369
	 * 
370
	 * @param title
371
	 *            a {@link java.lang.String} object.
372
	 * @param source
373
	 *            a {@link java.lang.Object} object.
374
	 * @param status
375
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
376
	 */
377
	public static void errorDialog(final String title, final Object source,
378
			final IStatus status) {
379
		Display.getDefault().asyncExec(new Runnable() {
380

    
381
			public void run() {
382
				MessageDialog.openError(getShell(), title, status.getMessage());
383
				Class<? extends Object> clazz = source != null ? source
384
						.getClass() : this.getClass();
385
				error(clazz, status.getMessage(), status.getException());
386
			}
387
		});
388
	}
389

    
390
	/**
391
	 * <p>
392
	 * confirmDialog
393
	 * </p>
394
	 * 
395
	 * @param title
396
	 *            a {@link java.lang.String} object.
397
	 * @param message
398
	 *            a {@link java.lang.String} object.
399
	 * @return a boolean.
400
	 */
401
	public static boolean confirmDialog(String title, String message) {
402
		return MessageDialog.openQuestion(getShell(), title, message);
403
	}
404

    
405
	/**
406
	 * <p>
407
	 * executeOperation
408
	 * </p>
409
	 * 
410
	 * @param operation
411
	 *            a
412
	 *            {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation}
413
	 *            object.
414
	 * @return a {@link org.eclipse.core.runtime.IStatus} object.
415
	 */
416
	public static IStatus executeOperation(final AbstractPostOperation operation) {
417
		if (getOperationHistory() == null) {
418
			throw new IllegalArgumentException(
419
					"There is no operation history for this context");
420
		}
421

    
422
		final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
423
				.getUIInfoAdapter(getShell());
424

    
425
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
426

    
427
			public void run(IProgressMonitor monitor)
428
					throws InvocationTargetException, InterruptedException {
429
				monitor.beginTask(operation.getLabel(), 100);
430
				IStatus status;
431
				try {
432
					operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
433
					status = getOperationHistory().execute(operation, monitor,
434
							uiInfoAdapter);
435
				} catch (ExecutionException e) {
436
					throw new RuntimeException(e);
437
				}
438
				monitor.done();
439
				String statusString = status.equals(Status.OK_STATUS) ? "completed"
440
						: "cancelled";
441
				setStatusLine(operation.getLabel() + " " + statusString + ".");
442

    
443
			}
444
		};
445

    
446
		try {
447
			runInUI(runnable, null);
448
		} catch (InvocationTargetException e) {
449
			throw new RuntimeException(e);
450
		} catch (InterruptedException e) {
451
			throw new RuntimeException(e);
452
		}
453

    
454
		// // Start the main progress monitor.
455
		// IProgressMonitor newMonitor =
456
		// startMainMonitor(getMonitor(),operation.getLabel(), 100);
457
		//
458
		// // Check whether operation was canceled and do some steps.
459
		// workedChecked(newMonitor, 10);
460
		//
461
		// try {
462
		// IStatus status = getOperationHistory().execute(operation, newMonitor,
463
		// WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
464
		//
465
		// // Check whether operation was canceled and do some steps.
466
		// workedChecked(newMonitor, 30);
467
		//
468
		// String statusString = status.equals(Status.OK_STATUS) ? "completed" :
469
		// "cancelled";
470
		// setStatusLine(operation.getLabel() + " " + statusString + ".");
471
		//
472
		// return status;
473
		// } catch (ExecutionException e) {
474
		// logger.error("Error executing operation: " + operation.getLabel(),
475
		// e);
476
		// errorDialog("Error executing operation: " + operation.getLabel(),
477
		// "Please refer to the error log.");
478
		// }
479
		// finally {
480
		//
481
		// // Stop the progress monitor.
482
		// newMonitor.done();
483
		// }
484

    
485
		IPostOperationEnabled postOperationEnabled = operation
486
				.getPostOperationEnabled();
487
		if (postOperationEnabled != null) {
488
			postOperationEnabled.onComplete();
489
		}
490
		return Status.OK_STATUS;
491
	}
492

    
493
	/**
494
	 * <p>
495
	 * getOperationHistory
496
	 * </p>
497
	 * 
498
	 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
499
	 *         object.
500
	 */
501
	public static IOperationHistory getOperationHistory() {
502
		return getWorkbench().getOperationSupport().getOperationHistory();
503
	}
504

    
505
	/**
506
	 * <p>
507
	 * setStatusLine
508
	 * </p>
509
	 * 
510
	 * @param message
511
	 *            a {@link java.lang.String} object.
512
	 */
513
	public static void setStatusLine(final String message) {
514
		Display.getDefault().asyncExec(new Runnable() {
515

    
516
			public void run() {
517
				statusLineManager.setMessage(message);
518
			}
519

    
520
		});
521

    
522
	}
523

    
524
	/**
525
	 * <p>
526
	 * getMonitor
527
	 * </p>
528
	 * 
529
	 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
530
	 */
531
	public static IProgressMonitor getMonitor() {
532
		statusLineManager.setCancelEnabled(false);
533
		return statusLineManager.getProgressMonitor();
534
	}
535

    
536
	/**
537
	 * Starts either the given {@link IProgressMonitor} if it's not
538
	 * <code>null</code> or a new {@link NullProgressMonitor}.
539
	 * 
540
	 * @param progressMonitor
541
	 *            The {@link IProgressMonitor} or <code>null</code> if no
542
	 *            progress should be reported.
543
	 * @param taskName
544
	 *            The name of the main task.
545
	 * @param steps
546
	 *            The number of steps this task is subdivided into.
547
	 * @return The {@link IProgressMonitor}.
548
	 */
549
	public static IProgressMonitor startMainMonitor(
550
			IProgressMonitor progressMonitor, String taskName, int steps) {
551
		IProgressMonitor newMonitor = progressMonitor;
552
		if (newMonitor == null) {
553
			newMonitor = new NullProgressMonitor();
554
		}
555
		newMonitor.beginTask(taskName == null ? "" : taskName, steps);
556
		newMonitor.subTask(" ");
557
		return newMonitor;
558
	}
559

    
560
	/**
561
	 * Creates a {@link SubProgressMonitor} if the given
562
	 * {@link IProgressMonitor} is not <code>null</code> and not a
563
	 * {@link NullProgressMonitor}.
564
	 * 
565
	 * @param progressMonitor
566
	 *            The parent {@link IProgressMonitor} of the
567
	 *            {@link SubProgressMonitor} to be created.
568
	 * @param ticks
569
	 *            The number of steps this subtask is subdivided into. Must be a
570
	 *            positive number and must not be
571
	 *            {@link IProgressMonitor#UNKNOWN}.
572
	 * @return The {@link IProgressMonitor}.
573
	 */
574
	public static IProgressMonitor getSubProgressMonitor(
575
			IProgressMonitor progressMonitor, int ticks) {
576
		if (progressMonitor == null) {
577
			return new NullProgressMonitor();
578
		}
579
		if (progressMonitor instanceof NullProgressMonitor) {
580
			return progressMonitor;
581
		}
582

    
583
		return new SubProgressMonitor(progressMonitor, ticks);
584
	}
585

    
586
	/**
587
	 * Checks whether the user canceled this operation. If not canceled, the
588
	 * given number of steps are declared as done.
589
	 * 
590
	 * @param newMonitor
591
	 *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
592
	 * @param steps
593
	 *            a int.
594
	 */
595
	public static void workedChecked(IProgressMonitor newMonitor, int steps) {
596
		// In case the progress monitor was canceled throw an exception.
597
		if (newMonitor.isCanceled()) {
598
			throw new OperationCanceledException();
599
		}
600
		// Otherwise declare this step as done.
601
		newMonitor.worked(steps);
602
	}
603

    
604
	/**
605
	 * Present a progress dialog to the user. This dialog will block the UI
606
	 * 
607
	 * @param runnable
608
	 *            an implementation of {@link IRunnableWithProgress}
609
	 * @throws java.lang.InterruptedException
610
	 *             if any.
611
	 * @throws java.lang.reflect.InvocationTargetException
612
	 *             if any.
613
	 */
614
	public static void busyCursorWhile(IRunnableWithProgress runnable)
615
			throws InvocationTargetException, InterruptedException {
616
		getProgressService().busyCursorWhile(runnable);
617
	}
618

    
619
	/**
620
	 * <p>
621
	 * runInUI
622
	 * </p>
623
	 * 
624
	 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
625
	 * @param runnable
626
	 *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
627
	 *            object.
628
	 * @param rule
629
	 *            a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
630
	 *            object.
631
	 * @throws java.lang.reflect.InvocationTargetException
632
	 *             if any.
633
	 * @throws java.lang.InterruptedException
634
	 *             if any.
635
	 */
636
	public static void runInUI(IRunnableWithProgress runnable,
637
			ISchedulingRule rule) throws InvocationTargetException,
638
			InterruptedException {
639
		getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
640
	}
641

    
642
	/**
643
	 * <p>
644
	 * run
645
	 * </p>
646
	 * 
647
	 * @param fork
648
	 *            a boolean.
649
	 * @param cancelable
650
	 *            a boolean.
651
	 * @param runnable
652
	 *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
653
	 *            object.
654
	 * @throws java.lang.reflect.InvocationTargetException
655
	 *             if any.
656
	 * @throws java.lang.InterruptedException
657
	 *             if any.
658
	 */
659
	public static void run(boolean fork, boolean cancelable,
660
			IRunnableWithProgress runnable) throws InvocationTargetException,
661
			InterruptedException {
662
		getProgressService().run(fork, cancelable, runnable);
663
	}
664

    
665
	/**
666
	 * <p>
667
	 * getProgressService
668
	 * </p>
669
	 * 
670
	 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
671
	 */
672
	public static IProgressService getProgressService() {
673
		IWorkbench workbench = PlatformUI.getWorkbench();
674
		return workbench.getProgressService();
675
	}
676

    
677
	/**
678
	 * <p>
679
	 * getProgressService2
680
	 * </p>
681
	 * 
682
	 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
683
	 *         object.
684
	 */
685
	public static IWorkbenchSiteProgressService getProgressService2() {
686
		return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
687
	}
688

    
689
	/**
690
	 * <p>
691
	 * info
692
	 * </p>
693
	 * 
694
	 * @param message
695
	 *            a {@link java.lang.String} object.
696
	 */
697
	public static void info(String message) {
698
		IStatus status = new Status(IStatus.INFO, getPluginId(), message);
699
		info(status);
700
	}
701

    
702
	/**
703
	 * <p>
704
	 * info
705
	 * </p>
706
	 * 
707
	 * @param status
708
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
709
	 */
710
	public static void info(IStatus status) {
711
		log(status);
712
	}
713

    
714
	/**
715
	 * <p>
716
	 * warn
717
	 * </p>
718
	 * 
719
	 * @param source
720
	 *            a {@link java.lang.Class} object.
721
	 * @param message
722
	 *            a {@link java.lang.String} object.
723
	 */
724
	public static void warn(Class source, String message) {
725
		IStatus status = new Status(IStatus.WARNING, getPluginId(), message);
726
		getLog4JLogger(source).warn(message);
727
		log(status);
728
	}
729

    
730
	/**
731
	 * <p>
732
	 * error
733
	 * </p>
734
	 * 
735
	 * @param source
736
	 *            a {@link java.lang.Class} object.
737
	 * @param t
738
	 *            a {@link java.lang.Throwable} object.
739
	 */
740
	public static void error(Class source, Throwable t) {
741
		error(source.getClass(), t.getMessage(), t);
742
	}
743

    
744
	/**
745
	 * <p>
746
	 * error
747
	 * </p>
748
	 * 
749
	 * @param source
750
	 *            a {@link java.lang.Class} object.
751
	 * @param message
752
	 *            a {@link java.lang.String} object.
753
	 * @param t
754
	 *            a {@link java.lang.Throwable} object.
755
	 */
756
	public static void error(Class source, String message, Throwable t) {
757
		IStatus status = new Status(IStatus.ERROR, getPluginId(), message, t);
758
		error(source, status);
759
	}
760

    
761
	/**
762
	 * <p>
763
	 * error
764
	 * </p>
765
	 * 
766
	 * @param source
767
	 *            a {@link java.lang.Class} object.
768
	 * @param status
769
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
770
	 */
771
	public static void error(Class source, IStatus status) {
772
		getLog4JLogger(source)
773
				.error(status.getMessage(), status.getException());
774
		log(status);
775
	}
776

    
777
	/**
778
	 * <p>
779
	 * getLog4JLogger
780
	 * </p>
781
	 * 
782
	 * @param clazz
783
	 *            a {@link java.lang.Class} object.
784
	 * @return a {@link org.apache.log4j.Logger} object.
785
	 */
786
	public static Logger getLog4JLogger(Class clazz) {
787
		return Logger.getLogger(clazz);
788
	}
789

    
790
	/**
791
	 * @see {@link ILog#log(IStatus)}
792
	 * 
793
	 * @param status
794
	 */
795
	private static void log(IStatus status) {
796
		TaxeditorStorePlugin.getDefault().getLog().log(status);
797
	}
798

    
799
	/**
800
	 * <p>
801
	 * getPluginId
802
	 * </p>
803
	 * 
804
	 * @return a {@link java.lang.String} object.
805
	 */
806
	protected static String getPluginId() {
807
		return "eu.taxeditor";
808
	}
809

    
810
	/**
811
	 * <p>
812
	 * getActiveEditor
813
	 * </p>
814
	 * 
815
	 * @return a {@link org.eclipse.ui.IEditorPart} object.
816
	 */
817
	public static IEditorPart getActiveEditor() {
818
		return getActivePage() != null ? getActivePage().getActiveEditor()
819
				: null;
820
	}
821

    
822
	/**
823
	 * <p>
824
	 * getDetailsView
825
	 * </p>
826
	 * 
827
	 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
828
	 *         object.
829
	 */
830
	public static DetailsViewPart getDetailsView() {
831
		return (DetailsViewPart) getView(DetailsViewPart.ID, false);
832
	}
833

    
834
	/**
835
	 * <p>
836
	 * refreshDetailsViewer
837
	 * </p>
838
	 */
839
	public static void refreshDetailsViewer() {
840
		if (getDetailsView() != null) {
841
			((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
842
		}
843
	}
844

    
845
	/**
846
	 * <p>
847
	 * reflowDetailsViewer
848
	 * </p>
849
	 */
850
	public static void reflowDetailsViewer() {
851
		if (getDetailsView() != null) {
852
			((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
853
		}
854
	}
855

    
856
	public static SupplementalDataViewPart getSupplementalDataView() {
857
		return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
858
				false);
859
	}
860

    
861
	public static void reflowSupplementalViewer() {
862
		if (getSupplementalDataView() != null) {
863
			((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
864
					.reflow();
865
		}
866
	}
867
}
(2-2/30)