3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.model
;
13 import java
.io
.PrintWriter
;
14 import java
.io
.StringWriter
;
15 import java
.io
.Writer
;
16 import java
.lang
.reflect
.InvocationTargetException
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Collection
;
19 import java
.util
.LinkedHashMap
;
20 import java
.util
.List
;
21 import java
.util
.TreeSet
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.eclipse
.core
.commands
.ExecutionException
;
25 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
26 import org
.eclipse
.core
.runtime
.IAdaptable
;
27 import org
.eclipse
.core
.runtime
.ILog
;
28 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
29 import org
.eclipse
.core
.runtime
.IStatus
;
30 import org
.eclipse
.core
.runtime
.MultiStatus
;
31 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
32 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
33 import org
.eclipse
.core
.runtime
.Status
;
34 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
35 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
36 import org
.eclipse
.jface
.action
.IStatusLineManager
;
37 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
38 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
39 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
40 import org
.eclipse
.jface
.resource
.ColorRegistry
;
41 import org
.eclipse
.jface
.resource
.FontRegistry
;
42 import org
.eclipse
.jface
.window
.ApplicationWindow
;
43 import org
.eclipse
.swt
.graphics
.Color
;
44 import org
.eclipse
.swt
.graphics
.Font
;
45 import org
.eclipse
.swt
.widgets
.Display
;
46 import org
.eclipse
.swt
.widgets
.Shell
;
47 import org
.eclipse
.ui
.IEditorPart
;
48 import org
.eclipse
.ui
.IViewPart
;
49 import org
.eclipse
.ui
.IViewReference
;
50 import org
.eclipse
.ui
.IWorkbench
;
51 import org
.eclipse
.ui
.IWorkbenchPage
;
52 import org
.eclipse
.ui
.IWorkbenchPart
;
53 import org
.eclipse
.ui
.PartInitException
;
54 import org
.eclipse
.ui
.PlatformUI
;
55 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
56 import org
.eclipse
.ui
.part
.EditorPart
;
57 import org
.eclipse
.ui
.progress
.IProgressService
;
58 import org
.eclipse
.ui
.progress
.IWorkbenchSiteProgressService
;
59 import org
.eclipse
.ui
.themes
.ITheme
;
60 import org
.eclipse
.ui
.themes
.IThemeManager
;
62 import eu
.etaxonomy
.cdm
.model
.common
.IEnumTerm
;
63 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.SecurityExceptionUtils
;
64 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
65 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
66 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
67 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmDataViewer
;
68 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
69 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
73 * Abstract AbstractUtility class.
80 public abstract class AbstractUtility
{
82 /** Constant <code>statusLineManager</code> */
83 protected static IStatusLineManager statusLineManager
;
92 public static boolean closeAll() {
93 return getActivePage().closeAllEditors(true);
97 * Close the given editor.
100 * The <tt>MultipageTaxonEditor</tt> to close.
101 * @return <tt>true</tt> on success
103 public static boolean close(EditorPart editor
) {
104 return getActivePage().closeEditor(editor
, true);
112 * @return a {@link org.eclipse.swt.widgets.Shell} object.
114 public static Shell
getShell() {
116 return TaxeditorStorePlugin
.getDefault().getWorkbench()
117 .getActiveWorkbenchWindow().getShell();
125 * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
127 public static IWorkbenchPage
getActivePage() {
129 return TaxeditorStorePlugin
.getDefault().getWorkbench()
130 .getActiveWorkbenchWindow().getActivePage();
138 * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
140 public static IWorkbenchPart
getActivePart() {
141 return getActivePage() != null ?
getActivePage().getActivePart() : null;
144 public static IWorkbench
getWorkbench() {
145 return TaxeditorStorePlugin
.getDefault().getWorkbench();
153 * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
155 public static ApplicationWindow
getWorkbenchWindow() {
156 if (getWorkbench().getWorkbenchWindowCount() > 1) {
157 throw new IllegalStateException("More than one workbench window");
159 return (ApplicationWindow
) getWorkbench().getWorkbenchWindows()[0];
168 * a {@link java.lang.String} object.
169 * @return a {@link org.eclipse.ui.IViewPart} object.
171 public static IViewPart
showView(String id
) {
173 return PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
175 .showView(id
, null, IWorkbenchPage
.VIEW_VISIBLE
);
176 } catch (PartInitException e
) {
177 errorDialog("Error opening view", AbstractUtility
.class, "Could not open view: " + id
, e
);
188 * a {@link org.eclipse.ui.IViewPart} object.
190 public static void hideView(IViewPart view
) {
191 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
201 * a {@link java.lang.String} object.
204 * @return a {@link org.eclipse.ui.IViewPart} object.
206 public static IViewPart
getView(String id
, boolean restore
) {
207 IViewReference
[] references
= PlatformUI
.getWorkbench()
208 .getActiveWorkbenchWindow().getActivePage().getViewReferences();
209 for (IViewReference reference
: references
) {
210 if (reference
.getId().equals(id
)) {
211 return reference
.getView(restore
);
223 * a {@link java.lang.Class} object.
224 * @return a {@link java.lang.Object} object.
226 public static Object
getService(Class api
) {
227 return TaxeditorStorePlugin
.getDefault().getWorkbench().getService(api
);
235 * @return a {@link org.eclipse.ui.themes.ITheme} object.
237 public static ITheme
getCurrentTheme() {
238 IThemeManager themeManager
= TaxeditorStorePlugin
.getDefault()
239 .getWorkbench().getThemeManager();
240 return themeManager
.getCurrentTheme();
244 * Fonts registered to the plugin may be obtained with the Eclipse themeing
245 * functionality. Thus fonts are chooseable by the user via
246 * Preferences->General->Appearance->Colors and Fonts
248 * @return the FontRegistry for the current theme
250 public static FontRegistry
getFontRegistry() {
251 return getCurrentTheme().getFontRegistry();
259 * @param symbolicName
260 * a {@link java.lang.String} object.
261 * @return a {@link org.eclipse.swt.graphics.Font} object.
263 public static Font
getFont(String symbolicName
) {
264 return getFontRegistry().get(symbolicName
);
268 * Color registered to the plugin may be obtained with the Eclipse themeing
269 * functionality. Thus colors are editable by the user via
270 * Preferences->General->Appearance->Colors and Fonts
272 * @return the ColorRegistry for the current theme
274 public static ColorRegistry
getColorRegistry() {
275 return getCurrentTheme().getColorRegistry();
283 * @param symbolicName
284 * a {@link java.lang.String} object.
285 * @return a {@link org.eclipse.swt.graphics.Color} object.
287 public static Color
getColor(String symbolicName
) {
288 return getColorRegistry().get(symbolicName
);
292 * Open a message box that informs the user about unimplemented
293 * functionality. This method is for developer convenience.
296 * a {@link java.lang.Object} object.
298 public static void notImplementedMessage(Object source
) {
299 warningDialog("Not yet implemented", source
,
300 "This functionality is not yet implemented.");
309 * a {@link java.lang.String} object.
311 * a {@link java.lang.String} object.
313 public static void informationDialog(final String title
,
314 final String message
) {
315 Display
.getDefault().asyncExec(new Runnable() {
319 MessageDialog
.openInformation(getShell(), title
, message
);
324 public static void informationDialog(final String title
,
325 final IStatus status
) {
326 informationDialog(title
, status
.getMessage());
337 * The object where the warning was generated (used by log4j)
339 * An informative String to be presented to the user
341 public static void warningDialog(final String title
, final Object source
,
342 final String message
) {
343 Display
.getDefault().asyncExec(new Runnable() {
347 MessageDialog
.openWarning(getShell(), title
, message
);
348 Class
<?
extends Object
> clazz
= source
!= null ? source
349 .getClass() : AbstractUtility
.class;
350 warn(clazz
, message
);
360 public static void warningDialog(String title
, Object source
,
362 warningDialog(title
, source
, status
.getMessage());
373 * The object where the warning was generated (used by log4j)
375 * An informative String to be presented to the user
379 * a Throwable if one exists or null
381 public static void errorDialog(final String title
, final Object source
,
382 final String message
, final Throwable t
) {
383 Display
.getDefault().asyncExec(new Runnable() {
387 MessageDialog
.openError(getShell(), title
, message
+ getCauseRecursively(t
));
388 Class
<?
extends Object
> clazz
= source
!= null ? source
389 .getClass() : this.getClass();
390 error(clazz
, message
, t
);
393 private String
getCauseRecursively(Throwable t
) {
398 if(t
.getCause() != null){
399 return getCauseRecursively(t
.getCause());
401 return String
.format("\n\nException: %s\nMessage: %s", t
.getClass().getSimpleName(), t
.getMessage());
408 public static void errorDialog(final String title
, final Object source
,
409 final String message
){
410 errorDialog(title
, source
, message
, null);
419 * a {@link java.lang.String} object.
421 * a {@link java.lang.Object} object.
423 * a {@link org.eclipse.core.runtime.IStatus} object.
425 public static void errorDialog(final String title
, final Object source
,
426 final IStatus status
) {
427 Display
.getDefault().asyncExec(new Runnable() {
431 ErrorDialog
.openError(getShell(), title
, null, status
);
432 Class
<?
extends Object
> clazz
= source
!= null ? source
433 .getClass() : this.getClass();
434 error(clazz
, status
);
445 * a {@link java.lang.String} object.
447 * a {@link java.lang.String} object.
450 public static boolean confirmDialog(String title
, String message
) {
451 return MessageDialog
.openQuestion(getShell(), title
, message
);
461 * {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
463 * @return a {@link org.eclipse.core.runtime.IStatus} object.
465 public static IStatus
executeOperation(final AbstractPostOperation operation
) {
466 if (getOperationHistory() == null) {
467 throw new IllegalArgumentException(
468 "There is no operation history for this context");
471 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
472 .getUIInfoAdapter(getShell());
474 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
477 public void run(IProgressMonitor monitor
)
478 throws InvocationTargetException
, InterruptedException
{
479 String operationlabel
= operation
.getLabel();
480 monitor
.beginTask(operationlabel
, 100);
481 IStatus status
= Status
.CANCEL_STATUS
;
483 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
484 status
= getOperationHistory().execute(operation
, monitor
,
486 } catch (ExecutionException e
) {
488 dialogForAbortedOperation(e
, this, operationlabel
, null);
494 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
496 setStatusLine(operationlabel
+ " " + statusString
+ ".");
502 runInUI(runnable
, null);
503 } catch (Exception e
) {
504 errorDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
507 // // Start the main progress monitor.
508 // IProgressMonitor newMonitor =
509 // startMainMonitor(getMonitor(),operation.getLabel(), 100);
511 // // Check whether operation was canceled and do some steps.
512 // workedChecked(newMonitor, 10);
515 // IStatus status = getOperationHistory().execute(operation, newMonitor,
516 // WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
518 // // Check whether operation was canceled and do some steps.
519 // workedChecked(newMonitor, 30);
521 // String statusString = status.equals(Status.OK_STATUS) ? "completed" :
523 // setStatusLine(operation.getLabel() + " " + statusString + ".");
526 // } catch (ExecutionException e) {
527 // logger.error("Error executing operation: " + operation.getLabel(),
529 // errorDialog("Error executing operation: " + operation.getLabel(),
530 // "Please refer to the error log.");
534 // // Stop the progress monitor.
535 // newMonitor.done();
538 IPostOperationEnabled postOperationEnabled
= operation
539 .getPostOperationEnabled();
540 if (postOperationEnabled
!= null) {
541 postOperationEnabled
.onComplete();
543 return Status
.OK_STATUS
;
548 * getOperationHistory
551 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
554 public static IOperationHistory
getOperationHistory() {
555 return getWorkbench().getOperationSupport().getOperationHistory();
564 * a {@link java.lang.String} object.
566 public static void setStatusLine(final String message
) {
567 Display
.getDefault().asyncExec(new Runnable() {
571 statusLineManager
.setMessage(message
);
583 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
585 public static IProgressMonitor
getMonitor() {
586 statusLineManager
.setCancelEnabled(false);
587 return statusLineManager
.getProgressMonitor();
591 * Starts either the given {@link IProgressMonitor} if it's not
592 * <code>null</code> or a new {@link NullProgressMonitor}.
594 * @param progressMonitor
595 * The {@link IProgressMonitor} or <code>null</code> if no
596 * progress should be reported.
598 * The name of the main task.
600 * The number of steps this task is subdivided into.
601 * @return The {@link IProgressMonitor}.
603 public static IProgressMonitor
startMainMonitor(
604 IProgressMonitor progressMonitor
, String taskName
, int steps
) {
605 IProgressMonitor newMonitor
= progressMonitor
;
606 if (newMonitor
== null) {
607 newMonitor
= new NullProgressMonitor();
609 newMonitor
.beginTask(taskName
== null ?
"" : taskName
, steps
);
610 newMonitor
.subTask(" ");
615 * Creates a {@link SubProgressMonitor} if the given
616 * {@link IProgressMonitor} is not <code>null</code> and not a
617 * {@link NullProgressMonitor}.
619 * @param progressMonitor
620 * The parent {@link IProgressMonitor} of the
621 * {@link SubProgressMonitor} to be created.
623 * The number of steps this subtask is subdivided into. Must be a
624 * positive number and must not be
625 * {@link IProgressMonitor#UNKNOWN}.
626 * @return The {@link IProgressMonitor}.
628 public static IProgressMonitor
getSubProgressMonitor(
629 IProgressMonitor progressMonitor
, int ticks
) {
630 if (progressMonitor
== null) {
631 return new NullProgressMonitor();
633 if (progressMonitor
instanceof NullProgressMonitor
) {
634 return progressMonitor
;
637 return new SubProgressMonitor(progressMonitor
, ticks
);
641 * Checks whether the user canceled this operation. If not canceled, the
642 * given number of steps are declared as done.
645 * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
649 public static void workedChecked(IProgressMonitor newMonitor
, int steps
) {
650 // In case the progress monitor was canceled throw an exception.
651 if (newMonitor
.isCanceled()) {
652 throw new OperationCanceledException();
654 // Otherwise declare this step as done.
655 newMonitor
.worked(steps
);
659 * Present a progress dialog to the user. This dialog will block the UI
662 * an implementation of {@link IRunnableWithProgress}
663 * @throws java.lang.InterruptedException
665 * @throws java.lang.reflect.InvocationTargetException
668 public static void busyCursorWhile(IRunnableWithProgress runnable
)
669 throws InvocationTargetException
, InterruptedException
{
670 getProgressService().busyCursorWhile(runnable
);
678 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
680 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
683 * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
685 * @throws java.lang.reflect.InvocationTargetException
687 * @throws java.lang.InterruptedException
690 public static void runInUI(IRunnableWithProgress runnable
,
691 ISchedulingRule rule
) throws InvocationTargetException
,
692 InterruptedException
{
693 getProgressService().runInUI(getWorkbenchWindow(), runnable
, rule
);
706 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
708 * @throws java.lang.reflect.InvocationTargetException
710 * @throws java.lang.InterruptedException
713 public static void run(boolean fork
, boolean cancelable
,
714 IRunnableWithProgress runnable
) throws InvocationTargetException
,
715 InterruptedException
{
716 getProgressService().run(fork
, cancelable
, runnable
);
724 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
726 public static IProgressService
getProgressService() {
727 IWorkbench workbench
= PlatformUI
.getWorkbench();
728 return workbench
.getProgressService();
733 * getProgressService2
736 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
739 public static IWorkbenchSiteProgressService
getProgressService2() {
740 return (IWorkbenchSiteProgressService
) getService(IWorkbenchSiteProgressService
.class);
749 * a {@link java.lang.String} object.
751 public static void info(String message
) {
752 IStatus status
= new Status(IStatus
.INFO
, getPluginId(), message
);
762 * a {@link org.eclipse.core.runtime.IStatus} object.
764 public static void info(IStatus status
) {
774 * a {@link java.lang.Class} object.
776 * a {@link java.lang.String} object.
778 public static void warn(Class source
, String message
) {
779 IStatus status
= new Status(IStatus
.WARNING
, getPluginId(), message
);
780 getLog4JLogger(source
).warn(message
);
784 public static void warn(Class source
, IStatus status
) {
785 getLog4JLogger(source
).warn(status
.getMessage(), status
.getException());
789 public static void warn(Class source
, Throwable t
) {
790 IStatus status
= new Status(IStatus
.WARNING
, getPluginId(), t
.getMessage(), t
);
791 getLog4JLogger(source
).warn(t
);
801 * a {@link java.lang.Class} object.
803 * a {@link java.lang.Throwable} object.
805 public static void error(Class source
, Throwable t
) {
806 error(source
.getClass(), t
.getMessage(), t
);
815 * a {@link java.lang.Class} object.
817 * a {@link java.lang.String} object.
819 * a {@link java.lang.Throwable} object.
821 public static void error(Class source
, String message
, Throwable t
) {
822 IStatus status
= new Status(IStatus
.ERROR
, getPluginId(), message
, t
);
823 error(source
, status
);
832 * a {@link java.lang.Class} object.
834 * a {@link org.eclipse.core.runtime.IStatus} object.
836 public static void error(Class source
, IStatus status
) {
837 getLog4JLogger(source
)
838 .error(status
.getMessage(), status
.getException());
848 * a {@link java.lang.Class} object.
849 * @return a {@link org.apache.log4j.Logger} object.
851 public static Logger
getLog4JLogger(Class clazz
) {
852 return Logger
.getLogger(clazz
);
856 * @see {@link ILog#log(IStatus)}
860 private static void log(IStatus status
) {
861 TaxeditorStorePlugin
.getDefault().getLog().log(status
);
869 * @return a {@link java.lang.String} object.
871 public static String
getPluginId() {
872 return "eu.taxeditor";
880 * @return a {@link org.eclipse.ui.IEditorPart} object.
882 public static IEditorPart
getActiveEditor() {
883 return getActivePage() != null ?
getActivePage().getActiveEditor()
892 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
895 public static DetailsViewPart
getDetailsView() {
896 return (DetailsViewPart
) getView(DetailsViewPart
.ID
, false);
901 * refreshDetailsViewer
904 public static void refreshDetailsViewer() {
905 if (getDetailsView() != null) {
906 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).refresh();
912 * reflowDetailsViewer
915 public static void reflowDetailsViewer() {
916 if (getDetailsView() != null) {
917 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).reflow();
921 public static SupplementalDataViewPart
getSupplementalDataView() {
922 return (SupplementalDataViewPart
) getView(SupplementalDataViewPart
.ID
,
926 public static void reflowSupplementalViewer() {
927 if (getSupplementalDataView() != null) {
928 ((AbstractCdmDataViewer
) getSupplementalDataView().getViewer())
935 * Orders a Collection of {@link IEnumTerm}s according to the term
938 * The returned map will be be ordered primarily by root elements,
939 * secondarily by the child elements and their children resp., both ascending alphabetically. <br>
941 * A {@link Collection} of {@link IEnumTerm}s for which the term
942 * hierarchy should be created
943 * @return a map which holds the terms as keys and their string
944 * representation via {@link IEnumTerm#getMessage()} as values
946 public static <T
extends IEnumTerm
<T
>> LinkedHashMap
<T
, String
> orderTerms(Collection
<T
> terms
) {
947 TreeSet
<TermNode
<T
>> parentElements
= new TreeSet
<TermNode
<T
>>();
948 parentElements
.addAll(getTermHierarchy(terms
));
950 // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically)
951 LinkedHashMap
<T
, String
> result
= new LinkedHashMap
<T
, String
>();
952 parseTermTree(parentElements
, result
, -1);
956 private static<T
extends IEnumTerm
<T
>> void parseTermTree(Collection
<TermNode
<T
>> children
, LinkedHashMap
<T
, String
> result
, int depth
){
958 for(TermNode
<T
> node
:children
){
959 String indentString
= "";
960 for(int i
=0;i
<depth
;i
++){
964 indentString
+= "- ";
966 result
.put(node
.term
, indentString
+ node
.term
.getMessage());
967 parseTermTree(node
.children
, result
, depth
);
971 private static<T
extends IEnumTerm
<T
>> void addToParents(List
<TermNode
<T
>> parents
, Collection
<T
> terms
){
972 List
<TermNode
<T
>> hasChildrenList
= new ArrayList
<TermNode
<T
>>();
974 // only terms with parents
975 if(term
.getKindOf()!=null){
976 TermNode
<T
> parentNode
= new TermNode
<T
>(term
.getKindOf());
977 TermNode
<T
> childNode
= new TermNode
<T
>(term
);
978 if(parents
.contains(parentNode
)){
979 // parent found in parent list -> add this term to parent's child list
980 parents
.get(parents
.indexOf(parentNode
)).addChild(childNode
);
981 if(!term
.getGeneralizationOf().isEmpty()){
982 // has more children -> add to list which will be the parent for the next recursion
983 hasChildrenList
.add(childNode
);
988 if(!hasChildrenList
.isEmpty()){
989 addToParents(hasChildrenList
, terms
);
993 private static<T
extends IEnumTerm
<T
>> List
<TermNode
<T
>> getTermHierarchy(Collection
<T
> terms
){
994 List
<TermNode
<T
>> parents
= new ArrayList
<TermNode
<T
>>();
997 T parentTerm
= term
.getKindOf();
998 if(parentTerm
==null){
1000 parents
.add(new TermNode
<T
>(term
));
1003 addToParents(parents
, terms
);
1007 @SuppressWarnings("unchecked")
1009 * Recursively iterates over all term parents until no more parent is found i.e. the root node
1010 * @param term The term for which the parent should be found
1011 * @return the root terms of the term hierarchy
1013 private static<T
extends IEnumTerm
<T
>> T
getParentFor(T term
){
1014 // PP: cast should be safe. Why is Eclipse complaining??
1015 T parent
= term
.getKindOf();
1020 return getParentFor(term
.getKindOf());
1024 public static void dialogForAbortedOperation(Exception e
, final Object source
, String operationlabel
, String hint
) {
1025 MultiStatus info
= null;
1026 String title
= null;
1028 // FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here
1029 // String PID = TaxonomicEditorPlugin.PLUGIN_ID;
1030 String PID
= "eu.etaxonomy.taxeditor.application";
1032 RuntimeException securityRuntimeException
= SecurityExceptionUtils
.findSecurityRuntimeException(e
);
1034 if(securityRuntimeException
!= null){
1035 title
= "Your changes could not be saved!";
1036 info
= new MultiStatus(PID
, 1, String
.format("You are missing sufficient permissions for the operation \"%s\". %s", operationlabel
, hint
), null);
1037 info
.add(new Status(IStatus
.WARNING
, PID
, 1, securityRuntimeException
.getMessage(), null));
1040 title
= "Error executing operation";
1041 info
= new MultiStatus(PID
, 1, String
.format("An error occured while executing %s. %s", operationlabel
, hint
), null);
1042 Writer writer
= new StringWriter();
1043 PrintWriter printWriter
= new PrintWriter(writer
);
1044 e
.printStackTrace(printWriter
);
1045 info
.add(new Status(IStatus
.ERROR
, PID
, 1, writer
.toString(), null));
1048 errorDialog(title
, source
, info
);
1051 private static class TermNode
<T
extends IEnumTerm
<T
>> implements Comparable
<TermNode
<T
>>{
1052 private final T term
;
1053 private final TreeSet
<TermNode
<T
>> children
;
1059 public TermNode(T term
) {
1062 this.children
= new TreeSet
<TermNode
<T
>>();
1065 public void addChild(TermNode
<T
> child
){
1066 this.children
.add(child
);
1070 * @return the children
1072 public TreeSet
<TermNode
<T
>> getChildren() {
1079 public T
getTerm() {
1084 * @see java.lang.Object#hashCode()
1087 public int hashCode() {
1088 final int prime
= 31;
1090 result
= prime
* result
+ ((term
== null) ?
0 : term
.hashCode());
1095 * @see java.lang.Object#equals(java.lang.Object)
1098 public boolean equals(Object obj
) {
1105 if (getClass() != obj
.getClass()) {
1108 TermNode other
= (TermNode
) obj
;
1110 if (other
.term
!= null) {
1113 } else if (!term
.equals(other
.term
)) {
1120 * @see java.lang.Comparable#compareTo(java.lang.Object)
1123 public int compareTo(TermNode
<T
> that
) {
1124 return this.term
.getMessage().compareTo(that
.term
.getMessage());