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
.lang
.reflect
.InvocationTargetException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.LinkedHashMap
;
17 import java
.util
.List
;
18 import java
.util
.TreeSet
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
23 import org
.eclipse
.core
.runtime
.IAdaptable
;
24 import org
.eclipse
.core
.runtime
.ILog
;
25 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
26 import org
.eclipse
.core
.runtime
.IStatus
;
27 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
29 import org
.eclipse
.core
.runtime
.Status
;
30 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
31 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
32 import org
.eclipse
.jface
.action
.IStatusLineManager
;
33 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
34 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
35 import org
.eclipse
.jface
.resource
.ColorRegistry
;
36 import org
.eclipse
.jface
.resource
.FontRegistry
;
37 import org
.eclipse
.jface
.window
.ApplicationWindow
;
38 import org
.eclipse
.swt
.graphics
.Color
;
39 import org
.eclipse
.swt
.graphics
.Font
;
40 import org
.eclipse
.swt
.widgets
.Display
;
41 import org
.eclipse
.swt
.widgets
.Shell
;
42 import org
.eclipse
.ui
.IEditorPart
;
43 import org
.eclipse
.ui
.IViewPart
;
44 import org
.eclipse
.ui
.IViewReference
;
45 import org
.eclipse
.ui
.IWorkbench
;
46 import org
.eclipse
.ui
.IWorkbenchPage
;
47 import org
.eclipse
.ui
.IWorkbenchPart
;
48 import org
.eclipse
.ui
.PartInitException
;
49 import org
.eclipse
.ui
.PlatformUI
;
50 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
51 import org
.eclipse
.ui
.part
.EditorPart
;
52 import org
.eclipse
.ui
.progress
.IProgressService
;
53 import org
.eclipse
.ui
.progress
.IWorkbenchSiteProgressService
;
54 import org
.eclipse
.ui
.themes
.ITheme
;
55 import org
.eclipse
.ui
.themes
.IThemeManager
;
57 import eu
.etaxonomy
.cdm
.model
.common
.IEnumTerm
;
58 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
59 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
60 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
61 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmDataViewer
;
62 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
63 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
67 * Abstract AbstractUtility class.
74 public abstract class AbstractUtility
{
76 /** Constant <code>statusLineManager</code> */
77 protected static IStatusLineManager statusLineManager
;
86 public static boolean closeAll() {
87 return getActivePage().closeAllEditors(true);
91 * Close the given editor.
94 * The <tt>MultipageTaxonEditor</tt> to close.
95 * @return <tt>true</tt> on success
97 public static boolean close(EditorPart editor
) {
98 return getActivePage().closeEditor(editor
, true);
106 * @return a {@link org.eclipse.swt.widgets.Shell} object.
108 public static Shell
getShell() {
110 return TaxeditorStorePlugin
.getDefault().getWorkbench()
111 .getActiveWorkbenchWindow().getShell();
119 * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
121 public static IWorkbenchPage
getActivePage() {
123 return TaxeditorStorePlugin
.getDefault().getWorkbench()
124 .getActiveWorkbenchWindow().getActivePage();
132 * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
134 public static IWorkbenchPart
getActivePart() {
135 return getActivePage() != null ?
getActivePage().getActivePart() : null;
138 public static IWorkbench
getWorkbench() {
139 return TaxeditorStorePlugin
.getDefault().getWorkbench();
147 * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
149 public static ApplicationWindow
getWorkbenchWindow() {
150 if (getWorkbench().getWorkbenchWindowCount() > 1) {
151 throw new IllegalStateException("More than one workbench window");
153 return (ApplicationWindow
) getWorkbench().getWorkbenchWindows()[0];
162 * a {@link java.lang.String} object.
163 * @return a {@link org.eclipse.ui.IViewPart} object.
165 public static IViewPart
showView(String id
) {
167 return PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
169 .showView(id
, null, IWorkbenchPage
.VIEW_VISIBLE
);
170 } catch (PartInitException e
) {
171 errorDialog("Error opening view", AbstractUtility
.class, "Could not open view: " + id
, e
);
182 * a {@link org.eclipse.ui.IViewPart} object.
184 public static void hideView(IViewPart view
) {
185 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
195 * a {@link java.lang.String} object.
198 * @return a {@link org.eclipse.ui.IViewPart} object.
200 public static IViewPart
getView(String id
, boolean restore
) {
201 IViewReference
[] references
= PlatformUI
.getWorkbench()
202 .getActiveWorkbenchWindow().getActivePage().getViewReferences();
203 for (IViewReference reference
: references
) {
204 if (reference
.getId().equals(id
)) {
205 return reference
.getView(restore
);
217 * a {@link java.lang.Class} object.
218 * @return a {@link java.lang.Object} object.
220 public static Object
getService(Class api
) {
221 return TaxeditorStorePlugin
.getDefault().getWorkbench().getService(api
);
229 * @return a {@link org.eclipse.ui.themes.ITheme} object.
231 public static ITheme
getCurrentTheme() {
232 IThemeManager themeManager
= TaxeditorStorePlugin
.getDefault()
233 .getWorkbench().getThemeManager();
234 return themeManager
.getCurrentTheme();
238 * Fonts registered to the plugin may be obtained with the Eclipse themeing
239 * functionality. Thus fonts are chooseable by the user via
240 * Preferences->General->Appearance->Colors and Fonts
242 * @return the FontRegistry for the current theme
244 public static FontRegistry
getFontRegistry() {
245 return getCurrentTheme().getFontRegistry();
253 * @param symbolicName
254 * a {@link java.lang.String} object.
255 * @return a {@link org.eclipse.swt.graphics.Font} object.
257 public static Font
getFont(String symbolicName
) {
258 return getFontRegistry().get(symbolicName
);
262 * Color registered to the plugin may be obtained with the Eclipse themeing
263 * functionality. Thus colors are editable by the user via
264 * Preferences->General->Appearance->Colors and Fonts
266 * @return the ColorRegistry for the current theme
268 public static ColorRegistry
getColorRegistry() {
269 return getCurrentTheme().getColorRegistry();
277 * @param symbolicName
278 * a {@link java.lang.String} object.
279 * @return a {@link org.eclipse.swt.graphics.Color} object.
281 public static Color
getColor(String symbolicName
) {
282 return getColorRegistry().get(symbolicName
);
286 * Open a message box that informs the user about unimplemented
287 * functionality. This method is for developer convenience.
290 * a {@link java.lang.Object} object.
292 public static void notImplementedMessage(Object source
) {
293 warningDialog("Not yet implemented", source
,
294 "This functionality is not yet implemented.");
303 * a {@link java.lang.String} object.
305 * a {@link java.lang.String} object.
307 public static void informationDialog(final String title
,
308 final String message
) {
309 Display
.getDefault().asyncExec(new Runnable() {
313 MessageDialog
.openInformation(getShell(), title
, message
);
318 public static void informationDialog(final String title
,
319 final IStatus status
) {
320 informationDialog(title
, status
.getMessage());
331 * The object where the warning was generated (used by log4j)
333 * An informative String to be presented to the user
335 public static void warningDialog(final String title
, final Object source
,
336 final String message
) {
337 Display
.getDefault().asyncExec(new Runnable() {
341 MessageDialog
.openWarning(getShell(), title
, message
);
342 Class
<?
extends Object
> clazz
= source
!= null ? source
343 .getClass() : AbstractUtility
.class;
344 warn(clazz
, message
);
354 public static void warningDialog(String title
, Object source
,
356 warningDialog(title
, source
, status
.getMessage());
367 * The object where the warning was generated (used by log4j)
369 * An informative String to be presented to the user
373 * a Throwable if one exists or null
375 public static void errorDialog(final String title
, final Object source
,
376 final String message
, final Throwable t
) {
377 Display
.getDefault().asyncExec(new Runnable() {
381 MessageDialog
.openError(getShell(), title
, message
+ getCauseRecursively(t
));
382 Class
<?
extends Object
> clazz
= source
!= null ? source
383 .getClass() : this.getClass();
384 error(clazz
, message
, t
);
387 private String
getCauseRecursively(Throwable t
) {
392 if(t
.getCause() != null){
393 return getCauseRecursively(t
.getCause());
395 return String
.format("\n\nException: %s\nMessage: %s", t
.getClass().getSimpleName(), t
.getMessage());
402 public static void errorDialog(final String title
, final Object source
,
403 final String message
){
404 errorDialog(title
, source
, message
, null);
413 * a {@link java.lang.String} object.
415 * a {@link java.lang.Object} object.
417 * a {@link org.eclipse.core.runtime.IStatus} object.
419 public static void errorDialog(final String title
, final Object source
,
420 final IStatus status
) {
421 Display
.getDefault().asyncExec(new Runnable() {
425 MessageDialog
.openError(getShell(), title
, status
.getMessage());
426 Class
<?
extends Object
> clazz
= source
!= null ? source
427 .getClass() : this.getClass();
428 error(clazz
, status
.getMessage(), status
.getException());
439 * a {@link java.lang.String} object.
441 * a {@link java.lang.String} object.
444 public static boolean confirmDialog(String title
, String message
) {
445 return MessageDialog
.openQuestion(getShell(), title
, message
);
455 * {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
457 * @return a {@link org.eclipse.core.runtime.IStatus} object.
459 public static IStatus
executeOperation(final AbstractPostOperation operation
) {
460 if (getOperationHistory() == null) {
461 throw new IllegalArgumentException(
462 "There is no operation history for this context");
465 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
466 .getUIInfoAdapter(getShell());
468 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
471 public void run(IProgressMonitor monitor
)
472 throws InvocationTargetException
, InterruptedException
{
473 monitor
.beginTask(operation
.getLabel(), 100);
474 IStatus status
= Status
.CANCEL_STATUS
;
476 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
477 status
= getOperationHistory().execute(operation
, monitor
,
479 } catch (ExecutionException e
) {
480 errorDialog("Error executing operation", getClass(), String
.format("An error occured while executing %s.", operation
.getLabel()), e
);
485 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
487 setStatusLine(operation
.getLabel() + " " + statusString
+ ".");
493 runInUI(runnable
, null);
494 } catch (Exception e
) {
495 errorDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
498 // // Start the main progress monitor.
499 // IProgressMonitor newMonitor =
500 // startMainMonitor(getMonitor(),operation.getLabel(), 100);
502 // // Check whether operation was canceled and do some steps.
503 // workedChecked(newMonitor, 10);
506 // IStatus status = getOperationHistory().execute(operation, newMonitor,
507 // WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
509 // // Check whether operation was canceled and do some steps.
510 // workedChecked(newMonitor, 30);
512 // String statusString = status.equals(Status.OK_STATUS) ? "completed" :
514 // setStatusLine(operation.getLabel() + " " + statusString + ".");
517 // } catch (ExecutionException e) {
518 // logger.error("Error executing operation: " + operation.getLabel(),
520 // errorDialog("Error executing operation: " + operation.getLabel(),
521 // "Please refer to the error log.");
525 // // Stop the progress monitor.
526 // newMonitor.done();
529 IPostOperationEnabled postOperationEnabled
= operation
530 .getPostOperationEnabled();
531 if (postOperationEnabled
!= null) {
532 postOperationEnabled
.onComplete();
534 return Status
.OK_STATUS
;
539 * getOperationHistory
542 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
545 public static IOperationHistory
getOperationHistory() {
546 return getWorkbench().getOperationSupport().getOperationHistory();
555 * a {@link java.lang.String} object.
557 public static void setStatusLine(final String message
) {
558 Display
.getDefault().asyncExec(new Runnable() {
562 statusLineManager
.setMessage(message
);
574 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
576 public static IProgressMonitor
getMonitor() {
577 statusLineManager
.setCancelEnabled(false);
578 return statusLineManager
.getProgressMonitor();
582 * Starts either the given {@link IProgressMonitor} if it's not
583 * <code>null</code> or a new {@link NullProgressMonitor}.
585 * @param progressMonitor
586 * The {@link IProgressMonitor} or <code>null</code> if no
587 * progress should be reported.
589 * The name of the main task.
591 * The number of steps this task is subdivided into.
592 * @return The {@link IProgressMonitor}.
594 public static IProgressMonitor
startMainMonitor(
595 IProgressMonitor progressMonitor
, String taskName
, int steps
) {
596 IProgressMonitor newMonitor
= progressMonitor
;
597 if (newMonitor
== null) {
598 newMonitor
= new NullProgressMonitor();
600 newMonitor
.beginTask(taskName
== null ?
"" : taskName
, steps
);
601 newMonitor
.subTask(" ");
606 * Creates a {@link SubProgressMonitor} if the given
607 * {@link IProgressMonitor} is not <code>null</code> and not a
608 * {@link NullProgressMonitor}.
610 * @param progressMonitor
611 * The parent {@link IProgressMonitor} of the
612 * {@link SubProgressMonitor} to be created.
614 * The number of steps this subtask is subdivided into. Must be a
615 * positive number and must not be
616 * {@link IProgressMonitor#UNKNOWN}.
617 * @return The {@link IProgressMonitor}.
619 public static IProgressMonitor
getSubProgressMonitor(
620 IProgressMonitor progressMonitor
, int ticks
) {
621 if (progressMonitor
== null) {
622 return new NullProgressMonitor();
624 if (progressMonitor
instanceof NullProgressMonitor
) {
625 return progressMonitor
;
628 return new SubProgressMonitor(progressMonitor
, ticks
);
632 * Checks whether the user canceled this operation. If not canceled, the
633 * given number of steps are declared as done.
636 * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
640 public static void workedChecked(IProgressMonitor newMonitor
, int steps
) {
641 // In case the progress monitor was canceled throw an exception.
642 if (newMonitor
.isCanceled()) {
643 throw new OperationCanceledException();
645 // Otherwise declare this step as done.
646 newMonitor
.worked(steps
);
650 * Present a progress dialog to the user. This dialog will block the UI
653 * an implementation of {@link IRunnableWithProgress}
654 * @throws java.lang.InterruptedException
656 * @throws java.lang.reflect.InvocationTargetException
659 public static void busyCursorWhile(IRunnableWithProgress runnable
)
660 throws InvocationTargetException
, InterruptedException
{
661 getProgressService().busyCursorWhile(runnable
);
669 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
671 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
674 * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
676 * @throws java.lang.reflect.InvocationTargetException
678 * @throws java.lang.InterruptedException
681 public static void runInUI(IRunnableWithProgress runnable
,
682 ISchedulingRule rule
) throws InvocationTargetException
,
683 InterruptedException
{
684 getProgressService().runInUI(getWorkbenchWindow(), runnable
, rule
);
697 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
699 * @throws java.lang.reflect.InvocationTargetException
701 * @throws java.lang.InterruptedException
704 public static void run(boolean fork
, boolean cancelable
,
705 IRunnableWithProgress runnable
) throws InvocationTargetException
,
706 InterruptedException
{
707 getProgressService().run(fork
, cancelable
, runnable
);
715 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
717 public static IProgressService
getProgressService() {
718 IWorkbench workbench
= PlatformUI
.getWorkbench();
719 return workbench
.getProgressService();
724 * getProgressService2
727 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
730 public static IWorkbenchSiteProgressService
getProgressService2() {
731 return (IWorkbenchSiteProgressService
) getService(IWorkbenchSiteProgressService
.class);
740 * a {@link java.lang.String} object.
742 public static void info(String message
) {
743 IStatus status
= new Status(IStatus
.INFO
, getPluginId(), message
);
753 * a {@link org.eclipse.core.runtime.IStatus} object.
755 public static void info(IStatus status
) {
765 * a {@link java.lang.Class} object.
767 * a {@link java.lang.String} object.
769 public static void warn(Class source
, String message
) {
770 IStatus status
= new Status(IStatus
.WARNING
, getPluginId(), message
);
771 getLog4JLogger(source
).warn(message
);
775 public static void warn(Class source
, IStatus status
) {
776 getLog4JLogger(source
).warn(status
.getMessage(), status
.getException());
780 public static void warn(Class source
, Throwable t
) {
781 IStatus status
= new Status(IStatus
.WARNING
, getPluginId(), t
.getMessage(), t
);
782 getLog4JLogger(source
).warn(t
);
792 * a {@link java.lang.Class} object.
794 * a {@link java.lang.Throwable} object.
796 public static void error(Class source
, Throwable t
) {
797 error(source
.getClass(), t
.getMessage(), t
);
806 * a {@link java.lang.Class} object.
808 * a {@link java.lang.String} object.
810 * a {@link java.lang.Throwable} object.
812 public static void error(Class source
, String message
, Throwable t
) {
813 IStatus status
= new Status(IStatus
.ERROR
, getPluginId(), message
, t
);
814 error(source
, status
);
823 * a {@link java.lang.Class} object.
825 * a {@link org.eclipse.core.runtime.IStatus} object.
827 public static void error(Class source
, IStatus status
) {
828 getLog4JLogger(source
)
829 .error(status
.getMessage(), status
.getException());
839 * a {@link java.lang.Class} object.
840 * @return a {@link org.apache.log4j.Logger} object.
842 public static Logger
getLog4JLogger(Class clazz
) {
843 return Logger
.getLogger(clazz
);
847 * @see {@link ILog#log(IStatus)}
851 private static void log(IStatus status
) {
852 TaxeditorStorePlugin
.getDefault().getLog().log(status
);
860 * @return a {@link java.lang.String} object.
862 public static String
getPluginId() {
863 return "eu.taxeditor";
871 * @return a {@link org.eclipse.ui.IEditorPart} object.
873 public static IEditorPart
getActiveEditor() {
874 return getActivePage() != null ?
getActivePage().getActiveEditor()
883 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
886 public static DetailsViewPart
getDetailsView() {
887 return (DetailsViewPart
) getView(DetailsViewPart
.ID
, false);
892 * refreshDetailsViewer
895 public static void refreshDetailsViewer() {
896 if (getDetailsView() != null) {
897 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).refresh();
903 * reflowDetailsViewer
906 public static void reflowDetailsViewer() {
907 if (getDetailsView() != null) {
908 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).reflow();
912 public static SupplementalDataViewPart
getSupplementalDataView() {
913 return (SupplementalDataViewPart
) getView(SupplementalDataViewPart
.ID
,
917 public static void reflowSupplementalViewer() {
918 if (getSupplementalDataView() != null) {
919 ((AbstractCdmDataViewer
) getSupplementalDataView().getViewer())
926 * Orders a Collection of {@link IEnumTerm}s according to the term
929 * The returned map will be be ordered primarily by root elements,
930 * secondarily by the child elements and their children resp., both ascending alphabetically. <br>
932 * A {@link Collection} of {@link IEnumTerm}s for which the term
933 * hierarchy should be created
934 * @return a map which holds the terms as keys and their string
935 * representation via {@link IEnumTerm#getMessage()} as values
937 public static <T
extends IEnumTerm
<T
>> LinkedHashMap
<T
, String
> orderTerms(Collection
<T
> terms
) {
938 TreeSet
<TermNode
<T
>> parentElements
= new TreeSet
<TermNode
<T
>>();
939 parentElements
.addAll(getTermHierarchy(terms
));
941 // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically)
942 LinkedHashMap
<T
, String
> result
= new LinkedHashMap
<T
, String
>();
943 parseTermTree(parentElements
, result
, -1);
947 private static<T
extends IEnumTerm
<T
>> void parseTermTree(Collection
<TermNode
<T
>> children
, LinkedHashMap
<T
, String
> result
, int depth
){
949 for(TermNode
<T
> node
:children
){
950 String indentString
= "";
951 for(int i
=0;i
<depth
;i
++){
955 indentString
+= "- ";
957 result
.put(node
.term
, indentString
+ node
.term
.getMessage());
958 parseTermTree(node
.children
, result
, depth
);
962 private static<T
extends IEnumTerm
<T
>> void addToParents(List
<TermNode
<T
>> parents
, Collection
<T
> terms
){
963 List
<TermNode
<T
>> hasChildrenList
= new ArrayList
<TermNode
<T
>>();
965 // only terms with parents
966 if(term
.getKindOf()!=null){
967 TermNode
<T
> parentNode
= new TermNode
<T
>(term
.getKindOf());
968 TermNode
<T
> childNode
= new TermNode
<T
>(term
);
969 if(parents
.contains(parentNode
)){
970 // parent found in parent list -> add this term to parent's child list
971 parents
.get(parents
.indexOf(parentNode
)).addChild(childNode
);
972 if(!term
.getGeneralizationOf().isEmpty()){
973 // has more children -> add to list which will be the parent for the next recursion
974 hasChildrenList
.add(childNode
);
979 if(!hasChildrenList
.isEmpty()){
980 addToParents(hasChildrenList
, terms
);
984 private static<T
extends IEnumTerm
<T
>> List
<TermNode
<T
>> getTermHierarchy(Collection
<T
> terms
){
985 List
<TermNode
<T
>> parents
= new ArrayList
<TermNode
<T
>>();
988 T parentTerm
= term
.getKindOf();
989 if(parentTerm
==null){
991 parents
.add(new TermNode
<T
>(term
));
994 addToParents(parents
, terms
);
998 @SuppressWarnings("unchecked")
1000 * Recursively iterates over all term parents until no more parent is found i.e. the root node
1001 * @param term The term for which the parent should be found
1002 * @return the root terms of the term hierarchy
1004 private static<T
extends IEnumTerm
<T
>> T
getParentFor(T term
){
1005 // PP: cast should be safe. Why is Eclipse complaining??
1006 T parent
= term
.getKindOf();
1011 return getParentFor(term
.getKindOf());
1015 private static class TermNode
<T
extends IEnumTerm
<T
>> implements Comparable
<TermNode
<T
>>{
1016 private final T term
;
1017 private final TreeSet
<TermNode
<T
>> children
;
1023 public TermNode(T term
) {
1026 this.children
= new TreeSet
<TermNode
<T
>>();
1029 public void addChild(TermNode
<T
> child
){
1030 this.children
.add(child
);
1034 * @return the children
1036 public TreeSet
<TermNode
<T
>> getChildren() {
1043 public T
getTerm() {
1048 * @see java.lang.Object#hashCode()
1051 public int hashCode() {
1052 final int prime
= 31;
1054 result
= prime
* result
+ ((term
== null) ?
0 : term
.hashCode());
1059 * @see java.lang.Object#equals(java.lang.Object)
1062 public boolean equals(Object obj
) {
1069 if (getClass() != obj
.getClass()) {
1072 TermNode other
= (TermNode
) obj
;
1074 if (other
.term
!= null) {
1077 } else if (!term
.equals(other
.term
)) {
1084 * @see java.lang.Comparable#compareTo(java.lang.Object)
1087 public int compareTo(TermNode
<T
> that
) {
1088 return this.term
.getMessage().compareTo(that
.term
.getMessage());