finalizing preferred refactoring
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / model / AbstractUtility.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.model;
12
13 import org.eclipse.jface.resource.ColorRegistry;
14 import org.eclipse.jface.resource.FontRegistry;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.MessageBox;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.themes.ITheme;
20 import org.eclipse.ui.themes.IThemeManager;
21
22 import eu.etaxonomy.taxeditor.store.StoreUtil;
23 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
24
25 /**
26 * @author n.hoffmann
27 * @created 11.05.2009
28 * @version 1.0
29 */
30 public abstract class AbstractUtility {
31
32 /**
33 * @return
34 */
35 public static Shell getShell() {
36 return TaxeditorStorePlugin.getDefault().getWorkbench()
37 .getActiveWorkbenchWindow().getShell();
38 }
39
40 public static IWorkbenchPage getActivePage(){
41 return TaxeditorStorePlugin.getDefault().getWorkbench()
42 .getActiveWorkbenchWindow().getActivePage();
43 }
44
45 public static boolean closeAll() {
46 return getActivePage().closeAllEditors(true);
47 }
48
49 public static ITheme getCurrentTheme(){
50 IThemeManager themeManager = TaxeditorStorePlugin.getDefault().getWorkbench().getThemeManager();
51 return themeManager.getCurrentTheme();
52 }
53
54 /**
55 * Fonts registered to the plugin may be obtained with the Eclipse themeing functionality.
56 * Thus fonts are chooseable by the user via Preferences->General->Appearance->Colors and Fonts
57 *
58 * @return the FontRegistry for the current theme
59 */
60 public static FontRegistry getFontRegistry(){
61 return getCurrentTheme().getFontRegistry();
62 }
63
64 /**
65 * Color registered to the plugin may be obtained with the Eclipse themeing functionality.
66 * Thus colors are editable by the user via Preferences->General->Appearance->Colors and Fonts
67 *
68 * @return the ColorRegistry for the current theme
69 */
70 public static ColorRegistry getColorRegistry(){
71 return getCurrentTheme().getColorRegistry();
72 }
73
74 /**
75 * Open a message box that informs the user about unimplemented functionality.
76 * This method is for developer convenience.
77 */
78 public static void notImplementedMessage(){
79 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.OK);
80 messageBox.setText("Not yet implemented");
81 messageBox.open();
82 }
83
84 }