Project

General

Profile

Download (6.33 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.propertysheet;
11

    
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;
23

    
24
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
25

    
26
/**
27
 * @author n.hoffmann
28
 * @created 20.01.2009
29
 * @version 1.0
30
 */
31
public class PropertySheetUtil {
32
	private static final Logger logger = Logger
33
			.getLogger(PropertySheetUtil.class);
34

    
35
	private static PropertySheetUtil instance;
36
	
37
	public static PropertySheetUtil getInstance(){
38
		if(instance == null){
39
			instance = new PropertySheetUtil();
40
		}
41
		return instance;
42
	}
43
	
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);
51
			}
52
		}
53
		return null;
54
	}
55

    
56
	/**
57
	 * By default, property sheet has buttons in the toolbar for 
58
	 * "Show advanced properties" and "Show categories".
59
	 * <p>
60
	 * This is confusing for the user, hence a method to remove them
61
	 * until such time as advanced properties or categories are implemented.
62
	 */
63
	public static void hidePropertySheetToolbar() {
64
		PropertySheet propertySheet = (PropertySheet) getPropertySheet();
65
		IActionBars actionBars = propertySheet.getViewSite().getActionBars();
66
		actionBars.getToolBarManager().removeAll();
67
		actionBars.getMenuManager().removeAll();
68
	}
69

    
70
	/**
71
		 * The property sheet listener ensures only property sheets
72
		 * 	with data cause the Property Sheet to be updated.
73
		 */
74
		@Deprecated // FIXME looks unused and does not make sense
75
		public static void addPropertySheetInputListener() {
76
			IViewPart propertySheet = getPropertySheet();
77
	//		propertySheet.get
78
			PropertySheet ps = (PropertySheet) propertySheet;
79
	//		ps.addPartPropertyListener(listener)
80
	//		ps.addPropertyListener(l)
81
		}
82

    
83
	public static void setPropertySheetTree(Tree tree) {
84
		getInstance().setPropertySheetTreeInternal(tree);		
85
	}
86

    
87
	public static Tree getPropertySheetTree() {
88
		return getInstance().getPropertySheetTreeInternal();		
89
	}
90

    
91
	public static void setPropertySheetPage(PropertySheetPage page) {
92
		getInstance().setPropertySheetPageInternal(page);
93
	}
94

    
95
	public static PropertySheetPage getPropertySheetPage() {
96
		return getInstance().getPropertySheetPageInternal();	
97
	}
98

    
99
	/**
100
	 * 		UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true);
101
	 * 		UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED);
102
	 * 
103
	 * @param id
104
	 * @param color
105
	 * @param doPaintChildren
106
	 */
107
//	public static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren) {
108
//		
109
//		// Catch null property sheet name
110
//		if (id == null) {
111
//			return;
112
//		}
113
//		
114
//		// Catch uninit'ed property sheet tree
115
//		if (getPropertySheetTree() == null) {
116
//			return;
117
//		}
118
//		
119
//		paintPropertySheetRow(id, color, doPaintChildren, getPropertySheetTree());
120
//	}
121

    
122
//	private static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren, Object treeOrItem) {
123
//		
124
//		// Init items w zero-length array
125
//		TreeItem[] items = new TreeItem[]{};
126
//		
127
//		// Get child items depending to class
128
//		if (treeOrItem instanceof Tree) {
129
//			items = ((Tree) treeOrItem).getItems();
130
//		}
131
//		if (treeOrItem instanceof TreeItem) {
132
//			items = ((TreeItem) treeOrItem).getItems();
133
//		}
134
//		
135
//		// If array hasn't been populated by the above, return
136
//		if (items.length == 0) {
137
//			return;
138
//		}
139
//	
140
//		// Prop. sheet id's take the form "01:xxxx" for sorting - truncate
141
//		id = EditorPropertySheetEntry.truncateDisplayName(id);
142
//		
143
//		// Iterate through child items
144
//		for (TreeItem item : items) {
145
//	
146
//			// Item found, paint it
147
//			if (id.equals(item.getText())) {
148
//				paintItem(item, color, doPaintChildren);
149
//				return;
150
//			}			
151
//	
152
//			// Recursively search for item to paint in child items
153
//			if (item.getItemCount() > 0) {
154
//				paintPropertySheetRow(id, color, doPaintChildren, item);
155
//			}
156
//		}	
157
//	}
158

    
159
//	public static void unpaintPropertySheetRow(String id) {
160
//		
161
//		// Catch uninit'ed property sheet tree
162
//		if (getPropertySheetTree() == null) {
163
//			return;
164
//		}
165
//		
166
//		// Get tree's background color to "unpaint"
167
//		Color color = getPropertySheetTree().getBackground();
168
//		
169
//		paintPropertySheetRow(id, color, true);
170
//	}
171

    
172
	/**
173
	 * Note: children are only painted if submenu has already been created, i.e. opened once.
174
	 * 
175
	 * @param item
176
	 * @param color
177
	 * @param doPaintChildren
178
	 */
179
	public static void paintItem(TreeItem item, Color color, boolean doPaintChildren) {
180
		
181
		// Paint the item
182
		item.setBackground(color);
183
		
184
		// Recursively paint child items if requested
185
		if (doPaintChildren) {
186
			for (TreeItem childItem : item.getItems()) {
187
				paintItem(childItem, color, doPaintChildren);
188
			}
189
		}
190
	}
191
	
192
	/***************************************************************************
193
	 * PROPERTY SHEET
194
	 **************************************************************************/
195
	
196
	private Tree propertySheetTree;
197
	
198
	private void setPropertySheetTreeInternal(Tree tree) {
199
		this.propertySheetTree = tree;
200
	}
201
	
202
	private Tree getPropertySheetTreeInternal() {
203
		return propertySheetTree;
204
	}
205

    
206
	private PropertySheetPage propertySheetPage;
207
	
208
	private void setPropertySheetPageInternal(PropertySheetPage page) {
209
		this.propertySheetPage = page;
210
	}
211
	
212
	private PropertySheetPage getPropertySheetPageInternal() {
213
		return propertySheetPage;
214
	}
215
	
216
}
(20-20/24)