Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a33fef2cef24a62075af865833a46a4255150f13 (plain) (blame)
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/**
 *  Copyright (c) 2012 Mia-Software.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  	Gregoire Dupe (Mia-Software) - Bug 361794 - [Restructuring] New customization meta-model
 *      Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
 *      Vincent Lorenzo (CEA-LIST) - Bug 372644 - Create Customizable tooltips for the TreeViewer using a CustomizableLabelProvider
 *      Gregoire Dupe (Mia-Software) - Bug 372644 - Create Customizable tooltips for the TreeViewer using a CustomizableLabelProvider
 *      Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
 *      Nicolas Bros (Mia-Software) - Bug 377866 - selection customization
 *      David Couvrand (Soft-Maint) - Bug 422058 - Implementation of strikethrough and underline in the CustomizedLabelProvider
 */
package org.eclipse.papyrus.emf.facet.custom.ui.internal;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.emf.facet.custom.ui.IContentPropertiesHandler;
import org.eclipse.papyrus.emf.facet.custom.ui.IFontPropertiesHandler;
import org.eclipse.papyrus.emf.facet.custom.ui.ISelectionPropertiesHandler;
import org.eclipse.papyrus.emf.facet.custom.ui.internal.exported.ILabelPropertiesHandler;
import org.eclipse.papyrus.emf.facet.efacet.core.FacetUtils;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;

public class PropertiesHandler implements IContentPropertiesHandler,
		ILabelPropertiesHandler, ISelectionPropertiesHandler, IFontPropertiesHandler {
	private static final String SEPARATOR = "::"; //$NON-NLS-1$
	private static final String CUSTOM_PROPERTIES = "resources/customproperties.efacet"; //$NON-NLS-1$

	private static final String CUSTOM = "CustomizedEObject"; //$NON-NLS-1$
	private static final String TT_CUSTOM = "CustomizedToolTipEObject"; //$NON-NLS-1$

	private static final String IMAGE = "image"; //$NON-NLS-1$
	private static final String LABEL = "label"; //$NON-NLS-1$
	private static final String BACKGROUND = "background"; //$NON-NLS-1$
	private static final String FOREGROUND = "foreground"; //$NON-NLS-1$
	private static final String FONT = "fontName"; //$NON-NLS-1$
	private static final String FONT_SIZE = "fontSize"; //$NON-NLS-1$
	private static final String IS_BOLD = "isBold"; //$NON-NLS-1$
	private static final String IS_ITALIC = "isItalic"; //$NON-NLS-1$
	private static final String COLLAPSE_LINK = "collapseLink"; //$NON-NLS-1$
	private static final String IS_VISIBLE = "isVisible"; //$NON-NLS-1$
	private static final String VISIBLE_REFERENCES = "visibleReferences"; //$NON-NLS-1$
	private static final String VISIBLE_ATTRIBUTES = "visibleAttributes"; //$NON-NLS-1$
	private static final String IS_UNDERLINED = "isUnderlined"; //$NON-NLS-1$
	private static final String IS_STRUCKTHROUGH = "isStruckthrough"; //$NON-NLS-1$
	private static final String TOP_L_OVERLAY = "topLeftOverlay"; //$NON-NLS-1$
	private static final String TOP_M_OVERLAY = "topMiddleOverlay"; //$NON-NLS-1$
	private static final String TOP_R_OVERLAY = "topRightOverlay"; //$NON-NLS-1$
	private static final String BOTTOM_L_OVERLAY = "bottomLeftOverlay"; //$NON-NLS-1$
	private static final String BOTTOM_M_OVERLAY = "bottomMiddleOverlay"; //$NON-NLS-1$
	private static final String BOTTOM_R_OVERLAY = "bottomRightOverlay"; //$NON-NLS-1$
	private static final String SELECTION = "selection"; //$NON-NLS-1$

	// for tooltips
	private static final String TEXT = "text"; //$NON-NLS-1$
	private static final String TIME_DISPLAYED = "timeDisplayed"; //$NON-NLS-1$
	private static final String DISPLAY_DELAY = "displayDelayTime"; //$NON-NLS-1$
	private static final String SHADOW = "shadow"; //$NON-NLS-1$
	private static final String ALIGNMENT = "alignment"; //$NON-NLS-1$

	private final Resource resource;
	private final Map<String, FacetOperation> map = new HashMap<String, FacetOperation>();

	/**
	 *
	 * @deprecated Must be replaced by
	 *             org.eclipse.papyrus.emf.facet.custom.ui.internal.PropertiesHandler
	 *             .PropertiesHandler(ICustomizationManager)
	 */
	@Deprecated
	public PropertiesHandler(final ResourceSet resourceSet) {
		final String bundleName = Activator.getDefault().getBundle().getSymbolicName();
		URI propertiesUri = URI.createPlatformPluginURI(bundleName, true);
		propertiesUri = propertiesUri
				.appendSegments(PropertiesHandler.CUSTOM_PROPERTIES.split("/")); //$NON-NLS-1$
		this.resource = resourceSet.getResource(propertiesUri, true);
	}

	public PropertiesHandler(final ICustomizationManager customizationMgr) {
		final String bundleName = Activator.getDefault().getBundle().getSymbolicName();
		URI propertiesUri = URI.createPlatformPluginURI(bundleName, true);
		propertiesUri = propertiesUri
				.appendSegments(PropertiesHandler.CUSTOM_PROPERTIES.split("/")); //$NON-NLS-1$
		final ResourceSet resourceSet = customizationMgr.getResourceSet();
		this.resource = resourceSet.getResource(propertiesUri, true);
		final FacetSet facetSet = (FacetSet) this.resource.getContents().get(0);
		customizationMgr.getFacetManager().getManagedFacetSets()
				.add(0, facetSet);
	}

	private FacetOperation getPropertyByName(final String facetName,
			final String propertyName) {
		final String key = facetName + PropertiesHandler.SEPARATOR + propertyName;
		FacetOperation result = this.map.get(key);
		if (result == null) {
			final FacetSet facetSet = (FacetSet) this.resource.getContents()
					.get(0);
			final Facet facet = FacetUtils.getFacet(
					FacetUtils.getFacets(facetSet),
					facetName);
			final ETypedElement eTypedElement = FacetUtils
					.getETypedElement(facet, propertyName,
							ETypedElement.class);
			if (eTypedElement instanceof FacetOperation) {
				result = (FacetOperation) eTypedElement;
				this.map.put(key, result);
			}
		}
		return result;
	}

	public FacetOperation getImageProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IMAGE);
	}


	@Override
	public FacetOperation getCollapseLink() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.COLLAPSE_LINK);
	}

	@Override
	public FacetOperation getLabelProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.LABEL);
	}

	@Override
	public FacetOperation getBackgroundProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.BACKGROUND);
	}

	@Override
	public FacetOperation getForegroundProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.FOREGROUND);
	}

	@Override
	public FacetOperation getFontNameProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.FONT);
	}

	@Override
	public FacetOperation getFontSizeProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.FONT_SIZE);
	}

	@Override
	public FacetOperation getIsBoldProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IS_BOLD);
	}

	@Override
	public FacetOperation getIsItalicProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IS_ITALIC);
	}

	@Override
	public FacetOperation getIsVisible() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IS_VISIBLE);
	}

	@Override
	public FacetOperation getIsUnderlinedProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IS_UNDERLINED);
	}

	@Override
	public FacetOperation getIsStruckthroughProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.IS_STRUCKTHROUGH);
	}

	public FacetOperation getTopLeftOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.TOP_L_OVERLAY);
	}

	public FacetOperation getTopMiddleOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.TOP_M_OVERLAY);
	}

	public FacetOperation getTopRightOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.TOP_R_OVERLAY);
	}

	public FacetOperation getBottomLeftOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.BOTTOM_L_OVERLAY);
	}

	public FacetOperation getBottomMiddleOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.BOTTOM_M_OVERLAY);
	}

	public FacetOperation getBottomRightOverlayProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.BOTTOM_R_OVERLAY);
	}

	@Override
	public FacetOperation getSelectionProperty() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.SELECTION);
	}

	// methods for tooltips
	public FacetOperation getToolTipTextProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.TEXT);
	}

	public FacetOperation getToolTipImageProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.IMAGE);
	}

	public FacetOperation getToolTipFontNameProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.FONT);
	}

	public FacetOperation getToolTipFontSizeProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.FONT_SIZE);
	}

	public FacetOperation getToolTipIsBoldProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.IS_BOLD);
	}

	public FacetOperation getToolTipIsItalicProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.IS_ITALIC);
	}

	public FacetOperation getToolTipBackgroundProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.BACKGROUND);
	}

	public FacetOperation getToolTipForegroundProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.FOREGROUND);
	}

	public FacetOperation getToolTipTopLeftOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.TOP_L_OVERLAY);
	}

	public FacetOperation getToolTipTopMiddleOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.TOP_M_OVERLAY);
	}

	public FacetOperation getToolTipTopRightOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.TOP_R_OVERLAY);
	}

	public FacetOperation getToolTipBottomLeftOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.BOTTOM_L_OVERLAY);
	}

	public FacetOperation getToolTipBottomMiddleOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.BOTTOM_M_OVERLAY);
	}

	public FacetOperation getToolTipBottomRightOverlayProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.BOTTOM_R_OVERLAY);
	}

	public FacetOperation getToolTipTimeDisplayedProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.TIME_DISPLAYED);
	}

	public FacetOperation getToolTipDisplayDelayTimeProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.DISPLAY_DELAY);
	}

	public FacetOperation getToolTipAlignmentProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.ALIGNMENT);
	}

	public FacetOperation getToolTipShadowProperty() {
		return getPropertyByName(PropertiesHandler.TT_CUSTOM,
				PropertiesHandler.SHADOW);
	}

	/**
	 * @see org.eclipse.papyrus.emf.facet.custom.ui.IContentPropertiesHandler#getVisibleAttributes()
	 *
	 * @return
	 */
	@Override
	public FacetOperation getVisibleAttributes() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.VISIBLE_ATTRIBUTES);
	}

	/**
	 * @see org.eclipse.papyrus.emf.facet.custom.ui.IContentPropertiesHandler#getVisibleReferences()
	 *
	 * @return
	 */
	@Override
	public FacetOperation getVisibleReferences() {
		return getPropertyByName(PropertiesHandler.CUSTOM,
				PropertiesHandler.VISIBLE_REFERENCES);
	}
}

Back to the top