refactored folder structure
[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.widgets.Shell;
16 import org.eclipse.ui.IEditorReference;
17 import org.eclipse.ui.IWorkbenchPage;
18 import org.eclipse.ui.themes.ITheme;
19 import org.eclipse.ui.themes.IThemeManager;
20
21 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
22
23 /**
24 * @author n.hoffmann
25 * @created 11.05.2009
26 * @version 1.0
27 */
28 public abstract class AbstractUtility {
29
30 /**
31 * @return
32 */
33 public static Shell getShell() {
34 return TaxeditorStorePlugin.getDefault().getWorkbench()
35 .getActiveWorkbenchWindow().getShell();
36 }
37
38 public static IWorkbenchPage getActivePage(){
39 return TaxeditorStorePlugin.getDefault().getWorkbench()
40 .getActiveWorkbenchWindow().getActivePage();
41 }
42
43 public static boolean closeAll() {
44 for (IEditorReference reference : getActivePage().getEditorReferences()) {
45 if (!getActivePage().closeEditor(reference.getEditor(false), true)) {
46 return false;
47 }
48 }
49 return true;
50 }
51
52 public static ITheme getCurrentTheme(){
53 IThemeManager themeManager = TaxeditorStorePlugin.getDefault().getWorkbench().getThemeManager();
54 return themeManager.getCurrentTheme();
55 }
56
57 /**
58 * Fonts registered to the plugin may be obtained with the Eclipse themeing functionality.
59 * Thus fonts are chooseable by the user via Preferences->General->Appearance->Colors and Fonts
60 *
61 * @return the FontRegistry for the current theme
62 */
63 public static FontRegistry getFontRegistry(){
64 return getCurrentTheme().getFontRegistry();
65 }
66
67 /**
68 * Color registered to the plugin may be obtained with the Eclipse themeing functionality.
69 * Thus colors are editable by the user via Preferences->General->Appearance->Colors and Fonts
70 *
71 * @return the ColorRegistry for the current theme
72 */
73 public static ColorRegistry getColorRegistry(){
74 return getCurrentTheme().getColorRegistry();
75 }
76
77 }