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 java.util.SortedSet;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.swt.graphics.Color;
|
16
|
import org.eclipse.swt.widgets.Tree;
|
17
|
import org.eclipse.swt.widgets.TreeItem;
|
18
|
import org.eclipse.ui.IActionBars;
|
19
|
import org.eclipse.ui.IPageLayout;
|
20
|
import org.eclipse.ui.IViewPart;
|
21
|
import org.eclipse.ui.IViewReference;
|
22
|
import org.eclipse.ui.IWorkbenchPage;
|
23
|
import org.eclipse.ui.views.properties.PropertySheet;
|
24
|
import org.eclipse.ui.views.properties.PropertySheetPage;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
27
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @created 20.01.2009
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class PropertySheetUtil {
|
36
|
private static final Logger logger = Logger
|
37
|
.getLogger(PropertySheetUtil.class);
|
38
|
|
39
|
private static PropertySheetUtil instance;
|
40
|
|
41
|
public static PropertySheetUtil getInstance(){
|
42
|
if(instance == null){
|
43
|
instance = new PropertySheetUtil();
|
44
|
}
|
45
|
return instance;
|
46
|
}
|
47
|
|
48
|
public static IViewPart getPropertySheet() {
|
49
|
IWorkbenchPage activePage = TaxeditorEditorPlugin.getDefault().getWorkbench()
|
50
|
.getActiveWorkbenchWindow().getActivePage();
|
51
|
for (IViewReference reference : activePage.getViewReferences()) {
|
52
|
if (reference.getId().equals(IPageLayout.ID_PROP_SHEET)) {
|
53
|
logger.warn(reference.getView(false).getSite().getPart().getTitle());
|
54
|
return reference.getView(false);
|
55
|
}
|
56
|
}
|
57
|
return null;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* By default, property sheet has buttons in the toolbar for
|
62
|
* "Show advanced properties" and "Show categories".
|
63
|
* <p>
|
64
|
* This is confusing for the user, hence a method to remove them
|
65
|
* until such time as advanced properties or categories are implemented.
|
66
|
*/
|
67
|
public static void hidePropertySheetToolbar() {
|
68
|
PropertySheet propertySheet = (PropertySheet) getPropertySheet();
|
69
|
IActionBars actionBars = propertySheet.getViewSite().getActionBars();
|
70
|
actionBars.getToolBarManager().removeAll();
|
71
|
actionBars.getMenuManager().removeAll();
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* The property sheet listener ensures only property sheets
|
76
|
* with data cause the Property Sheet to be updated.
|
77
|
*/
|
78
|
public static void addPropertySheetInputListener() {
|
79
|
IViewPart propertySheet = getPropertySheet();
|
80
|
// propertySheet.get
|
81
|
PropertySheet ps = (PropertySheet) propertySheet;
|
82
|
// ps.addPartPropertyListener(listener)
|
83
|
// ps.addPropertyListener(l)
|
84
|
}
|
85
|
|
86
|
public static void setPropertySheetTree(Tree tree) {
|
87
|
getInstance().setPropertySheetTreeInternal(tree);
|
88
|
}
|
89
|
|
90
|
public static Tree getPropertySheetTree() {
|
91
|
return getInstance().getPropertySheetTreeInternal();
|
92
|
}
|
93
|
|
94
|
public static void setPropertySheetPage(PropertySheetPage page) {
|
95
|
getInstance().setPropertySheetPageInternal(page);
|
96
|
}
|
97
|
|
98
|
public static PropertySheetPage getPropertySheetPage() {
|
99
|
return getInstance().getPropertySheetPageInternal();
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true);
|
104
|
* UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED);
|
105
|
*
|
106
|
* @param id
|
107
|
* @param color
|
108
|
* @param doPaintChildren
|
109
|
*/
|
110
|
// public static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren) {
|
111
|
//
|
112
|
// // Catch null property sheet name
|
113
|
// if (id == null) {
|
114
|
// return;
|
115
|
// }
|
116
|
//
|
117
|
// // Catch uninit'ed property sheet tree
|
118
|
// if (getPropertySheetTree() == null) {
|
119
|
// return;
|
120
|
// }
|
121
|
//
|
122
|
// paintPropertySheetRow(id, color, doPaintChildren, getPropertySheetTree());
|
123
|
// }
|
124
|
|
125
|
// private static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren, Object treeOrItem) {
|
126
|
//
|
127
|
// // Init items w zero-length array
|
128
|
// TreeItem[] items = new TreeItem[]{};
|
129
|
//
|
130
|
// // Get child items depending to class
|
131
|
// if (treeOrItem instanceof Tree) {
|
132
|
// items = ((Tree) treeOrItem).getItems();
|
133
|
// }
|
134
|
// if (treeOrItem instanceof TreeItem) {
|
135
|
// items = ((TreeItem) treeOrItem).getItems();
|
136
|
// }
|
137
|
//
|
138
|
// // If array hasn't been populated by the above, return
|
139
|
// if (items.length == 0) {
|
140
|
// return;
|
141
|
// }
|
142
|
//
|
143
|
// // Prop. sheet id's take the form "01:xxxx" for sorting - truncate
|
144
|
// id = EditorPropertySheetEntry.truncateDisplayName(id);
|
145
|
//
|
146
|
// // Iterate through child items
|
147
|
// for (TreeItem item : items) {
|
148
|
//
|
149
|
// // Item found, paint it
|
150
|
// if (id.equals(item.getText())) {
|
151
|
// paintItem(item, color, doPaintChildren);
|
152
|
// return;
|
153
|
// }
|
154
|
//
|
155
|
// // Recursively search for item to paint in child items
|
156
|
// if (item.getItemCount() > 0) {
|
157
|
// paintPropertySheetRow(id, color, doPaintChildren, item);
|
158
|
// }
|
159
|
// }
|
160
|
// }
|
161
|
|
162
|
// public static void unpaintPropertySheetRow(String id) {
|
163
|
//
|
164
|
// // Catch uninit'ed property sheet tree
|
165
|
// if (getPropertySheetTree() == null) {
|
166
|
// return;
|
167
|
// }
|
168
|
//
|
169
|
// // Get tree's background color to "unpaint"
|
170
|
// Color color = getPropertySheetTree().getBackground();
|
171
|
//
|
172
|
// paintPropertySheetRow(id, color, true);
|
173
|
// }
|
174
|
|
175
|
/**
|
176
|
* Note: children are only painted if submenu has already been created, i.e. opened once.
|
177
|
*
|
178
|
* @param item
|
179
|
* @param color
|
180
|
* @param doPaintChildren
|
181
|
*/
|
182
|
public static void paintItem(TreeItem item, Color color, boolean doPaintChildren) {
|
183
|
|
184
|
// Paint the item
|
185
|
item.setBackground(color);
|
186
|
|
187
|
// Recursively paint child items if requested
|
188
|
if (doPaintChildren) {
|
189
|
for (TreeItem childItem : item.getItems()) {
|
190
|
paintItem(childItem, color, doPaintChildren);
|
191
|
}
|
192
|
}
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* Get the name out of the session's name relations vocabulary, not directly
|
197
|
* from the object.
|
198
|
*
|
199
|
* @param type
|
200
|
* @return
|
201
|
*/
|
202
|
public static String getNameRelationLabelType(NameRelationshipType type) {
|
203
|
SortedSet<NameRelationshipType> vocab =
|
204
|
CdmStore.getDefault().getNameRelationshipTypes();
|
205
|
for (NameRelationshipType type1 : vocab) {
|
206
|
if (type1.equals(type)) {
|
207
|
return type1.getLabel();
|
208
|
}
|
209
|
}
|
210
|
return "";
|
211
|
}
|
212
|
|
213
|
/***************************************************************************
|
214
|
* PROPERTY SHEET
|
215
|
**************************************************************************/
|
216
|
|
217
|
private Tree propertySheetTree;
|
218
|
|
219
|
private void setPropertySheetTreeInternal(Tree tree) {
|
220
|
this.propertySheetTree = tree;
|
221
|
}
|
222
|
|
223
|
private Tree getPropertySheetTreeInternal() {
|
224
|
return propertySheetTree;
|
225
|
}
|
226
|
|
227
|
private PropertySheetPage propertySheetPage;
|
228
|
|
229
|
private void setPropertySheetPageInternal(PropertySheetPage page) {
|
230
|
this.propertySheetPage = page;
|
231
|
}
|
232
|
|
233
|
private PropertySheetPage getPropertySheetPageInternal() {
|
234
|
return propertySheetPage;
|
235
|
}
|
236
|
|
237
|
}
|