Project

General

Profile

Download (24.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.cdm.model.common.TermBase;
53
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
54
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
55
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
56
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
57
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
58
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
59
import eu.etaxonomy.taxeditor.view.userecords.UseRecordsViewPart;
60

    
61
/**
62
 * <p>
63
 * Abstract AbstractUtility class.
64
 * </p>
65
 * 
66
 * @author n.hoffmann
67
 * @created 11.05.2009
68
 * @version 1.0
69
 */
70
public abstract class AbstractUtility {
71

    
72
	/** Constant <code>statusLineManager</code> */
73
	protected static IStatusLineManager statusLineManager;
74

    
75
	/**
76
	 * <p>
77
	 * closeAll
78
	 * </p>
79
	 * 
80
	 * @return a boolean.
81
	 */
82
	public static boolean closeAll() {
83
		return getActivePage().closeAllEditors(true);
84
	}
85

    
86
	/**
87
	 * Close the given editor.
88
	 * 
89
	 * @param editor
90
	 *            The <tt>MultipageTaxonEditor</tt> to close.
91
	 * @return <tt>true</tt> on success
92
	 */
93
	public static boolean close(EditorPart editor) {
94
		return getActivePage().closeEditor(editor, true);
95
	}
96

    
97
	/**
98
	 * <p>
99
	 * getShell
100
	 * </p>
101
	 * 
102
	 * @return a {@link org.eclipse.swt.widgets.Shell} object.
103
	 */
104
	public static Shell getShell() {
105

    
106
		return TaxeditorStorePlugin.getDefault().getWorkbench()
107
				.getActiveWorkbenchWindow().getShell();
108
	}
109

    
110
	/**
111
	 * <p>
112
	 * getActivePage
113
	 * </p>
114
	 * 
115
	 * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
116
	 */
117
	public static IWorkbenchPage getActivePage() {
118

    
119
		return TaxeditorStorePlugin.getDefault().getWorkbench()
120
				.getActiveWorkbenchWindow().getActivePage();
121
	}
122

    
123
	/**
124
	 * <p>
125
	 * getActivePart
126
	 * </p>
127
	 * 
128
	 * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
129
	 */
130
	public static IWorkbenchPart getActivePart() {
131
		return getActivePage() != null ? getActivePage().getActivePart() : null;
132
	}
133

    
134
	public static IWorkbench getWorkbench() {
135
		return TaxeditorStorePlugin.getDefault().getWorkbench();
136
	}
137

    
138
	/**
139
	 * <p>
140
	 * getWorkbenchWindow
141
	 * </p>
142
	 * 
143
	 * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
144
	 */
145
	public static ApplicationWindow getWorkbenchWindow() {
146
		if (getWorkbench().getWorkbenchWindowCount() > 1) {
147
			throw new IllegalStateException("More than one workbench window");
148
		}
149
		return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
150
	}
151

    
152
	/**
153
	 * <p>
154
	 * showView
155
	 * </p>
156
	 * 
157
	 * @param id
158
	 *            a {@link java.lang.String} object.
159
	 * @return a {@link org.eclipse.ui.IViewPart} object.
160
	 */
161
	public static IViewPart showView(String id) {
162
		try {
163
			return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
164
					.getActivePage()
165
					.showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
166
		} catch (PartInitException e) {
167
			errorDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
168
			return null;
169
		}
170
	}
171

    
172
	/**
173
	 * <p>
174
	 * hideView
175
	 * </p>
176
	 * 
177
	 * @param view
178
	 *            a {@link org.eclipse.ui.IViewPart} object.
179
	 */
180
	public static void hideView(IViewPart view) {
181
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
182
				.hideView(view);
183
	}
184

    
185
	/**
186
	 * <p>
187
	 * getView
188
	 * </p>
189
	 * 
190
	 * @param id
191
	 *            a {@link java.lang.String} object.
192
	 * @param restore
193
	 *            a boolean.
194
	 * @return a {@link org.eclipse.ui.IViewPart} object.
195
	 */
196
	public static IViewPart getView(String id, boolean restore) {
197
		IViewReference[] references = PlatformUI.getWorkbench()
198
				.getActiveWorkbenchWindow().getActivePage().getViewReferences();
199
		for (IViewReference reference : references) {
200
			if (reference.getId().equals(id)) {
201
				return reference.getView(restore);
202
			}
203
		}
204
		return null;
205
	}
206

    
207
	/**
208
	 * <p>
209
	 * getService
210
	 * </p>
211
	 * 
212
	 * @param api
213
	 *            a {@link java.lang.Class} object.
214
	 * @return a {@link java.lang.Object} object.
215
	 */
216
	public static Object getService(Class api) {
217
		return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
218
	}
219

    
220
	/**
221
	 * <p>
222
	 * getCurrentTheme
223
	 * </p>
224
	 * 
225
	 * @return a {@link org.eclipse.ui.themes.ITheme} object.
226
	 */
227
	public static ITheme getCurrentTheme() {
228
		IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
229
				.getWorkbench().getThemeManager();
230
		return themeManager.getCurrentTheme();
231
	}
232

    
233
	/**
234
	 * Fonts registered to the plugin may be obtained with the Eclipse themeing
235
	 * functionality. Thus fonts are chooseable by the user via
236
	 * Preferences->General->Appearance->Colors and Fonts
237
	 * 
238
	 * @return the FontRegistry for the current theme
239
	 */
240
	public static FontRegistry getFontRegistry() {
241
		return getCurrentTheme().getFontRegistry();
242
	}
243

    
244
	/**
245
	 * <p>
246
	 * getFont
247
	 * </p>
248
	 * 
249
	 * @param symbolicName
250
	 *            a {@link java.lang.String} object.
251
	 * @return a {@link org.eclipse.swt.graphics.Font} object.
252
	 */
253
	public static Font getFont(String symbolicName) {
254
		return getFontRegistry().get(symbolicName);
255
	}
256

    
257
	/**
258
	 * Color registered to the plugin may be obtained with the Eclipse themeing
259
	 * functionality. Thus colors are editable by the user via
260
	 * Preferences->General->Appearance->Colors and Fonts
261
	 * 
262
	 * @return the ColorRegistry for the current theme
263
	 */
264
	public static ColorRegistry getColorRegistry() {
265
		return getCurrentTheme().getColorRegistry();
266
	}
267

    
268
	/**
269
	 * <p>
270
	 * getColor
271
	 * </p>
272
	 * 
273
	 * @param symbolicName
274
	 *            a {@link java.lang.String} object.
275
	 * @return a {@link org.eclipse.swt.graphics.Color} object.
276
	 */
277
	public static Color getColor(String symbolicName) {
278
		return getColorRegistry().get(symbolicName);
279
	}
280

    
281
	/**
282
	 * Open a message box that informs the user about unimplemented
283
	 * functionality. This method is for developer convenience.
284
	 * 
285
	 * @param source
286
	 *            a {@link java.lang.Object} object.
287
	 */
288
	public static void notImplementedMessage(Object source) {
289
		warningDialog("Not yet implemented", source,
290
				"This functionality is not yet implemented.");
291
	}
292

    
293
	/**
294
	 * <p>
295
	 * informationDialog
296
	 * </p>
297
	 * 
298
	 * @param title
299
	 *            a {@link java.lang.String} object.
300
	 * @param message
301
	 *            a {@link java.lang.String} object.
302
	 */
303
	public static void informationDialog(final String title,
304
			final String message) {
305
		Display.getDefault().asyncExec(new Runnable() {
306

    
307
			public void run() {
308
				MessageDialog.openInformation(getShell(), title, message);
309
			}
310
		});
311
	}
312

    
313
	public static void informationDialog(final String title,
314
			final IStatus status) {
315
		informationDialog(title, status.getMessage());
316
	}
317
	
318
	/**
319
	 * <p>
320
	 * warningDialog
321
	 * </p>
322
	 * 
323
	 * @param title
324
	 *            The dialogs title
325
	 * @param source
326
	 *            The object where the warning was generated (used by log4j)
327
	 * @param message
328
	 *            An informative String to be presented to the user
329
	 */
330
	public static void warningDialog(final String title, final Object source,
331
			final String message) {
332
		Display.getDefault().asyncExec(new Runnable() {
333

    
334
			public void run() {
335
				MessageDialog.openWarning(getShell(), title, message);
336
				Class<? extends Object> clazz = source != null ? source
337
						.getClass() : AbstractUtility.class;
338
				warn(clazz, message);
339
			}
340
		});
341
	}
342
	
343
	/**
344
	 * @param title
345
	 * @param termBase
346
	 * @param status
347
	 */
348
	public static void warningDialog(String title, Object source,
349
			IStatus status) {
350
		warningDialog(title, source, status.getMessage());
351
	}
352

    
353
	/**
354
	 * <p>
355
	 * errorDialog
356
	 * </p>
357
	 * 
358
	 * @param title
359
	 *            The dialogs title
360
	 * @param source
361
	 *            The object where the warning was generated (used by log4j)
362
	 * @param message
363
	 *            An informative String to be presented to the user
364
	 * @param title
365
	 *            The dialogs title
366
	 * @param t
367
	 *            a Throwable if one exists or null
368
	 */
369
	public static void errorDialog(final String title, final Object source,
370
			final String message, final Throwable t) {
371
		Display.getDefault().asyncExec(new Runnable() {
372

    
373
			public void run() {
374
				MessageDialog.openError(getShell(), title, message + getCauseRecursively(t));
375
				Class<? extends Object> clazz = source != null ? source
376
						.getClass() : this.getClass();
377
				error(clazz, message, t);
378
			}
379

    
380
			private String getCauseRecursively(Throwable t) {
381
				if(t == null){
382
					return null;
383
				}
384
				
385
				if(t.getCause() != null){
386
					return getCauseRecursively(t.getCause());
387
				}else{
388
					return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
389
				}
390

    
391
			}
392
		});
393
	}
394
	
395
	public static void errorDialog(final String title, final Object source,
396
			final String message){
397
		errorDialog(title, source, message, null);
398
	}
399

    
400
	/**
401
	 * <p>
402
	 * errorDialog
403
	 * </p>
404
	 * 
405
	 * @param title
406
	 *            a {@link java.lang.String} object.
407
	 * @param source
408
	 *            a {@link java.lang.Object} object.
409
	 * @param status
410
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
411
	 */
412
	public static void errorDialog(final String title, final Object source,
413
			final IStatus status) {
414
		Display.getDefault().asyncExec(new Runnable() {
415

    
416
			public void run() {
417
				MessageDialog.openError(getShell(), title, status.getMessage());
418
				Class<? extends Object> clazz = source != null ? source
419
						.getClass() : this.getClass();
420
				error(clazz, status.getMessage(), status.getException());
421
			}
422
		});
423
	}
424

    
425
	/**
426
	 * <p>
427
	 * confirmDialog
428
	 * </p>
429
	 * 
430
	 * @param title
431
	 *            a {@link java.lang.String} object.
432
	 * @param message
433
	 *            a {@link java.lang.String} object.
434
	 * @return a boolean.
435
	 */
436
	public static boolean confirmDialog(String title, String message) {
437
		return MessageDialog.openQuestion(getShell(), title, message);
438
	}
439

    
440
	/**
441
	 * <p>
442
	 * executeOperation
443
	 * </p>
444
	 * 
445
	 * @param operation
446
	 *            a
447
	 *            {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation}
448
	 *            object.
449
	 * @return a {@link org.eclipse.core.runtime.IStatus} object.
450
	 */
451
	public static IStatus executeOperation(final AbstractPostOperation operation) {
452
		if (getOperationHistory() == null) {
453
			throw new IllegalArgumentException(
454
					"There is no operation history for this context");
455
		}
456

    
457
		final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
458
				.getUIInfoAdapter(getShell());
459

    
460
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
461

    
462
			public void run(IProgressMonitor monitor)
463
					throws InvocationTargetException, InterruptedException {
464
				monitor.beginTask(operation.getLabel(), 100);
465
				IStatus status = Status.CANCEL_STATUS;
466
				try {
467
					operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
468
					status = getOperationHistory().execute(operation, monitor,
469
							uiInfoAdapter);
470
				} catch (ExecutionException e) {
471
					errorDialog("Error executing operation", getClass(), String.format("An error occured while executing %s.", operation.getLabel()), e);
472
				} finally {
473
					monitor.done();
474
				}
475
				
476
				String statusString = status.equals(Status.OK_STATUS) ? "completed"
477
						: "cancelled";
478
				setStatusLine(operation.getLabel() + " " + statusString + ".");
479

    
480
			}
481
		};
482

    
483
		try {
484
			runInUI(runnable, null);
485
		} catch (Exception e) {
486
			errorDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
487
		}
488

    
489
		// // Start the main progress monitor.
490
		// IProgressMonitor newMonitor =
491
		// startMainMonitor(getMonitor(),operation.getLabel(), 100);
492
		//
493
		// // Check whether operation was canceled and do some steps.
494
		// workedChecked(newMonitor, 10);
495
		//
496
		// try {
497
		// IStatus status = getOperationHistory().execute(operation, newMonitor,
498
		// WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
499
		//
500
		// // Check whether operation was canceled and do some steps.
501
		// workedChecked(newMonitor, 30);
502
		//
503
		// String statusString = status.equals(Status.OK_STATUS) ? "completed" :
504
		// "cancelled";
505
		// setStatusLine(operation.getLabel() + " " + statusString + ".");
506
		//
507
		// return status;
508
		// } catch (ExecutionException e) {
509
		// logger.error("Error executing operation: " + operation.getLabel(),
510
		// e);
511
		// errorDialog("Error executing operation: " + operation.getLabel(),
512
		// "Please refer to the error log.");
513
		// }
514
		// finally {
515
		//
516
		// // Stop the progress monitor.
517
		// newMonitor.done();
518
		// }
519

    
520
		IPostOperationEnabled postOperationEnabled = operation
521
				.getPostOperationEnabled();
522
		if (postOperationEnabled != null) {
523
			postOperationEnabled.onComplete();
524
		}
525
		return Status.OK_STATUS;
526
	}
527

    
528
	/**
529
	 * <p>
530
	 * getOperationHistory
531
	 * </p>
532
	 * 
533
	 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
534
	 *         object.
535
	 */
536
	public static IOperationHistory getOperationHistory() {
537
		return getWorkbench().getOperationSupport().getOperationHistory();
538
	}
539

    
540
	/**
541
	 * <p>
542
	 * setStatusLine
543
	 * </p>
544
	 * 
545
	 * @param message
546
	 *            a {@link java.lang.String} object.
547
	 */
548
	public static void setStatusLine(final String message) {
549
		Display.getDefault().asyncExec(new Runnable() {
550

    
551
			public void run() {
552
				statusLineManager.setMessage(message);
553
			}
554

    
555
		});
556

    
557
	}
558

    
559
	/**
560
	 * <p>
561
	 * getMonitor
562
	 * </p>
563
	 * 
564
	 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
565
	 */
566
	public static IProgressMonitor getMonitor() {
567
		statusLineManager.setCancelEnabled(false);
568
		return statusLineManager.getProgressMonitor();
569
	}
570

    
571
	/**
572
	 * Starts either the given {@link IProgressMonitor} if it's not
573
	 * <code>null</code> or a new {@link NullProgressMonitor}.
574
	 * 
575
	 * @param progressMonitor
576
	 *            The {@link IProgressMonitor} or <code>null</code> if no
577
	 *            progress should be reported.
578
	 * @param taskName
579
	 *            The name of the main task.
580
	 * @param steps
581
	 *            The number of steps this task is subdivided into.
582
	 * @return The {@link IProgressMonitor}.
583
	 */
584
	public static IProgressMonitor startMainMonitor(
585
			IProgressMonitor progressMonitor, String taskName, int steps) {
586
		IProgressMonitor newMonitor = progressMonitor;
587
		if (newMonitor == null) {
588
			newMonitor = new NullProgressMonitor();
589
		}
590
		newMonitor.beginTask(taskName == null ? "" : taskName, steps);
591
		newMonitor.subTask(" ");
592
		return newMonitor;
593
	}
594

    
595
	/**
596
	 * Creates a {@link SubProgressMonitor} if the given
597
	 * {@link IProgressMonitor} is not <code>null</code> and not a
598
	 * {@link NullProgressMonitor}.
599
	 * 
600
	 * @param progressMonitor
601
	 *            The parent {@link IProgressMonitor} of the
602
	 *            {@link SubProgressMonitor} to be created.
603
	 * @param ticks
604
	 *            The number of steps this subtask is subdivided into. Must be a
605
	 *            positive number and must not be
606
	 *            {@link IProgressMonitor#UNKNOWN}.
607
	 * @return The {@link IProgressMonitor}.
608
	 */
609
	public static IProgressMonitor getSubProgressMonitor(
610
			IProgressMonitor progressMonitor, int ticks) {
611
		if (progressMonitor == null) {
612
			return new NullProgressMonitor();
613
		}
614
		if (progressMonitor instanceof NullProgressMonitor) {
615
			return progressMonitor;
616
		}
617

    
618
		return new SubProgressMonitor(progressMonitor, ticks);
619
	}
620

    
621
	/**
622
	 * Checks whether the user canceled this operation. If not canceled, the
623
	 * given number of steps are declared as done.
624
	 * 
625
	 * @param newMonitor
626
	 *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
627
	 * @param steps
628
	 *            a int.
629
	 */
630
	public static void workedChecked(IProgressMonitor newMonitor, int steps) {
631
		// In case the progress monitor was canceled throw an exception.
632
		if (newMonitor.isCanceled()) {
633
			throw new OperationCanceledException();
634
		}
635
		// Otherwise declare this step as done.
636
		newMonitor.worked(steps);
637
	}
638

    
639
	/**
640
	 * Present a progress dialog to the user. This dialog will block the UI
641
	 * 
642
	 * @param runnable
643
	 *            an implementation of {@link IRunnableWithProgress}
644
	 * @throws java.lang.InterruptedException
645
	 *             if any.
646
	 * @throws java.lang.reflect.InvocationTargetException
647
	 *             if any.
648
	 */
649
	public static void busyCursorWhile(IRunnableWithProgress runnable)
650
			throws InvocationTargetException, InterruptedException {
651
		getProgressService().busyCursorWhile(runnable);
652
	}
653

    
654
	/**
655
	 * <p>
656
	 * runInUI
657
	 * </p>
658
	 * 
659
	 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
660
	 * @param runnable
661
	 *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
662
	 *            object.
663
	 * @param rule
664
	 *            a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
665
	 *            object.
666
	 * @throws java.lang.reflect.InvocationTargetException
667
	 *             if any.
668
	 * @throws java.lang.InterruptedException
669
	 *             if any.
670
	 */
671
	public static void runInUI(IRunnableWithProgress runnable,
672
			ISchedulingRule rule) throws InvocationTargetException,
673
			InterruptedException {
674
		getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
675
	}
676

    
677
	/**
678
	 * <p>
679
	 * run
680
	 * </p>
681
	 * 
682
	 * @param fork
683
	 *            a boolean.
684
	 * @param cancelable
685
	 *            a boolean.
686
	 * @param runnable
687
	 *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
688
	 *            object.
689
	 * @throws java.lang.reflect.InvocationTargetException
690
	 *             if any.
691
	 * @throws java.lang.InterruptedException
692
	 *             if any.
693
	 */
694
	public static void run(boolean fork, boolean cancelable,
695
			IRunnableWithProgress runnable) throws InvocationTargetException,
696
			InterruptedException {
697
		getProgressService().run(fork, cancelable, runnable);
698
	}
699

    
700
	/**
701
	 * <p>
702
	 * getProgressService
703
	 * </p>
704
	 * 
705
	 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
706
	 */
707
	public static IProgressService getProgressService() {
708
		IWorkbench workbench = PlatformUI.getWorkbench();
709
		return workbench.getProgressService();
710
	}
711

    
712
	/**
713
	 * <p>
714
	 * getProgressService2
715
	 * </p>
716
	 * 
717
	 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
718
	 *         object.
719
	 */
720
	public static IWorkbenchSiteProgressService getProgressService2() {
721
		return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
722
	}
723

    
724
	/**
725
	 * <p>
726
	 * info
727
	 * </p>
728
	 * 
729
	 * @param message
730
	 *            a {@link java.lang.String} object.
731
	 */
732
	public static void info(String message) {
733
		IStatus status = new Status(IStatus.INFO, getPluginId(), message);
734
		info(status);
735
	}
736

    
737
	/**
738
	 * <p>
739
	 * info
740
	 * </p>
741
	 * 
742
	 * @param status
743
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
744
	 */
745
	public static void info(IStatus status) {
746
		log(status);
747
	}
748

    
749
	/**
750
	 * <p>
751
	 * warn
752
	 * </p>
753
	 * 
754
	 * @param source
755
	 *            a {@link java.lang.Class} object.
756
	 * @param message
757
	 *            a {@link java.lang.String} object.
758
	 */
759
	public static void warn(Class source, String message) {
760
		IStatus status = new Status(IStatus.WARNING, getPluginId(), message);
761
		getLog4JLogger(source).warn(message);
762
		log(status);
763
	}
764
	
765
	public static void warn(Class source, IStatus status) {
766
		getLog4JLogger(source).warn(status.getMessage(), status.getException());
767
		log(status);
768
	}
769
	
770
	public static void warn(Class source, Throwable t) {
771
		IStatus status = new Status(IStatus.WARNING, getPluginId(), t.getMessage(), t);
772
		getLog4JLogger(source).warn(t);
773
		log(status);
774
	}
775

    
776
	/**
777
	 * <p>
778
	 * error
779
	 * </p>
780
	 * 
781
	 * @param source
782
	 *            a {@link java.lang.Class} object.
783
	 * @param t
784
	 *            a {@link java.lang.Throwable} object.
785
	 */
786
	public static void error(Class source, Throwable t) {
787
		error(source.getClass(), t.getMessage(), t);
788
	}
789

    
790
	/**
791
	 * <p>
792
	 * error
793
	 * </p>
794
	 * 
795
	 * @param source
796
	 *            a {@link java.lang.Class} object.
797
	 * @param message
798
	 *            a {@link java.lang.String} object.
799
	 * @param t
800
	 *            a {@link java.lang.Throwable} object.
801
	 */
802
	public static void error(Class source, String message, Throwable t) {
803
		IStatus status = new Status(IStatus.ERROR, getPluginId(), message, t);
804
		error(source, status);
805
	}
806

    
807
	/**
808
	 * <p>
809
	 * error
810
	 * </p>
811
	 * 
812
	 * @param source
813
	 *            a {@link java.lang.Class} object.
814
	 * @param status
815
	 *            a {@link org.eclipse.core.runtime.IStatus} object.
816
	 */
817
	public static void error(Class source, IStatus status) {
818
		getLog4JLogger(source)
819
				.error(status.getMessage(), status.getException());
820
		log(status);
821
	}
822

    
823
	/**
824
	 * <p>
825
	 * getLog4JLogger
826
	 * </p>
827
	 * 
828
	 * @param clazz
829
	 *            a {@link java.lang.Class} object.
830
	 * @return a {@link org.apache.log4j.Logger} object.
831
	 */
832
	public static Logger getLog4JLogger(Class clazz) {
833
		return Logger.getLogger(clazz);
834
	}
835

    
836
	/**
837
	 * @see {@link ILog#log(IStatus)}
838
	 * 
839
	 * @param status
840
	 */
841
	private static void log(IStatus status) {
842
		TaxeditorStorePlugin.getDefault().getLog().log(status);
843
	}
844

    
845
	/**
846
	 * <p>
847
	 * getPluginId
848
	 * </p>
849
	 * 
850
	 * @return a {@link java.lang.String} object.
851
	 */
852
	public static String getPluginId() {
853
		return "eu.taxeditor";
854
	}
855

    
856
	/**
857
	 * <p>
858
	 * getActiveEditor
859
	 * </p>
860
	 * 
861
	 * @return a {@link org.eclipse.ui.IEditorPart} object.
862
	 */
863
	public static IEditorPart getActiveEditor() {
864
		return getActivePage() != null ? getActivePage().getActiveEditor()
865
				: null;
866
	}
867

    
868
	/**
869
	 * <p>
870
	 * getDetailsView
871
	 * </p>
872
	 * 
873
	 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
874
	 *         object.
875
	 */
876
	public static DetailsViewPart getDetailsView() {
877
		return (DetailsViewPart) getView(DetailsViewPart.ID, false);
878
	}
879

    
880
	/**
881
	 * <p>
882
	 * refreshDetailsViewer
883
	 * </p>
884
	 */
885
	public static void refreshDetailsViewer() {
886
		if (getDetailsView() != null) {
887
			((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
888
		}
889
	}
890

    
891
	/**
892
	 * <p>
893
	 * reflowDetailsViewer
894
	 * </p>
895
	 */
896
	public static void reflowDetailsViewer() {
897
		if (getDetailsView() != null) {
898
			((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
899
		}
900
	}
901

    
902
	public static SupplementalDataViewPart getSupplementalDataView() {
903
		return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
904
				false);
905
	}
906

    
907
	public static void reflowSupplementalViewer() {
908
		if (getSupplementalDataView() != null) {
909
			((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
910
					.reflow();
911
		}
912
	}
913
	
914
	public static UseRecordsViewPart getUseRecordsView() {
915
		return (UseRecordsViewPart) getView(UseRecordsViewPart.ID, false);
916
	}
917

    
918
	/**
919
	 * <p>
920
	 * refreshUseRecordsViewer
921
	 * </p>
922
	 */
923
	public static void refreshUseRecordsViewer() {
924
		if (getUseRecordsView() != null) {
925
			((AbstractCdmDataViewer) getUseRecordsView().getViewer()).refresh();
926
		}
927
	}
928

    
929
	/**
930
	 * <p>
931
	 * reflowUseRecordsViewer
932
	 * </p>
933
	 */
934
	public static void reflowUseRecordsViewer() {
935
		if (getUseRecordsView() != null) {
936
			((AbstractCdmDataViewer) getUseRecordsView().getViewer()).reflow();
937
		}
938
	}
939
}
(2-2/31)