Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d8546aeacbc58e09951d25dd0cdcc6bab308f0f4 (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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*******************************************************************************
 * Copyright (c) 2008, 2012 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.eef.navigation.components;

// Start of user code for imports
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.WrappedException;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;

import org.eclipse.emf.ecore.resource.ResourceSet;

import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;

import org.eclipse.emf.eef.eefnr.EefnrPackage;

import org.eclipse.emf.eef.eefnr.navigation.AttributeNavigationSample;
import org.eclipse.emf.eef.eefnr.navigation.NavigationPackage;

import org.eclipse.emf.eef.eefnr.navigation.parts.AttributeNavigationSamplePropertiesEditionPart;
import org.eclipse.emf.eef.eefnr.navigation.parts.NavigationViewsRepository;

import org.eclipse.emf.eef.runtime.api.notify.EStructuralFeatureNotificationFilter;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.api.notify.NotificationFilter;

import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext;

import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent;

import org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart;

import org.eclipse.emf.eef.runtime.impl.utils.EEFConverterUtil;

import org.eclipse.emf.eef.runtime.ui.widgets.settings.EEFEditorSettingsBuilder;

import org.eclipse.emf.eef.runtime.ui.widgets.settings.EEFEditorSettingsBuilder.EEFEditorSettingsImpl;

import org.eclipse.emf.eef.runtime.ui.widgets.settings.EEFFilter;
import org.eclipse.emf.eef.runtime.ui.widgets.settings.EEFInitializer;
import org.eclipse.emf.eef.runtime.ui.widgets.settings.NavigationStepBuilder;


// End of user code

/**
 * @author <a href="mailto:nathalie.lepine@obeo.fr">Nathalie Lepine</a>
 * 
 */
public class AttributeNavigationSamplePropertiesEditionComponent extends SinglePartPropertiesEditingComponent {

	
	public static String BASE_PART = "Base"; //$NON-NLS-1$

	
	
	/**
	 * Settings for delegate1ForSingleValued editor
	 */
	protected EEFEditorSettingsImpl delegate1ForSingleValuedSettings = (EEFEditorSettingsImpl) EEFEditorSettingsBuilder.create(semanticObject, NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1())
	.nextStep(NavigationStepBuilder.create(NavigationPackage.eINSTANCE.getAttributeNavigationSample_SingleValuedAttributeDelegate())
	.index(0).build())
	.build();
	
	/**
	 * Settings for delegate2ForSingleValued editor
	 */
	protected EEFEditorSettingsImpl delegate2ForSingleValuedSettings = (EEFEditorSettingsImpl) EEFEditorSettingsBuilder.create(semanticObject, NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2())
	.nextStep(NavigationStepBuilder.create(NavigationPackage.eINSTANCE.getAttributeNavigationSample_SingleValuedAttributeDelegate())
	.index(0).build())
	.build();
	
	/**
	 * Settings for delegate1ForMultiValued editor
	 */
	protected EEFEditorSettingsImpl delegate1ForMultiValuedSettings = (EEFEditorSettingsImpl) EEFEditorSettingsBuilder.create(semanticObject, NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1())
	.nextStep(NavigationStepBuilder.create(NavigationPackage.eINSTANCE.getAttributeNavigationSample_MultiValuedAttributeDelegate())
	.index(0).build())
	.build();
	
	/**
	 * Settings for delegate2ForMultiValued editor
	 */
	protected EEFEditorSettingsImpl delegate2ForMultiValuedSettings = (EEFEditorSettingsImpl) EEFEditorSettingsBuilder.create(semanticObject, NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2())
	.nextStep(NavigationStepBuilder.create(NavigationPackage.eINSTANCE.getAttributeNavigationSample_MultiValuedAttributeDelegate())
	.index(0).build())
	.build();
	
	/**
	 * Default constructor
	 * 
	 */
	public AttributeNavigationSamplePropertiesEditionComponent(PropertiesEditingContext editingContext, EObject attributeNavigationSample, String editing_mode) {
		super(editingContext, attributeNavigationSample, editing_mode);
		parts = new String[] { BASE_PART };
		repositoryKey = NavigationViewsRepository.class;
		partKey = NavigationViewsRepository.AttributeNavigationSample.class;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject, 
	 *      org.eclipse.emf.ecore.resource.ResourceSet)
	 * 
	 */
	public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
		setInitializing(true);
		if (editingPart != null && key == partKey) {
			editingPart.setContext(elt, allResource);
			if (editingPart instanceof CompositePropertiesEditionPart) {
				((CompositePropertiesEditionPart) editingPart).getSettings().add(delegate1ForSingleValuedSettings);
				((CompositePropertiesEditionPart) editingPart).getSettings().add(delegate2ForSingleValuedSettings);
				((CompositePropertiesEditionPart) editingPart).getSettings().add(delegate1ForMultiValuedSettings);
				((CompositePropertiesEditionPart) editingPart).getSettings().add(delegate2ForMultiValuedSettings);
			}
			final AttributeNavigationSample attributeNavigationSample = (AttributeNavigationSample)elt;
			final AttributeNavigationSamplePropertiesEditionPart basePart = (AttributeNavigationSamplePropertiesEditionPart)editingPart;
			// init values
			if (isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.name))
				basePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, attributeNavigationSample.getName()));
			
			if (delegate1ForSingleValuedSettings.getValue() != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued))
				basePart.setDelegate1ForSingleValued(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, delegate1ForSingleValuedSettings.getValue()));
			
			if (isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForSingleValued)) {
				basePart.setDelegate2ForSingleValued(EEFConverterUtil.convertToString(EcorePackage.Literals.EINT, delegate2ForSingleValuedSettings.getValue()));
			}
			
			if (delegate1ForMultiValuedSettings.getValue() != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued))
				basePart.setDelegate1ForMultiValued(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, delegate1ForMultiValuedSettings.getValue()));
			
			if (isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForMultiValued)) {
				basePart.setDelegate2ForMultiValued(EEFConverterUtil.convertToString(EcorePackage.Literals.EINT, delegate2ForMultiValuedSettings.getValue()));
			}
			
			// init filters
			
			
			
			
			
			// init values for referenced views
			
			// init filters for referenced views
			
		}
		setInitializing(false);
	}







	
	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent#shouldProcess(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 */
	protected boolean shouldProcess(IPropertiesEditionEvent event) {
		if (event.getAffectedEditor() == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued) {
			return (delegate1ForSingleValuedSettings.getValue() == null) ? (event.getNewValue() != null) : (!delegate1ForSingleValuedSettings.getValue().equals(event.getNewValue()));
		}
		if (event.getAffectedEditor() == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForSingleValued) {
			return (delegate2ForSingleValuedSettings.getValue() == null) ? (event.getNewValue() != null) : (!delegate2ForSingleValuedSettings.getValue().equals(event.getNewValue()));
		}
		if (event.getAffectedEditor() == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued) {
			return (delegate1ForMultiValuedSettings.getValue() == null) ? (event.getNewValue() != null) : (!delegate1ForMultiValuedSettings.getValue().equals(event.getNewValue()));
		}
		if (event.getAffectedEditor() == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForMultiValued) {
			return (delegate2ForMultiValuedSettings.getValue() == null) ? (event.getNewValue() != null) : (!delegate2ForMultiValuedSettings.getValue().equals(event.getNewValue()));
		}
		return super.shouldProcess(event);
	}	

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#associatedFeature(java.lang.Object)
	 */
	public EStructuralFeature associatedFeature(Object editorKey) {
		if (editorKey == NavigationViewsRepository.AttributeNavigationSample.Properties.name) {
			return EefnrPackage.eINSTANCE.getAbstractSample_Name();
		}
		return super.associatedFeature(editorKey);
	}

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * 
	 */
	public void updateSemanticModel(final IPropertiesEditionEvent event) {
		AttributeNavigationSample attributeNavigationSample = (AttributeNavigationSample)semanticObject;
		if (NavigationViewsRepository.AttributeNavigationSample.Properties.name == event.getAffectedEditor()) {
			attributeNavigationSample.setName((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String)event.getNewValue()));
		}
		if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued == event.getAffectedEditor()) {
			delegate1ForSingleValuedSettings.setValue((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String)event.getNewValue()));
		}
		if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForSingleValued == event.getAffectedEditor()) {
			delegate2ForSingleValuedSettings.setValue((EEFConverterUtil.createIntFromString(EcorePackage.Literals.EINT, (String)event.getNewValue())));
		}
		if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued == event.getAffectedEditor()) {
			delegate1ForMultiValuedSettings.setValue((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String)event.getNewValue()));
		}
		if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForMultiValued == event.getAffectedEditor()) {
			delegate2ForMultiValuedSettings.setValue((EEFConverterUtil.createIntFromString(EcorePackage.Literals.EINT, (String)event.getNewValue())));
		}
	}

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification)
	 */
	public void updatePart(Notification msg) {
		super.updatePart(msg);
		if (editingPart.isVisible()) {
			AttributeNavigationSamplePropertiesEditionPart basePart = (AttributeNavigationSamplePropertiesEditionPart)editingPart;
			if (EefnrPackage.eINSTANCE.getAbstractSample_Name().equals(msg.getFeature()) && msg.getNotifier().equals(semanticObject) && basePart != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.name)) {
				if (msg.getNewValue() != null) {
					basePart.setName(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, msg.getNewValue()));
				} else {
					basePart.setName("");
				}
			}
			if (!(msg.getNewValue() instanceof EObject) && delegate1ForSingleValuedSettings.isAffectingEvent(msg) && basePart != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued)) {
				if (msg.getNewValue() != null) {
					basePart.setDelegate1ForSingleValued(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, msg.getNewValue()));
				} else {
					basePart.setDelegate1ForSingleValued("");
				}
			}
			if (!(msg.getNewValue() instanceof EObject) && delegate2ForSingleValuedSettings.isAffectingEvent(msg) && basePart != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForSingleValued)) {
				if (msg.getNewValue() != null) {
					basePart.setDelegate2ForSingleValued(EcoreUtil.convertToString(EcorePackage.Literals.EINT, msg.getNewValue()));
				} else {
					basePart.setDelegate2ForSingleValued("");
				}
			}
			if (!(msg.getNewValue() instanceof EObject) && delegate1ForMultiValuedSettings.isAffectingEvent(msg) && basePart != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued)) {
				if (msg.getNewValue() != null) {
					basePart.setDelegate1ForMultiValued(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, msg.getNewValue()));
				} else {
					basePart.setDelegate1ForMultiValued("");
				}
			}
			if (!(msg.getNewValue() instanceof EObject) && delegate2ForMultiValuedSettings.isAffectingEvent(msg) && basePart != null && isAccessible(NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForMultiValued)) {
				if (msg.getNewValue() != null) {
					basePart.setDelegate2ForMultiValued(EcoreUtil.convertToString(EcorePackage.Literals.EINT, msg.getNewValue()));
				} else {
					basePart.setDelegate2ForMultiValued("");
				}
			}
			
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#getNotificationFilters()
	 */
	@Override
	protected NotificationFilter[] getNotificationFilters() {
		NotificationFilter filter = new EStructuralFeatureNotificationFilter(
			EefnrPackage.eINSTANCE.getAbstractSample_Name(),
			NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1()
			,
			NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2()
			,
			NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1()
			,
			NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2()
					);
		return new NotificationFilter[] {filter,};
	}


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#isRequired(java.lang.Object, int)
	 * 
	 */
	public boolean isRequired(Object key, int kind) {
		return key == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued || key == NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * 
	 */
	public Diagnostic validateValue(IPropertiesEditionEvent event) {
		Diagnostic ret = Diagnostic.OK_INSTANCE;
		if (event.getNewValue() != null) {
			try {
				if (NavigationViewsRepository.AttributeNavigationSample.Properties.name == event.getAffectedEditor()) {
					Object newValue = event.getNewValue();
					if (newValue instanceof String) {
						newValue = EEFConverterUtil.createFromString(EefnrPackage.eINSTANCE.getAbstractSample_Name().getEAttributeType(), (String)newValue);
					}
					ret = Diagnostician.INSTANCE.validate(EefnrPackage.eINSTANCE.getAbstractSample_Name().getEAttributeType(), newValue);
				}
				if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForSingleValued == event.getAffectedEditor()) {
					Object newValue = event.getNewValue();
					if (newValue instanceof String) {
						newValue = EEFConverterUtil.createFromString(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1().getEAttributeType(), (String)newValue);
					}
					ret = Diagnostician.INSTANCE.validate(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1().getEAttributeType(), newValue);
				}
				if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForSingleValued == event.getAffectedEditor()) {
					Object newValue = event.getNewValue();
					if (newValue instanceof String) {
						newValue = EEFConverterUtil.createFromString(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2().getEAttributeType(), (String)newValue);
					}
					ret = Diagnostician.INSTANCE.validate(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2().getEAttributeType(), newValue);
				}
				if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate1ForMultiValued == event.getAffectedEditor()) {
					Object newValue = event.getNewValue();
					if (newValue instanceof String) {
						newValue = EEFConverterUtil.createFromString(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1().getEAttributeType(), (String)newValue);
					}
					ret = Diagnostician.INSTANCE.validate(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate1().getEAttributeType(), newValue);
				}
				if (NavigationViewsRepository.AttributeNavigationSample.Properties.delegate2ForMultiValued == event.getAffectedEditor()) {
					Object newValue = event.getNewValue();
					if (newValue instanceof String) {
						newValue = EEFConverterUtil.createFromString(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2().getEAttributeType(), (String)newValue);
					}
					ret = Diagnostician.INSTANCE.validate(NavigationPackage.eINSTANCE.getAttributeDelegate_Delegate2().getEAttributeType(), newValue);
				}
			} catch (IllegalArgumentException iae) {
				ret = BasicDiagnostic.toDiagnostic(iae);
			} catch (WrappedException we) {
				ret = BasicDiagnostic.toDiagnostic(we);
			}
		}
		return ret;
	}


	
	/**
	 * @ return settings for delegate1ForSingleValued editor
	 */
	public EEFEditorSettingsImpl getDelegate1ForSingleValuedSettings() {
			return delegate1ForSingleValuedSettings;
	}
	/**
	 * @ return settings for delegate2ForSingleValued editor
	 */
	public EEFEditorSettingsImpl getDelegate2ForSingleValuedSettings() {
			return delegate2ForSingleValuedSettings;
	}
	/**
	 * @ return settings for delegate1ForMultiValued editor
	 */
	public EEFEditorSettingsImpl getDelegate1ForMultiValuedSettings() {
			return delegate1ForMultiValuedSettings;
	}
	/**
	 * @ return settings for delegate2ForMultiValued editor
	 */
	public EEFEditorSettingsImpl getDelegate2ForMultiValuedSettings() {
			return delegate2ForMultiValuedSettings;
	}

	

}

Back to the top