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