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
.editor
.MultiPageTaxonEditor
;
35 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
38 * A collection of useful methods related to the UI.
44 public class GlobalController
{
45 private static final Logger logger
= Logger
.getLogger(GlobalController
.class);
47 private static Set
<Feature
> preferredFeatureSet
;
48 private static Set
<Rank
> preferredRankSet
;
53 public static IWorkbenchPage
getActivePage() {
54 return TaxEditorPlugin
.getDefault().getWorkbench()
55 .getActiveWorkbenchWindow().getActivePage();
61 public static Shell
getShell() {
62 return TaxEditorPlugin
.getDefault().getWorkbench()
63 .getActiveWorkbenchWindow().getShell();
66 public static IViewPart
getViewById(String id
) {
67 return TaxEditorPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().
68 getActivePage().findView(id
);
72 public static IWorkbenchOperationSupport
getOperationSupport() {
73 return TaxEditorPlugin
.getDefault().getWorkbench().
74 getOperationSupport();
77 public static IOperationHistory
getOperationHistory() {
78 // if (operationHistory == null) {
79 //// operationHistory = getOperationSupport().getOperationHistory();
80 // operationHistory = OperationHistoryFactory.getOperationHistory();
82 // return operationHistory;
83 return getOperationSupport().getOperationHistory();
86 public static IUndoContext
getWorkbenchUndoContext() {
87 // TODO make this more specific than GLOBAL_UNDO_CONTEXT
88 // return getOperationSupport().getUndoContext();
89 return IOperationHistory
.GLOBAL_UNDO_CONTEXT
;
92 public static void setStatusMessage(String msg
) {
93 PropertySheetController
.getPropertySheet().getViewSite().getActionBars().getStatusLineManager().setMessage(msg
);
97 * Get the name out of the session's name relations vocabulary, not directly
103 public static String
getNameRelationLabelType(NameRelationshipType type
) {
104 SortedSet
<NameRelationshipType
> vocab
=
105 CdmSessionDataRepository
.getDefault().getNameRelationshipTypes();
106 for (NameRelationshipType type1
: vocab
) {
107 if (type1
.equals(type
)) {
108 return type1
.getLabel();
114 private static IStatusLineManager statusLineManager
;
116 public static void setStatusLineManager(IStatusLineManager manager
) {
117 statusLineManager
= manager
;
120 public static void setStatusLine(String message
) {
121 statusLineManager
.setMessage(message
);
124 public static IProgressMonitor
getStatusLineProgressMonitor() {
125 statusLineManager
.setCancelEnabled(false);
126 return statusLineManager
.getProgressMonitor();
129 public static Set
<Feature
> getPreferredFeatures() {
130 return preferredFeatureSet
;
133 public static void setPreferredFeatures(Set
<Feature
> preferredFeatureSet
) {
134 GlobalController
.preferredFeatureSet
= preferredFeatureSet
;
137 public static Set
<Rank
> getPreferredRanks() {
138 return preferredRankSet
;
141 public static void setPreferredRanks(Set
<Rank
> preferredRankSet
) {
142 GlobalController
.preferredRankSet
= preferredRankSet
;
145 public static void addPreferredRank(Rank rank
) {
146 preferredRankSet
.add(rank
);
149 public static void addPreferredFeature(Feature feature
) {
150 GlobalController
.preferredFeatureSet
.add(feature
);
153 public static void executeOperation(IUndoableOperation operation
){
155 IStatus status
= getOperationHistory().execute(operation
, getStatusLineProgressMonitor(),
156 WorkspaceUndoUtil
.getUIInfoAdapter(getShell()));
157 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed" : "cancelled";
158 setStatusLine(operation
.getLabel() + " " + statusString
+ ".");
159 } catch (ExecutionException e
) {
160 logger
.error("Error executing operation: " + operation
.getLabel(), e
);