Skip to main content
summaryrefslogtreecommitdiffstats
blob: 270fff75f4c1d307cdcdac6efd6460151d81082b (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
/*******************************************************************************
 * Copyright (c) 2007, 2010 BMW Car IT, Technische Universitaet Muenchen, and others.
 * 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:
 *     BMW Car IT - Initial API and implementation
 *     Technische Universitaet Muenchen - Major refactoring and extension
 *******************************************************************************/
package org.eclipse.emf.edapt.history.reconstruction.ui;


// CB Migrate
//import org.eclipse.emf.compare.diff.metamodel.AttributeChange;
//import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
//import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeLeftTarget;
//import org.eclipse.emf.compare.diff.metamodel.ModelElementChangeRightTarget;
//import org.eclipse.emf.compare.diff.metamodel.ReferenceChange;
//import org.eclipse.emf.compare.diff.metamodel.UpdateModelElement;
//import org.eclipse.emf.compare.diff.metamodel.util.DiffSwitch;


import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edapt.common.ui.ModelSash;
import org.eclipse.emf.edapt.common.ui.PropertiesTableViewer;
import org.eclipse.emf.edapt.history.reconstruction.MappingBase;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TreeItem;


/**
 * Adapter to listen to the difference viewer that automatically updates
 * source and target metamodel viewer
 * 
 * @author herrmama
 * @author $Author$
 * @version $Rev$
 * @levd.rating RED Rev:
 */
public class DiffSelectionAdapter extends SelectionAdapter {

	/**
	 * Viewer for the structure of the source metamodel
	 */
	private final Viewer sourceStructureViewer;

	/**
	 * Viewer for the properties of the source metamodel (can be null)
	 */
	private final PropertiesTableViewer sourcePropertiesViewer;
	
	/**
	 * Viewer for the structure of the target metamodel
	 */
	private final Viewer targetStructureViewer;

	/**
	 * Viewer for the properties of the target metamodel (can be null)
	 */
	private final PropertiesTableViewer targetPropertiesViewer;
	
	/**
	 * Mapping between elements of source and target metamodel
	 */
	private MappingBase mapping;
	
	/**
	 * Constructor
	 */
	public DiffSelectionAdapter(ModelSash sourceSash, ModelSash targetSash) {
		this(sourceSash.getStructureViewer(), sourceSash.getPropertiesViewer(), targetSash.getStructureViewer(), targetSash.getPropertiesViewer());
	}

	/**
	 * Constructor
	 */
	public DiffSelectionAdapter(Viewer sourceStructureViewer,
			PropertiesTableViewer sourcePropertiesViewer,
			Viewer targetStructureViewer,
			PropertiesTableViewer targetPropertiesViewer) {
		this.sourceStructureViewer = sourceStructureViewer;
		this.sourcePropertiesViewer = sourcePropertiesViewer;
		this.targetStructureViewer = targetStructureViewer;
		this.targetPropertiesViewer = targetPropertiesViewer;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void widgetSelected(SelectionEvent e) {
		Object data = ((TreeItem) e.item).getData();
		if(data instanceof EObject) {
			EObject element = (EObject) data;
			
			System.out.println(" Diff Selection adapter widget seelected"); 
			// CB Migrate, another diffswitch. 
//			DiffSwitch<Boolean> s = new DiffSwitch<Boolean>() {
//				
//				@Override
//				public Boolean caseDiffGroup(DiffGroup object) {
//					EObject source = object.getRightParent();
//					selectSource(source);
//					if(mapping != null) {
//						selectTarget(mapping.getTarget(source));
//					}
//					return true;
//				}
//				
//				@Override
//				public Boolean caseModelElementChangeLeftTarget(ModelElementChangeLeftTarget object) {
//					selectSource(object.getRightParent());
//					selectTarget(object.getLeftElement());
//					return true;
//				}
//				
//				@Override
//				public Boolean caseModelElementChangeRightTarget(ModelElementChangeRightTarget object) {
//					selectSource(object.getRightElement());
//					selectTarget(object.getLeftParent());
//					return true;
//				}
//				
//				@Override
//				public Boolean caseUpdateModelElement(UpdateModelElement object) {
//					selectSource(object.getRightElement());
//					selectTarget(object.getLeftElement());
//					return true;
//				}
//				
//				@Override
//				public Boolean caseReferenceChange(ReferenceChange object) {
//					selectSource(object.getRightElement());
//					selectTarget(object.getLeftElement());
//					selectSourceProperty(object.getReference());
//					selectTargetProperty(object.getReference());
//					return true;
//				}
//				
//				@Override
//				public Boolean caseAttributeChange(AttributeChange object) {
//					selectSource(object.getRightElement());
//					selectTarget(object.getLeftElement());
//					selectSourceProperty(object.getAttribute());
//					selectTargetProperty(object.getAttribute());
//					return true;
//				}
//
//			};
//			s.doSwitch(element);
		}
	}

	/**
	 * Selects an element in the structure viewer of the source metamodel
	 */
	public void selectSource(EObject element) {
		sourceStructureViewer.setSelection(element == null ? StructuredSelection.EMPTY : new StructuredSelection(element), true);
	}

	/**
	 * Selects an element in the structure viewer of the target metamodel
	 */
	public void selectTarget(EObject element) {
		targetStructureViewer.setSelection(element == null ? StructuredSelection.EMPTY : new StructuredSelection(element), true);
	}

	/**
	 * Selects a feature in the properties viewer of the source metamodel
	 */
	private void selectSourceProperty(EStructuralFeature feature) {
		selectProperty(sourcePropertiesViewer, feature);
	}
	
	/**
	 * Selects a feature in the properties viewer of the target metamodel
	 */
	private void selectTargetProperty(EStructuralFeature feature) {
		selectProperty(targetPropertiesViewer, feature);
	}

	/**
	 * Select a feature in a properties viewer
	 */
	private void selectProperty(Viewer viewer, EStructuralFeature feature) {
		if(viewer != null) {
			viewer.setSelection(new StructuredSelection(feature), true);
		}
	}

	/** Sets mapping. */
	public void setMapping(MappingBase mapping) {
		this.mapping = mapping;
	}

	/** Returns mapping. */
	public MappingBase getMapping() {
		return mapping;
	}

}

Back to the top