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
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.swt
.graphics
.Color
;
14 import org
.eclipse
.swt
.widgets
.Tree
;
15 import org
.eclipse
.swt
.widgets
.TreeItem
;
16 import org
.eclipse
.ui
.IActionBars
;
17 import org
.eclipse
.ui
.IPageLayout
;
18 import org
.eclipse
.ui
.IViewPart
;
19 import org
.eclipse
.ui
.IViewReference
;
20 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
21 import org
.eclipse
.ui
.views
.properties
.PropertySheetPage
;
23 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
24 import eu
.etaxonomy
.taxeditor
.propertysheet
.EditorPropertySheetEntry
;
31 public class PropertySheetController
{
32 private static final Logger logger
= Logger
33 .getLogger(PropertySheetController
.class);
35 public static IViewPart
getPropertySheet() {
36 for (IViewReference reference
: GlobalController
.getActivePage().getViewReferences()) {
37 if (reference
.getId().equals(IPageLayout
.ID_PROP_SHEET
)) {
38 logger
.warn(reference
.getView(false).getSite().getPart().getTitle());
39 return reference
.getView(false);
46 * By default, property sheet has buttons in the toolbar for
47 * "Show advanced properties" and "Show categories".
49 * This is confusing for the user, hence a method to remove them
50 * until such time as advanced properties or categories are implemented.
52 public static void hidePropertySheetToolbar() {
53 PropertySheet propertySheet
= (PropertySheet
) getPropertySheet();
54 IActionBars actionBars
= propertySheet
.getViewSite().getActionBars();
55 actionBars
.getToolBarManager().removeAll();
56 actionBars
.getMenuManager().removeAll();
60 * The property sheet listener ensures only property sheets
61 * with data cause the Property Sheet to be updated.
63 public static void addPropertySheetInputListener() {
64 IViewPart propertySheet
= getPropertySheet();
66 PropertySheet ps
= (PropertySheet
) propertySheet
;
67 // ps.addPartPropertyListener(listener)
68 // ps.addPropertyListener(l)
71 public static void setPropertySheetTree(Tree tree
) {
72 TaxEditorPlugin
.getDefault().setPropertySheetTree(tree
);
75 public static Tree
getPropertySheetTree() {
76 return TaxEditorPlugin
.getDefault().getPropertySheetTree();
79 public static void setPropertySheetPage(PropertySheetPage page
) {
80 TaxEditorPlugin
.getDefault().setPropertySheetPage(page
);
83 public static PropertySheetPage
getPropertySheetPage() {
84 return TaxEditorPlugin
.getDefault().getPropertySheetPage();
88 * UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true);
89 * UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED);
93 * @param doPaintChildren
95 public static void paintPropertySheetRow(String id
, Color color
, boolean doPaintChildren
) {
97 // Catch null property sheet name
102 // Catch uninit'ed property sheet tree
103 if (getPropertySheetTree() == null) {
107 paintPropertySheetRow(id
, color
, doPaintChildren
, getPropertySheetTree());
110 private static void paintPropertySheetRow(String id
, Color color
, boolean doPaintChildren
, Object treeOrItem
) {
112 // Init items w zero-length array
113 TreeItem
[] items
= new TreeItem
[]{};
115 // Get child items depending to class
116 if (treeOrItem
instanceof Tree
) {
117 items
= ((Tree
) treeOrItem
).getItems();
119 if (treeOrItem
instanceof TreeItem
) {
120 items
= ((TreeItem
) treeOrItem
).getItems();
123 // If array hasn't been populated by the above, return
124 if (items
.length
== 0) {
128 // Prop. sheet id's take the form "01:xxxx" for sorting - truncate
129 id
= EditorPropertySheetEntry
.truncateDisplayName(id
);
131 // Iterate through child items
132 for (TreeItem item
: items
) {
134 // Item found, paint it
135 if (id
.equals(item
.getText())) {
136 paintItem(item
, color
, doPaintChildren
);
140 // Recursively search for item to paint in child items
141 if (item
.getItemCount() > 0) {
142 paintPropertySheetRow(id
, color
, doPaintChildren
, item
);
147 public static void unpaintPropertySheetRow(String id
) {
149 // Catch uninit'ed property sheet tree
150 if (getPropertySheetTree() == null) {
154 // Get tree's background color to "unpaint"
155 Color color
= getPropertySheetTree().getBackground();
157 paintPropertySheetRow(id
, color
, true);
161 * Note: children are only painted if submenu has already been created, i.e. opened once.
165 * @param doPaintChildren
167 public static void paintItem(TreeItem item
, Color color
, boolean doPaintChildren
) {
170 item
.setBackground(color
);
172 // Recursively paint child items if requested
173 if (doPaintChildren
) {
174 for (TreeItem childItem
: item
.getItems()) {
175 paintItem(childItem
, color
, doPaintChildren
);