merged/implemented cdm3.3 model adaptations
[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.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 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 Display.getDefault().asyncExec(new Runnable() {
304
305 public void run() {
306 MessageDialog.openInformation(getShell(), title, message);
307 }
308 });
309 }
310
311 public static void informationDialog(final String title,
312 final IStatus status) {
313 informationDialog(title, status.getMessage());
314 }
315
316 /**
317 * <p>
318 * warningDialog
319 * </p>
320 *
321 * @param title
322 * The dialogs title
323 * @param source
324 * The object where the warning was generated (used by log4j)
325 * @param message
326 * An informative String to be presented to the user
327 */
328 public static void warningDialog(final String title, final Object source,
329 final String message) {
330 Display.getDefault().asyncExec(new Runnable() {
331
332 public void run() {
333 MessageDialog.openWarning(getShell(), title, message);
334 Class<? extends Object> clazz = source != null ? source
335 .getClass() : AbstractUtility.class;
336 warn(clazz, message);
337 }
338 });
339 }
340
341 /**
342 * @param title
343 * @param termBase
344 * @param status
345 */
346 public static void warningDialog(String title, Object source,
347 IStatus status) {
348 warningDialog(title, source, status.getMessage());
349 }
350
351 /**
352 * <p>
353 * errorDialog
354 * </p>
355 *
356 * @param title
357 * The dialogs title
358 * @param source
359 * The object where the warning was generated (used by log4j)
360 * @param message
361 * An informative String to be presented to the user
362 * @param title
363 * The dialogs title
364 * @param t
365 * a Throwable if one exists or null
366 */
367 public static void errorDialog(final String title, final Object source,
368 final String message, final Throwable t) {
369 Display.getDefault().asyncExec(new Runnable() {
370
371 public void run() {
372 MessageDialog.openError(getShell(), title, message + getCauseRecursively(t));
373 Class<? extends Object> clazz = source != null ? source
374 .getClass() : this.getClass();
375 error(clazz, message, t);
376 }
377
378 private String getCauseRecursively(Throwable t) {
379 if(t == null){
380 return null;
381 }
382
383 if(t.getCause() != null){
384 return getCauseRecursively(t.getCause());
385 }else{
386 return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
387 }
388
389 }
390 });
391 }
392
393 public static void errorDialog(final String title, final Object source,
394 final String message){
395 errorDialog(title, source, message, null);
396 }
397
398 /**
399 * <p>
400 * errorDialog
401 * </p>
402 *
403 * @param title
404 * a {@link java.lang.String} object.
405 * @param source
406 * a {@link java.lang.Object} object.
407 * @param status
408 * a {@link org.eclipse.core.runtime.IStatus} object.
409 */
410 public static void errorDialog(final String title, final Object source,
411 final IStatus status) {
412 Display.getDefault().asyncExec(new Runnable() {
413
414 public void run() {
415 MessageDialog.openError(getShell(), title, status.getMessage());
416 Class<? extends Object> clazz = source != null ? source
417 .getClass() : this.getClass();
418 error(clazz, status.getMessage(), status.getException());
419 }
420 });
421 }
422
423 /**
424 * <p>
425 * confirmDialog
426 * </p>
427 *
428 * @param title
429 * a {@link java.lang.String} object.
430 * @param message
431 * a {@link java.lang.String} object.
432 * @return a boolean.
433 */
434 public static boolean confirmDialog(String title, String message) {
435 return MessageDialog.openQuestion(getShell(), title, message);
436 }
437
438 /**
439 * <p>
440 * executeOperation
441 * </p>
442 *
443 * @param operation
444 * a
445 * {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation}
446 * object.
447 * @return a {@link org.eclipse.core.runtime.IStatus} object.
448 */
449 public static IStatus executeOperation(final AbstractPostOperation operation) {
450 if (getOperationHistory() == null) {
451 throw new IllegalArgumentException(
452 "There is no operation history for this context");
453 }
454
455 final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
456 .getUIInfoAdapter(getShell());
457
458 IRunnableWithProgress runnable = new IRunnableWithProgress() {
459
460 public void run(IProgressMonitor monitor)
461 throws InvocationTargetException, InterruptedException {
462 monitor.beginTask(operation.getLabel(), 100);
463 IStatus status = Status.CANCEL_STATUS;
464 try {
465 operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
466 status = getOperationHistory().execute(operation, monitor,
467 uiInfoAdapter);
468 } catch (ExecutionException e) {
469 errorDialog("Error executing operation", getClass(), String.format("An error occured while executing %s.", operation.getLabel()), e);
470 } finally {
471 monitor.done();
472 }
473
474 String statusString = status.equals(Status.OK_STATUS) ? "completed"
475 : "cancelled";
476 setStatusLine(operation.getLabel() + " " + statusString + ".");
477
478 }
479 };
480
481 try {
482 runInUI(runnable, null);
483 } catch (Exception e) {
484 errorDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
485 }
486
487 // // Start the main progress monitor.
488 // IProgressMonitor newMonitor =
489 // startMainMonitor(getMonitor(),operation.getLabel(), 100);
490 //
491 // // Check whether operation was canceled and do some steps.
492 // workedChecked(newMonitor, 10);
493 //
494 // try {
495 // IStatus status = getOperationHistory().execute(operation, newMonitor,
496 // WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
497 //
498 // // Check whether operation was canceled and do some steps.
499 // workedChecked(newMonitor, 30);
500 //
501 // String statusString = status.equals(Status.OK_STATUS) ? "completed" :
502 // "cancelled";
503 // setStatusLine(operation.getLabel() + " " + statusString + ".");
504 //
505 // return status;
506 // } catch (ExecutionException e) {
507 // logger.error("Error executing operation: " + operation.getLabel(),
508 // e);
509 // errorDialog("Error executing operation: " + operation.getLabel(),
510 // "Please refer to the error log.");
511 // }
512 // finally {
513 //
514 // // Stop the progress monitor.
515 // newMonitor.done();
516 // }
517
518 IPostOperationEnabled postOperationEnabled = operation
519 .getPostOperationEnabled();
520 if (postOperationEnabled != null) {
521 postOperationEnabled.onComplete();
522 }
523 return Status.OK_STATUS;
524 }
525
526 /**
527 * <p>
528 * getOperationHistory
529 * </p>
530 *
531 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
532 * object.
533 */
534 public static IOperationHistory getOperationHistory() {
535 return getWorkbench().getOperationSupport().getOperationHistory();
536 }
537
538 /**
539 * <p>
540 * setStatusLine
541 * </p>
542 *
543 * @param message
544 * a {@link java.lang.String} object.
545 */
546 public static void setStatusLine(final String message) {
547 Display.getDefault().asyncExec(new Runnable() {
548
549 public void run() {
550 statusLineManager.setMessage(message);
551 }
552
553 });
554
555 }
556
557 /**
558 * <p>
559 * getMonitor
560 * </p>
561 *
562 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
563 */
564 public static IProgressMonitor getMonitor() {
565 statusLineManager.setCancelEnabled(false);
566 return statusLineManager.getProgressMonitor();
567 }
568
569 /**
570 * Starts either the given {@link IProgressMonitor} if it's not
571 * <code>null</code> or a new {@link NullProgressMonitor}.
572 *
573 * @param progressMonitor
574 * The {@link IProgressMonitor} or <code>null</code> if no
575 * progress should be reported.
576 * @param taskName
577 * The name of the main task.
578 * @param steps
579 * The number of steps this task is subdivided into.
580 * @return The {@link IProgressMonitor}.
581 */
582 public static IProgressMonitor startMainMonitor(
583 IProgressMonitor progressMonitor, String taskName, int steps) {
584 IProgressMonitor newMonitor = progressMonitor;
585 if (newMonitor == null) {
586 newMonitor = new NullProgressMonitor();
587 }
588 newMonitor.beginTask(taskName == null ? "" : taskName, steps);
589 newMonitor.subTask(" ");
590 return newMonitor;
591 }
592
593 /**
594 * Creates a {@link SubProgressMonitor} if the given
595 * {@link IProgressMonitor} is not <code>null</code> and not a
596 * {@link NullProgressMonitor}.
597 *
598 * @param progressMonitor
599 * The parent {@link IProgressMonitor} of the
600 * {@link SubProgressMonitor} to be created.
601 * @param ticks
602 * The number of steps this subtask is subdivided into. Must be a
603 * positive number and must not be
604 * {@link IProgressMonitor#UNKNOWN}.
605 * @return The {@link IProgressMonitor}.
606 */
607 public static IProgressMonitor getSubProgressMonitor(
608 IProgressMonitor progressMonitor, int ticks) {
609 if (progressMonitor == null) {
610 return new NullProgressMonitor();
611 }
612 if (progressMonitor instanceof NullProgressMonitor) {
613 return progressMonitor;
614 }
615
616 return new SubProgressMonitor(progressMonitor, ticks);
617 }
618
619 /**
620 * Checks whether the user canceled this operation. If not canceled, the
621 * given number of steps are declared as done.
622 *
623 * @param newMonitor
624 * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
625 * @param steps
626 * a int.
627 */
628 public static void workedChecked(IProgressMonitor newMonitor, int steps) {
629 // In case the progress monitor was canceled throw an exception.
630 if (newMonitor.isCanceled()) {
631 throw new OperationCanceledException();
632 }
633 // Otherwise declare this step as done.
634 newMonitor.worked(steps);
635 }
636
637 /**
638 * Present a progress dialog to the user. This dialog will block the UI
639 *
640 * @param runnable
641 * an implementation of {@link IRunnableWithProgress}
642 * @throws java.lang.InterruptedException
643 * if any.
644 * @throws java.lang.reflect.InvocationTargetException
645 * if any.
646 */
647 public static void busyCursorWhile(IRunnableWithProgress runnable)
648 throws InvocationTargetException, InterruptedException {
649 getProgressService().busyCursorWhile(runnable);
650 }
651
652 /**
653 * <p>
654 * runInUI
655 * </p>
656 *
657 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
658 * @param runnable
659 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
660 * object.
661 * @param rule
662 * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
663 * object.
664 * @throws java.lang.reflect.InvocationTargetException
665 * if any.
666 * @throws java.lang.InterruptedException
667 * if any.
668 */
669 public static void runInUI(IRunnableWithProgress runnable,
670 ISchedulingRule rule) throws InvocationTargetException,
671 InterruptedException {
672 getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
673 }
674
675 /**
676 * <p>
677 * run
678 * </p>
679 *
680 * @param fork
681 * a boolean.
682 * @param cancelable
683 * a boolean.
684 * @param runnable
685 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
686 * object.
687 * @throws java.lang.reflect.InvocationTargetException
688 * if any.
689 * @throws java.lang.InterruptedException
690 * if any.
691 */
692 public static void run(boolean fork, boolean cancelable,
693 IRunnableWithProgress runnable) throws InvocationTargetException,
694 InterruptedException {
695 getProgressService().run(fork, cancelable, runnable);
696 }
697
698 /**
699 * <p>
700 * getProgressService
701 * </p>
702 *
703 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
704 */
705 public static IProgressService getProgressService() {
706 IWorkbench workbench = PlatformUI.getWorkbench();
707 return workbench.getProgressService();
708 }
709
710 /**
711 * <p>
712 * getProgressService2
713 * </p>
714 *
715 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
716 * object.
717 */
718 public static IWorkbenchSiteProgressService getProgressService2() {
719 return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
720 }
721
722 /**
723 * <p>
724 * info
725 * </p>
726 *
727 * @param message
728 * a {@link java.lang.String} object.
729 */
730 public static void info(String message) {
731 IStatus status = new Status(IStatus.INFO, getPluginId(), message);
732 info(status);
733 }
734
735 /**
736 * <p>
737 * info
738 * </p>
739 *
740 * @param status
741 * a {@link org.eclipse.core.runtime.IStatus} object.
742 */
743 public static void info(IStatus status) {
744 log(status);
745 }
746
747 /**
748 * <p>
749 * warn
750 * </p>
751 *
752 * @param source
753 * a {@link java.lang.Class} object.
754 * @param message
755 * a {@link java.lang.String} object.
756 */
757 public static void warn(Class source, String message) {
758 IStatus status = new Status(IStatus.WARNING, getPluginId(), message);
759 getLog4JLogger(source).warn(message);
760 log(status);
761 }
762
763 public static void warn(Class source, IStatus status) {
764 getLog4JLogger(source).warn(status.getMessage(), status.getException());
765 log(status);
766 }
767
768 public static void warn(Class source, Throwable t) {
769 IStatus status = new Status(IStatus.WARNING, getPluginId(), t.getMessage(), t);
770 getLog4JLogger(source).warn(t);
771 log(status);
772 }
773
774 /**
775 * <p>
776 * error
777 * </p>
778 *
779 * @param source
780 * a {@link java.lang.Class} object.
781 * @param t
782 * a {@link java.lang.Throwable} object.
783 */
784 public static void error(Class source, Throwable t) {
785 error(source.getClass(), t.getMessage(), t);
786 }
787
788 /**
789 * <p>
790 * error
791 * </p>
792 *
793 * @param source
794 * a {@link java.lang.Class} object.
795 * @param message
796 * a {@link java.lang.String} object.
797 * @param t
798 * a {@link java.lang.Throwable} object.
799 */
800 public static void error(Class source, String message, Throwable t) {
801 IStatus status = new Status(IStatus.ERROR, getPluginId(), message, t);
802 error(source, status);
803 }
804
805 /**
806 * <p>
807 * error
808 * </p>
809 *
810 * @param source
811 * a {@link java.lang.Class} object.
812 * @param status
813 * a {@link org.eclipse.core.runtime.IStatus} object.
814 */
815 public static void error(Class source, IStatus status) {
816 getLog4JLogger(source)
817 .error(status.getMessage(), status.getException());
818 log(status);
819 }
820
821 /**
822 * <p>
823 * getLog4JLogger
824 * </p>
825 *
826 * @param clazz
827 * a {@link java.lang.Class} object.
828 * @return a {@link org.apache.log4j.Logger} object.
829 */
830 public static Logger getLog4JLogger(Class clazz) {
831 return Logger.getLogger(clazz);
832 }
833
834 /**
835 * @see {@link ILog#log(IStatus)}
836 *
837 * @param status
838 */
839 private static void log(IStatus status) {
840 TaxeditorStorePlugin.getDefault().getLog().log(status);
841 }
842
843 /**
844 * <p>
845 * getPluginId
846 * </p>
847 *
848 * @return a {@link java.lang.String} object.
849 */
850 public static String getPluginId() {
851 return "eu.taxeditor";
852 }
853
854 /**
855 * <p>
856 * getActiveEditor
857 * </p>
858 *
859 * @return a {@link org.eclipse.ui.IEditorPart} object.
860 */
861 public static IEditorPart getActiveEditor() {
862 return getActivePage() != null ? getActivePage().getActiveEditor()
863 : null;
864 }
865
866 /**
867 * <p>
868 * getDetailsView
869 * </p>
870 *
871 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
872 * object.
873 */
874 public static DetailsViewPart getDetailsView() {
875 return (DetailsViewPart) getView(DetailsViewPart.ID, false);
876 }
877
878 /**
879 * <p>
880 * refreshDetailsViewer
881 * </p>
882 */
883 public static void refreshDetailsViewer() {
884 if (getDetailsView() != null) {
885 ((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
886 }
887 }
888
889 /**
890 * <p>
891 * reflowDetailsViewer
892 * </p>
893 */
894 public static void reflowDetailsViewer() {
895 if (getDetailsView() != null) {
896 ((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
897 }
898 }
899
900 public static SupplementalDataViewPart getSupplementalDataView() {
901 return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
902 false);
903 }
904
905 public static void reflowSupplementalViewer() {
906 if (getSupplementalDataView() != null) {
907 ((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
908 .reflow();
909 }
910 }
911
912 }