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 org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.action
.IStatusLineManager
;
21 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
22 import org
.eclipse
.jface
.resource
.ColorRegistry
;
23 import org
.eclipse
.jface
.resource
.FontRegistry
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
25 import org
.eclipse
.ui
.IViewPart
;
26 import org
.eclipse
.ui
.IWorkbenchPage
;
27 import org
.eclipse
.ui
.PartInitException
;
28 import org
.eclipse
.ui
.PlatformUI
;
29 import org
.eclipse
.ui
.themes
.ITheme
;
30 import org
.eclipse
.ui
.themes
.IThemeManager
;
31 import org
.eclipse
.ui
.ide
.undo
.WorkspaceUndoUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
40 public abstract class AbstractUtility
{
41 private static final Logger logger
= Logger
.getLogger(AbstractUtility
.class);
43 protected static IStatusLineManager statusLineManager
;
48 public static Shell
getShell() {
49 return TaxeditorStorePlugin
.getDefault().getWorkbench()
50 .getActiveWorkbenchWindow().getShell();
53 public static IWorkbenchPage
getActivePage(){
54 return TaxeditorStorePlugin
.getDefault().getWorkbench()
55 .getActiveWorkbenchWindow().getActivePage();
58 public static IViewPart
getView(String id
) throws PartInitException
{
59 return PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id
);
62 public static boolean closeAll() {
63 return getActivePage().closeAllEditors(true);
71 public static Object
getService(Class api
){
72 return TaxeditorStorePlugin
.getDefault().getWorkbench().getService(api
);
75 public static ITheme
getCurrentTheme(){
76 IThemeManager themeManager
= TaxeditorStorePlugin
.getDefault().getWorkbench().getThemeManager();
77 return themeManager
.getCurrentTheme();
81 * Fonts registered to the plugin may be obtained with the Eclipse themeing functionality.
82 * Thus fonts are chooseable by the user via Preferences->General->Appearance->Colors and Fonts
84 * @return the FontRegistry for the current theme
86 public static FontRegistry
getFontRegistry(){
87 return getCurrentTheme().getFontRegistry();
91 * Color registered to the plugin may be obtained with the Eclipse themeing functionality.
92 * Thus colors are editable by the user via Preferences->General->Appearance->Colors and Fonts
94 * @return the ColorRegistry for the current theme
96 public static ColorRegistry
getColorRegistry(){
97 return getCurrentTheme().getColorRegistry();
101 * Open a message box that informs the user about unimplemented functionality.
102 * This method is for developer convenience.
104 public static void notImplementedMessage(){
105 warningDialog("Not yet implemented", "This functionality is not yet implemented.");
108 public static void informationDialog(String title
, String message
){
109 MessageDialog
.openInformation(getShell(), title
, message
);
112 public static void warningDialog(String title
, String message
){
113 MessageDialog
.openWarning(getShell(), title
, message
);
116 public static void errorDialog(String title
, String message
){
117 MessageDialog
.openError(getShell(), title
, message
);
120 public static IStatus
executeOperation(IUndoableOperation operation
){
121 if(getOperationHistory() == null){
122 throw new IllegalArgumentException("Ther is no operation history for this context");
126 IStatus status
= getOperationHistory().execute(operation
, getMonitor(),
127 WorkspaceUndoUtil
.getUIInfoAdapter(getShell()));
128 String statusString
= status
.equals(Status
.OK_STATUS
) ?
"completed" : "cancelled";
129 setStatusLine(operation
.getLabel() + " " + statusString
+ ".");
131 } catch (ExecutionException e
) {
132 logger
.error("Error executing operation: " + operation
.getLabel(), e
);
137 public static IOperationHistory
getOperationHistory(){
138 return TaxeditorStorePlugin
.getDefault().getWorkbench().
139 getOperationSupport().getOperationHistory();
142 public static void setStatusLine(String message
) {
143 statusLineManager
.setMessage(message
);
146 protected static IProgressMonitor
getMonitor() {
147 statusLineManager
.setCancelEnabled(false);
148 return statusLineManager
.getProgressMonitor();