/
VirtualContent.java
278 lines (236 loc) · 6.55 KB
/
VirtualContent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*******************************************************************************************************
*
* VirtualContent.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.ui.navigator.contents;
import static ummisco.gama.ui.resources.IGamaIcons.OVERLAY_OK;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import ummisco.gama.ui.resources.GamaColors.GamaUIColor;
import ummisco.gama.ui.resources.GamaIcons;
import ummisco.gama.ui.resources.IGamaColors;
/**
* The Class VirtualContent.
*
* @param <P>
* the generic type
*/
public abstract class VirtualContent<P extends VirtualContent<?>> {
/**
* The Enum VirtualContentType.
*/
public enum VirtualContentType {
/** The root. */
ROOT,
/** The virtual folder. */
VIRTUAL_FOLDER,
/** The project. */
PROJECT,
/** The folder. */
FOLDER,
/** The file. */
FILE,
/** The file reference. */
FILE_REFERENCE,
/** The category. */
CATEGORY,
/** The gaml element. */
GAML_ELEMENT
}
/** The default label provider. */
public static ILabelProvider DEFAULT_LABEL_PROVIDER = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider();
/** The Constant DESCRIPTORS. */
public static final Map<Integer, ImageDescriptor> DESCRIPTORS = new HashMap<>() {
{
put(CLOSED, GamaIcons.create("navigator/overlay.closed2").descriptor());
put(NO_PROBLEM, GamaIcons.create(OVERLAY_OK).descriptor());
put(IMarker.SEVERITY_INFO, GamaIcons.create(OVERLAY_OK).descriptor());
put(IMarker.SEVERITY_WARNING, GamaIcons.create("navigator/overlay.warning2").descriptor());
put(IMarker.SEVERITY_ERROR, GamaIcons.create("navigator/overlay.error2").descriptor());
put(LINK_OK, GamaIcons.create("navigator/overlay.ok").descriptor());
put(LINK_BROKEN, GamaIcons.create("navigator/overlay.link.broken").descriptor());
put(WEBLINK_OK, GamaIcons.create("navigator/overlay.cloud").descriptor());
put(WEBLINK_BROKEN, GamaIcons.create("navigator/overlay.link.broken").descriptor());
}
};
/** The Constant NO_PROBLEM. */
public static final int NO_PROBLEM = -1;
/** The Constant CLOSED. */
public static final int CLOSED = -2;
/** The Constant LINK_OK. */
public static final int LINK_OK = -3;
/** The Constant LINK_BROKEN. */
public static final int LINK_BROKEN = -4;
/** The Constant WEBLINK_OK. */
public static final int WEBLINK_OK = -5;
/** The Constant WEBLINK_BROKEN. */
public static final int WEBLINK_BROKEN = -6;
/** The empty. */
public static Object[] EMPTY = {};
/** The root. */
private final P root;
/** The name. */
private final String name;
/**
* Instantiates a new virtual content.
*
* @param root
* the root
* @param name
* the name
*/
public VirtualContent(final P root, final String name) {
this.root = root;
this.name = name;
}
/**
* Gets the manager.
*
* @return the manager
*/
public ResourceManager getManager() { return NavigatorRoot.getInstance().getManager(); }
/**
* Gets the type.
*
* @return the type
*/
public abstract VirtualContentType getType();
/**
* Should both perform something and answer whether or not it has performed it, so that the navigator knows whether
* it should handle double-clicks itself
*
* @return
*/
public boolean handleDoubleClick() {
return false;
}
/**
* Handle single click.
*
* @return true, if successful
*/
public boolean handleSingleClick() {
return false;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() { return name; }
/**
* Gets the parent.
*
* @return the parent
*/
public P getParent() { return root; }
/**
* Checks for children.
*
* @return true, if successful
*/
public abstract boolean hasChildren();
/**
* Gets the navigator children.
*
* @return the navigator children
*/
public abstract Object[] getNavigatorChildren();
/**
* Gets the image.
*
* @return the image
*/
public abstract Image getImage();
public Color getColor() { return null; }
/**
* Gets the suffix.
*
* @param sb
* the sb
* @return the suffix
*/
public abstract void getSuffix(StringBuilder sb);
// public Font getFont() {
// return GamaFonts.getNavigFolderFont(); // by default
// }
/**
* Find max problem severity.
*
* @return the int
*/
public abstract int findMaxProblemSeverity();
/**
* Gets the overlay.
*
* @return the overlay
*/
public abstract ImageDescriptor getOverlay();
/**
* Gets the top level folder.
*
* @return the top level folder
*/
public TopLevelFolder getTopLevelFolder() {
final Object p = getParent();
if (p instanceof VirtualContent) return ((VirtualContent<?>) p).getTopLevelFolder();
return null;
}
/**
* Gets the project.
*
* @return the project
*/
public WrappedProject getProject() {
final Object p = getParent();
if (p instanceof VirtualContent) return ((VirtualContent<?>) p).getProject();
return null;
}
/**
* Gets the status message.
*
* @return the status message
*/
public String getStatusMessage() { return getName(); }
/**
* Gets the status tooltip.
*
* @return the status tooltip
*/
public String getStatusTooltip() { return null; }
/**
* Gets the status color.
*
* @return the status color
*/
public GamaUIColor getStatusColor() { return IGamaColors.GRAY_LABEL; }
/**
* Gets the status image.
*
* @return the status image
*/
public Image getStatusImage() { return getImage(); }
/**
* Checks if is contained in.
*
* @param current
* the current
* @return true, if is contained in
*/
public boolean isContainedIn(final VirtualContent<?> current) {
if (root == null) return false;
return root == current || root.isContainedIn(current);
}
}