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
.PartInitException
;
54 import org
.eclipse
.ui
.PlatformUI
;
55 import org
.eclipse
.ui
.handlers
.IHandlerService
;
56 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
57 import org
.eclipse
.ui
.part
.EditorPart
;
58 import org
.eclipse
.ui
.progress
.IProgressConstants
;
59 import org
.eclipse
.ui
.progress
.IProgressService
;
60 import org
.eclipse
.ui
.progress
.IWorkbenchSiteProgressService
;
61 import org
.eclipse
.ui
.themes
.ITheme
;
62 import org
.eclipse
.ui
.themes
.IThemeManager
;
64 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
65 import eu
.etaxonomy
.cdm
.api
.service
.IProgressMonitorService
;
66 import eu
.etaxonomy
.cdm
.common
.monitor
.IRemotingProgressMonitor
;
67 import eu
.etaxonomy
.cdm
.model
.common
.IEnumTerm
;
68 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
69 import eu
.etaxonomy
.taxeditor
.operation
.IFeedbackGenerator
;
70 import eu
.etaxonomy
.taxeditor
.operation
.IPostMoniteredOperationEnabled
;
71 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
72 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
73 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
74 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
75 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.ReportTextDialog
;
76 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmDataViewer
;
77 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
78 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
82 * Abstract AbstractUtility class.
89 public abstract class AbstractUtility
{
91 private static final Logger logger
= Logger
.getLogger(AbstractUtility
.class);
93 /** Constant <code>statusLineManager</code> */
94 protected static IStatusLineManager statusLineManager
;
104 public static boolean closeAll() {
105 return getActivePage().closeAllEditors(true);
109 * Close the given editor.
112 * The <tt>MultipageTaxonEditor</tt> to close.
113 * @return <tt>true</tt> on success
115 public static boolean close(EditorPart editor
) {
116 return getActivePage().closeEditor(editor
, true);
124 * @return a {@link org.eclipse.swt.widgets.Shell} object.
126 public static Shell
getShell() {
128 return TaxeditorStorePlugin
.getDefault().getWorkbench()
129 .getActiveWorkbenchWindow().getShell();
137 * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
139 public static IWorkbenchPage
getActivePage() {
141 return TaxeditorStorePlugin
.getDefault().getWorkbench()
142 .getActiveWorkbenchWindow().getActivePage();
150 * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
152 public static IWorkbenchPart
getActivePart() {
153 return getActivePage() != null ?
getActivePage().getActivePart() : null;
156 public static IWorkbench
getWorkbench() {
157 return TaxeditorStorePlugin
.getDefault().getWorkbench();
165 * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
167 public static ApplicationWindow
getWorkbenchWindow() {
168 if (getWorkbench().getWorkbenchWindowCount() > 1) {
169 throw new IllegalStateException("More than one workbench window");
171 return (ApplicationWindow
) getWorkbench().getWorkbenchWindows()[0];
180 * a {@link java.lang.String} object.
181 * @return a {@link org.eclipse.ui.IViewPart} object.
183 public static IViewPart
showView(String id
) {
185 return PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
187 .showView(id
, null, IWorkbenchPage
.VIEW_VISIBLE
);
188 } catch (PartInitException e
) {
189 MessagingUtils
.messageDialog("Error opening view", AbstractUtility
.class, "Could not open view: " + id
, e
);
200 * a {@link org.eclipse.ui.IViewPart} object.
202 public static void hideView(IViewPart view
) {
203 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
213 * a {@link java.lang.String} object.
216 * @return a {@link org.eclipse.ui.IViewPart} object.
218 public static IViewPart
getView(String id
, boolean restore
) {
219 IViewReference
[] references
= PlatformUI
.getWorkbench()
220 .getActiveWorkbenchWindow().getActivePage().getViewReferences();
221 for (IViewReference reference
: references
) {
222 if (reference
.getId().equals(id
)) {
223 return reference
.getView(restore
);
235 * a {@link java.lang.Class} object.
236 * @return a {@link java.lang.Object} object.
238 public static Object
getService(Class api
) {
239 return TaxeditorStorePlugin
.getDefault().getWorkbench().getService(api
);
247 * @return a {@link org.eclipse.ui.themes.ITheme} object.
249 public static ITheme
getCurrentTheme() {
250 IThemeManager themeManager
= TaxeditorStorePlugin
.getDefault()
251 .getWorkbench().getThemeManager();
252 return themeManager
.getCurrentTheme();
256 * Fonts registered to the plugin may be obtained with the Eclipse themeing
257 * functionality. Thus fonts are chooseable by the user via
258 * Preferences->General->Appearance->Colors and Fonts
260 * @return the FontRegistry for the current theme
262 public static FontRegistry
getFontRegistry() {
263 return getCurrentTheme().getFontRegistry();
271 * @param symbolicName
272 * a {@link java.lang.String} object.
273 * @return a {@link org.eclipse.swt.graphics.Font} object.
275 public static Font
getFont(String symbolicName
) {
276 return getFontRegistry().get(symbolicName
);
280 * Color registered to the plugin may be obtained with the Eclipse themeing
281 * functionality. Thus colors are editable by the user via
282 * Preferences->General->Appearance->Colors and Fonts
284 * @return the ColorRegistry for the current theme
286 public static ColorRegistry
getColorRegistry() {
287 return getCurrentTheme().getColorRegistry();
295 * @param symbolicName
296 * a {@link java.lang.String} object.
297 * @return a {@link org.eclipse.swt.graphics.Color} object.
299 public static Color
getColor(String symbolicName
) {
300 return getColorRegistry().get(symbolicName
);
310 * {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
312 * @return a {@link org.eclipse.core.runtime.IStatus} object.
314 public static IStatus
executeOperation(final AbstractPostOperation operation
) {
315 if (getOperationHistory() == null) {
316 throw new IllegalArgumentException(
317 "There is no operation history for this context");
320 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
321 .getUIInfoAdapter(getShell());
323 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
326 public void run(IProgressMonitor monitor
)
327 throws InvocationTargetException
, InterruptedException
{
328 String operationlabel
= operation
.getLabel();
329 monitor
.beginTask(operationlabel
, 100);
330 IStatus status
= Status
.CANCEL_STATUS
;
332 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
333 status
= getOperationHistory().execute(operation
, monitor
,
335 } catch (ExecutionException e
) {
337 MessagingUtils
.operationDialog(this, e
, TaxeditorStorePlugin
.PLUGIN_ID
, operationlabel
, null);
343 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
345 setStatusLine(operationlabel
+ " " + statusString
+ ".");
351 runInUI(runnable
, null);
352 } catch (Exception e
) {
353 MessagingUtils
.messageDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
356 IPostOperationEnabled postOperationEnabled
= operation
357 .getPostOperationEnabled();
358 if (postOperationEnabled
!= null) {
359 postOperationEnabled
.onComplete();
361 return Status
.OK_STATUS
;
364 public static IStatus
executeOperation(final AbstractOperation operation
, final RemotingCdmHandler handler
) {
365 if (getOperationHistory() == null) {
366 throw new IllegalArgumentException(
367 "There is no operation history for this context");
370 final IAdaptable uiInfoAdapter
= WorkspaceUndoUtil
371 .getUIInfoAdapter(getShell());
373 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
376 public void run(IProgressMonitor monitor
)
377 throws InvocationTargetException
, InterruptedException
{
378 String operationlabel
= operation
.getLabel();
379 monitor
.beginTask(operationlabel
, 100);
380 IStatus status
= Status
.CANCEL_STATUS
;
382 operation
.addContext(IOperationHistory
.GLOBAL_UNDO_CONTEXT
);
383 status
= getOperationHistory().execute(operation
, monitor
,
385 if(handler
!= null) {
386 handler
.postOperation(status
);
388 } catch (ExecutionException e
) {
389 MessagingUtils
.operationDialog(this, e
, TaxeditorStorePlugin
.PLUGIN_ID
, operationlabel
, null);
394 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed"
396 setStatusLine(operationlabel
+ " " + statusString
+ ".");
402 runInUI(runnable
, null);
403 } catch (Exception e
) {
404 MessagingUtils
.messageDialog("Error executing operation", AbstractUtility
.class, "An error occured while executing " + operation
.getLabel(), e
);
407 return Status
.OK_STATUS
;
411 * Executes a remoting monitored operation
413 * @param label for the operation
414 * @param uuid of the remoting monitor already started on the server
415 * @param pollInterval in milliseconds
416 * @param cancelable flag which determines whether the operation can be cancelled
417 * @param postOp callback for running post operation logic
420 public static IStatus
executeMoniteredOperation(final String label
,
422 final int pollInterval
,
423 final boolean cancelable
,
424 final IPostMoniteredOperationEnabled postOp
,
425 final IFeedbackGenerator feedbackGenerator
) {
428 // get the remoting monitor the first time to make sure that the
429 // operation is valid
430 final IProgressMonitorService progressMonitorService
= CdmApplicationState
.getCurrentAppConfig().getProgressMonitorService();
431 final IRemotingProgressMonitor firstRemotingMonitor
= progressMonitorService
.getRemotingMonitor(uuid
);
432 if(firstRemotingMonitor
== null) {
433 throw new IllegalStateException("Remoting progress monitor is null");
436 Job job
= new Job(label
) {
440 public IStatus
run(IProgressMonitor monitor
) {
441 // run the monitor until the operation is finished
442 IRemotingProgressMonitor remotingMonitor
;
444 remotingMonitor
= CdmStore
.getProgressMonitorClientManager().pollMonitor(label
,
450 } catch (Exception ex
) {
451 return new Status(Status
.ERROR
, TaxeditorStorePlugin
.PLUGIN_ID
, "Operation Interrupted", ex
);
453 final StringBuilder reportSb
= new StringBuilder();
455 for(String report
: remotingMonitor
.getReports()) {
456 reportSb
.append(report
);
458 if(!StringUtils
.isBlank(reportSb
.toString())) {
459 Display
.getDefault().asyncExec(new Runnable() {
462 // display reports with possibility to save
463 ReportTextDialog dialog
= new ReportTextDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
464 dialog
.setTitle(label
+ " Report");
465 dialog
.setReportText(reportSb
.toString());
470 return Status
.OK_STATUS
;
474 protected void canceling() {
475 CdmStore
.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid
);
480 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
485 } catch (Exception e
) {
486 MessagingUtils
.errorDialog("Error executing operation",
487 AbstractUtility
.class,
488 "An error occured while executing " + label
,
489 TaxeditorStorePlugin
.PLUGIN_ID
,
494 return Status
.OK_STATUS
;
500 * getOperationHistory
503 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
506 public static IOperationHistory
getOperationHistory() {
507 return getWorkbench().getOperationSupport().getOperationHistory();
516 * a {@link java.lang.String} object.
518 public static void setStatusLine(final String message
) {
519 Display
.getDefault().asyncExec(new Runnable() {
523 statusLineManager
.setMessage(message
);
535 * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
537 public static IProgressMonitor
getMonitor() {
538 statusLineManager
.setCancelEnabled(false);
539 return statusLineManager
.getProgressMonitor();
543 * Starts either the given {@link IProgressMonitor} if it's not
544 * <code>null</code> or a new {@link NullProgressMonitor}.
546 * @param progressMonitor
547 * The {@link IProgressMonitor} or <code>null</code> if no
548 * progress should be reported.
550 * The name of the main task.
552 * The number of steps this task is subdivided into.
553 * @return The {@link IProgressMonitor}.
555 public static IProgressMonitor
startMainMonitor(
556 IProgressMonitor progressMonitor
, String taskName
, int steps
) {
557 IProgressMonitor newMonitor
= progressMonitor
;
558 if (newMonitor
== null) {
559 newMonitor
= new NullProgressMonitor();
561 newMonitor
.beginTask(taskName
== null ?
"" : taskName
, steps
);
562 newMonitor
.subTask(" ");
567 * Creates a {@link SubProgressMonitor} if the given
568 * {@link IProgressMonitor} is not <code>null</code> and not a
569 * {@link NullProgressMonitor}.
571 * @param progressMonitor
572 * The parent {@link IProgressMonitor} of the
573 * {@link SubProgressMonitor} to be created.
575 * The number of steps this subtask is subdivided into. Must be a
576 * positive number and must not be
577 * {@link IProgressMonitor#UNKNOWN}.
578 * @return The {@link IProgressMonitor}.
580 public static IProgressMonitor
getSubProgressMonitor(
581 IProgressMonitor progressMonitor
, int ticks
) {
582 if (progressMonitor
== null) {
583 return new NullProgressMonitor();
585 if (progressMonitor
instanceof NullProgressMonitor
) {
586 return progressMonitor
;
589 return new SubProgressMonitor(progressMonitor
, ticks
);
593 * Checks whether the user canceled this operation. If not canceled, the
594 * given number of steps are declared as done.
597 * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
601 public static void workedChecked(IProgressMonitor newMonitor
, int steps
) {
602 // In case the progress monitor was canceled throw an exception.
603 if (newMonitor
.isCanceled()) {
604 throw new OperationCanceledException();
606 // Otherwise declare this step as done.
607 newMonitor
.worked(steps
);
611 * Present a progress dialog to the user. This dialog will block the UI
614 * an implementation of {@link IRunnableWithProgress}
615 * @throws java.lang.InterruptedException
617 * @throws java.lang.reflect.InvocationTargetException
620 public static void busyCursorWhile(IRunnableWithProgress runnable
)
621 throws InvocationTargetException
, InterruptedException
{
622 getProgressService().busyCursorWhile(runnable
);
630 * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
632 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
635 * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
637 * @throws java.lang.reflect.InvocationTargetException
639 * @throws java.lang.InterruptedException
642 public static void runInUI(IRunnableWithProgress runnable
,
643 ISchedulingRule rule
) throws InvocationTargetException
,
644 InterruptedException
{
645 getProgressService().runInUI(getWorkbenchWindow(), runnable
, rule
);
658 * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
660 * @throws java.lang.reflect.InvocationTargetException
662 * @throws java.lang.InterruptedException
665 public static void run(boolean fork
, boolean cancelable
,
666 IRunnableWithProgress runnable
) throws InvocationTargetException
,
667 InterruptedException
{
668 getProgressService().run(fork
, cancelable
, runnable
);
676 * @return a {@link org.eclipse.ui.progress.IProgressService} object.
678 public static IProgressService
getProgressService() {
679 IWorkbench workbench
= PlatformUI
.getWorkbench();
680 return workbench
.getProgressService();
685 * getProgressService2
688 * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
691 public static IWorkbenchSiteProgressService
getProgressService2() {
692 return (IWorkbenchSiteProgressService
) getService(IWorkbenchSiteProgressService
.class);
700 * @return a {@link java.lang.String} object.
702 public static String
getPluginId() {
703 return "eu.taxeditor";
711 * @return a {@link org.eclipse.ui.IEditorPart} object.
713 public static IEditorPart
getActiveEditor() {
714 return getActivePage() != null ?
getActivePage().getActiveEditor()
723 * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
726 public static DetailsViewPart
getDetailsView() {
727 return (DetailsViewPart
) getView(DetailsViewPart
.ID
, false);
732 * refreshDetailsViewer
735 public static void refreshDetailsViewer() {
736 if (getDetailsView() != null) {
737 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).refresh();
743 * reflowDetailsViewer
746 public static void reflowDetailsViewer() {
747 if (getDetailsView() != null) {
748 ((AbstractCdmDataViewer
) getDetailsView().getViewer()).reflow();
752 public static SupplementalDataViewPart
getSupplementalDataView() {
753 return (SupplementalDataViewPart
) getView(SupplementalDataViewPart
.ID
,
757 public static void reflowSupplementalViewer() {
758 if (getSupplementalDataView() != null) {
759 ((AbstractCdmDataViewer
) getSupplementalDataView().getViewer())
766 * Orders a Collection of {@link IEnumTerm}s according to the term
769 * The returned map will be be ordered primarily by root elements,
770 * secondarily by the child elements and their children resp., both ascending alphabetically. <br>
772 * A {@link Collection} of {@link IEnumTerm}s for which the term
773 * hierarchy should be created
774 * @return a map which holds the terms as keys and their string
775 * representation via {@link IEnumTerm#getMessage()} as values
777 public static <T
extends IEnumTerm
<T
>> LinkedHashMap
<T
, String
> orderTerms(Collection
<T
> terms
) {
778 TreeSet
<TermNode
<T
>> parentElements
= new TreeSet
<TermNode
<T
>>();
779 parentElements
.addAll(getTermHierarchy(terms
));
781 // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically)
782 LinkedHashMap
<T
, String
> result
= new LinkedHashMap
<T
, String
>();
783 parseTermTree(parentElements
, result
, -1);
787 private static<T
extends IEnumTerm
<T
>> void parseTermTree(Collection
<TermNode
<T
>> children
, LinkedHashMap
<T
, String
> result
, int depth
){
789 for(TermNode
<T
> node
:children
){
790 String indentString
= "";
791 for(int i
=0;i
<depth
;i
++){
795 indentString
+= "- ";
797 result
.put(node
.term
, indentString
+ node
.term
.getMessage());
798 parseTermTree(node
.children
, result
, depth
);
802 private static<T
extends IEnumTerm
<T
>> void addToParents(List
<TermNode
<T
>> parents
, Collection
<T
> terms
){
803 List
<TermNode
<T
>> hasChildrenList
= new ArrayList
<TermNode
<T
>>();
805 // only terms with parents
806 if(term
.getKindOf()!=null){
807 TermNode
<T
> parentNode
= new TermNode
<T
>(term
.getKindOf());
808 TermNode
<T
> childNode
= new TermNode
<T
>(term
);
809 if(parents
.contains(parentNode
)){
810 // parent found in parent list -> add this term to parent's child list
811 parents
.get(parents
.indexOf(parentNode
)).addChild(childNode
);
812 if(!term
.getGeneralizationOf().isEmpty()){
813 // has more children -> add to list which will be the parent for the next recursion
814 hasChildrenList
.add(childNode
);
819 if(!hasChildrenList
.isEmpty()){
820 addToParents(hasChildrenList
, terms
);
824 private static<T
extends IEnumTerm
<T
>> List
<TermNode
<T
>> getTermHierarchy(Collection
<T
> terms
){
825 List
<TermNode
<T
>> parents
= new ArrayList
<TermNode
<T
>>();
828 T parentTerm
= term
.getKindOf();
829 if(parentTerm
==null){
831 parents
.add(new TermNode
<T
>(term
));
834 addToParents(parents
, terms
);
838 @SuppressWarnings("unchecked")
840 * Recursively iterates over all term parents until no more parent is found i.e. the root node
841 * @param term The term for which the parent should be found
842 * @return the root terms of the term hierarchy
844 private static<T
extends IEnumTerm
<T
>> T
getParentFor(T term
){
845 // PP: cast should be safe. Why is Eclipse complaining??
846 T parent
= term
.getKindOf();
851 return getParentFor(term
.getKindOf());
855 private static class TermNode
<T
extends IEnumTerm
<T
>> implements Comparable
<TermNode
<T
>>{
856 private final T term
;
857 private final TreeSet
<TermNode
<T
>> children
;
863 public TermNode(T term
) {
866 this.children
= new TreeSet
<TermNode
<T
>>();
869 public void addChild(TermNode
<T
> child
){
870 this.children
.add(child
);
874 * @return the children
876 public TreeSet
<TermNode
<T
>> getChildren() {
888 * @see java.lang.Object#hashCode()
891 public int hashCode() {
892 final int prime
= 31;
894 result
= prime
* result
+ ((term
== null) ?
0 : term
.hashCode());
899 * @see java.lang.Object#equals(java.lang.Object)
902 public boolean equals(Object obj
) {
909 if (getClass() != obj
.getClass()) {
912 TermNode other
= (TermNode
) obj
;
914 if (other
.term
!= null) {
917 } else if (!term
.equals(other
.term
)) {
924 * @see java.lang.Comparable#compareTo(java.lang.Object)
927 public int compareTo(TermNode
<T
> that
) {
928 return this.term
.getMessage().compareTo(that
.term
.getMessage());
933 public static void executeCommand(String commandId
, Object source
, String pluginId
) {
934 IHandlerService handlerService
= (IHandlerService
) AbstractUtility
.getService(IHandlerService
.class);
935 Exception exception
= null;
937 handlerService
.executeCommand(commandId
, null);
938 } catch (ExecutionException e
) {
940 } catch (NotDefinedException e
) {
942 } catch (NotEnabledException e
) {
944 } catch (NotHandledException e
) {
947 if(exception
!= null) {
948 MessagingUtils
.errorDialog("Error executing command",
950 "Could not execute command with id " + commandId
,