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
.propertysheet
;
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
.IWorkbenchPage
;
21 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
22 import org
.eclipse
.ui
.views
.properties
.PropertySheetPage
;
24 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
31 public class PropertySheetUtil
{
32 private static final Logger logger
= Logger
33 .getLogger(PropertySheetUtil
.class);
35 private static PropertySheetUtil instance
;
37 public static PropertySheetUtil
getInstance(){
39 instance
= new PropertySheetUtil();
44 public static IViewPart
getPropertySheet() {
45 IWorkbenchPage activePage
= TaxeditorEditorPlugin
.getDefault().getWorkbench()
46 .getActiveWorkbenchWindow().getActivePage();
47 for (IViewReference reference
: activePage
.getViewReferences()) {
48 if (reference
.getId().equals(IPageLayout
.ID_PROP_SHEET
)) {
49 logger
.warn(reference
.getView(false).getSite().getPart().getTitle());
50 return reference
.getView(false);
57 * By default, property sheet has buttons in the toolbar for
58 * "Show advanced properties" and "Show categories".
60 * This is confusing for the user, hence a method to remove them
61 * until such time as advanced properties or categories are implemented.
63 public static void hidePropertySheetToolbar() {
64 PropertySheet propertySheet
= (PropertySheet
) getPropertySheet();
65 IActionBars actionBars
= propertySheet
.getViewSite().getActionBars();
66 actionBars
.getToolBarManager().removeAll();
67 actionBars
.getMenuManager().removeAll();
71 * The property sheet listener ensures only property sheets
72 * with data cause the Property Sheet to be updated.
74 @Deprecated // FIXME looks unused and does not make sense
75 public static void addPropertySheetInputListener() {
76 IViewPart propertySheet
= getPropertySheet();
78 PropertySheet ps
= (PropertySheet
) propertySheet
;
79 // ps.addPartPropertyListener(listener)
80 // ps.addPropertyListener(l)
83 public static void setPropertySheetTree(Tree tree
) {
84 getInstance().setPropertySheetTreeInternal(tree
);
87 public static Tree
getPropertySheetTree() {
88 return getInstance().getPropertySheetTreeInternal();
91 public static void setPropertySheetPage(PropertySheetPage page
) {
92 getInstance().setPropertySheetPageInternal(page
);
95 public static PropertySheetPage
getPropertySheetPage() {
96 return getInstance().getPropertySheetPageInternal();
100 * UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true);
101 * UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED);
105 * @param doPaintChildren
107 // public static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren) {
109 // // Catch null property sheet name
114 // // Catch uninit'ed property sheet tree
115 // if (getPropertySheetTree() == null) {
119 // paintPropertySheetRow(id, color, doPaintChildren, getPropertySheetTree());
122 // private static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren, Object treeOrItem) {
124 // // Init items w zero-length array
125 // TreeItem[] items = new TreeItem[]{};
127 // // Get child items depending to class
128 // if (treeOrItem instanceof Tree) {
129 // items = ((Tree) treeOrItem).getItems();
131 // if (treeOrItem instanceof TreeItem) {
132 // items = ((TreeItem) treeOrItem).getItems();
135 // // If array hasn't been populated by the above, return
136 // if (items.length == 0) {
140 // // Prop. sheet id's take the form "01:xxxx" for sorting - truncate
141 // id = EditorPropertySheetEntry.truncateDisplayName(id);
143 // // Iterate through child items
144 // for (TreeItem item : items) {
146 // // Item found, paint it
147 // if (id.equals(item.getText())) {
148 // paintItem(item, color, doPaintChildren);
152 // // Recursively search for item to paint in child items
153 // if (item.getItemCount() > 0) {
154 // paintPropertySheetRow(id, color, doPaintChildren, item);
159 // public static void unpaintPropertySheetRow(String id) {
161 // // Catch uninit'ed property sheet tree
162 // if (getPropertySheetTree() == null) {
166 // // Get tree's background color to "unpaint"
167 // Color color = getPropertySheetTree().getBackground();
169 // paintPropertySheetRow(id, color, true);
173 * Note: children are only painted if submenu has already been created, i.e. opened once.
177 * @param doPaintChildren
179 public static void paintItem(TreeItem item
, Color color
, boolean doPaintChildren
) {
182 item
.setBackground(color
);
184 // Recursively paint child items if requested
185 if (doPaintChildren
) {
186 for (TreeItem childItem
: item
.getItems()) {
187 paintItem(childItem
, color
, doPaintChildren
);
192 /***************************************************************************
194 **************************************************************************/
196 private Tree propertySheetTree
;
198 private void setPropertySheetTreeInternal(Tree tree
) {
199 this.propertySheetTree
= tree
;
202 private Tree
getPropertySheetTreeInternal() {
203 return propertySheetTree
;
206 private PropertySheetPage propertySheetPage
;
208 private void setPropertySheetPageInternal(PropertySheetPage page
) {
209 this.propertySheetPage
= page
;
212 private PropertySheetPage
getPropertySheetPageInternal() {
213 return propertySheetPage
;