Révision 2416

tmp/org.txm.rcp/src/main/java/org/txm/rcp/utils/SWTEditorsUtils.java (revision 2416)
36 36
 *
37 37
 */
38 38
public class SWTEditorsUtils {
39

  
40

  
39
	
40
	
41 41
	/**
42 42
	 * Gets an editor for the specified result if its opened.
43
	 * 
43 44
	 * @param result the result used by the editor to find
44 45
	 * @return the editor if its opened otherwise null
45 46
	 */
46
	public static IEditorPart getEditor(TXMResult result)	{
47

  
47
	public static IEditorPart getEditor(TXMResult result) {
48
		
48 49
		// FIXME: SJ: old version, doesn't work with ChartEditorInput
49
		//		for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
50
		//			for (IWorkbenchPage page : window.getPages()) {
51
		//				return page.findEditor(new TXMResultEditorInput<TXMResult>(result));
52
		//			}
53
		//		}
54
		//		return null;
55

  
50
		// for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
51
		// for (IWorkbenchPage page : window.getPages()) {
52
		// return page.findEditor(new TXMResultEditorInput<TXMResult>(result));
53
		// }
54
		// }
55
		// return null;
56
		
56 57
		// FIXME: SJ: new version, also works with ChartEditorInput
57 58
		ArrayList<ITXMResultEditor<?>> editors = getEditors(result);
58
		if(!editors.isEmpty())	{
59
		if (!editors.isEmpty()) {
59 60
			return editors.get(0);
60 61
		}
61

  
62
		
62 63
		return null;
63 64
	}
64

  
65
	
65 66
	/**
66 67
	 * Gets all opened editors.
68
	 * 
67 69
	 * @return all opened editors if there is at least one otherwise returns an empty list
68 70
	 */
69 71
	public static ArrayList<ITXMResultEditor<?>> getEditors() {
70
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
71

  
72
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<>();
73
		
72 74
		IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
73 75
		for (IWorkbenchWindow window : windows) {
74 76
			IWorkbenchPage[] pages = window.getPages();
......
76 78
				for (IEditorReference reference : page.getEditorReferences()) {
77 79
					IEditorPart tmpEditor = reference.getEditor(false);
78 80
					
79
					if(tmpEditor instanceof TXMMultiPageEditor)	{
80
						TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor);
81
					if (tmpEditor instanceof TXMMultiPageEditor) {
82
						TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor) tmpEditor);
81 83
						for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
82
							if(txmMultipageEditor.getEditors().get(i) instanceof ITXMResultEditor)	{
83
								ITXMResultEditor txmEditor = ((ITXMResultEditor)txmMultipageEditor.getEditors().get(i));
84
							if (txmMultipageEditor.getEditors().get(i) instanceof ITXMResultEditor) {
85
								ITXMResultEditor txmEditor = ((ITXMResultEditor) txmMultipageEditor.getEditors().get(i));
84 86
								editors.add(txmEditor);
85 87
							}
86 88
						}
87
					} else if(tmpEditor instanceof ITXMResultEditor)	{
89
					}
90
					else if (tmpEditor instanceof ITXMResultEditor) {
88 91
						editors.add((ITXMResultEditor<?>) tmpEditor);
89 92
					}
90 93
				}
......
92 95
		}
93 96
		return editors;
94 97
	}
95

  
96

  
98
	
99
	
97 100
	/**
98 101
	 * Gets all opened editors for the specified result.
102
	 * 
99 103
	 * @param result
100 104
	 * @return all opened editors for the specified result if there is at least one otherwise returns an empty list
101 105
	 */
102
	public static ArrayList<ITXMResultEditor<?>> getEditors(HashSet<TXMResult> results)	{
103

  
104
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
105

  
106
	public static ArrayList<ITXMResultEditor<?>> getEditors(HashSet<TXMResult> results) {
107
		
108
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<>();
109
		
106 110
		ArrayList<ITXMResultEditor<?>> all_editors = getEditors();
107

  
111
		
108 112
		for (ITXMResultEditor<?> txmEditor : all_editors) {
109

  
110
			if (results.contains(txmEditor.getResult()))	{
113
			
114
			if (results.contains(txmEditor.getResult())) {
111 115
				editors.add(txmEditor);
112 116
			}
113 117
		}
114

  
118
		
115 119
		return editors;
116 120
	}
117

  
121
	
118 122
	/**
119 123
	 * Gets all opened editors for the specified result.
124
	 * 
120 125
	 * @param result
121 126
	 * @return all opened editors for the specified result if there is at least one otherwise returns an empty list
122 127
	 */
123
	public static ArrayList<ITXMResultEditor<?>> getEditors(TXMResult result)	{
124

  
125
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
126

  
128
	public static ArrayList<ITXMResultEditor<?>> getEditors(TXMResult result) {
129
		
130
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<>();
131
		
127 132
		ArrayList<ITXMResultEditor<?>> all_editors = getEditors();
128

  
133
		
129 134
		for (ITXMResultEditor<?> txmEditor : all_editors) {
130

  
131
			if (result == txmEditor.getResult())	{
135
			
136
			if (result == txmEditor.getResult()) {
132 137
				editors.add(txmEditor);
133 138
			}
134 139
		}
135

  
140
		
136 141
		return editors;
137 142
	}
138

  
143
	
139 144
	/**
140 145
	 * Gets the current active editor.
146
	 * 
141 147
	 * @param event
142 148
	 * @return
143 149
	 */
144
	public static ITXMResultEditor getActiveEditor(ExecutionEvent event)	{
145

  
150
	public static ITXMResultEditor getActiveEditor(ExecutionEvent event) {
151
		
146 152
		IEditorPart editor = null;
147

  
148
		if(event != null)	{
153
		
154
		if (event != null) {
149 155
			editor = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor();
150 156
		}
151
		else	{
157
		else {
152 158
			editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
153 159
		}
154

  
155
		if(editor instanceof TXMMultiPageEditor)	{
156
			editor = ((TXMMultiPageEditor)editor).getMainEditorPart();
157

  
160
		
161
		if (editor instanceof TXMMultiPageEditor) {
162
			editor = ((TXMMultiPageEditor) editor).getMainEditorPart();
163
			
158 164
		}
159

  
160
		if(!(editor instanceof ITXMResultEditor))	{
165
		
166
		if (!(editor instanceof ITXMResultEditor)) {
161 167
			return null;
162 168
		}
163

  
164
		return (ITXMResultEditor)editor;
169
		
170
		return (ITXMResultEditor) editor;
165 171
	}
166

  
172
	
167 173
	/**
168 174
	 * Checks if the editor specified by its editor input is already open in the active page.
175
	 * 
169 176
	 * @param editorInput
170 177
	 * @return
171 178
	 */
172
	public static boolean isOpenEditor(IEditorInput editorInput, String editorId)	{
179
	public static boolean isOpenEditor(IEditorInput editorInput, String editorId) {
173 180
		return (getEditor(editorInput, editorId) != null);
174 181
	}
175

  
182
	
176 183
	/**
177 184
	 * Gets an editor by its editor input.
185
	 * 
178 186
	 * @param editorInput
179 187
	 * @return
180 188
	 */
181
	public static IEditorPart getEditor(IEditorInput editorInput, String editorId)	{
189
	public static IEditorPart getEditor(IEditorInput editorInput, String editorId) {
182 190
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
183 191
		IWorkbenchPage page = window.getActivePage();
184 192
		IEditorReference[] editorsReferences = page.findEditors(editorInput, editorId, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
185
		if(editorsReferences.length > 0)	{
193
		if (editorsReferences.length > 0) {
186 194
			return editorsReferences[0].getEditor(false);
187 195
		}
188 196
		return null;
189 197
	}
190

  
198
	
191 199
	/**
192
	 * Splits the parent area of an editor and add another one in this area by splitting it. 
200
	 * Splits the parent area of an editor and add another one in this area by splitting it.
193 201
	 * (Same behavior than the splitting drag and drop event on editor.)
194 202
	 * EModelService.ABOVE, EModelService.BELOW, etc. can be used as position.
195 203
	 * 
......
199 207
	 * @param percent The percentage of the area to be occupied by the inserted element
200 208
	 */
201 209
	public static void addEditor(EditorPart parentEditor, EditorPart editorToAdd, int position, float percent) {
202
		addPart((MPart) parentEditor.getSite().getService(MPart.class), (MPart) editorToAdd.getSite().getService(MPart.class), position, percent);
210
		addPart(parentEditor.getSite().getService(MPart.class), editorToAdd.getSite().getService(MPart.class), position, percent);
203 211
	}
204

  
212
	
205 213
	/**
206
	 * Splits the parent area of an editor and add another one in this area by splitting it by the middle. 
214
	 * Splits the parent area of an editor and add another one in this area by splitting it by the middle.
207 215
	 * (Same behavior than the splitting drag and drop event on editor.)
208 216
	 * EModelService.ABOVE, EModelService.BELOW, etc. can be used as position.
209 217
	 * 
......
214 222
	public static void addEditor(EditorPart parentEditor, EditorPart editorToAdd, int position) {
215 223
		addEditor(parentEditor, editorToAdd, position, 0.5f);
216 224
	}
217

  
225
	
218 226
	/**
219
	 * Splits the parent area of a part and add another one in this area by splitting it. 
227
	 * Splits the parent area of a part and add another one in this area by splitting it.
220 228
	 * (Same behavior than the splitting drag and drop event on editor.)
221 229
	 * EModelService.ABOVE, EModelService.BELOW, etc. can be used as position.
222 230
	 * 
......
227 235
	 */
228 236
	public static void addPart(MPart parentPart, MPart partToAdd, int position, float percent) {
229 237
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
230
		EModelService service = (EModelService) window.getService(EModelService.class);
238
		EModelService service = window.getService(EModelService.class);
231 239
		
232 240
		MUIElement parent = parentPart.getParent();
233
		while (!(parent instanceof MPartSashContainerElement))	{
241
		while (!(parent instanceof MPartSashContainerElement)) {
234 242
			parent = parent.getParent();
235 243
		}
236
		MPartSashContainerElement sashContainer = (MPartSashContainerElement)parent;
244
		MPartSashContainerElement sashContainer = (MPartSashContainerElement) parent;
237 245
		
238 246
		MPartStack stackToInsert = createPartStack(partToAdd);
239 247
		
240
		//TODO find out why the insert method always create a new sash
248
		// TODO find out why the insert method always create a new sash
241 249
		service.insert(stackToInsert, sashContainer, position, percent);
242 250
	}
243

  
251
	
244 252
	/**
245 253
	 * Creates a part stack for the specified part
254
	 * 
246 255
	 * @param part
247 256
	 * @return
248 257
	 */
249 258
	private static MPartStack createPartStack(MPart part) {
250 259
		MStackElement stackElement = part;
251

  
260
		
252 261
		MPartStack stack = BasicFactoryImpl.eINSTANCE.createPartStack();
253 262
		stack.getChildren().add(stackElement);
254 263
		stack.setSelectedElement(stackElement);
255 264
		return stack;
256 265
	}
257

  
266
	
258 267
	/**
259 268
	 * close a ITXMResultEditor from its result
260 269
	 * 
......
262 271
	 */
263 272
	public static boolean closeEditor(TXMResult r) {
264 273
		IEditorPart e = getEditor(r);
265
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor)e).getResult() == r) {
266
			((ITXMResultEditor)e).close();
274
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor) e).getResult() == r) {
275
			((ITXMResultEditor) e).close();
267 276
			return true;
268 277
		}
269 278
		return false;
270 279
	}
271

  
280
	
272 281
	public static boolean refreshEditor(TXMResult r) {
273 282
		IEditorPart e = getEditor(r);
274
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor)e).getResult() == r) {
283
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor) e).getResult() == r) {
275 284
			try {
276
				((ITXMResultEditor)e).refresh(true);
285
				((ITXMResultEditor) e).refresh(true);
277 286
				return true;
278
			} catch (Exception e1) {
287
			}
288
			catch (Exception e1) {
279 289
				// TODO Auto-generated catch block
280 290
				e1.printStackTrace();
281 291
			}
282 292
		}
283 293
		return false;
284 294
	}
285

  
295
	
286 296
	public static boolean activateEditor(TXMResult r) {
287 297
		IEditorPart e = getEditor(r);
288
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor<?>)e).getResult() == r) {
298
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor<?>) e).getResult() == r) {
289 299
			try {
290
				((ITXMResultEditor<?>)e).getSite().getPage().activate(e);
300
				((ITXMResultEditor<?>) e).getSite().getPage().activate(e);
291 301
				return true;
292
			} catch (Exception e1) {
302
			}
303
			catch (Exception e1) {
293 304
				// TODO Auto-generated catch block
294 305
				e1.printStackTrace();
295 306
			}
tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/chartsengine/events/ProgressionEventCallBack.java (revision 2416)
53 53
 *
54 54
 */
55 55
public class ProgressionEventCallBack extends EventCallBack {
56

  
56
	
57 57
	/**
58 58
	 * To keep track of the concordance lines and recomputing only if the selected item is out of this range.
59 59
	 */
......
63 63
	 * To keep track of the concordance lines sort and recomputing only if the sorting order has changed.
64 64
	 */
65 65
	protected LineComparator lastSortingComparator = null;
66

  
66
	
67 67
	@Override
68 68
	public void processEvent(final Object event, final int eventArea, final Object o) {
69 69
		
70 70
		// Need to run this in the SWT UI thread because it's called from the AWT UI thread in TBX charts engine layer
71 71
		chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
72
			
73
			@Override
72 74
			public void run() {
73

  
75
				
74 76
				AWTEvent awtEvent = (AWTEvent) event;
75 77
				
76 78
				// Mouse event
77
				if(event instanceof MouseEvent)	{
78
				
79
					MouseEvent mouseEvent = (MouseEvent)event;
79
				if (event instanceof MouseEvent) {
80 80
					
81
					//return if it's not the left mouse button
82
					if(mouseEvent.getButton() != MouseEvent.BUTTON1)	{
81
					MouseEvent mouseEvent = (MouseEvent) event;
82
					
83
					// return if it's not the left mouse button
84
					if (mouseEvent.getButton() != MouseEvent.BUTTON1) {
83 85
						return;
84 86
					}
85 87
					
86 88
					ChartMouseEvent chartEvent = (ChartMouseEvent) o;
87 89
					ChartEntity entity = chartEvent.getEntity();
88 90
					final ArrayList<Integer> selectedPointPositions = ((ProgressionChartCreator) chartEditor.getResult().getChartCreator()).getSelectedPointPositions(chartEditor.getChart());
89
	
90
					if(awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 2 && eventArea == EventCallBack.AREA_ITEM && !selectedPointPositions.isEmpty()) {
91
	
91
					
92
					if (awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 2 && eventArea == EventCallBack.AREA_ITEM && !selectedPointPositions.isEmpty()) {
93
						
92 94
						// Linked edition (CTRL/CMD + double click)
93
						if((mouseEvent.getModifiers() & ZoomAndPanCallBack.keyboardZoomModifierKeyMask) != 0) {
95
						if ((mouseEvent.getModifiers() & ZoomAndPanCallBack.keyboardZoomModifierKeyMask) != 0) {
94 96
							// Creates or updates the linked editor
95 97
							updateLinkedEditionEditor((SynopticEditionEditor) chartEditor.getLinkedEditor(SynopticEditionEditor.class), selectedPointPositions);
96 98
						}
97 99
						// Linked concordance
98
						else	{
100
						else {
99 101
							// Creates or updates the linked editor
100 102
							updateLinkedConcordanceEditor(chartEditor.getLinkedEditors(ConcordanceEditor.class), selectedPointPositions);
101 103
						}
102 104
					}
103
					else if(awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 1 && eventArea == EventCallBack.AREA_ITEM) {
104

  
105
					else if (awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 1 && eventArea == EventCallBack.AREA_ITEM) {
106
						
105 107
						// Get the linked concordance editors and update the one linked to the progression curve if it exists
106 108
						ArrayList<EditorPart> linkedConcordancesEditors = chartEditor.getLinkedEditors(ConcordanceEditor.class);
107
						if(!linkedConcordancesEditors.isEmpty())	{
109
						if (!linkedConcordancesEditors.isEmpty()) {
108 110
							updateLinkedConcordanceEditor(linkedConcordancesEditors, selectedPointPositions);
109 111
						}
110 112
						
111 113
						
112 114
						// Get the linked edition editor and update it if exists
113
						SynopticEditionEditor linkedEditionEditor = (SynopticEditionEditor)chartEditor.getLinkedEditor(SynopticEditionEditor.class);
114
						if(linkedEditionEditor != null)	{
115
						SynopticEditionEditor linkedEditionEditor = (SynopticEditionEditor) chartEditor.getLinkedEditor(SynopticEditionEditor.class);
116
						if (linkedEditionEditor != null) {
115 117
							updateLinkedEditionEditor(linkedEditionEditor, selectedPointPositions);
116 118
						}
117 119
						
118 120
					}
119
					else if(awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 2 && eventArea == EventCallBack.AREA_EMPTY) {
121
					else if (awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 2 && eventArea == EventCallBack.AREA_EMPTY) {
120 122
						// FIXME: debug
121
						//System.err.println("ProgressionMouseClickedCallBack.processEvent(...).new Runnable() {...}.run(): double click in empty area");
123
						// System.err.println("ProgressionMouseClickedCallBack.processEvent(...).new Runnable() {...}.run(): double click in empty area");
122 124
					}
123
					else if(awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 1 && eventArea == EventCallBack.AREA_EMPTY) {
125
					else if (awtEvent.getID() == MouseEvent.MOUSE_CLICKED && mouseEvent.getClickCount() == 1 && eventArea == EventCallBack.AREA_EMPTY) {
124 126
						// FIXME: debug
125
						//System.err.println("ProgressionMouseClickedCallBack.processEvent(...).new Runnable() {...}.run(): single click in empty area");
127
						// System.err.println("ProgressionMouseClickedCallBack.processEvent(...).new Runnable() {...}.run(): single click in empty area");
126 128
					}
127 129
				}
128 130
				// Key event
129
				else if(event instanceof KeyEvent)	{
130
					KeyEvent keyEvent = (KeyEvent)event;
131
				else if (event instanceof KeyEvent) {
132
					KeyEvent keyEvent = (KeyEvent) event;
131 133
					
132 134
					// return if zoom and pan modifier
133
					if((keyEvent.getModifiers() & ZoomAndPanCallBack.keyboardZoomModifierKeyMask) != 0) {
135
					if ((keyEvent.getModifiers() & ZoomAndPanCallBack.keyboardZoomModifierKeyMask) != 0) {
134 136
						return;
135 137
					}
136 138
					
137 139
					// Arrow keys + return key
138
					if(keyEvent.getKeyCode() == KeyEvent.VK_LEFT || keyEvent.getKeyCode() == KeyEvent.VK_RIGHT
139
							 || keyEvent.getKeyCode() == KeyEvent.VK_ENTER)	{
140
					
140
					if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT || keyEvent.getKeyCode() == KeyEvent.VK_RIGHT
141
							|| keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
142
						
141 143
						final ArrayList<Integer> selectedPointPositions = ((ProgressionChartCreator) chartEditor.getResult().getChartCreator()).getSelectedPointPositions(chartEditor.getChart());
142
	
144
						
143 145
						// Get the linked concordance editors and update the one linked to the progression curve if it exists
144 146
						ArrayList<EditorPart> linkedConcordancesEditors = chartEditor.getLinkedEditors(ConcordanceEditor.class);
145
						if(keyEvent.getKeyCode() == KeyEvent.VK_ENTER || !linkedConcordancesEditors.isEmpty())	{
147
						if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER || !linkedConcordancesEditors.isEmpty()) {
146 148
							updateLinkedConcordanceEditor(linkedConcordancesEditors, selectedPointPositions);
147 149
						}
148 150
						
149 151
						// Get the linked edition editor and update it if exists
150
						SynopticEditionEditor linkedEditionEditor = (SynopticEditionEditor)chartEditor.getLinkedEditor(SynopticEditionEditor.class);
151
						if(linkedEditionEditor != null)	{
152
						SynopticEditionEditor linkedEditionEditor = (SynopticEditionEditor) chartEditor.getLinkedEditor(SynopticEditionEditor.class);
153
						if (linkedEditionEditor != null) {
152 154
							updateLinkedEditionEditor(linkedEditionEditor, selectedPointPositions);
153 155
						}
154 156
					}
155 157
				}
156 158
			}
157 159
		});
158

  
160
		
159 161
	}
160 162
	
161 163
	
......
167 169
	 * @param linkedEditors
168 170
	 * @param selectedPointPositions
169 171
	 */
170
	public void updateLinkedConcordanceEditor(ArrayList<EditorPart> linkedEditors, final ArrayList<Integer> selectedPointPositions)	{
171

  
172
	public void updateLinkedConcordanceEditor(ArrayList<EditorPart> linkedEditors, final ArrayList<Integer> selectedPointPositions) {
173
		
172 174
		// Debug
173 175
		Log.finest("ProgressionEventCallBack.updateLinkedConcordanceEditor(): linked editors count: " + linkedEditors.size()); //$NON-NLS-1$
174 176
		
175 177
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
176 178
		IWorkbenchPage page = window.getActivePage();
177

  
179
		
178 180
		// Get and format the progression query from the selected chart series
179 181
		// FIXME: case 1, the query is the query of the selected chart series
180
//		ArrayList<Integer> selectedSeries = chartEditor.getEditorInput().getSWTChartComponentsProvider().getChartsEngine().getProgressionChartSelectedSeries(chartEditor.getChart());
181
//		String query = ((Progression) chartEditor.getResultData()).getQueries().get(selectedSeries.get(selectedSeries.size() - 1).intValue()).getQueryString();
182
		// ArrayList<Integer> selectedSeries = chartEditor.getEditorInput().getSWTChartComponentsProvider().getChartsEngine().getProgressionChartSelectedSeries(chartEditor.getChart());
183
		// String query = ((Progression) chartEditor.getResultData()).getQueries().get(selectedSeries.get(selectedSeries.size() - 1).intValue()).getQueryString();
182 184
		
183 185
		int lastSelectedSeries = ((ProgressionChartCreator) chartEditor.getResult().getChartCreator()).getLastSelectedSeries(chartEditor.getChart());
184 186
		if (lastSelectedSeries == -1) { // no selection
185 187
			return;
186 188
		}
187 189
		String query = ((Progression) chartEditor.getResult()).getQueries().get(lastSelectedSeries).getQueryString();
188

  
189
//		// Remove "[" and "]" only if it's a simple query as "[faire]" 
190
//		if(query.startsWith("[") && !query.contains("="))	{ //$NON-NLS-1$ //$NON-NLS-2$
191
//			int length = query.length();
192
//			if(query.endsWith("]"))	{ //$NON-NLS-1$
193
//				length--;
194
//			}
195
//			query = query.substring(1, length);
196
//		}
197

  
190
		
191
		// // Remove "[" and "]" only if it's a simple query as "[faire]"
192
		// if(query.startsWith("[") && !query.contains("=")) { //$NON-NLS-1$ //$NON-NLS-2$
193
		// int length = query.length();
194
		// if(query.endsWith("]")) { //$NON-NLS-1$
195
		// length--;
196
		// }
197
		// query = query.substring(1, length);
198
		// }
199
		
198 200
		// FIXME: case 2, the query is the combination of all the queries of the progression
199
//		String query = ((Progression) chartEditor.getResultData()).getQueriesString();
201
		// String query = ((Progression) chartEditor.getResultData()).getQueriesString();
200 202
		
201 203
		// gets the linked editor according to the query if it exists
202 204
		ConcordanceEditor linkedEditor = null;
203
		for(int i = 0; i < linkedEditors.size(); i++) {
204
			if(query.equals(((ConcordanceEditor) linkedEditors.get(i)).getConcordance().getQuery().getQueryString()))	{
205
		for (int i = 0; i < linkedEditors.size(); i++) {
206
			if (query.equals(((ConcordanceEditor) linkedEditors.get(i)).getConcordance().getQuery().getQueryString())) {
205 207
				linkedEditor = ((ConcordanceEditor) linkedEditors.get(i));
206 208
				break;
207 209
			}
......
219 221
			newEditor = true;
220 222
		}
221 223
		else {
222
			editorInput = (TXMResultEditorInput) linkedEditor.getEditorInput();
224
			editorInput = linkedEditor.getEditorInput();
223 225
		}
224

  
226
		
225 227
		try {
226 228
			boolean wasOpenedEditor = SWTEditorsUtils.isOpenEditor(editorInput, ConcordanceEditor.ID);
227 229
			
228 230
			linkedEditor = (ConcordanceEditor) page.openEditor(editorInput, ConcordanceEditor.ID, false);
229
			if(newEditor)	{
231
			if (newEditor) {
230 232
				chartEditor.addLinkedEditor(linkedEditor);
231 233
			}
232 234
			
233 235
			// Split the area and insert the new editor
234
			if(!wasOpenedEditor)	{
236
			if (!wasOpenedEditor) {
235 237
				
236 238
				int position = EModelService.BELOW;
237 239
				EditorPart parentEditor = chartEditor;
238 240
				
239 241
				// Split vertically if there is already a concordance or an edition editor otherwise split horizontally
240
				if(linkedEditors != null && !linkedEditors.isEmpty())	 {
242
				if (linkedEditors != null && !linkedEditors.isEmpty()) {
241 243
					position = EModelService.RIGHT_OF;
242 244
					parentEditor = linkedEditors.get(linkedEditors.size() - 1);
243 245
					
......
252 254
		catch (PartInitException e) {
253 255
			System.err.println(NLS.bind(TXMCoreMessages.errorColonP0, e.getLocalizedMessage()));
254 256
		}
255

  
257
		
256 258
		// Compute the concordance if it has never been computed
257
		if(newEditor)	{
259
		if (newEditor) {
258 260
			Job job = linkedEditor.compute(false);
259

  
261
			
260 262
			final ConcordanceEditor linkedEditor2 = linkedEditor;
261 263
			
262
			job.addJobChangeListener(new JobChangeAdapter() 	{
264
			job.addJobChangeListener(new JobChangeAdapter() {
265
				
263 266
				@Override
264 267
				public void done(IJobChangeEvent event) {
265 268
					super.done(event);
266 269
					
267 270
					// initialize range change tracking variables
268 271
					lastConcordanceTopLine = -1;
269
					//lastConcordanceBottomLine = linkedEditor.getLinePerPage();
272
					// lastConcordanceBottomLine = linkedEditor.getLinePerPage();
270 273
					lastSortingComparator = linkedEditor2.getCurrentComparator();
271

  
274
					
272 275
					updateLinkedConcordanceEditor(linkedEditor2, selectedPointPositions, true);
273 276
					
274 277
					// give back the focus to the chart editor and chart composite
275 278
					chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
279
						
276 280
						@Override
277 281
						public void run() {
278 282
							chartEditor.setFocus();
......
286 290
			
287 291
			
288 292
		}
289
		else	{
293
		else {
290 294
			updateLinkedConcordanceEditor(linkedEditor, selectedPointPositions, false);
291
			//chartEditor.getChartComposite().setFocus();
295
			// chartEditor.getChartComposite().setFocus();
292 296
		}
293 297
		
294 298
		// give back the focus to chart editor and the chart composite
295
		//chartEditor.setFocus();
296
		//chartEditor.getChartComposite().setFocus();
299
		// chartEditor.setFocus();
300
		// chartEditor.getChartComposite().setFocus();
297 301
	}
298

  
299

  
302
	
303
	
300 304
	/**
301 305
	 * 
302 306
	 * @param linkedEditor
303 307
	 * @param selectedPointPositions
304 308
	 * @param loadLines
305 309
	 */
306
	public void updateLinkedConcordanceEditor(final ConcordanceEditor linkedEditor, final ArrayList<Integer> selectedPointPositions, boolean loadLines)	{
310
	public void updateLinkedConcordanceEditor(final ConcordanceEditor linkedEditor, final ArrayList<Integer> selectedPointPositions, boolean loadLines) {
307 311
		
308 312
		final TableViewer tableViewer = linkedEditor.getLineTableViewer();
309 313
		
310
		if(tableViewer.getTable().isDisposed())	{
314
		if (tableViewer.getTable().isDisposed()) {
311 315
			return;
312 316
		}
313 317
		
314
		if(selectedPointPositions.size() > 0)	{
315

  
318
		if (selectedPointPositions.size() > 0) {
319
			
316 320
			// Get the index of the last selected point in concordance according to the global token position and concordance sorting order
317 321
			int lineIndex = linkedEditor.getConcordance().indexOf(selectedPointPositions.get(selectedPointPositions.size() - 1));
318 322
			
......
322 326
			
323 327
			// Manage the lazy loading of new lines range in the concordance table
324 328
			// page change
325
			if(lastConcordanceTopLine != top)	{
329
			if (lastConcordanceTopLine != top) {
326 330
				loadLines = true;
327 331
			}
328 332
			// sort change
329
			else if(lastSortingComparator != linkedEditor.getCurrentComparator())	{
333
			else if (lastSortingComparator != linkedEditor.getCurrentComparator()) {
330 334
				loadLines = true;
331 335
			}
332

  
333 336
			
337
			
334 338
			// Loads new lines, fill the display area and select the table row
335
			if(loadLines)	{
339
			if (loadLines) {
336 340
				Display.getDefault().syncExec(new Runnable() {
341
					
337 342
					@Override
338 343
					public void run() {
339 344
						linkedEditor.fillDisplayArea(true);
340 345
					}
341 346
				});
342 347
			}
343

  
348
			
344 349
			// update range change tracking variables
345 350
			lastConcordanceTopLine = top;
346
			//lastConcordanceBottomLine = bottom;
351
			// lastConcordanceBottomLine = bottom;
347 352
			lastSortingComparator = linkedEditor.getCurrentComparator();
348 353
			
349 354
			
350
			final int selectedPointInTableRange = lineIndex - top;						
351
	
355
			final int selectedPointInTableRange = lineIndex - top;
356
			
352 357
			tableViewer.getControl().getDisplay().asyncExec(new Runnable() {
358
				
353 359
				@Override
354 360
				public void run() {
355 361
					tableViewer.getTable().deselectAll();
356 362
					
357 363
					Object line = tableViewer.getElementAt(selectedPointInTableRange);
358
					if(line != null)	{
364
					if (line != null) {
359 365
						tableViewer.setSelection(new StructuredSelection(line), true);
360 366
						// FIXME: commented because the set top index makes the read of the table difficult
361
						//tableViewer.getTable().setTopIndex(selectedPointInTableRange);
362
						Log.finest("ProgressionEventCallBack.updateLinkedConcordanceEditor(...).new Runnable() {...}.run(): Selecting progression point (" + selectedPointInTableRange + " / " + tableViewer.getTable().getItemCount() + ") in the linked Concordance table."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
367
						// tableViewer.getTable().setTopIndex(selectedPointInTableRange);
368
						Log.finest("ProgressionEventCallBack.updateLinkedConcordanceEditor(...).new Runnable() {...}.run(): Selecting progression point (" + selectedPointInTableRange + " / " //$NON-NLS-1$ //$NON-NLS-2$
369
								+ tableViewer.getTable().getItemCount() + ") in the linked Concordance table.");  //$NON-NLS-1$
363 370
					}
364
					else	{
365
						Log.finest("ProgressionEventCallBack.updateLinkedConcordanceEditor(...).new Runnable() {...}.run(): Selected progression point (" + selectedPointInTableRange + " / " + tableViewer.getTable().getItemCount() + ") doesn't exist in the linked Concordance table."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
371
					else {
372
						Log.finest("ProgressionEventCallBack.updateLinkedConcordanceEditor(...).new Runnable() {...}.run(): Selected progression point (" + selectedPointInTableRange + " / " //$NON-NLS-1$ //$NON-NLS-2$
373
								+ tableViewer.getTable().getItemCount() + ") doesn't exist in the linked Concordance table.");  //$NON-NLS-1$
366 374
					}
367 375
				}
368 376
			});
369 377
		}
370
		else	{
378
		else {
371 379
			tableViewer.getTable().deselectAll();
372 380
		}
373 381
	}
374 382
	
375
	//FIXME: version with new SynopticEditionEditor system edition
383
	// FIXME: version with new SynopticEditionEditor system edition
376 384
	/**
377 385
	 * Updates the linked edition editor.
378 386
	 * If the editor doesn't exist it will be created.
387
	 * 
379 388
	 * @param editor
380 389
	 */
381
	public void updateLinkedEditionEditor(SynopticEditionEditor linkedEditor, ArrayList<Integer> selectedPointPositions)	{
390
	public void updateLinkedEditionEditor(SynopticEditionEditor linkedEditor, ArrayList<Integer> selectedPointPositions) {
382 391
		
383 392
		try {
384
		
393
			
385 394
			ArrayList<Color> seriesColors = chartEditor.getResult().getChartCreator().getSeriesShapesColors(chartEditor.getChart());
386 395
			RGBA selectedWordColor = new RGBA(255, 10, 10);
387

  
396
			
388 397
			// Unhighlight all tokens
389
			if(linkedEditor != null)	{
398
			if (linkedEditor != null) {
390 399
				linkedEditor.removeHighlightWords();
391 400
				linkedEditor.updateWordStyles();
392 401
			}
......
396 405
			Property textP = textS.getProperty(CorpusBuild.ID);
397 406
			Match selectedWordMatch = new Match(selectedPointPositions.get(selectedPointPositions.size() - 1), selectedPointPositions.get(selectedPointPositions.size() - 1));
398 407
			String textId = selectedWordMatch.getValueForProperty(textP);
399

  
408
			
400 409
			Text text = corpus.getProject().getText(textId);
401
			if(text == null) {
410
			if (text == null) {
402 411
				Log.severe(ProgressionUIMessages.bind(ProgressionUIMessages.textP0IsMissing, textId));
403 412
				return;
404 413
			}
405

  
414
			
406 415
			Edition edition = text.getEdition(corpus.getProject().getDefaultEdition());
407

  
408
			if(edition == null) {
416
			
417
			if (edition == null) {
409 418
				Log.severe(ProgressionUIMessages.defaultEditionIsMissing);
410 419
				return;
411 420
			}
412

  
421
			
413 422
			// Compute the edition if needed
414
			if(!edition.hasBeenComputedOnce())	{
423
			if (!edition.hasBeenComputedOnce()) {
415 424
				edition.compute();
416 425
			}
417 426
			
418 427
			// Get the current selected word to highlight more
419 428
			List<String> selectedWordIds = selectedWordMatch.getValuesForProperty(corpus.getProperty(CorpusBuild.ID));
420

  
429
			
421 430
			// Get all words to highlight from the progression chart data set
422
			ArrayList<ArrayList<Integer>> allPointPositionsBySeries = ((ProgressionChartCreator)chartEditor.getResult().getChartCreator()).getAllPointPositionsBySeries(chartEditor.getChart());
431
			ArrayList<ArrayList<Integer>> allPointPositionsBySeries = ((ProgressionChartCreator) chartEditor.getResult().getChartCreator()).getAllPointPositionsBySeries(chartEditor.getChart());
423 432
			
424
			ArrayList<ArrayList<String>> allWordIds = new ArrayList<ArrayList<String>>(allPointPositionsBySeries.size());
425
			for(int i = 0; i < allPointPositionsBySeries.size(); i++) {
433
			ArrayList<ArrayList<String>> allWordIds = new ArrayList<>(allPointPositionsBySeries.size());
434
			for (int i = 0; i < allPointPositionsBySeries.size(); i++) {
426 435
				ArrayList<Integer> positions = allPointPositionsBySeries.get(i);
427
				ArrayList<String> wordsIds = new ArrayList<String>(); 
428
				for(int j = 0; j < positions.size(); j++) {
429
					Match match = new Match(positions.get(j), positions.get(j));					
430
					if(match.getValueForProperty(textP).equals(textId)) {
431
						wordsIds.add(match.getValueForProperty(corpus.getProperty(CorpusBuild.ID))); //$NON-NLS-1$;
436
				ArrayList<String> wordsIds = new ArrayList<>();
437
				for (int j = 0; j < positions.size(); j++) {
438
					Match match = new Match(positions.get(j), positions.get(j));
439
					if (match.getValueForProperty(textP).equals(textId)) {
440
						wordsIds.add(match.getValueForProperty(corpus.getProperty(CorpusBuild.ID))); // ;
432 441
					}
433 442
				}
434 443
				allWordIds.add(wordsIds);
435 444
			}
436

  
445
			
437 446
			Page openPage = edition.getPageForWordId(selectedWordIds.get(0));
438

  
439
			if(openPage != null) {
440

  
447
			
448
			if (openPage != null) {
449
				
441 450
				// Create the linked editor if needed
442
				if(linkedEditor == null || linkedEditor.isDisposed()) {
451
				if (linkedEditor == null || linkedEditor.isDisposed()) {
443 452
					linkedEditor = OpenEdition.openEdition(corpus, OpenEdition.getDefaultEditions(corpus));
444 453
					chartEditor.addLinkedEditor(linkedEditor);
445 454
					
446 455
					
447
					int position = EModelService.BELOW;;
456
					int position = EModelService.BELOW;
457
					;
448 458
					EditorPart parentEditor = chartEditor;
449 459
					// Split vertically if there is already a concordance editor otherwise split horizontally
450
					ConcordanceEditor linkedConcordanceEditor = (ConcordanceEditor)chartEditor.getLinkedEditor(ConcordanceEditor.class);
451
					if(linkedConcordanceEditor != null)	{
460
					ConcordanceEditor linkedConcordanceEditor = (ConcordanceEditor) chartEditor.getLinkedEditor(ConcordanceEditor.class);
461
					if (linkedConcordanceEditor != null) {
452 462
						position = EModelService.RIGHT_OF;
453 463
						parentEditor = linkedConcordanceEditor;
454 464
					}
......
456 466
					// Split and add linked editor
457 467
					SWTEditorsUtils.addEditor(parentEditor, linkedEditor, position);
458 468
				}
459

  
469
				
460 470
				linkedEditor.setText(text, true);
461 471
				linkedEditor.goToPage(openPage.getName());
462 472
				
463 473
				// Highlight tokens by series
464
				for(int i = 0; i < allWordIds.size(); i++) {
474
				for (int i = 0; i < allWordIds.size(); i++) {
465 475
					linkedEditor.addHighlightWordsById(new RGBA(seriesColors.get(i).getRed(), seriesColors.get(i).getGreen(), seriesColors.get(i).getBlue()), allWordIds.get(i));
466 476
				}
467 477
				// Highlight selected curve token
......
473 483
				
474 484
				// FIXME: SJ: need to check that. Under Linux it seems we need to give back the focus to the chart editor and composite
475 485
				// give back the focus to the chart editor and chart composite
476
//				chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
477
//					@Override
478
//					public void run() {
479
//						chartEditor.setFocus();
480
//						chartEditor.getChartComposite().setFocus();
481
//					}
482
//				});
483

  
486
				// chartEditor.getComposite().getDisplay().asyncExec(new Runnable() {
487
				// @Override
488
				// public void run() {
489
				// chartEditor.setFocus();
490
				// chartEditor.getChartComposite().setFocus();
491
				// }
492
				// });
493
				
484 494
			}
485 495
		}
486
		catch(Exception e) {
496
		catch (Exception e) {
487 497
			Log.printStackTrace(e);
488 498
		}
489 499
	}
490

  
491 500
	
492
	    
493
}
501
	
502
	
503
}

Formats disponibles : Unified diff