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