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
;
19 import java
.util
.UUID
;
21 import org
.apache
.commons
.lang
.StringUtils
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.eclipse
.core
.commands
.ExecutionException
;
24 import org
.eclipse
.core
.commands
.NotEnabledException
;
25 import org
.eclipse
.core
.commands
.NotHandledException
;
26 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
27 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
28 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
29 import org
.eclipse
.core
.runtime
.IAdaptable
;
30 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
31 import org
.eclipse
.core
.runtime
.IStatus
;
32 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
33 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
34 import org
.eclipse
.core
.runtime
.Status
;
35 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
36 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
37 import org
.eclipse
.core
.runtime
.jobs
.Job
;
38 import org
.eclipse
.jface
.action
.IStatusLineManager
;
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
.IWorkbenchWindow
;
54 import org
.eclipse
.ui
.PartInitException
;
55 import org
.eclipse
.ui
.PlatformUI
;
56 import org
.eclipse
.ui
.handlers
.IHandlerService
;
57 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
58 import org
.eclipse
.ui
.part
.EditorPart
;
59 import org
.eclipse
.ui
.progress
.IProgressConstants
;
60 import org
.eclipse
.ui
.progress
.IProgressService
;
61 import org
.eclipse
.ui
.progress
.IWorkbenchSiteProgressService
;
62 import org
.eclipse
.ui
.themes
.ITheme
;
63 import org
.eclipse
.ui
.themes
.IThemeManager
;
65 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
66 import eu
.etaxonomy
.cdm
.api
.service
.IProgressMonitorService
;
67 import eu
.etaxonomy
.cdm
.common
.monitor
.IRemotingProgressMonitor
;
68 import eu
.etaxonomy
.cdm
.model
.common
.IEnumTerm
;
69 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
70 import eu
.etaxonomy
.taxeditor
.operation
.IFeedbackGenerator
;
71 import eu
.etaxonomy
.taxeditor
.operation
.IPostMoniteredOperationEnabled
;
72 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
73 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
74 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
75 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
76 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.ReportTextDialog
;
77 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmDataViewer
;
78 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
79 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
83 * Abstract AbstractUtility class.
90 public abstract class AbstractUtility
{
92 private static final Logger logger
= Logger
.getLogger(AbstractUtility
.class);
94 /** Constant <code>statusLineManager</code> */
95 protected static IStatusLineManager statusLineManager
;
105 public static boolean closeAll() {
106 return getActivePage().closeAllEditors(true);
110 * Close the given editor.
113 * The <tt>MultipageTaxonEditor</tt> to close.
114 * @return <tt>true</tt> on success
116 public static boolean close(EditorPart editor
) {
117 return getActivePage().closeEditor(editor
, true);
125 * @return a {@link org.eclipse.swt.widgets.Shell} object.
127 public static Shell
getShell() {
129 return TaxeditorStorePlugin
.getDefault().getWorkbench()
130 .getActiveWorkbenchWindow().getShell();
138 * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
140 public static IWorkbenchPage
getActivePage() {
142 return TaxeditorStorePlugin
.getDefault().getWorkbench()
143 .getActiveWorkbenchWindow().getActivePage();
151 * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
153 public static IWorkbenchPart
getActivePart() {
154 return getActivePage() != null ?
getActivePage().getActivePart() : null;
157 public static IWorkbench
getWorkbench() {
158 return TaxeditorStorePlugin
.getDefault().getWorkbench();
166 * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
168 public static ApplicationWindow
getWorkbenchWindow() {
169 if (getWorkbench().getWorkbenchWindowCount() > 1) {
170 throw new IllegalStateException("More than one workbench window");
172 return (ApplicationWindow
) getWorkbench().getWorkbenchWindows()[0];
181 * a {@link java.lang.String} object.
182 * @return a {@link org.eclipse.ui.IViewPart} object.
184 public static IViewPart
showView(String id
) {
186 return PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
188 .showView(id
, null, IWorkbenchPage
.VIEW_VISIBLE
);
189 } catch (PartInitException e
) {
190 MessagingUtils
.messageDialog("Error opening view", AbstractUtility
.class, "Could not open view: " + id
, e
);
201 * a {@link org.eclipse.ui.IViewPart} object.
203 public static void hideView(IViewPart view
) {
204 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
214 * a {@link java.lang.String} object.
217 * @return a {@link org.eclipse.ui.IViewPart} object.
219 public static IViewPart
getView(String id
, boolean restore
) {
220 IWorkbenchWindow activeWorkbenchWindow
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
221 IViewReference
[] references
= null;
222 if(activeWorkbenchWindow
!=null){
223 references
= PlatformUI
.getWorkbench()
224 .getActiveWorkbenchWindow().getActivePage().getViewReferences();
226 else if(PlatformUI
.getWorkbench().getWorkbenchWindows().length
>0){
227 references
= PlatformUI
.getWorkbench().getWorkbenchWindows()[0].getActivePage().getViewReferences();
229 if(references
!=null){
230 for (IViewReference reference
: references
) {
231 if (reference
.getId().equals(id
)) {
232 return reference
.getView(restore
);
245 * a {@link java.lang.Class} object.
246 * @return a {@link java.lang.Object} object.
248 public static Object
getService(Class api
) {
249 return TaxeditorStorePlugin
.getDefault().getWorkbench().getService(api
);
257 * @return a {@link org.eclipse.ui.themes.ITheme} object.
259 public static ITheme
getCurrentTheme() {
260 IThemeManager themeManager
= TaxeditorStorePlugin
.getDefault()
261 .getWorkbench().getThemeManager();
262 return themeManager
.getCurrentTheme();
266 * Fonts registered to the plugin may be obtained with the Eclipse themeing
267 * functionality. Thus fonts are chooseable by the user via
268 * Preferences->General->Appearance->Colors and Fonts
270 * @return the FontRegistry for the current theme
272 public static FontRegistry
getFontRegistry() {
273 return getCurrentTheme().getFontRegistry();
281 * @param symbolicName
282 * a {@link java.lang.String} object.
283 * @return a {@link org.eclipse.swt.graphics.Font} object.
285 public static Font
getFont(String symbolicName
) {
286 return getFontRegistry().get(symbolicName
);
290 * Color registered to the plugin may be obtained with the Eclipse themeing
291 * functionality. Thus colors are editable by the user via
292 * Preferences->General->Appearance->Colors and Fonts
294 * @return the ColorRegistry for the current theme
296 public static ColorRegistry
getColorRegistry() {
297 return getCurrentTheme().getColorRegistry();
305 * @param symbolicName
306 * a {@link java.lang.String} object.
307 * @return a {@link org.eclipse.swt.graphics.Color} object.
309 public static Color
getColor(String symbolicName
) {
310 return getColorRegistry().get(symbolicName
);
320 * {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
322 * @return a {@link org.eclipse.core.runtime.IStatus} object.
324 public static IStatus
executeOperation(final AbstractPostOperation operation
) {
325 if (getOperationHistory() == null) {
326 throw new IllegalArgumentException(
327 "There is no operation history for this context");
330 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
331 .getUIInfoAdapter(getShell());
333 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
336 public void run(IProgressMonitor monitor
)
337 throws InvocationTargetException
, InterruptedException
{
338 String operationlabel
= operation
.getLabel();
339 monitor
.beginTask(operationlabel
, 100);
340 IStatus status
= Status
.CANCEL_STATUS
;
342 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
343 status
= getOperationHistory().execute(operation
, monitor
,
345 } catch (ExecutionException e
) {
347 MessagingUtils
.operationDialog(this, e
, TaxeditorStorePlugin
.PLUGIN_ID
, operationlabel
, null);
353 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
355 setStatusLine(operationlabel
+ " " + statusString
+ ".");
361 runInUI(runnable
, null);
362 } catch (Exception e
) {
363 MessagingUtils
.messageDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
366 IPostOperationEnabled postOperationEnabled
= operation
367 .getPostOperationEnabled();
368 if (postOperationEnabled
!= null) {
369 postOperationEnabled
.onComplete();
371 return Status
.OK_STATUS
;
374 public static IStatus
executeOperation(final AbstractOperation operation
, final RemotingCdmHandler handler
) {
375 if (getOperationHistory() == null) {
376 throw new IllegalArgumentException(
377 "There is no operation history for this context");
380 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
381 .getUIInfoAdapter(getShell());
383 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
386 public void run(IProgressMonitor monitor
)
387 throws InvocationTargetException
, InterruptedException
{
388 String operationlabel
= operation
.getLabel();
389 monitor
.beginTask(operationlabel
, 100);
390 IStatus status
= Status
.CANCEL_STATUS
;
392 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
393 status
= getOperationHistory().execute(operation
, monitor
,
395 if(handler
!= null) {
396 handler
.postOperation(status
);
398 } catch (ExecutionException e
) {
399 MessagingUtils
.operationDialog(this, e
, TaxeditorStorePlugin
.PLUGIN_ID
, operationlabel
, null);
404 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
406 setStatusLine(operationlabel
+ " " + statusString
+ ".");
412 runInUI(runnable
, null);
413 } catch (Exception e
) {
414 MessagingUtils
.messageDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
417 return Status
.OK_STATUS
;
421 * Executes a remoting monitored operation
423 * @param label for the operation
424 * @param uuid of the remoting monitor already started on the server
425 * @param pollInterval in milliseconds
426 * @param cancelable flag which determines whether the operation can be cancelled
427 * @param postOp callback for running post operation logic
430 public static IStatus
executeMoniteredOperation(final String label
,
432 final int pollInterval
,
433 final boolean cancelable
,
434 final IPostMoniteredOperationEnabled postOp
,
435 final IFeedbackGenerator feedbackGenerator
) {
438 // get the remoting monitor the first time to make sure that the
439 // operation is valid
440 final IProgressMonitorService progressMonitorService
= CdmApplicationState
.getCurrentAppConfig().getProgressMonitorService();
441 final IRemotingProgressMonitor firstRemotingMonitor
= progressMonitorService
.getRemotingMonitor(uuid
);
442 if(firstRemotingMonitor
== null) {
443 throw new IllegalStateException("Remoting progress monitor is null");
446 Job job
= new Job(label
) {
450 public IStatus
run(IProgressMonitor monitor
) {
451 // run the monitor until the operation is finished
452 IRemotingProgressMonitor remotingMonitor
;
454 remotingMonitor
= CdmStore
.getProgressMonitorClientManager().pollMonitor(label
,
460 } catch (Exception ex
) {
461 return new Status(Status
.ERROR
, TaxeditorStorePlugin
.PLUGIN_ID
, "Operation Interrupted", ex
);
463 final StringBuilder reportSb
= new StringBuilder();
465 for(String report
: remotingMonitor
.getReports()) {
466 reportSb
.append(report
);
468 if(!StringUtils
.isBlank(reportSb
.toString())) {
469 Display
.getDefault().asyncExec(new Runnable() {
472 // display reports with possibility to save
473 ReportTextDialog dialog
= new ReportTextDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
474 dialog
.setTitle(label
+ " Report");
475 dialog
.setReportText(reportSb
.toString());
480 return Status
.OK_STATUS
;
484 protected void canceling() {
485 CdmStore
.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid
);
490 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
495 } catch (Exception e
) {
496 MessagingUtils
.errorDialog("Error executing operation",
497 AbstractUtility
.class,
498 "An error occured while executing " + label
,
499 TaxeditorStorePlugin
.PLUGIN_ID
,
504 return Status
.OK_STATUS
;
510 * getOperationHistory
513 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
516 public static IOperationHistory
getOperationHistory() {
517 return getWorkbench().getOperationSupport().getOperationHistory();
526 * a {@link java.lang.String} object.
528 public static void setStatusLine(final String message
) {
529 Display
.getDefault().asyncExec(new Runnable() {
533 statusLineManager
.setMessage(message
);
545 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
547 public static IProgressMonitor
getMonitor() {
548 statusLineManager
.setCancelEnabled(false);
549 return statusLineManager
.getProgressMonitor();
553 * Starts either the given {@link IProgressMonitor} if it's not
554 * <code>null</code> or a new {@link NullProgressMonitor}.
556 * @param progressMonitor
557 * The {@link IProgressMonitor} or <code>null</code> if no
558 * progress should be reported.
560 * The name of the main task.
562 * The number of steps this task is subdivided into.
563 * @return The {@link IProgressMonitor}.
565 public static IProgressMonitor
startMainMonitor(
566 IProgressMonitor progressMonitor
, String taskName
, int steps
) {
567 IProgressMonitor newMonitor
= progressMonitor
;
568 if (newMonitor
== null) {
569 newMonitor
= new NullProgressMonitor();
571 newMonitor
.beginTask(taskName
== null ?
"" : taskName
, steps
);
572 newMonitor
.subTask(" ");
577 * Creates a {@link SubProgressMonitor} if the given
578 * {@link IProgressMonitor} is not <code>null</code> and not a
579 * {@link NullProgressMonitor}.
581 * @param progressMonitor
582 * The parent {@link IProgressMonitor} of the
583 * {@link SubProgressMonitor} to be created.
585 * The number of steps this subtask is subdivided into. Must be a
586 * positive number and must not be
587 * {@link IProgressMonitor#UNKNOWN}.
588 * @return The {@link IProgressMonitor}.
590 public static IProgressMonitor
getSubProgressMonitor(
591 IProgressMonitor progressMonitor
, int ticks
) {
592 if (progressMonitor
== null) {
593 return new NullProgressMonitor();
595 if (progressMonitor
instanceof NullProgressMonitor
) {
596 return progressMonitor
;
599 return new SubProgressMonitor(progressMonitor
, ticks
);
603 * Checks whether the user canceled this operation. If not canceled, the
604 * given number of steps are declared as done.
607 * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
611 public static void workedChecked(IProgressMonitor newMonitor
, int steps
) {
612 // In case the progress monitor was canceled throw an exception.
613 if (newMonitor
.isCanceled()) {
614 throw new OperationCanceledException();
616 // Otherwise declare this step as done.
617 newMonitor
.worked(steps
);
621 * Present a progress dialog to the user. This dialog will block the UI
624 * an implementation of {@link IRunnableWithProgress}
625 * @throws java.lang.InterruptedException
627 * @throws java.lang.reflect.InvocationTargetException
630 public static void busyCursorWhile(IRunnableWithProgress runnable
)
631 throws InvocationTargetException
, InterruptedException
{
632 getProgressService().busyCursorWhile(runnable
);
640 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
642 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
645 * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
647 * @throws java.lang.reflect.InvocationTargetException
649 * @throws java.lang.InterruptedException
652 public static void runInUI(IRunnableWithProgress runnable
,
653 ISchedulingRule rule
) throws InvocationTargetException
,
654 InterruptedException
{
655 getProgressService().runInUI(getWorkbenchWindow(), runnable
, rule
);
668 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
670 * @throws java.lang.reflect.InvocationTargetException
672 * @throws java.lang.InterruptedException
675 public static void run(boolean fork
, boolean cancelable
,
676 IRunnableWithProgress runnable
) throws InvocationTargetException
,
677 InterruptedException
{
678 getProgressService().run(fork
, cancelable
, runnable
);
686 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
688 public static IProgressService
getProgressService() {
689 IWorkbench workbench
= PlatformUI
.getWorkbench();
690 return workbench
.getProgressService();
695 * getProgressService2
698 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
701 public static IWorkbenchSiteProgressService
getProgressService2() {
702 return (IWorkbenchSiteProgressService
) getService(IWorkbenchSiteProgressService
.class);
710 * @return a {@link java.lang.String} object.
712 public static String
getPluginId() {
713 return "eu.taxeditor";
721 * @return a {@link org.eclipse.ui.IEditorPart} object.
723 public static IEditorPart
getActiveEditor() {
724 return getActivePage() != null ?
getActivePage().getActiveEditor()
733 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
736 public static DetailsViewPart
getDetailsView() {
737 return (DetailsViewPart
) getView(DetailsViewPart
.ID
, false);
742 * refreshDetailsViewer
745 public static void refreshDetailsViewer() {
746 if (getDetailsView() != null) {
747 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).refresh();
753 * reflowDetailsViewer
756 public static void reflowDetailsViewer() {
757 if (getDetailsView() != null) {
758 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).reflow();
762 public static SupplementalDataViewPart
getSupplementalDataView() {
763 return (SupplementalDataViewPart
) getView(SupplementalDataViewPart
.ID
,
767 public static void reflowSupplementalViewer() {
768 if (getSupplementalDataView() != null) {
769 ((AbstractCdmDataViewer
) getSupplementalDataView().getViewer())
776 * Orders a Collection of {@link IEnumTerm}s according to the term
779 * The returned map will be be ordered primarily by root elements,
780 * secondarily by the child elements and their children resp., both ascending alphabetically. <br>
782 * A {@link Collection} of {@link IEnumTerm}s for which the term
783 * hierarchy should be created
784 * @return a map which holds the terms as keys and their string
785 * representation via {@link IEnumTerm#getMessage()} as values
787 public static <T
extends IEnumTerm
<T
>> LinkedHashMap
<T
, String
> orderTerms(Collection
<T
> terms
) {
788 TreeSet
<TermNode
<T
>> parentElements
= new TreeSet
<TermNode
<T
>>();
789 parentElements
.addAll(getTermHierarchy(terms
));
791 // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically)
792 LinkedHashMap
<T
, String
> result
= new LinkedHashMap
<T
, String
>();
793 parseTermTree(parentElements
, result
, -1);
797 private static<T
extends IEnumTerm
<T
>> void parseTermTree(Collection
<TermNode
<T
>> children
, LinkedHashMap
<T
, String
> result
, int depth
){
799 for(TermNode
<T
> node
:children
){
800 String indentString
= "";
801 for(int i
=0;i
<depth
;i
++){
805 indentString
+= "- ";
807 result
.put(node
.term
, indentString
+ node
.term
.getMessage());
808 parseTermTree(node
.children
, result
, depth
);
812 private static<T
extends IEnumTerm
<T
>> void addToParents(List
<TermNode
<T
>> parents
, Collection
<T
> terms
){
813 List
<TermNode
<T
>> hasChildrenList
= new ArrayList
<TermNode
<T
>>();
815 // only terms with parents
816 if(term
.getKindOf()!=null){
817 TermNode
<T
> parentNode
= new TermNode
<T
>(term
.getKindOf());
818 TermNode
<T
> childNode
= new TermNode
<T
>(term
);
819 if(parents
.contains(parentNode
)){
820 // parent found in parent list -> add this term to parent's child list
821 parents
.get(parents
.indexOf(parentNode
)).addChild(childNode
);
822 if(!term
.getGeneralizationOf().isEmpty()){
823 // has more children -> add to list which will be the parent for the next recursion
824 hasChildrenList
.add(childNode
);
829 if(!hasChildrenList
.isEmpty()){
830 addToParents(hasChildrenList
, terms
);
834 private static<T
extends IEnumTerm
<T
>> List
<TermNode
<T
>> getTermHierarchy(Collection
<T
> terms
){
835 List
<TermNode
<T
>> parents
= new ArrayList
<TermNode
<T
>>();
838 T parentTerm
= term
.getKindOf();
839 if(parentTerm
==null){
841 parents
.add(new TermNode
<T
>(term
));
844 addToParents(parents
, terms
);
848 @SuppressWarnings("unchecked")
850 * Recursively iterates over all term parents until no more parent is found i.e. the root node
851 * @param term The term for which the parent should be found
852 * @return the root terms of the term hierarchy
854 private static<T
extends IEnumTerm
<T
>> T
getParentFor(T term
){
855 // PP: cast should be safe. Why is Eclipse complaining??
856 T parent
= term
.getKindOf();
861 return getParentFor(term
.getKindOf());
865 private static class TermNode
<T
extends IEnumTerm
<T
>> implements Comparable
<TermNode
<T
>>{
866 private final T term
;
867 private final TreeSet
<TermNode
<T
>> children
;
873 public TermNode(T term
) {
876 this.children
= new TreeSet
<TermNode
<T
>>();
879 public void addChild(TermNode
<T
> child
){
880 this.children
.add(child
);
884 * @return the children
886 public TreeSet
<TermNode
<T
>> getChildren() {
898 * @see java.lang.Object#hashCode()
901 public int hashCode() {
902 final int prime
= 31;
904 result
= prime
* result
+ ((term
== null) ?
0 : term
.hashCode());
909 * @see java.lang.Object#equals(java.lang.Object)
912 public boolean equals(Object obj
) {
919 if (getClass() != obj
.getClass()) {
922 TermNode other
= (TermNode
) obj
;
924 if (other
.term
!= null) {
927 } else if (!term
.equals(other
.term
)) {
934 * @see java.lang.Comparable#compareTo(java.lang.Object)
937 public int compareTo(TermNode
<T
> that
) {
938 return this.term
.getMessage().compareTo(that
.term
.getMessage());
943 public static void executeCommand(String commandId
, Object source
, String pluginId
) {
944 IHandlerService handlerService
= (IHandlerService
) AbstractUtility
.getService(IHandlerService
.class);
945 Exception exception
= null;
947 handlerService
.executeCommand(commandId
, null);
948 } catch (ExecutionException e
) {
950 } catch (NotDefinedException e
) {
952 } catch (NotEnabledException e
) {
954 } catch (NotHandledException e
) {
957 if(exception
!= null) {
958 MessagingUtils
.errorDialog("Error executing command",
960 "Could not execute command with id " + commandId
,