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