2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.controller
;
13 import java
.util
.SortedSet
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
18 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
19 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.jface
.action
.IStatusLineManager
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
25 import org
.eclipse
.ui
.IViewPart
;
26 import org
.eclipse
.ui
.IWorkbenchPage
;
27 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
28 import org
.eclipse
.ui
.operations
.IWorkbenchOperationSupport
;
30 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
31 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
32 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
33 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
34 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
37 * A collection of useful methods related to the UI.
43 public class GlobalController
{
44 private static final Logger logger
= Logger
.getLogger(GlobalController
.class);
46 private static Set
<Feature
> preferredFeatureSet
;
47 private static Set
<Rank
> preferredRankSet
;
52 public static IWorkbenchPage
getActivePage() {
53 return TaxEditorPlugin
.getDefault().getWorkbench()
54 .getActiveWorkbenchWindow().getActivePage();
60 public static Shell
getShell() {
61 return TaxEditorPlugin
.getDefault().getWorkbench()
62 .getActiveWorkbenchWindow().getShell();
65 public static IViewPart
getViewById(String id
) {
66 return TaxEditorPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().
67 getActivePage().findView(id
);
71 public static IWorkbenchOperationSupport
getOperationSupport() {
72 return TaxEditorPlugin
.getDefault().getWorkbench().
73 getOperationSupport();
76 public static IOperationHistory
getOperationHistory() {
77 // if (operationHistory == null) {
78 //// operationHistory = getOperationSupport().getOperationHistory();
79 // operationHistory = OperationHistoryFactory.getOperationHistory();
81 // return operationHistory;
82 return getOperationSupport().getOperationHistory();
85 public static IUndoContext
getWorkbenchUndoContext() {
86 // TODO make this more specific than GLOBAL_UNDO_CONTEXT
87 // return getOperationSupport().getUndoContext();
88 return IOperationHistory
.GLOBAL_UNDO_CONTEXT
;
91 public static void setStatusMessage(String msg
) {
92 PropertySheetController
.getPropertySheet().getViewSite().getActionBars().getStatusLineManager().setMessage(msg
);
96 * Get the name out of the session's name relations vocabulary, not directly
102 public static String
getNameRelationLabelType(NameRelationshipType type
) {
103 SortedSet
<NameRelationshipType
> vocab
=
104 CdmSessionDataRepository
.getDefault().getNameRelationshipTypes();
105 for (NameRelationshipType type1
: vocab
) {
106 if (type1
.equals(type
)) {
107 return type1
.getLabel();
113 private static IStatusLineManager statusLineManager
;
115 public static void setStatusLineManager(IStatusLineManager manager
) {
116 statusLineManager
= manager
;
119 public static void setStatusLine(String message
) {
120 statusLineManager
.setMessage(message
);
123 public static IProgressMonitor
getStatusLineProgressMonitor() {
124 statusLineManager
.setCancelEnabled(false);
125 return statusLineManager
.getProgressMonitor();
128 public static Set
<Feature
> getPreferredFeatures() {
129 return preferredFeatureSet
;
132 public static void setPreferredFeatures(Set
<Feature
> preferredFeatureSet
) {
133 GlobalController
.preferredFeatureSet
= preferredFeatureSet
;
136 public static Set
<Rank
> getPreferredRanks() {
137 return preferredRankSet
;
140 public static void setPreferredRanks(Set
<Rank
> preferredRankSet
) {
141 GlobalController
.preferredRankSet
= preferredRankSet
;
144 public static void addPreferredRank(Rank rank
) {
145 preferredRankSet
.add(rank
);
148 public static void addPreferredFeature(Feature feature
) {
149 GlobalController
.preferredFeatureSet
.add(feature
);
152 public static void executeOperation(IUndoableOperation operation
){
154 IStatus status
= getOperationHistory().execute(operation
, getStatusLineProgressMonitor(),
155 WorkspaceUndoUtil
.getUIInfoAdapter(getShell()));
156 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed" : "cancelled";
157 setStatusLine(operation
.getLabel() + " " + statusString
+ ".");
158 } catch (ExecutionException e
) {
159 logger
.error("Error executing operation: " + operation
.getLabel(), e
);