Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e43a7bd55f16bc56b4e005b4922103243b614418 (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
/*******************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * 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:
 *     Cedric Dumoulin - cedric.dumoulin@lifl.fr
 ******************************************************************************/
/**
 */
package org.eclipse.papyrus.layers.stackmodel.layers.impl;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer;
import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptor;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
import org.eclipse.papyrus.layers.stackmodel.layers.StackedLayerOperator;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Stacked Layer Operator</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class StackedLayerOperatorImpl extends AbstractLayerOperatorImpl implements StackedLayerOperator {

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	protected StackedLayerOperatorImpl() {
		super();
		
		// Add an observer
		Adapter adapter = new LayerDescriptorSynchronizer();
		this.eAdapters().add(adapter);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return LayersPackage.Literals.STACKED_LAYER_OPERATOR;
	}

	/**
	 * Reset the descriptor accordingly to the descriptor name.
	 * The descriptor is resseted only if the ::application and ::layerOperatorDescriptorName are set.
	 * Nothing is done if one of the attribute is not set.
	 * Nothing is done if the descriptor can not be found (maybe a log is issue).
	 * <!-- begin-user-doc -->
	 * Not used ?
	 * <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void resetDescriptor() {
		
		if( getApplication() == null || getLayerOperatorDescriptorName() == null) {
			// A property is not yet set.
			// do nothing
			return;
		}
		
		try {
			LayerOperatorDescriptor descriptor = getApplication().getLayerOperatorDescriptorRegistry().getLayerOperatorDescriptor(getLayerOperatorDescriptorName());
			setLayerOperatorDescriptor(descriptor);
		} catch (NotFoundException e) {
			// Not found
			// TODO log the error
			System.err.println("LOG-" + this.getClass().getName() 
					+ "- Can't get LayerOperatorDescriptor for descriptorName '" + getLayerOperatorDescriptorName() + "'.");
		}
	}

	/**
	 * This class listen to #propertyValueMap, and synchronize propertyValues accordingly.
	 * 
	 *
	 */
	public class LayerDescriptorSynchronizer extends AdapterImpl {
		
		@Override
		public void notifyChanged(Notification msg) {
//			System.err.println("event " + msg.getEventType());
			
			switch(msg.getFeatureID(AbstractLayer.class)) {
			case LayersPackage.STACKED_LAYER_OPERATOR__LAYER_OPERATOR_DESCRIPTOR_NAME:
				notifyDescriptorNameChanged(msg);
				break;
	
			case LayersPackage.STACKED_LAYER_OPERATOR__APPLICATION:
				notifyLayerApplicationFeatureChanged(msg);
				break;
	
			default:
				break;
			}
		}
		
		/**
		 * The {@link LayerImpl#propertyValueMap} has changed. Synchronize the {@link LayerImpl#propertyValues} list.
		 * @param msg
		 */
		protected void notifyDescriptorNameChanged(Notification msg) {
//			System.err.println("descriptor name changed " + msg.getEventType());
			switch(msg.getEventType()) {
			case Notification.SET:	
			{
				// Name is set
				resetDescriptor();
				break;
			}
			default:
				break;
			}
	
		}
		/**
		 * The {@link LayerImpl#propertyValueMap} has changed. Synchronize the {@link LayerImpl#propertyValues} list.
		 * @param msg
		 */
		protected void notifyLayerApplicationFeatureChanged(Notification msg) {
//			System.err.println("application changed " + msg.getEventType());
			switch(msg.getEventType()) {
			case Notification.SET:	
			{
				// Application is set
				resetDescriptor();
				break;
			}
			}
		}
	
	}


} //StackedLayerOperatorImpl

Back to the top