Révision 349

tmp/org.txm.para.rcp/.settings/org.eclipse.jdt.core.prefs (revision 349)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.para.rcp/.classpath (revision 349)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.para.rcp/META-INF/MANIFEST.MF (revision 349)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Rcp
4
Bundle-SymbolicName: org.txm.para.rcp
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Activator: org.txm.para.rcp.Activator
7
Require-Bundle: org.txm.rcp;bundle-version="0.7.8",
8
 org.txm.core;bundle-version="0.7.0",
9
 org.eclipse.ui,
10
 org.eclipse.core.runtime,
11
 org.txm.para.core
12
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
13
Bundle-ActivationPolicy: lazy
14
Export-Package: org.txm.para.rcp,
15
 org.txm.para.rcp.editors
0 16

  
tmp/org.txm.para.rcp/.project (revision 349)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.para.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.para.rcp/src/org/txm/para/rcp/editors/ParaBrowserEditor.java (revision 349)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.para.rcp.editors;
29

  
30
import java.util.ArrayList;
31
import java.util.Collections;
32
import java.util.HashMap;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Set;
37

  
38
import org.eclipse.core.runtime.IProgressMonitor;
39
import org.eclipse.jface.action.Action;
40
import org.eclipse.jface.action.IMenuListener;
41
import org.eclipse.jface.action.IMenuManager;
42
import org.eclipse.jface.action.MenuManager;
43
import org.eclipse.osgi.util.NLS;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.custom.StyledText;
46
import org.eclipse.swt.events.SelectionEvent;
47
import org.eclipse.swt.events.SelectionListener;
48
import org.eclipse.swt.layout.GridData;
49
import org.eclipse.swt.layout.GridLayout;
50
import org.eclipse.swt.widgets.Button;
51
import org.eclipse.swt.widgets.Combo;
52
import org.eclipse.swt.widgets.Composite;
53
import org.eclipse.swt.widgets.Event;
54
import org.eclipse.swt.widgets.Label;
55
import org.eclipse.swt.widgets.Listener;
56
import org.eclipse.ui.IEditorInput;
57
import org.eclipse.ui.IEditorSite;
58
import org.eclipse.ui.PartInitException;
59
import org.eclipse.ui.part.EditorPart;
60
import org.txm.functions.ReferencePattern;
61
import org.txm.para.functions.ParaBrowser;
62
import org.txm.rcp.Messages;
63
import org.txm.rcp.StatusLine;
64
import org.txm.rcp.editors.input.ParaBrowserEditorInput;
65
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
66
import org.txm.searchengine.cqp.corpus.MainCorpus;
67
import org.txm.searchengine.cqp.corpus.Property;
68
import org.txm.searchengine.cqp.corpus.QueryResult;
69
import org.txm.searchengine.cqp.corpus.StructuralUnit;
70
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
71
import org.txm.utils.Pair;
72

  
73
// TODO: Auto-generated Javadoc
74
/**
75
 * The Class ParaBrowserEditor.
76
 */
77
public class ParaBrowserEditor extends EditorPart {
78

  
79
	/** The Constant ID. */
80
	public static final String ID = "org.txm.rcp.editors.parabrowser.ParaBrowserEditor"; //$NON-NLS-1$
81

  
82
	/** The display area. */
83
	private Composite displayArea;
84
	
85
	/** The define reference pattern action. */
86
	protected Action defineReferencePatternAction;
87
	
88
	/** The define order corpus action. */
89
	protected Action defineOrderCorpusAction;
90

  
91
	/** The corpus text areas. */
92
	private Map<MainCorpus, StyledText> corpusTextAreas;
93
	
94
	/** The corpus ref areas. */
95
	private Map<MainCorpus, Label> corpusRefAreas;
96
	
97
	/** The corpus query result areas. */
98
	private Map<MainCorpus, QueryResult> corpusQueryResultAreas;
99

  
100
	/** The selected structural unit. */
101
	private StructuralUnit selectedStructuralUnit;
102
	
103
	/** The selected structural unit para id. */
104
	private StructuralUnitProperty selectedStructuralUnitParaId;
105
	
106
	/** The selected value. */
107
	private String selectedValue;
108

  
109
	/** The structural units combo. */
110
	private Combo structuralUnitsCombo;
111
	
112
	/** The structural units final. */
113
	private List<StructuralUnit> structuralUnitsFinal;
114
	
115
	/** The para id combo. */
116
	private Combo paraIdCombo;
117

  
118
	/** The reference pattern. */
119
	private ReferencePattern referencePattern = new ReferencePattern();
120
	
121
	/** The selected reference. */
122
	private String selectedReference = ""; //$NON-NLS-1$
123

  
124
	/** The selected view corpus. */
125
	private List<MainCorpus> selectedViewCorpus;
126
	
127
	/** The available view corpus. */
128
	private List<MainCorpus> availableViewCorpus;
129

  
130
	/** The available view properties. */
131
	private List<StructuralUnit> availableViewProperties;
132
	
133
	/** The selected view properties. */
134
	private List<StructuralUnit> selectedViewProperties;
135
	
136
	private ParaBrowser paraBrowser = new ParaBrowser();
137
	
138
	/** The next. */
139
	private Button next;
140
	
141
	/** The prev. */
142
	private Button prev;
143

  
144
	/**
145
	 * Instantiates a new para browser editor.
146
	 */
147
	public ParaBrowserEditor() {
148
	}
149

  
150
	/**
151
	 * Do save.
152
	 *
153
	 * @param arg0 the arg0
154
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
155
	 */
156
	@Override
157
	public void doSave(IProgressMonitor arg0) {
158
		// TODO Auto-generated method stub
159
	}
160

  
161
	/**
162
	 * Do save as.
163
	 *
164
	 * @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs()
165
	 */
166
	@Override
167
	public void doSaveAs() {
168
		// TODO Auto-generated method stub
169
	}
170

  
171
	/**
172
	 * Inits the.
173
	 *
174
	 * @param site the site
175
	 * @param input the input
176
	 * @throws PartInitException the part init exception
177
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
178
	 * org.eclipse.ui.IEditorInput)
179
	 */
180
	@Override
181
	public void init(IEditorSite site, IEditorInput input)
182
			throws PartInitException {
183
		setSite(site);
184
		setInput(input);
185

  
186
		this.selectedViewCorpus = ((ParaBrowserEditorInput) input)
187
				.getCorpusList();
188
		List<MainCorpus> tempView = new ArrayList<MainCorpus>();
189
		availableViewCorpus = new ArrayList<MainCorpus>();
190
		if (selectedViewCorpus.size() > 3) {
191
			int i = 0;
192
			for (MainCorpus corpus : selectedViewCorpus) {
193
				if (i < 4) {
194
					tempView.add(corpus);
195
				} else {
196
					availableViewCorpus.add(corpus);
197
				}
198
				++i;
199
			}
200
			selectedViewCorpus = tempView;
201
		}
202
	}
203

  
204
	/**
205
	 * Checks if is dirty.
206
	 *
207
	 * @return true, if is dirty
208
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
209
	 */
210
	@Override
211
	public boolean isDirty() {
212
		return false;
213
	}
214

  
215
	/**
216
	 * Checks if is save as allowed.
217
	 *
218
	 * @return true, if is save as allowed
219
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
220
	 */
221
	@Override
222
	public boolean isSaveAsAllowed() {
223
		return false;
224
	}
225

  
226
	/**
227
	 * Creates the part control.
228
	 *
229
	 * @param parent the parent
230
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
231
	 */
232
	@Override
233
	public void createPartControl(final Composite parent) {
234
		corpusTextAreas = new HashMap<MainCorpus, StyledText>();
235
		corpusRefAreas = new HashMap<MainCorpus, Label>();
236
		corpusQueryResultAreas = new HashMap<MainCorpus, QueryResult>();
237

  
238
		parent.setLayout(new GridLayout(1, false));
239

  
240
		Composite controlArea = new Composite(parent, SWT.BORDER);
241
		controlArea
242
				.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));// FILL,
243
		composeControlArea(controlArea);
244

  
245
		displayArea = new Composite(parent, SWT.NONE);
246
		displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));// 2ème
247
																				// arg
248
																				// :
249
																				// true
250
		composeDisplayArea(displayArea);
251
		reloadTexts();
252
	}
253

  
254
	/**
255
	 * Compose display area.
256
	 *
257
	 * @param displayArea the display area
258
	 */
259
	private void composeDisplayArea(Composite displayArea) {
260

  
261
		if (selectedViewCorpus != null) {
262
			displayArea.setLayout(new GridLayout(selectedViewCorpus.size(),
263
					true));
264

  
265
			for (int i = 0; i < selectedViewCorpus.size(); ++i) {
266
				composeSingleTextDisplayArea(displayArea, selectedViewCorpus
267
						.get(i), selectedViewCorpus.size());
268
			}
269
		} else {
270
			displayArea.setLayout(new GridLayout(1, false));
271

  
272
			selectedViewCorpus = new ArrayList<MainCorpus>();
273
			selectedViewCorpus.add(selectedViewCorpus.get(0));
274
			composeSingleTextDisplayArea(displayArea,
275
					selectedViewCorpus.get(0), 1);
276
		}
277

  
278
	}
279

  
280
	/**
281
	 * Compose single text display area.
282
	 *
283
	 * @param displayArea the display area
284
	 * @param displayedCorpus the displayed corpus
285
	 * @param nbtextDisplayAreas the nbtext display areas
286
	 */
287
	private void composeSingleTextDisplayArea(Composite displayArea,
288
			MainCorpus displayedCorpus, int nbtextDisplayAreas) {
289
		Composite singleCorpusArea = new Composite(displayArea, SWT.NONE);
290
		singleCorpusArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
291
				true));
292
		GridLayout layout = new GridLayout(1, false);
293
		singleCorpusArea.setLayout(layout);
294

  
295
		// Corpus name Label
296
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297

  
298
		Label nameCorpusLabel = new Label(singleCorpusArea, SWT.NONE);
299
		nameCorpusLabel.setText(displayedCorpus.getName());
300
		nameCorpusLabel.setLayoutData(new GridData(GridData.FILL,
301
				GridData.FILL, true, false));
302

  
303
		// Text
304
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305

  
306
		StyledText corpusTextArea = new StyledText(singleCorpusArea, SWT.WRAP
307
				| SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); // SWT.BORDER
308
		corpusTextArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
309
				true, true));
310
		// String text = displayedCorpus.getTextRegion(selectedStructuralUnit,
311
		// selectedStructuralUnitParaId, selectedValue);
312
		corpusTextArea.setText(""); //$NON-NLS-1$
313
		corpusTextAreas.put(displayedCorpus, corpusTextArea);
314

  
315
		// Reference Label
316
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
317

  
318
		Label referenceLabel = new Label(singleCorpusArea, SWT.NONE);
319
		referenceLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
320
				true, false));
321
		if (referencePattern != null) {
322
			// selectedStructuralUnit.getName()
323
			List<Property> references = referencePattern.getProperties();
324
			for (Property property : references) {
325
				selectedReference += property.getName() + "/"; //$NON-NLS-1$
326
			}
327
		}
328
		referenceLabel.setText(Messages.ParaBrowserEditor_3 + selectedReference);
329
		corpusRefAreas.put(displayedCorpus, referenceLabel);
330
	}
331

  
332
	/**
333
	 * Compose control area.
334
	 *
335
	 * @param controlArea the control area
336
	 */
337
	private void composeControlArea(Composite controlArea) {
338
		controlArea.setLayout(new GridLayout(6, false));
339
		// composeCorpusDisplay(controlArea);
340
		composeStructuralNavigation(controlArea);
341
		composeNavigation(controlArea);
342

  
343
		createActions();
344

  
345
		MenuManager menuManager = new MenuManager("#PopupMenu"); //$NON-NLS-1$
346
		menuManager.setRemoveAllWhenShown(true);
347
		menuManager.addMenuListener(new IMenuListener() {
348
			@Override
349
			public void menuAboutToShow(IMenuManager manager) {
350
				manager.add(defineReferencePatternAction);
351
				manager.add(defineOrderCorpusAction);
352
			}
353
		});
354
		controlArea.setMenu(menuManager.createContextMenu(controlArea));
355
		getSite().registerContextMenu(menuManager,
356
				this.getSite().getSelectionProvider());
357
	}
358

  
359
	/*
360
	 * private void composeCorpusDisplay(Composite controlArea){ //Manager for
361
	 * corpus display Button buttonManager = new Button(controlArea, SWT.PUSH);
362
	 * buttonManager.setText("manage view"); buttonManager.addMouseListener(new
363
	 * MouseListener() {
364
	 * 
365
	 * @Override public void mouseUp(MouseEvent e) {
366
	 * launchCorpusSelectionManager(); }
367
	 * 
368
	 * @Override public void mouseDown(MouseEvent e) {
369
	 * launchCorpusSelectionManager(); }
370
	 * 
371
	 * @Override public void mouseDoubleClick(MouseEvent e) { // TODO
372
	 * Auto-generated method stub
373
	 * 
374
	 * } });
375
	 * 
376
	 * //Manager to build reference Button buttonReference = new
377
	 * Button(controlArea, SWT.PUSH); buttonReference.setText("reference");
378
	 * buttonReference.addMouseListener(new MouseListener() {
379
	 * 
380
	 * @Override public void mouseUp(MouseEvent e) {
381
	 * launchCorpusReferenceManager(); }
382
	 * 
383
	 * @Override public void mouseDown(MouseEvent e) {
384
	 * launchCorpusReferenceManager(); }
385
	 * 
386
	 * @Override public void mouseDoubleClick(MouseEvent e) { // TODO
387
	 * Auto-generated method stub
388
	 * 
389
	 * } }); }
390
	 */
391

  
392
	/**
393
	 * Compose navigation.
394
	 *
395
	 * @param controlArea the control area
396
	 */
397
	private void composeNavigation(Composite controlArea) {
398
		Composite navigationArea = new Composite(controlArea, SWT.NONE);
399
		navigationArea.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,
400
				false));// false, false
401
		navigationArea.setLayout(new GridLayout(2, false));
402
		// [<] [>]
403

  
404
		// [<]
405
		prev = new Button(navigationArea, SWT.PUSH);
406
		prev.setText(Messages.ConcordancesEditor_12);
407
		prev.addListener(SWT.Selection, new Listener() {
408
			@Override
409
			public void handleEvent(Event event) {
410
				nextorpreviousText(false);
411
			}
412
		});
413
		prev.setEnabled(true);
414

  
415
		// [>]
416
		next = new Button(navigationArea, SWT.PUSH);
417
		next.setText(Messages.ConcordancesEditor_13);
418
		next.addListener(SWT.Selection, new Listener() {
419
			@Override
420
			public void handleEvent(Event event) {
421
				nextorpreviousText(true);
422
			}
423
		});
424
		next.setEnabled(true);
425

  
426
	}
427

  
428
	/**
429
	 * Compose structural navigation.
430
	 *
431
	 * @param controlArea the control area
432
	 */
433
	private void composeStructuralNavigation(Composite controlArea) {
434
		// StructuralUnit
435
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
436
		Button refButton = new Button(controlArea, SWT.PUSH);
437
		refButton.setText(Messages.ParaBrowserEditor_4);
438
		refButton
439
				.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
440
		refButton.addSelectionListener(new SelectionListener() {
441
			@Override
442
			public void widgetSelected(SelectionEvent e) {
443
				defineReferencePatternAction.run();
444
			}
445

  
446
			@Override
447
			public void widgetDefaultSelected(SelectionEvent e) {
448
			}
449
		});
450

  
451
		Label structureLabel = new Label(controlArea, SWT.NONE);
452
		structureLabel.setText(Messages.ParaBrowserEditor_5); // LEFT
453
		structureLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
454
				true));
455

  
456
		structuralUnitsCombo = new Combo(controlArea, SWT.READ_ONLY);
457

  
458
		List<StructuralUnit> structuralUnits = null;
459
		if (selectedViewCorpus.size() > 0) {
460
			try {
461
				// same structure in all corpus, therefore use the first in the
462
				// list
463
				structuralUnits = selectedViewCorpus.get(0)
464
						.getOrderedStructuralUnits();
465
			} catch (CqiClientException e) {
466
				System.err
467
						.println(Messages.ObjectExplorer_9);
468
				return;
469
			}
470
		}
471
		structuralUnitsFinal = new ArrayList<StructuralUnit>();
472
		if (structuralUnits != null) {
473
			for (StructuralUnit unit : structuralUnits) {
474
				if (unit.getOrderedProperties() != null
475
						&& unit.getOrderedProperties().size() != 0) {
476
					structuralUnitsCombo.add(unit.getName());
477
					structuralUnitsFinal.add(unit);
478
				}
479
			}
480
		}
481

  
482
		if (structuralUnitsCombo.getItemCount() == 0) {
483
			// this.getButton(IDialogConstants.OK_ID).setEnabled(false);
484
		} else {
485
			structuralUnitsCombo.select(0);
486
			selectedStructuralUnit = structuralUnitsFinal.get(0);
487
		}
488

  
489
		// StructuralUnitParaId
490
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
491

  
492
		Label paraIdLabel = new Label(controlArea, SWT.NONE);
493
		paraIdLabel.setText("paraid"); //$NON-NLS-1$
494
		paraIdLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
495
				true));
496

  
497
		paraIdCombo = new Combo(controlArea, SWT.READ_ONLY);
498
		paraIdCombo
499
				.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
500

  
501
		structuralUnitsCombo.addSelectionListener(new SelectionListener() {
502
			@Override
503
			public void widgetDefaultSelected(SelectionEvent e) {
504
			}
505

  
506
			@Override
507
			public void widgetSelected(SelectionEvent event) {
508
				reloadIds();
509
			}
510
		});
511

  
512
		for (StructuralUnitProperty property : structuralUnitsFinal.get(0)
513
				.getOrderedProperties()) {
514
			if (property.getName().equals("id")) { //$NON-NLS-1$
515
				selectedStructuralUnitParaId = property;
516
				try {
517
					for (String value : property.getValues()) {
518
						paraIdCombo.add(value);
519
					}
520
				} catch (CqiClientException e1) {
521
					// TODO Auto-generated catch block
522
					org.txm.rcp.utils.Logger.printStackTrace(e1);
523
				}
524
			}
525
		}
526
		paraIdCombo.select(0);
527
		try {
528
			if (selectedStructuralUnitParaId != null)
529
				selectedValue = selectedStructuralUnitParaId.getValues().get(0);
530
		} catch (CqiClientException e1) {
531
			// TODO Auto-generated catch block
532
			org.txm.rcp.utils.Logger.printStackTrace(e1);
533
		}
534

  
535
		paraIdCombo.addSelectionListener(new SelectionListener() {
536
			@Override
537
			public void widgetDefaultSelected(SelectionEvent e) {
538
			}
539

  
540
			@Override
541
			public void widgetSelected(SelectionEvent event) {
542
				// selectedStructuralUnitParaId =
543
				// selectedStructuralUnit.getProperties().get(paraIdCombo.getSelectionIndex());
544
				if (selectedStructuralUnitParaId != null) {
545
					try {
546
						List<String> values = selectedStructuralUnitParaId
547
								.getValues();
548
						Collections.sort(values);
549
						selectedValue = values.get(paraIdCombo
550
								.getSelectionIndex());
551
						// System.out.println("Selection of id = "+selectedValue);
552
					} catch (CqiClientException e) {
553
						// TODO Auto-generated catch block
554
						org.txm.rcp.utils.Logger.printStackTrace(e);
555
					}
556
				}
557
				reloadTexts();
558
				reloadReferences();
559
			}
560
		});
561
	}
562

  
563
	/**
564
	 * Creates the actions.
565
	 */
566
	private void createActions() {
567
		defineReferencePatternAction = new DefineParaViewReferencePattern(getSite()
568
				.getWorkbenchWindow(), this);
569
		defineOrderCorpusAction = new CorpusSelection(getSite()
570
				.getWorkbenchWindow(), this);
571
	}
572

  
573
	/**
574
	 * Reload display.
575
	 */
576
	private void reloadDisplay() {
577
		if (selectedViewCorpus != null) {
578
			displayArea.setLayout(new GridLayout(selectedViewCorpus.size(),
579
					true));
580

  
581
			for (int i = 0; i < selectedViewCorpus.size(); ++i) {
582
				composeSingleTextDisplayArea(displayArea, selectedViewCorpus
583
						.get(i), selectedViewCorpus.size());
584
			}
585
		} else {
586
			displayArea.setLayout(new GridLayout(1, false));
587

  
588
			selectedViewCorpus = new ArrayList<MainCorpus>();
589
			selectedViewCorpus.add(selectedViewCorpus.get(0));
590
			composeSingleTextDisplayArea(displayArea,
591
					selectedViewCorpus.get(0), 1);
592
		}
593
		displayArea.layout();
594
		displayArea.pack(true);
595
	}
596

  
597
	/**
598
	 * Reload texts.
599
	 */
600
	private void reloadTexts() {
601
		Set keys = corpusTextAreas.keySet();
602
		Iterator<MainCorpus> it = keys.iterator();
603
		while (it.hasNext()) {
604
			MainCorpus corpus = it.next();
605
			StyledText textArea = corpusTextAreas.get(corpus);
606
			Pair<String, QueryResult> pair = paraBrowser.getTextRegion(corpus,
607
					selectedStructuralUnit, selectedStructuralUnitParaId,
608
					selectedValue);
609
			// corpusQueryResultAreas.put(corpus, pair.getSecond());
610
			textArea.setText(pair.getFirst());
611
			// Label ref = corpusRefAreas.get(corpus);
612
			// ref.setText("Ref: ...");
613
		}
614
	}
615

  
616
	/**
617
	 * Reload ids.
618
	 */
619
	private void reloadIds() {
620
		selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo
621
				.getSelectionIndex());
622
		paraIdCombo.removeAll();
623

  
624
		for (StructuralUnitProperty property : structuralUnitsFinal.get(
625
				structuralUnitsCombo.getSelectionIndex()).getOrderedProperties()) {
626
			if (property.getName().equals("id")) { //$NON-NLS-1$
627
				selectedStructuralUnitParaId = property;
628
				try {
629
					List<String> values = property.getValues();
630
					Collections.sort(values);
631
					for (String value : values) {
632
						paraIdCombo.add(value);
633
					}
634
				} catch (CqiClientException e1) {
635
					// TODO Auto-generated catch block
636
					org.txm.rcp.utils.Logger.printStackTrace(e1);
637
				}
638
			}
639
		}
640

  
641
		if (paraIdCombo.getItemCount() > 0) {
642
			paraIdCombo.select(0);
643
			try {
644
				if (selectedStructuralUnitParaId != null) {
645
					List<String> values = selectedStructuralUnitParaId
646
							.getValues();
647
					Collections.sort(values);
648
					selectedValue = values.get(0);
649
					reloadTexts();
650
					reloadReferences();
651
				}
652
			} catch (CqiClientException e1) {
653
				// TODO Auto-generated catch block
654
				org.txm.rcp.utils.Logger.printStackTrace(e1);
655
			}
656
			// selectedStructuralUnitParaId =
657
			// selectedStructuralUnit.getProperties().get(0);
658
		}
659
	}
660

  
661
	/**
662
	 * Reload references.
663
	 */
664
	private void reloadReferences() {
665
		Set<MainCorpus> keys = corpusRefAreas.keySet();
666
		Iterator<MainCorpus> it = keys.iterator();
667
		while (it.hasNext()) {
668
			MainCorpus corpus = it.next();
669

  
670
			// get all reference values of all lines
671
			/*
672
			 * List<Integer> beginingOfKeywordsPositions = new
673
			 * ArrayList<Integer>(j-i); Map<Property, List<List<String>>>
674
			 * refValues = new HashMap<Property, List<List<String>>>(); for
675
			 * (Property property : referencePattern){
676
			 * refValues.put(property,cache
677
			 * .get(property).getData(beginingOfKeywordsPositions,
678
			 * Collections.nCopies(beginingOfKeywordsPositions.size(), 1))); }
679
			 */
680

  
681
			Label refArea = corpusRefAreas.get(corpus);
682
			refArea.setText(NLS.bind(Messages.ParaBrowserEditor_9, corpus.getName(), selectedReference));
683
		}
684

  
685
	}
686

  
687
	/**
688
	 * Nextorprevious text.
689
	 *
690
	 * @param findNext the find next
691
	 */
692
	public void nextorpreviousText(boolean findNext) {
693
		// get Property
694
		System.out.println(NLS.bind(Messages.ParaBrowserEditor_11, 
695
			new Object[]{findNext, selectedStructuralUnit, selectedStructuralUnitParaId, selectedValue}));
696
		if (selectedStructuralUnit != null) {
697
			// Multiple Query, as many as there are corpuses displayed
698
			Set keys = corpusTextAreas.keySet();
699
			Iterator<MainCorpus> it = keys.iterator();
700
			String newValue = ""; //$NON-NLS-1$
701
			for (int i = 0; it.hasNext(); ++i) {
702
				// if (i==0){
703
				MainCorpus corpus = it.next();
704
				System.out.println("CORPUS ################### " //$NON-NLS-1$
705
						+ corpus.getName());
706
				newValue = paraBrowser.getNextOrPrevious(corpus, selectedStructuralUnit,
707
						selectedStructuralUnitParaId, selectedValue, findNext);
708
				// }
709
			}
710
			if (!newValue.equals("")) { //$NON-NLS-1$
711
				System.out.println(Messages.ParaBrowserEditor_18 + newValue);
712
				int index = paraIdCombo.indexOf(newValue);
713
				if (index != -1) {
714
					selectedValue = newValue;
715
					paraIdCombo.select(index);
716
				}
717
			} else {
718
				System.out.println(Messages.ParaBrowserEditor_19 + newValue);
719
			}
720
			reloadTexts();
721
			reloadReferences();
722
		}
723
	}
724

  
725
	/**
726
	 * Sets the reference pattern.
727
	 *
728
	 * @param referencePattern the new reference pattern
729
	 */
730
	public void setReferencePattern(ReferencePattern referencePattern) {
731
		this.referencePattern = referencePattern;
732
		selectedReference = Messages.ObjectExplorer_9;
733
		if (referencePattern != null) {
734
			// selectedStructuralUnit.getName()
735
			List<Property> references = referencePattern.getProperties();
736
			for (Property property : references) {
737
				selectedReference += property.getName() + Messages.ParaBrowserEditor_21;
738
			}
739
		}
740
		reloadReferences();
741
	}
742

  
743
	/**
744
	 * Sets the focus.
745
	 *
746
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
747
	 */
748
	@Override
749
	public void setFocus() {
750
		StatusLine.setMessage(Messages.ParaBrowserEditor_22);
751
	}
752

  
753
	/**
754
	 * Gets the corpus.
755
	 *
756
	 * @return the corpus
757
	 */
758
	public MainCorpus getCorpus() {
759
		if (selectedViewCorpus.size() > 0) {
760
			return selectedViewCorpus.get(0);
761
		} else
762
			return null;
763
	}
764

  
765
	/**
766
	 * Gets the selected corpus.
767
	 *
768
	 * @return the selected corpus
769
	 */
770
	public List<MainCorpus> getSelectedCorpus() {
771
		return selectedViewCorpus;
772
	}
773

  
774
	/**
775
	 * Sets the selected corpus.
776
	 *
777
	 * @param corpus the corpus
778
	 * @param corpusAvailable the corpus available
779
	 */
780
	public void setSelectedCorpus(List<MainCorpus> corpus,
781
			List<MainCorpus> corpusAvailable) {
782
		selectedViewCorpus = corpus;
783
		availableViewCorpus = corpusAvailable;
784
		reloadDisplay();
785
	}
786

  
787
	/**
788
	 * Gets the available corpus.
789
	 *
790
	 * @return the available corpus
791
	 */
792
	public List<MainCorpus> getAvailableCorpus() {
793
		if (availableViewCorpus == null) {
794
			availableViewCorpus = new ArrayList<MainCorpus>();
795
		}
796
		return availableViewCorpus;
797
	}
798

  
799
	/**
800
	 * Gets the selected references.
801
	 *
802
	 * @return the selected references
803
	 */
804
	public List<Property> getSelectedReferences() {
805
		return referencePattern.getProperties();
806
	}
807
}
0 808

  
tmp/org.txm.para.rcp/src/org/txm/para/rcp/editors/CorpusSelection.java (revision 349)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.para.rcp.editors;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.jface.action.Action;
33
import org.eclipse.jface.dialogs.Dialog;
34
import org.eclipse.jface.window.Window;
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.MouseAdapter;
37
import org.eclipse.swt.events.MouseEvent;
38
import org.eclipse.swt.events.SelectionAdapter;
39
import org.eclipse.swt.events.SelectionEvent;
40
import org.eclipse.swt.layout.GridData;
41
import org.eclipse.swt.layout.GridLayout;
42
import org.eclipse.swt.widgets.Button;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.ui.IWorkbenchWindow;
47
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
48
import org.txm.searchengine.cqp.corpus.MainCorpus;
49

  
50
// TODO: Auto-generated Javadoc
51
/**
52
 * The Class CorpusSelection.
53
 */
54
public class CorpusSelection extends Action implements IWorkbenchAction {
55

  
56
	/** The Constant ID. */
57
	private static final String ID = "org.txm.rcp.editors.parabrowser.corpusselection"; //$NON-NLS-1$
58
	
59
	/** The window. */
60
	private IWorkbenchWindow window;
61
	
62
	/** The para browser editor. */
63
	private ParaBrowserEditor paraBrowserEditor;
64

  
65
	/**
66
	 * Instantiates a new corpus selection.
67
	 *
68
	 * @param window the window
69
	 * @param paraBrowserEditor the para browser editor
70
	 */
71
	public CorpusSelection(IWorkbenchWindow window,
72
			ParaBrowserEditor paraBrowserEditor) {
73
		this.window = window;
74
		this.paraBrowserEditor = paraBrowserEditor;
75
		setId(ID);
76
		setText("Définir les corpus à l'affichage"); //$NON-NLS-1$
77
		setToolTipText("Corpus à l'affichage"); //$NON-NLS-1$
78
	}
79

  
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
82
	 */
83
	@Override
84
	public void dispose() {
85
	}
86

  
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jface.action.Action#run()
89
	 */
90
	@Override
91
	public void run() {
92
		if (paraBrowserEditor != null) {
93
			List<MainCorpus> selectedCorpus = paraBrowserEditor
94
					.getSelectedCorpus();
95
			List<MainCorpus> availableCorpus = paraBrowserEditor
96
					.getAvailableCorpus();
97

  
98
			CorpusSelectionDialog d = new CorpusSelectionDialog(window
99
					.getShell(), availableCorpus, selectedCorpus);
100
			if (d.open() == Window.OK) {
101
				if (paraBrowserEditor == null) {
102
					paraBrowserEditor.setSelectedCorpus(d.getSelectedCorpus(),
103
							d.getAvailableCorpus());
104
				}
105
			}
106
		}
107
	}
108

  
109
	/**
110
	 * The Class CorpusSelectionDialog.
111
	 */
112
	private class CorpusSelectionDialog extends Dialog {
113

  
114
		/** The available corpus. */
115
		final private List<MainCorpus> availableCorpus;
116
		
117
		/** The selected corpus. */
118
		final private List<MainCorpus> selectedCorpus;
119

  
120
		/** The available corpus view. */
121
		org.eclipse.swt.widgets.List availableCorpusView;
122
		
123
		/** The selected corpus view. */
124
		org.eclipse.swt.widgets.List selectedCorpusView;
125

  
126
		/**
127
		 * Instantiates a new corpus selection dialog.
128
		 *
129
		 * @param parentShell the parent shell
130
		 * @param availableCorpus the available corpus
131
		 * @param selectedCorpus the selected corpus
132
		 */
133
		protected CorpusSelectionDialog(Shell parentShell,
134
				List<MainCorpus> availableCorpus,
135
				List<MainCorpus> selectedCorpus) {
136
			super(parentShell);
137
			this.availableCorpus = availableCorpus;
138
			this.selectedCorpus = selectedCorpus;
139
			// TODO Auto-generated constructor stub
140
		}
141

  
142
		/**
143
		 * Gets the selected corpus.
144
		 *
145
		 * @return the selected corpus
146
		 */
147
		public List<MainCorpus> getSelectedCorpus() {
148
			return selectedCorpus;
149
		}
150

  
151
		/**
152
		 * Gets the available corpus.
153
		 *
154
		 * @return the available corpus
155
		 */
156
		public List<MainCorpus> getAvailableCorpus() {
157
			return availableCorpus;
158
		}
159

  
160
		/* (non-Javadoc)
161
		 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
162
		 */
163
		@Override
164
		protected Control createDialogArea(Composite parent) {
165
			// parent.setLayout(new FormLayout());
166
			Composite mainArea = new Composite(parent, SWT.NONE);
167
			mainArea
168
					.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
169

  
170
			// 4 columns
171
			GridLayout layout = new GridLayout(4, false);
172
			mainArea.setLayout(layout);
173

  
174
			availableCorpusView = new org.eclipse.swt.widgets.List(mainArea,
175
					SWT.BORDER | SWT.V_SCROLL);
176
			GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
177
			availableCorpusView.setLayoutData(gridData);
178

  
179
			Composite selectionButtons = new Composite(mainArea, SWT.NONE);
180
			selectionButtons.setLayout(new GridLayout(1, false));
181
			Button select = new Button(selectionButtons, SWT.ARROW | SWT.RIGHT);
182
			Button unselect = new Button(selectionButtons, SWT.ARROW | SWT.LEFT);
183

  
184
			selectedCorpusView = new org.eclipse.swt.widgets.List(mainArea,
185
					SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
186
			gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
187
			selectedCorpusView.setLayoutData(gridData);
188

  
189
			Composite orderButtons = new Composite(mainArea, SWT.NONE);
190
			orderButtons.setLayout(new GridLayout(1, false));
191
			Button up = new Button(orderButtons, SWT.ARROW | SWT.UP);
192
			Button down = new Button(orderButtons, SWT.ARROW | SWT.DOWN);
193

  
194
			select.addSelectionListener(new SelectionAdapter() {
195
				@Override
196
				public void widgetSelected(SelectionEvent e) {
197
					int index = availableCorpusView.getSelectionIndex();
198

  
199
					selectedCorpus.add(availableCorpus.get(index));
200
					availableCorpus.remove(index);
201

  
202
					reload();
203
					availableCorpusView.setSelection(index);
204
				}
205
			});
206

  
207
			unselect.addSelectionListener(new SelectionAdapter() {
208
				@Override
209
				public void widgetSelected(SelectionEvent e) {
210
					if (selectedCorpus.size() > 1) {
211
						int index = selectedCorpusView.getSelectionIndex();
212

  
213
						availableCorpus.add(selectedCorpus.get(index));
214
						selectedCorpus.remove(index);
215

  
216
						reload();
217
						selectedCorpusView.setSelection(index);
218
					}
219
				}
220
			});
221

  
222
			up.addSelectionListener(new SelectionAdapter() {
223
				@Override
224
				public void widgetSelected(SelectionEvent e) {
225
					int index = selectedCorpusView.getSelectionIndex();
226
					if (index > 0) {
227
						MainCorpus selectedC = selectedCorpus.get(index);
228
						MainCorpus upperC = selectedCorpus.get(index - 1);
229

  
230
						selectedCorpus.set(index, upperC);
231
						selectedCorpus.set(index - 1, selectedC);
232

  
233
						reload();
234
						selectedCorpusView.setSelection(index - 1);
235
					}
236
				}
237
			});
238

  
239
			down.addSelectionListener(new SelectionAdapter() {
240
				@Override
241
				public void widgetSelected(SelectionEvent e) {
242
					int index = selectedCorpusView.getSelectionIndex();
243
					if (index < selectedCorpus.size() - 1) {
244
						MainCorpus selectedC = selectedCorpus.get(index);
245
						MainCorpus bellowC = selectedCorpus.get(index + 1);
246

  
247
						selectedCorpus.set(index, bellowC);
248
						selectedCorpus.set(index + 1, selectedC);
249

  
250
						reload();
251
						selectedCorpusView.setSelection(index + 1);
252
					}
253
				}
254
			});
255

  
256
			availableCorpusView.addMouseListener(new MouseAdapter() {
257
				@Override
258
				public void mouseDoubleClick(MouseEvent e) {
259
					int index = selectedCorpusView.getSelectionIndex();
260

  
261
					selectedCorpus.add(availableCorpus.get(index));
262
					availableCorpus.remove(index);
263

  
264
					reload();
265
					availableCorpusView.setSelection(index);
266
				}
267
			});
268

  
269
			selectedCorpusView.addMouseListener(new MouseAdapter() {
270
				@Override
271
				public void mouseDoubleClick(MouseEvent e) {
272
					if (selectedCorpus.size() > 1) {
273
						int index = selectedCorpusView.getSelectionIndex();
274

  
275
						availableCorpus.add(selectedCorpus.get(index));
276
						selectedCorpus.remove(index);
277

  
278
						reload();
279
						selectedCorpusView.setSelection(index);
280
					}
281
				}
282
			});
283

  
284
			reload();
285
			return mainArea;
286
		}
287

  
288
		/**
289
		 * Reload.
290
		 */
291
		public void reload() {
292
			System.out
293
					.println("CorpusSelectionDialog.reload() => availableCorpus[" //$NON-NLS-1$
294
							+ availableCorpus.size()
295
							+ "] / selectedCorpus[" //$NON-NLS-1$
296
							+ selectedCorpus.size() + "]"); //$NON-NLS-1$
297
			availableCorpusView.removeAll();
298
			for (MainCorpus corpus : availableCorpus) {
299
				if (!corpus.getName().equals("id")) //$NON-NLS-1$
300
					availableCorpusView.add(corpus.getName());
301
			}
302
			selectedCorpusView.removeAll();
303
			for (MainCorpus corpus : selectedCorpus) {
304
				if (!corpus.getName().equals("id")) //$NON-NLS-1$
305
					selectedCorpusView.add(corpus.getName());
306
			}
307

  
308
			availableCorpusView.getParent().layout();
309
		}
310

  
311
		/* (non-Javadoc)
312
		 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
313
		 */
314
		@Override
315
		protected void okPressed() {
316
			if (selectedCorpus.size() != 0)
317
				super.okPressed();
318
		}
319
	}
320
}
0 321

  
tmp/org.txm.para.rcp/src/org/txm/para/rcp/editors/DefineParaSortReferencePattern.java (revision 349)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.para.rcp.editors;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.eclipse.jface.action.Action;
34
import org.eclipse.jface.dialogs.Dialog;
35
import org.eclipse.jface.window.Window;
36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.events.MouseEvent;
38
import org.eclipse.swt.events.MouseListener;
39
import org.eclipse.swt.events.SelectionAdapter;
40
import org.eclipse.swt.events.SelectionEvent;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Control;
46
import org.eclipse.swt.widgets.Shell;
47
import org.eclipse.ui.IWorkbenchWindow;
48
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
49
import org.txm.functions.ReferencePattern;
50
import org.txm.para.rcp.editors.ParaBrowserEditor;
51
import org.txm.rcp.Messages;
52
import org.txm.rcp.editors.concordances.ConcordancesEditor;
53
import org.txm.searchengine.cqp.corpus.Property;
54
import org.txm.searchengine.cqp.corpus.StructuralUnit;
55
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
56
// TODO: Auto-generated Javadoc
57
/**
58
 * Action to build the reference pattern.
59
 *
60
 * @ author mdecorde
61
 */
62
public class DefineParaSortReferencePattern extends Action implements IWorkbenchAction {
63

  
64
	/** The Constant ID. */
65
	private static final String ID = "org.txm.rcp.editors.concordances.definereferencepattern"; //$NON-NLS-1$
66
	
67
	/** The window. */
68
	private IWorkbenchWindow window;
69
	
70
	/** The concordance editor. */
71
	private ConcordancesEditor concordanceEditor;
72
	
73
	/** The para browser editor. */
74
	private ParaBrowserEditor paraBrowserEditor;
75

  
76
	/**
77
	 * Instantiates a new define reference pattern.
78
	 *
79
	 * @param window the window
80
	 * @param concordanceEditor the concordance editor
81
	 */
82
	public DefineParaSortReferencePattern(IWorkbenchWindow window,
83
			ConcordancesEditor concordanceEditor) {
84
		this.window = window;
85
		this.concordanceEditor = concordanceEditor;
86
		setId(ID);
87
		setText(Messages.DefineReferencePattern_3);
88
		setToolTipText(Messages.DefineReferencePattern_4);
89
	}
90

  
91
	/**
92
	 * Instantiates a new define reference pattern.
93
	 *
94
	 * @param window the window
95
	 * @param paraBrowserEditor the para browser editor
96
	 */
97
	public DefineParaSortReferencePattern(IWorkbenchWindow window,
98
			ParaBrowserEditor paraBrowserEditor) {
99
		this.window = window;
100
		this.paraBrowserEditor = paraBrowserEditor;
101
		setId(ID);
102
		setText(Messages.DefineReferencePattern_3);
103
		setToolTipText(Messages.DefineReferencePattern_4);
104
	}
105

  
106
	
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
109
	 */
110
	@Override
111
	public void dispose() {
112
	}
113

  
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.jface.action.Action#run()
116
	 */
117
	@Override
118
	public void run() {
119
		List<StructuralUnit> structuralUnits = null;
120
		List<Property> availableReferenceItems = new ArrayList<Property>();
121
		try {
122
			if (paraBrowserEditor != null) {
123
				structuralUnits = paraBrowserEditor.getCorpus()
124
						.getOrderedStructuralUnits();
125
				availableReferenceItems.addAll(paraBrowserEditor.getCorpus()
126
						.getOrderedProperties());
127

  
128
			} else if (concordanceEditor != null) {
129
				structuralUnits = concordanceEditor.getCorpus()
130
						.getOrderedStructuralUnits();
131
				availableReferenceItems.addAll(concordanceEditor.getCorpus()
132
						.getOrderedProperties());
133

  
134
			}
135

  
136
		} catch (Exception e) {
137
			org.txm.rcp.utils.Logger.printStackTrace(e);
138
		}
139

  
140
		for (StructuralUnit unit : structuralUnits) {
141
			availableReferenceItems.addAll(unit.getProperties());
142
		}
143

  
144
		// System.out.println("selected "+concordanceEditor.getSelectedReferences());
145
		// System.out.println("before avail"+availableReferenceItems);
146
		if (paraBrowserEditor != null) {
147
			availableReferenceItems.remove(paraBrowserEditor
148
					.getSelectedReferences());
149
		} else {
150
			availableReferenceItems.remove(concordanceEditor
151
					.getSelectedSortReferences());
152
		}
153

  
154
		// System.out.println("after avail"+availableReferenceItems);
155
		DefineReferencePatternDialog d = null;
156
		if (paraBrowserEditor != null) {
157
			d = new DefineReferencePatternDialog(window.getShell(),
158
					availableReferenceItems, paraBrowserEditor
159
							.getSelectedReferences());
160
		} else if (concordanceEditor != null) {
161
			d = new DefineReferencePatternDialog(window.getShell(),
162
					availableReferenceItems, concordanceEditor
163
							.getSelectedSortReferences());
164
		}
165

  
166
		if (d.open() == Window.OK) {
167
			if (paraBrowserEditor != null) {
168
				paraBrowserEditor.setReferencePattern(new ReferencePattern(d
169
						.getSelectesdReferenceItems()));
170
			} else if (concordanceEditor != null) {
171
				concordanceEditor.setRefSortPattern(new ReferencePattern(d
172
						.getSelectesdReferenceItems()));
173
			}
174
			//System.out.println(concordanceEditor.getSortReferencePattern());
175
		}
176
	}
177

  
178
	/**
179
	 * The Class DefineReferencePatternDialog.
180
	 */
181
	private class DefineReferencePatternDialog extends Dialog {
182

  
183
		/** The available reference items. */
184
		private List<Property> availableReferenceItems;
185
		
186
		/** The selected reference items. */
187
		private List<Property> selectedReferenceItems;
188

  
189
		/**
190
		 * Instantiates a new define reference pattern dialog.
191
		 *
192
		 * @param parentShell the parent shell
193
		 * @param availableReferenceItems the available reference items
194
		 * @param selectedReferences the selected references
195
		 */
196
		protected DefineReferencePatternDialog(Shell parentShell,
197
				List<Property> availableReferenceItems,
198
				List<Property> selectedReferences) {
199
			super(parentShell);
200
			
201
			this.availableReferenceItems = availableReferenceItems;
202
			this.selectedReferenceItems = selectedReferences;
203
			this.availableReferenceItems.removeAll(selectedReferences);
204
			this.setShellStyle(this.getShellStyle() | SWT.RESIZE);	
205
		}
206

  
207
		/**
208
		 * Gets the selectesd reference items.
209
		 *
210
		 * @return the selectesd reference items
211
		 */
212
		public List<Property> getSelectesdReferenceItems() {
213
			return selectedReferenceItems;
214
		}
215

  
216
		/* (non-Javadoc)
217
		 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
218
		 */
219
		@Override
220
		protected void configureShell(Shell shell) {
221
		      super.configureShell(shell);
222
		      shell.setText(Messages.DefineReferencePattern_5);
223
		      
224
		      shell.setSize(400, 500);
225
		      shell.setLocation(shell.getParent().getLocation());
226
		   }
227
		
228
		/* (non-Javadoc)
229
		 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
230
		 */
231
		@Override
232
		protected Control createDialogArea(Composite parent) {
233

  
234
			Composite mainArea = new Composite(parent, SWT.NONE);
235
			mainArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
236
					true, true));
237
			mainArea.setLayout(new GridLayout(4, false));
238

  
239
			final org.eclipse.swt.widgets.List availbleItems = new org.eclipse.swt.widgets.List(
240
					mainArea, SWT.BORDER | SWT.V_SCROLL);
241
			for (Property property : availableReferenceItems) {
242
				if (property instanceof StructuralUnitProperty) {
243
					StructuralUnitProperty sProperty = (StructuralUnitProperty) property;
244
					availbleItems.add(sProperty.getStructuralUnit().getName()
245
							+ ": " + property.getName()); //$NON-NLS-1$
246
				} else {
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff