Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6dc421621507a650f788948c130260f804ecaa1f (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
/*******************************************************************************
 * 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.runtime;

import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.layers.runtime.model.LayersModel;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;


/**
 * This class manage a notation.Diagram. It allows to :
 * <ul>
 * <li>Add or remove a LayersStack</li>
 * <li>get the LayersStackMngr if a LayersStack exist.</li>
 * </ul>
 * 
 * @author Cedric dumoulin
 * 
 */
public class NotationDiagramHelper {

	/**
	 * Associated Diagram.
	 */
	protected Diagram diagram;
	
	/**
	 * Layers model.
	 */
	protected LayersModel layersModel;
	
	protected LayersStackApplication layersApplication;

//	/**
//	 * The associated {@link LayersStackMngr}. Maybe null if no LayersStack is associated.
//	 */
//	protected LayersStackMngr layerStackMngr;
//
//	/**
//	 * Notifier sending event when the layerStack is added or removed.
//	 */
//	private LayersStackAttachedNotifier layerStackAttachedNotifier;

//	/**
//	 * Listen on events from the layerStackAttachedNotifier.
//	 */
//	private LayersStackAttachedListener layerStackAttachedListener = new LayersStackAttachedListener() {
//
//		public void layerStackRemoved(LayersStackAttachedEvent event) {
//			layerStackMngr.dispose();
//			layerStackMngr = null;
//		}
//
//		public void layerStackAttached(LayersStackAttachedEvent event) {
//
//			if(layerStackMngr != null)
//			{
//				layerStackMngr.dispose();
//				layerStackMngr = null;
//			}
//
//			layerStackMngr = new LayersStackMngr(event.getLayersStack());
//		}
//
//		public void diagramChanged(LayersStackAttachedEvent event) {
//			// Not used because diagram is never set.
//			if(layerStackMngr != null)
//			{
//				layerStackMngr.dispose();
//				layerStackMngr = null;
//			}
//
//			layerStackMngr = new LayersStackMngr(event.getLayersStack());
//
//		}
//	};

	/**
	 * Constructor.
	 * Construct the manager and initialize it.
	 * @param layersModel 
	 * 
	 */
	public NotationDiagramHelper(LayersModel layersModel, Diagram diagram) {
		this.diagram = diagram;
		this.layersModel = layersModel;

//		// Set the layerStackMngr if necessary
//		LayersStack layerStack = LayersStackUtil.getInstance().lookupLayersStack(diagram);
//		if(layerStack != null) {
//			layerStackMngr = new LayersStackMngr(layerStack);
//		}
//
//		// Set the listeners on changes
//		layerStackAttachedNotifier = new LayersStackAttachedNotifier(diagram);
//		layerStackAttachedNotifier.addLayersStackAttachedEventListener(layerStackAttachedListener);

		activate();
	}

	/**
	 * Activate the manager.
	 */
	public void activate() {
//		layerStackAttachedNotifier.activate();
	}

	/**
	 * Deactivate the manager.
	 */
	public void deactivate() {
//		layerStackAttachedNotifier.deactivate();
	}

	/**
	 * Dispose all resources.
	 */
	public void dispose() {
//		layerStackAttachedNotifier.deactivate();

		diagram = null;
	}

	
	/**
	 * @return the diagram
	 */
	public Diagram getDiagram() {
		return diagram;
	}

	
//	/**
//	 * Return the {@link LayersStackMngr} if any. Throw an 
//	 * @return the layerStackMngr
//	 * @throws NotSetException If the layerStackMngr is not set.
//	 */
//	public LayersStackMngr getLayersStackMngr() throws NotSetException {
//		
//		if(layerStackMngr == null)
//			throw new NotSetException(this.getClass().getSimpleName() + ".getLayersStackMngr(): layerStackMngr is not set.");
//		
//		return layerStackMngr;
//	}

	/**
	 * Attach the {@link LayersStack} to the diagram.
	 * Do nothing if a LayersStack is already attached.
	 */
	public void attachLayersStack() {

		LayersStackApplication application = layersModel.getLayerStackApplication();
		application.getLayersStackFor(diagram);
	}

	/**
	 * detach the {@link LayersStack} from the diagram.
	 * Do nothing if no LayersStack is attached.
	 */
	public void removeLayersStack() {
		LayersStackApplication application = layersModel.getLayerStackApplication();
		application.removeLayersStackFor(diagram);
	}

	/**
	 * Return True if a {@link LayersStack} is attached to the diagram.
	 * 
	 * @return True if a {@link LayersStack} is attached to the diagram.
	 */
	public boolean isLayersStackAttached() {
		LayersStackApplication application = layersModel.lookupLayerStackApplication();
		if(application == null ) {
			return false;
		}
		return application.isLayersStackAttachedFor(diagram);
	}

//	/**
//	 * Add a listener for the {@link LayersStackActivatedEvent}.
//	 * 
//	 * @param listener
//	 */
//	public void addLayersStackAttachedEventListener(LayersStackAttachedListener listener) {
//		layerStackAttachedNotifier.addLayersStackAttachedEventListener(listener);
//	}
//
//	/**
//	 * Remove a listener for the {@link LayersStackActivatedEvent}.
//	 * 
//	 * @param listener
//	 */
//	public void removeLayersStackAttachedEventListener(LayersStackAttachedListener listener) {
//		layerStackAttachedNotifier.removeLayersStackAttachedEventListener(listener);
//	}


}

Back to the top