Révision 3709

TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/preferences/URSPreferencePage.java (revision 3709)
1 1
package org.txm.annotation.urs.preferences;
2 2

  
3 3
import org.eclipse.jface.preference.BooleanFieldEditor;
4
import org.eclipse.jface.preference.ColorFieldEditor;
4 5
import org.eclipse.jface.preference.IntegerFieldEditor;
6
import org.eclipse.jface.preference.PreferenceConverter;
5 7
import org.eclipse.jface.preference.RadioGroupFieldEditor;
8
import org.eclipse.jface.preference.StringFieldEditor;
9
import org.eclipse.jface.util.PropertyChangeEvent;
6 10
import org.eclipse.ui.IWorkbench;
7 11
import org.eclipse.ui.IWorkbenchPreferencePage;
8 12
import org.eclipse.ui.preferences.ScopedPreferenceStore;
......
11 15
import org.txm.rcp.preferences.TXMPreferenceStore;
12 16

  
13 17
public class URSPreferencePage extends TXMPreferencePage implements IWorkbenchPreferencePage {
14
	
18

  
15 19
	private BooleanFieldEditor analec_limit_scheme_field;
16
	
20

  
17 21
	private BooleanFieldEditor prefix_autocompletion_field;
18
	
22

  
19 23
	private IntegerFieldEditor save_timer_field;
20
	
24

  
21 25
	// public static final String SELECTED_UNIT_COLOR = "selected_unit_color";
22 26
	// private ColorFieldEditor selected_unit_color;
23 27
	// public static final String HIGHLIGHTED_UNIT_COLOR = "hightlighted_unit_color";
24 28
	// private ColorFieldEditor hightlighted_unit_color;
25
	
29

  
26 30
	ScopedPreferenceStore preferences;
27
	
31

  
28 32
	public static final String COLOR_PALETTE = "color_palette"; //$NON-NLS-1$
29
	
33

  
30 34
	private RadioGroupFieldEditor color_palette;
31
	
35

  
36
	private StringFieldEditor hightlighted_unit_color;
37

  
38
	private StringFieldEditor selected_unit_color;
39

  
32 40
	/**
33 41
	 * Creates the field editors. Field editors are abstractions of the common
34 42
	 * GUI blocks needed to manipulate various types of preferences. Each field
......
40 48
				URSPreferences.ANALEC_LIMIT_CORRECTION_SCHEME, Messages.AnalecPreferencePage_3,
41 49
				getFieldEditorParent());
42 50
		addField(analec_limit_scheme_field);
43
		
51

  
44 52
		prefix_autocompletion_field = new BooleanFieldEditor(
45 53
				URSPreferences.PREFIX_AUTOCOMPLETION, Messages.AnalecPreferencePage_4,
46 54
				getFieldEditorParent());
47 55
		addField(prefix_autocompletion_field);
48
		
56

  
49 57
		save_timer_field = new IntegerFieldEditor(
50 58
				URSPreferences.SAVE_TIMER, "Delay between saves/Délai entre les sauvegardes (0 desactivate the timer)",
51 59
				getFieldEditorParent());
52 60
		addField(save_timer_field);
53
		
54
		// hightlighted_unit_color = new ColorFieldEditor(
55
		// HIGHLIGHTED_UNIT_COLOR, "Highlighted units background color",
56
		// getFieldEditorParent());
57
		// addField(hightlighted_unit_color);
58
		//
59
		//
60
		// selected_unit_color = new ColorFieldEditor(
61
		// SELECTED_UNIT_COLOR, "Selected units background color",
62
		// getFieldEditorParent());
63
		// addField(selected_unit_color);
64
		
65
		String[][] values = { { "green", "green" }, { "yellow", "yellow" } }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
66
		color_palette = new RadioGroupFieldEditor(COLOR_PALETTE, Messages.AnalecPreferencePage_9, 2, values, getFieldEditorParent());
61

  
62

  
63

  
64
		String[][] values = { { "green", "green" }, { "yellow", "yellow" } , { "custom (set colors below)", "custom" } }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
65
		color_palette = new RadioGroupFieldEditor(COLOR_PALETTE, Messages.AnalecPreferencePage_9, 3, values, getFieldEditorParent());
67 66
		addField(color_palette);
67

  
68
		hightlighted_unit_color = new StringFieldEditor(URSPreferences.HIGHLIGHTED_UNIT_COLOR, "Highlighted units color (format=R,G,B,A or #RRGGBBAA)",
69
				getFieldEditorParent());
70
		addField(hightlighted_unit_color);
71

  
72
		selected_unit_color = new StringFieldEditor(URSPreferences.SELECTED_UNIT_COLOR, "Selected units color (format=R,G,B,A or #RRGGBBAA)",
73
				getFieldEditorParent());
74
		addField(selected_unit_color);
75

  
76
		hightlighted_unit_color.setEnabled("custom".equals(URSPreferences.getInstance().getString(URSPreferences.COLOR_PALETTE)), getFieldEditorParent());
77
		selected_unit_color.setEnabled("custom".equals(URSPreferences.getInstance().getString(URSPreferences.COLOR_PALETTE)), getFieldEditorParent());
68 78
	}
69
	
79

  
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
82
	 */
70 83
	@Override
84
	public void propertyChange(PropertyChangeEvent event) {
85

  
86
		hightlighted_unit_color.setEnabled("custom".equals(color_palette.getSelectionValue()), getFieldEditorParent());
87
		selected_unit_color.setEnabled("custom".equals(color_palette.getSelectionValue()), getFieldEditorParent());
88
	}
89

  
90

  
91

  
92
	@Override
71 93
	public void init(IWorkbench workbench) {
72 94
		this.setPreferenceStore(new TXMPreferenceStore(URSPreferences.getInstance().getPreferencesNodeQualifier()));
73 95
		this.setTitle("URS");
TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/preferences/URSPreferences.java (revision 3709)
1 1
package org.txm.annotation.urs.preferences;
2 2

  
3 3
import org.eclipse.core.runtime.preferences.DefaultScope;
4
import org.osgi.framework.FrameworkUtil;
5 4
import org.osgi.service.prefs.Preferences;
5
import org.txm.annotation.urs.toolbar.URSAnnotationToolbar;
6 6
import org.txm.core.preferences.TXMPreferences;
7
import org.txm.rcp.preferences.RCPPreferences;
8 7

  
9
public class URSPreferences extends TXMPreferences{
8
public class URSPreferences extends TXMPreferences {
10 9
	
11 10
//	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(URSPreferences.class).getSymbolicName();
12 11
	
......
15 14
	public static final String PREFIX_AUTOCOMPLETION = "prefix_autocompletion"; //$NON-NLS-1$
16 15
	public static final String ANALEC_LIMIT_CORRECTION_SCHEME = "urs_limit_correction_scheme"; //$NON-NLS-1$
17 16
	public static final String SAVE_TIMER = "save_timer_duration"; //$NON-NLS-1$
17
	public static final String SELECTED_UNIT_COLOR = "selected_unit_color";
18
	public static final String HIGHLIGHTED_UNIT_COLOR = "highlighted_unit_color";
18 19

  
19 20
	
20 21
	@Override
......
23 24
		Preferences preferences = DefaultScope.INSTANCE.getNode(getPreferencesNodeQualifier());
24 25
		preferences.put(VERSION, "");
25 26
		preferences.put(COLOR_PALETTE, "green");
27
		preferences.put(SELECTED_UNIT_COLOR, URSAnnotationToolbar.green.toString());
28
		preferences.put(HIGHLIGHTED_UNIT_COLOR, URSAnnotationToolbar.lightgreen.toString());
26 29
		preferences.putBoolean(ANALEC_LIMIT_CORRECTION_SCHEME, false);
27 30
		preferences.putBoolean(PREFIX_AUTOCOMPLETION, false);
28 31
		preferences.putInt(SAVE_TIMER, 0);
32
		
29 33
	}
30 34
	
31 35
	/**
32 36
	 * Gets the instance.
33 37
	 * @return the instance
34 38
	 */
35
	public static TXMPreferences getInstance()	{
39
	public static URSPreferences getInstance()	{
36 40
		if (!TXMPreferences.instances.containsKey(URSPreferences.class)) {
37 41
			new URSPreferences();
38 42
		}
39
		return TXMPreferences.instances.get(URSPreferences.class);
43
		return (URSPreferences) TXMPreferences.instances.get(URSPreferences.class);
40 44
	}
41 45
}
TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/toolbar/SchemaToolbar.java (revision 3709)
63 63

  
64 64
	public RGBA highlighted_unit_color = new RGBA(183, 191, 237, 0.7f);
65 65
	public RGBA selected_unit_color = new RGBA(255, 255, 0, 0.5f);
66
	
66

  
67 67
	//	private Button createButton;
68 68
	private Button deleteSchemaButton;
69 69
	private Button deleteUniteButton;
......
73 73
	private Label l;
74 74
	private MenuListener menuListener;
75 75

  
76
//	private List<String> previousSelectedTypeSchemaIDS;
76
	//	private List<String> previousSelectedTypeSchemaIDS;
77 77
	private List<String> previousSelectedSchemaIDS;
78 78
	private List<String> previousSelectedUniteIDS;
79 79

  
......
91 91

  
92 92
	@Override
93 93
	protected boolean _install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
94
		
94

  
95 95
		annotationArea.getLayout().numColumns = 8;
96 96
		annotationArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
97
		
97

  
98 98
		String color_palette = URSPreferences.getInstance().getString(URSPreferences.COLOR_PALETTE);
99 99
		if ("yellow".equals(color_palette)) { //$NON-NLS-1$
100 100
			this.highlighted_unit_color = URSAnnotationToolbar.lightyellow;
......
103 103
			this.highlighted_unit_color = URSAnnotationToolbar.lightgreen;
104 104
			this.selected_unit_color = URSAnnotationToolbar.green;
105 105
		} else { // custom palette
106
			//		String highlighted_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.HIGHLIGHTED_UNIT_COLOR, "255,255,176");
107
			//		String selected_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.SELECTED_UNIT_COLOR, "255,255,96");
108
			//		this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref, 0.7f);
109
			//		this.selected_unit_color = new RGBA(selected_unit_color_pref, 1f);
106
			String highlighted_unit_color_pref = URSPreferences.getInstance().getString(URSPreferences.HIGHLIGHTED_UNIT_COLOR, "255,255,176");
107
			String selected_unit_color_pref = URSPreferences.getInstance().getString(URSPreferences.SELECTED_UNIT_COLOR, "255,255,96");
108
			this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref);
109
			this.selected_unit_color = new RGBA(selected_unit_color_pref);
110 110
		}
111
		
111

  
112 112
		this.editor = (SynopticEditionEditor) txmeditor;
113 113
		analecCorpus.addEventListener(this);
114 114

  
......
187 187

  
188 188
		reloadTypeSchemas(); // reloads ids also
189 189
		reloadIdentifiants();
190
		
190

  
191 191
		if (schemasAVoir.length > 0) {
192 192
			typeCombo.select(1);
193 193
			onTypeComboSelected(null);
194 194

  
195 195
			//testIfAwordSpanIsSelected();
196
			
197
//			if (schemas.length > 0) {
198
//				navigationField.selectFirst();
199
//				onIdentifiantComboSelected(null);
200
//			}
196

  
197
			//			if (schemas.length > 0) {
198
			//				navigationField.selectFirst();
199
			//				onIdentifiantComboSelected(null);
200
			//			}
201 201
		}
202 202

  
203 203
		//		createButton.setEnabled(false);
......
205 205
		//		editButton.setEnabled(false);
206 206
		editor.updateWordStyles();
207 207
		ElementPropertiesView.openView();
208
		
208

  
209 209
		return true;
210 210
	}
211
	
211

  
212 212
	protected void testIfAwordSpanIsSelected() {
213 213
		EditionPanel panel = editor.getEditionPanel(0);
214 214
		if (panel == null) return;
......
232 232
			editor.removeFontWeightWordsById(previousSelectedSchemaIDS);
233 233
			previousSelectedSchemaIDS = null; // release memory
234 234
		}
235
//		if (previousSelectedTypeSchemaIDS != null) {
236
//			editor.removeHighlightWordsById(lightblue, previousSelectedTypeSchemaIDS);
237
//			previousSelectedTypeSchemaIDS = null; // release memory
238
//		}
235
		//		if (previousSelectedTypeSchemaIDS != null) {
236
		//			editor.removeHighlightWordsById(lightblue, previousSelectedTypeSchemaIDS);
237
		//			previousSelectedTypeSchemaIDS = null; // release memory
238
		//		}
239 239
	}
240 240

  
241 241

  
......
252 252
	public MouseListener getEditorClickListener() {
253 253

  
254 254
		if (editorMouseListener != null) return editorMouseListener;
255
		
255

  
256 256
		editorMouseListener = new MouseListener() {
257 257

  
258 258
			boolean dblClick = false;
......
475 475
	}
476 476

  
477 477
	protected void highlightType() {
478
		
478

  
479 479
		if (schemas == null) return;
480 480
		if (schemas.length == 0) return;
481 481

  
482 482
		// highlight all units of all schemas ? -> too much
483
		
483

  
484 484
	}
485 485

  
486 486
	protected void highlightSchema(Schema schema) {
......
558 558
			Page newPage = newEdition.getPageForWordId(firstWordId); // find out the page containing the word
559 559

  
560 560
			previousSelectedUniteIDS = Arrays.asList(ids);
561
//			System.out.println("HU: "+previousSelectedUniteIDS);
561
			//			System.out.println("HU: "+previousSelectedUniteIDS);
562 562
			editor.addHighlightWordsById(selected_unit_color, previousSelectedUniteIDS);
563 563
			editor.addFontWeightWordsById(EditionPanel.WEIGHT_BOLD, previousSelectedUniteIDS);
564
			
564

  
565 565
			if (previousSelectedUniteIDS.size() > 0)	editor.setFocusedWordID(previousSelectedUniteIDS.get(0));
566 566
			//System.out.println("Word page= "+p+" current="+panel.getCurrentPage());
567 567
			if (panel.getCurrentPage() != newPage || panel.getCurrentText() != newText) { // do we need to change page ?
......
570 570
			} else  { // just reload the page to highlight words
571 571
				//editor.updateWordStyles();
572 572
			}
573
			
573

  
574 574
		} catch (Exception e1) {
575 575
			e1.printStackTrace();
576 576
		}
......
638 638
			clearUnitesHighlight();
639 639
			deleteUniteButton.setEnabled(false);
640 640
		}
641
		
641

  
642 642
		if (e != null) editor.updateWordStyles();
643 643
	}
644 644

  
......
664 664
			updatePropertiesView(schema);
665 665
			deleteSchemaButton.setEnabled(true);
666 666
		}
667
		
667

  
668 668
		if (e != null) editor.updateWordStyles();
669 669
	}
670 670

  
......
766 766
	}
767 767

  
768 768
	public void setEnable(boolean enable) {
769
		
769

  
770 770
		l.setEnabled(enable);
771 771
		typeCombo.setEnabled(enable);
772 772
		//		createButton.setEnabled(enable);
......
777 777

  
778 778
	@Override
779 779
	public void traiterEvent(Message e) {
780
		
780

  
781 781
		if (annotationArea.isDisposed()) return;
782 782

  
783 783
		if (e.getType().equals(TypeMessage.MODIF_STRUCTURE)) {
......
801 801
	}
802 802

  
803 803
	protected void tryHighlightingWord(String id, org.txm.searchengine.cqp.corpus.CQPCorpus c) throws CqiClientException {
804
		
804

  
805 805
		EditionPanel panel = editor.getEditionPanel(0);
806 806
		if (panel == null) return;
807 807
		if (id != null) {
......
930 930
	@Override
931 931
	public void onBackToText(Text text, String id) {
932 932
		// TODO Auto-generated method stub
933
		
933

  
934 934
	}
935 935

  
936 936
	@Override
......
958 958
	@Override
959 959
	public void notifyEndOfRefresh() throws Exception {
960 960
		// TODO Auto-generated method stub
961
		
961

  
962 962
	}
963 963

  
964 964
	@Override
965 965
	public void notifyStartOfCreatePartControl() throws Exception {
966 966
		// TODO Auto-generated method stub
967
		
967

  
968 968
	}
969 969

  
970 970
	@Override
971 971
	public void notifyStartOfRefresh() throws Exception {
972 972
		// TODO Auto-generated method stub
973
		
973

  
974 974
	}
975
	
975

  
976 976
	ProgressListener pageProgressListener = null;
977 977
	@Override
978 978
	protected ProgressListener getPageReloadListener() {
979 979
		if (pageProgressListener != null) {
980 980
			return pageProgressListener;
981 981
		}
982
		
982

  
983 983
		pageProgressListener = new ProgressListener() {
984
			
984

  
985 985
			@Override
986 986
			public void completed(ProgressEvent event) {
987 987
				if (typeCombo.getSelectionIndex() >= 0) {
988 988
					highlightType();
989 989
				}
990 990
			}
991
			
991

  
992 992
			@Override
993 993
			public void changed(ProgressEvent event) { }
994 994
		};
......
999 999
	public boolean needToUpdateIndexes() {
1000 1000
		return false;
1001 1001
	}
1002
	
1002

  
1003 1003
	@Override
1004 1004
	public boolean hasChanges() {
1005 1005
		return analecCorpus.isModifie();
TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/toolbar/URSAnnotationToolbar.java (revision 3709)
15 15
import org.eclipse.swt.events.SelectionListener;
16 16
import org.eclipse.swt.widgets.Button;
17 17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.ToolItem;
19 18
import org.txm.annotation.rcp.editor.AnnotationArea;
20 19
import org.txm.annotation.rcp.editor.AnnotationExtension;
21 20
import org.txm.annotation.urs.URSCorpora;
......
39 38
import org.txm.utils.logger.Log;
40 39

  
41 40
import visuAnalec.Message;
42
import visuAnalec.Message.TypeMessage;
43 41
import visuAnalec.donnees.Corpus;
44 42
import visuAnalec.donnees.Corpus.CorpusListener;
45 43
import visuAnalec.elements.Element;
TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/toolbar/UnitToolbar.java (revision 3709)
51 51
import org.txm.searchengine.cqp.AbstractCqiClient;
52 52
import org.txm.searchengine.cqp.CQPSearchEngine;
53 53
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
54
import org.txm.searchengine.cqp.corpus.MainCorpus;
54 55
import org.txm.searchengine.cqp.corpus.Property;
55 56
import org.txm.searchengine.cqp.corpus.QueryResult;
56 57
import org.txm.searchengine.cqp.corpus.query.Match;
......
64 65
import visuAnalec.elements.Unite;
65 66

  
66 67
public class UnitToolbar extends URSAnnotationToolbar {
67
	
68

  
68 69
	// boolean AnalecUnitLimitCorrectionScheme = TxmPreferences.getBoolean(AnalecPreferencePage.ANALEC_LIMIT_CORRECTION_SCHEME); // use Analec scheme to fix unit limits or TXM's
69
	
70

  
70 71
	public RGBA highlighted_unit_color = new RGBA(183, 191, 237, 0.7f);
71
	
72

  
72 73
	public RGBA selected_unit_color = new RGBA(255, 255, 0, 0.5f);
73
	
74

  
74 75
	private Button createButton;
75
	
76

  
76 77
	private Button deleteButton;
77
	
78

  
78 79
	private Button editButton;
79
	
80

  
80 81
	private KeyListener editorKeyListener;
81
	
82

  
82 83
	private MouseListener editorMouseListener;
83
	
84

  
84 85
	private int fixingAnnotationLimits = 0;
85
	
86

  
86 87
	private NavigationField navigationField;
87
	
88

  
88 89
	private Label l;
89
	
90

  
90 91
	private MenuListener menuListener;
91
	
92

  
92 93
	private List<String> previousSelectedTypeUnitIDS;
93
	
94

  
94 95
	private List<String> previousSelectedUnitIDS;
95
	
96

  
96 97
	protected boolean startFixingUnitLimit;
97
	
98

  
98 99
	private Combo typeCombo;
99
	
100

  
100 101
	private Unite[] unites;
101
	
102

  
102 103
	private String[] typesUnitesAVoir;
103
	
104

  
104 105
	private int maxCorpusPosition;
105
	
106

  
106 107
	private DragDetectListener dragDetectListener;
107
	
108

  
108 109
	private Button drop_b;
109
	
110

  
110 111
	private Button editLeftButton;
111
	
112

  
112 113
	private Button editRightButton;
113
	
114

  
114 115
	public UnitToolbar() {}
115
	
116

  
116 117
	@Override
117 118
	protected boolean _install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
118
		
119

  
119 120
		annotationArea.getLayout().numColumns = 11;
120 121
		annotationArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
121
		
122

  
122 123
		String color_palette = URSPreferences.getInstance().getString(URSPreferences.COLOR_PALETTE);
123 124
		if ("yellow".equals(color_palette)) { //$NON-NLS-1$
124 125
			this.highlighted_unit_color = URSAnnotationToolbar.lightyellow;
......
129 130
			this.selected_unit_color = URSAnnotationToolbar.green;
130 131
		}
131 132
		else { // custom palette
132
			// String highlighted_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.HIGHLIGHTED_UNIT_COLOR, "255,255,176");
133
			// String selected_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.SELECTED_UNIT_COLOR, "255,255,96");
134
			// this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref, 0.7f);
135
			// this.selected_unit_color = new RGBA(selected_unit_color_pref, 1f);
133
			URSPreferences urs = URSPreferences.getInstance();
134
			String highlighted_unit_color_pref = urs.getString(URSPreferences.HIGHLIGHTED_UNIT_COLOR);
135
			String selected_unit_color_pref = urs.getString(URSPreferences.SELECTED_UNIT_COLOR);
136
			this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref);
137
			this.selected_unit_color = new RGBA(selected_unit_color_pref);
136 138
		}
137
		
139

  
138 140
		//		this.button = extension.getSaveButton();
139 141
		this.maincorpus = this.editor.getCorpus().getMainCorpus();
140 142
		try {
......
145 147
			Log.printStackTrace(e);
146 148
		}
147 149
		analecCorpus.addEventListener(this);
148
		
149
		
150

  
151

  
150 152
		l = new Label(annotationArea, SWT.NONE);
151 153
		l.setText(Messages.UnitToolbar_6);
152 154
		l.setToolTipText(Messages.UnitToolbar_6);
153 155
		l.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
154
		
156

  
155 157
		typeCombo = new Combo(annotationArea, SWT.NONE | SWT.READ_ONLY);
156 158
		typeCombo.setToolTipText(Messages.UnitToolbar_7);
157 159
		GridData gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
......
160 162
		typeCombo.setSize(150, SWT.DEFAULT);
161 163
		typeCombo.setLayoutData(gdata);
162 164
		typeCombo.addSelectionListener(new SelectionListener() {
163
			
165

  
164 166
			@Override
165 167
			public void widgetDefaultSelected(SelectionEvent e) {}
166
			
168

  
167 169
			@Override
168 170
			public void widgetSelected(SelectionEvent e) {
169 171
				onTypecomboSelected(e);
170 172
			}
171 173
		});
172
		
174

  
173 175
		navigationField = new NavigationField(this, SWT.NONE);
174 176
		gdata = new GridData(GridData.FILL, GridData.CENTER, true, false);
175 177
		navigationField.setLayoutData(gdata);
176 178
		navigationField.addListener(SWT.Selection, new Listener() {
177
			
179

  
178 180
			@Override
179 181
			public void handleEvent(Event event) {
180 182
				onIdentifiantComboSelected(event);
181 183
			}
182 184
		});
183
		
185

  
184 186
		// l = new Label(this, SWT.NONE);
185
		
187

  
186 188
		createButton = new Button(annotationArea, SWT.PUSH);
187 189
		createButton.setText(Messages.UnitToolbar_8);
188 190
		gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
189 191
		createButton.setLayoutData(gdata);
190 192
		createButton.addSelectionListener(new SelectionListener() {
191
			
193

  
192 194
			@Override
193 195
			public void widgetDefaultSelected(SelectionEvent e) {}
194
			
196

  
195 197
			@Override
196 198
			public void widgetSelected(SelectionEvent e) {
197 199
				onCreateButtonSelected(e);
198 200
			}
199 201
		});
200
		
202

  
201 203
		deleteButton = new Button(annotationArea, SWT.PUSH);
202 204
		gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
203 205
		deleteButton.setLayoutData(gdata);
204 206
		deleteButton.setImage(IImageKeys.getImage("platform:/plugin/org.txm.rcp/icons/cross.png")); //$NON-NLS-1$
205 207
		deleteButton.setToolTipText(Messages.UnitToolbar_10);
206 208
		deleteButton.addSelectionListener(new SelectionListener() {
207
			
209

  
208 210
			@Override
209 211
			public void widgetDefaultSelected(SelectionEvent e) {}
210
			
212

  
211 213
			@Override
212 214
			public void widgetSelected(SelectionEvent e) {
213 215
				onDeleteComboSelected(e);
214 216
			}
215 217
		});
216
		
218

  
217 219
		l = new Label(annotationArea, SWT.NONE);
218
		
220

  
219 221
		editLeftButton = new Button(annotationArea, SWT.TOGGLE);
220 222
		gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
221 223
		editLeftButton.setLayoutData(gdata);
222 224
		editLeftButton.setText("[ ↔"); //$NON-NLS-1$
223 225
		editLeftButton.setToolTipText(Messages.UnitToolbar_12);
224 226
		editLeftButton.addSelectionListener(new SelectionListener() {
225
			
227

  
226 228
			@Override
227 229
			public void widgetDefaultSelected(SelectionEvent e) {}
228
			
230

  
229 231
			@Override
230 232
			public void widgetSelected(SelectionEvent e) {
231 233
				onEditButtonSelected(e, 1);
232 234
			}
233 235
		});
234
		
236

  
235 237
		editButton = new Button(annotationArea, SWT.TOGGLE);
236 238
		editButton.setText("[↔]"); //$NON-NLS-1$
237 239
		editButton.setToolTipText(Messages.UnitToolbar_14);
238 240
		editButton.addSelectionListener(new SelectionListener() {
239
			
241

  
240 242
			@Override
241 243
			public void widgetDefaultSelected(SelectionEvent e) {}
242
			
244

  
243 245
			@Override
244 246
			public void widgetSelected(SelectionEvent e) {
245 247
				onEditButtonSelected(e);
246 248
			}
247 249
		});
248
		
250

  
249 251
		editRightButton = new Button(annotationArea, SWT.TOGGLE);
250 252
		editRightButton.setText("↔ ]"); //$NON-NLS-1$
251 253
		editRightButton.setToolTipText(Messages.UnitToolbar_16);
252 254
		editRightButton.addSelectionListener(new SelectionListener() {
253
			
255

  
254 256
			@Override
255 257
			public void widgetDefaultSelected(SelectionEvent e) {}
256
			
258

  
257 259
			@Override
258 260
			public void widgetSelected(SelectionEvent e) {
259 261
				onEditButtonSelected(e, 2);
260 262
			}
261 263
		});
262
		
264

  
263 265
		annotationArea.layout();
264 266
		annotationArea.getParent().layout(true);
265 267
		editor.layout(true);
266
		
268

  
267 269
		reloadUnits(); // reloads types
268 270
		reloadIdentifiants();
269
		
271

  
270 272
		createButton.setEnabled(false);
271 273
		deleteButton.setEnabled(false);
272 274
		editButton.setEnabled(false);
273 275
		editLeftButton.setEnabled(false);
274 276
		editRightButton.setEnabled(false);
275
		
277

  
276 278
		// drop_b.setEnabled(false);
277 279
		if (typesUnitesAVoir.length > 0) {
278 280
			typeCombo.select(1);
279 281
			onTypecomboSelected(null);
280
			
282

  
281 283
			testIfAwordSpanIsSelected();
282 284
		}
283
		
285

  
284 286
		ElementPropertiesView.openView();
285 287
		editor.updateWordStyles();
286 288
		annotationArea.layout();
287 289
		return true;
288 290
	}
289
	
291

  
290 292
	@Override
291 293
	public void clearHighlight() {
292 294
		if (previousSelectedUnitIDS != null) {
......
300 302
			editor.removeHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
301 303
			previousSelectedTypeUnitIDS = null; // release memory
302 304
		}
303
		
305

  
304 306
		if (!createButton.isDisposed()) createButton.setEnabled(false);
305 307
		if (!deleteButton.isDisposed()) deleteButton.setEnabled(false);
306 308
		if (!editButton.isDisposed()) editButton.setEnabled(false);
307 309
		// drop_b.setEnabled(false);
308 310
	}
309
	
311

  
310 312
	@Override
311 313
	public MouseListener getEditorClickListener() {
312 314
		if (editorMouseListener != null) return editorMouseListener;
313 315
		editorMouseListener = new MouseListener() {
314
			
316

  
315 317
			boolean dblClick = false;
316
			
318

  
317 319
			boolean debug = Log.isLoggingFineLevel();
318
			
320

  
319 321
			private int t, x, y;
320
			
322

  
321 323
			@Override
322 324
			public void mouseDoubleClick(MouseEvent e) {
323 325
				if (debug) Log.finer("DOUBLE CLICK"); //$NON-NLS-1$
324 326
				dblClick = true;
325
				
327

  
326 328
				EditionPanel panel = editor.getEditionPanel(0);
327 329
				if (panel == null) return;
328 330
				String[] ids = panel.getWordSelection(); // may be null
......
336 338
				// ex.printStackTrace();
337 339
				// }
338 340
				// }
339
				
341

  
340 342
				if (ids != null && typeCombo.getSelectionIndex() > 0 && typeCombo.getEnabled()) {
341 343
					createButton.setEnabled(true); // there is a text selection in the browser
342 344
				}
343 345
			}
344
			
346

  
345 347
			@Override
346 348
			public void mouseDown(MouseEvent e) {
347 349
				if (debug) Log.finer("MOUSE DOWN"); //$NON-NLS-1$
......
350 352
				x = e.x;
351 353
				y = e.y;
352 354
			}
353
			
355

  
354 356
			@Override
355 357
			public void mouseUp(MouseEvent e) {
356 358
				if (dblClick) { // doucle click raised by mouseDoubleClick
......
360 362
				if (debug) Log.finer("MOUSE UP"); //$NON-NLS-1$
361 363
				EditionPanel panel = editor.getEditionPanel(0);
362 364
				if (panel == null) return;
363
				
365

  
364 366
				if (typeCombo.getSelectionIndex() <= 0) {
365 367
					createButton.setEnabled(false);
366 368
					deleteButton.setEnabled(false);
......
370 372
					// drop_b.setEnabled(false);
371 373
					return; // nothing to do with annotations
372 374
				}
373
				
375

  
374 376
				// filter click that are not a left simple click (no drag)
375 377
				// System.out.println("click count="+e.count+" button="+e.button+" time="+e.time+" diff="+(e.time-t)+" dist="+(Math.abs(e.x - x) + Math.abs(e.y - y)));
376 378
				if (e.count > 1) {
......
378 380
					// System.out.println("not a simple click");
379 381
					return;
380 382
				}
381
				
383

  
382 384
				int dist = Math.abs(e.x - x) + Math.abs(e.y - y);
383 385
				int deltat = (e.time - t);
384 386
				// System.out.println("deltat ="+deltat);
385 387
				if (dist != 0 && (deltat > 120 || dist > 4)) {
386 388
					// System.out.println(" DRAG dist="+dist+" deltat="+deltat);
387
					
389

  
388 390
					String[] ids = panel.getWordSelection(); // may be null
389
					
391

  
390 392
					if (fixingAnnotationLimits == 3) { // fixing limit with a mouse drag an drop
391 393
						if (debug) Log.finer(" EDITING ANNOTATION POSITION mode=" + fixingAnnotationLimits); //$NON-NLS-1$
392 394
						onFixingAnnotationLimits(ids);
393 395
						return;
394 396
					}
395 397
					else {
396
						
398

  
397 399
						testIfAwordSpanIsSelected(ids);
398
						
400

  
399 401
						// panel.expandSelectionTo(ids);
400 402
						return;
401 403
					}
402 404
				}
403
				
405

  
404 406
				if (e.button != 1) {
405 407
					if (debug) Log.finer(" NO LEFT"); //$NON-NLS-1$
406 408
					// System.out.println("not a left click");
......
411 413
					// System.out.println("not a short click");
412 414
					return;
413 415
				}
414
				
416

  
415 417
				String[] ids = panel.getWordSelection(); // may be null
416
				
418

  
417 419
				if (fixingAnnotationLimits > 0) {
418 420
					if (debug) Log.finer(" EDITING ANNOTATION POSITION mode=" + fixingAnnotationLimits); //$NON-NLS-1$
419 421
					onFixingAnnotationLimits(ids);
420 422
					return;
421 423
				}
422
				
424

  
423 425
				if (ids == null) { // clear selection
424 426
					if (debug) Log.finer(" NO WORD SELECTION"); //$NON-NLS-1$
425 427
					navigationField.setSelectionIndex(0); // clear selection
426
					
428

  
427 429
					return;
428 430
				}
429
				
431

  
430 432
				org.txm.searchengine.cqp.corpus.CQPCorpus c = UnitToolbar.this.editor.getCorpus();
431
				
433

  
432 434
				try {
433 435
					if (debug) Log.finer(" HIGHLIGHTING ANNOT IF ANY AT " + ids[0]); //$NON-NLS-1$
434 436
					if (tryHighlightingUnitsWord(ids[0], c)) {
......
446 448
		};
447 449
		return editorMouseListener;
448 450
	}
449
	
451

  
450 452
	protected void testIfAwordSpanIsSelected() {
451 453
		EditionPanel panel = editor.getEditionPanel(0);
452 454
		if (panel == null) return;
453 455
		String[] ids = panel.getWordSelection(); // may be null
454 456
		testIfAwordSpanIsSelected(ids);
455 457
	}
456
	
458

  
457 459
	protected void testIfAwordSpanIsSelected(String[] ids) {
458 460
		if (ids != null && typeCombo.getItemCount() > 1 && typeCombo.getEnabled()) {
459 461
			// System.out.println("ids:"+Arrays.toString(ids));
......
464 466
				editRightButton.setEnabled(true);
465 467
				// drop_b.setEnabled(true);
466 468
			}
467
			
469

  
468 470
			createButton.setEnabled(ids != null);
469 471
		}
470 472
	}
471
	
472
	
473
	
473

  
474

  
475

  
474 476
	protected void onFixingAnnotationLimits(String[] ids) {
475
		
477

  
476 478
		if (ids == null || ids.length == 0) {
477 479
			Log.info(Messages.UnitToolbar_27);
478 480
			return;
479 481
		}
480
		
482

  
481 483
		boolean uniteFixed = false;
482 484
		int i = navigationField.getSelectionIndex();
483 485
		if (i > 0) {
484 486
			Unite unite = unites[i - 1];
485
			
487

  
486 488
			try {
487 489
				uniteFixed = updateUniteLimits(unite, ids, fixingAnnotationLimits);
488 490
			}
......
490 492
				Log.warning(NLS.bind(Messages.UnitToolbar_28, ids[0]));
491 493
				Log.printStackTrace(e1);
492 494
			}
493
			
495

  
494 496
			editButton.setSelection(false);
495 497
			editLeftButton.setSelection(false);
496 498
			editRightButton.setSelection(false);
497 499
			fixingAnnotationLimits = 0;
498 500
			typeCombo.setEnabled(true);
499
			
501

  
500 502
			navigationField.setEnabled(true);
501 503
			createButton.setEnabled(true);
502 504
			deleteButton.setEnabled(true);
503
			
505

  
504 506
			if (uniteFixed) {
505 507
				// button.setEnabled(analecCorpus.isModifie());
506 508
				reloadIdentifiants();
......
512 514
			}
513 515
		}
514 516
	}
515
	
516
	
517
	
517

  
518

  
519

  
518 520
	@Override
519 521
	public KeyListener getEditorKeyListener() {
520 522
		if (editorKeyListener != null) return editorKeyListener;
521 523
		editorKeyListener = new KeyListener() {
522
			
524

  
523 525
			@Override
524 526
			public void keyPressed(KeyEvent e) {}
525
			
527

  
526 528
			@Override
527 529
			public void keyReleased(KeyEvent e) {
528 530
				int mask = SWT.CTRL;
529 531
				if (Util.isMac()) mask = SWT.COMMAND;
530
				
532

  
531 533
				if (((e.stateMask & mask) == mask)) {
532 534
					if (e.keyCode == SWT.SPACE) {
533 535
						int i = navigationField.getSelectionIndex();
......
567 569
		};
568 570
		return editorKeyListener;
569 571
	}
570
	
572

  
571 573
	@Override
572 574
	public MenuListener getMenuListener() {
573
		
575

  
574 576
		if (menuListener != null) return menuListener;
575
		
577

  
576 578
		this.menuListener = new MenuListener() {
577
			
579

  
578 580
			HashSet<MenuItem> entries = new HashSet<>();
579
			
581

  
580 582
			@Override
581 583
			public void menuHidden(MenuEvent e) {}
582
			
584

  
583 585
			@Override
584 586
			public void menuShown(MenuEvent e) {
585
				
587

  
586 588
				EditionPanel panel = editor.getEditionPanel(0);
587 589
				if (panel == null) return;
588 590
				Menu menu = panel.getBrowser().getMenu();
589
				
591

  
590 592
				for (MenuItem item : entries)
591 593
					item.dispose();
592
				
594

  
593 595
				String[] ids = panel.getWordSelection();
594 596
				// System.out.println("Word under mouse: "+id);
595 597
				if (ids != null && ids.length > 0) {
......
604 606
						noEntries.add(i);
605 607
						i++;
606 608
					}
607
					
609

  
608 610
					if (unitEntries.size() > 0) {
609 611
						MenuItem item = new MenuItem(menu, SWT.SEPARATOR);
610 612
						entries.add(item);
611 613
					}
612
					
614

  
613 615
					for (i = 0; i < unitEntries.size(); i++) {
614 616
						final Unite unit = unitEntries.get(i);
615 617
						final Integer unitNo = Arrays.binarySearch(unites, unit) + 1;
616
						
618

  
617 619
						MenuItem item = new MenuItem(menu, SWT.NONE);
618
						AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
619
						try {
620
							if (unit.getDeb() == unit.getFin()) {
621
								String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb() });
622
								item.setText(NLS.bind(Messages.UnitToolbar_29, unit.getType() + "-" + unitNo + ":" + firstWords[0])); //$NON-NLS-2$
623
							}
624
							else {
625
								String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb(), unit.getDeb() + 1 });
626
								item.setText(NLS.bind(Messages.UnitToolbar_32, unit.getType() + "-" + unitNo + "=" + firstWords[0] + " " + firstWords[1])); //$NON-NLS-2$ //$NON-NLS-3$
627
							}
620
						if (unit.getDeb() == unit.getFin()) {
621
							item.setText(NLS.bind(Messages.UnitToolbar_29, getUnitWordSurface(maincorpus, unit, unitNo))); //$NON-NLS-2$
628 622
						}
629
						catch (Exception e1) {
630
							e1.printStackTrace();
623
						else {
624
							item.setText(NLS.bind(Messages.UnitToolbar_32, getUnitWordSurface(maincorpus, unit, unitNo))); //$NON-NLS-2$ //$NON-NLS-3$
631 625
						}
632 626
						item.addSelectionListener(new SelectionListener() {
633
							
627

  
634 628
							@Override
635 629
							public void widgetDefaultSelected(SelectionEvent e) {}
636
							
630

  
637 631
							@Override
638 632
							public void widgetSelected(SelectionEvent e) {
639 633
								selectUniteInIdentifants(unit);
......
644 638
				}
645 639
			}
646 640
		};
647
		
641

  
648 642
		return menuListener;
649 643
	}
650
	
644

  
645
	public static String getUnitWordSurface(MainCorpus maincorpus, Element elem, Object unitNo) {
646
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
647
		Unite unit = elem.getUnite0();
648
		String no = "";
649
		if (unitNo != null) no = "-"+unitNo;
650
		
651
		if (unit == null) return elem.getType()+ "-" + unitNo;
652
		
653
		try {
654
			if (unit.getDeb() == unit.getFin()) {
655
				String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb() });
656
				return unit.getType() + no + "=" + firstWords[0]; //$NON-NLS-2$
657
			}
658
			else {
659
				String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb(), unit.getFin()});
660
				if (unit.getFin() - unit.getDeb() > 1) {
661
					return unit.getType() + no + "=" + firstWords[0] + " ... " + firstWords[1]; //$NON-NLS-2$ //$NON-NLS-3$
662
				} else {
663
					return unit.getType() + no + "=" + firstWords[0] + " " + firstWords[1]; //$NON-NLS-2$ //$NON-NLS-3$
664
				}
665
			}
666
		}
667
		catch (Exception e1) {
668
			e1.printStackTrace();
669
		}
670
		return unit.getType() + "-" + unitNo;
671
	}
672

  
651 673
	public String uniteToWords(Unite unit) {
652
		
674

  
653 675
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
654 676
		String[] firstWords = null;
655 677
		try {
......
665 687
		}
666 688
		return StringUtils.join(firstWords, " "); //$NON-NLS-1$
667 689
	}
668
	
690

  
669 691
	/**
670 692
	 * Highlight units of the current page
671 693
	 */
672 694
	protected synchronized void highlightType() {
673
		
695

  
674 696
		if (unites == null) return;
675 697
		if (editor.getEditionPanels().size() == 0) return;
676
		
698

  
677 699
		try {
678 700
			Page page = editor.getEditionPanel(0).getCurrentPage();
679 701
			Edition e = page.getEdition();
680 702
			Page next = e.getNextPage(page);
681 703
			String currentPageWordID = page.getWordId();
682 704
			if (currentPageWordID == null || currentPageWordID.length() == 0) return;
683
			
705

  
684 706
			String qid = maincorpus.getProperty("id").getQualifiedName();
685 707
			int first_ids[] = CQPSearchEngine.getCqiClient().str2Id(qid, new String[] { currentPageWordID });
686
			
708

  
687 709
			if (first_ids.length == 0) return;
688
			
710

  
689 711
			int first_id = first_ids[0];
690 712
			if (first_id < 0) return;
691
			
713

  
692 714
			int last_ids[] = null;
693 715
			if (next != null && next != page) {
694 716
				String nextPageWordID = next.getWordId();
......
699 721
					}
700 722
				}
701 723
			}
702
			
724

  
703 725
			int first_pos = CQPSearchEngine.getCqiClient().id2Cpos(qid, first_id)[0];
704 726
			int last_pos = Integer.MAX_VALUE;
705 727
			if (last_ids != null && last_ids.length > 0 && last_ids[0] != -1) {
......
710 732
					last_pos = v[0];
711 733
				}
712 734
			}
713
			
735

  
714 736
			int n2 = 0; // first loop to determine the allpositions array length
715 737
			for (int i = 0; i < unites.length; i++) {
716 738
				for (int p = unites[i].getDeb(); p <= unites[i].getFin(); p++) {
......
719 741
					}
720 742
				}
721 743
			}
722
			
744

  
723 745
			int allpositions[] = new int[n2];
724 746
			n2 = 0;
725 747
			for (int i = 0; i < unites.length; i++) {
......
729 751
					}
730 752
				}
731 753
			}
732
			
754

  
733 755
			if (previousSelectedTypeUnitIDS != null) {
734 756
				editor.removeHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
735 757
				editor.removeFontWeightWordsById(previousSelectedTypeUnitIDS);
......
737 759
			}
738 760
			String ids2[] = CQPSearchEngine.getCqiClient().cpos2Str(maincorpus.getProperty("id").getQualifiedName(), allpositions); //$NON-NLS-1$
739 761
			previousSelectedTypeUnitIDS = Arrays.asList(ids2);
740
			
762

  
741 763
			editor.addHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
742 764
		}
743 765
		catch (Exception e) {
744 766
			e.printStackTrace();
745 767
		}
746 768
	}
747
	
769

  
748 770
	/**
749 771
	 * Highlight a unit and don't focus it
750 772
	 * 
......
767 789
		for (int p = start; p <= end; p++) {
768 790
			positions[n++] = p;
769 791
		}
770
		
792

  
771 793
		try {
772 794
			if (previousSelectedUnitIDS != null) { // remove previous highlighted words
773 795
				editor.removeHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
774 796
				editor.removeFontWeightWordsById(previousSelectedUnitIDS);
775 797
				previousSelectedUnitIDS = null; // release memory
776 798
			}
777
			
799

  
778 800
			String ids[] = CQPSearchEngine.getCqiClient().cpos2Str(maincorpus.getProperty("id").getQualifiedName(), positions); //$NON-NLS-1$
779 801
			// System.out.println("Highlight words with ids="+Arrays.toString(ids));
780
			
802

  
781 803
			// positions = new int[]{positions[0]};
782 804
			Property text_id = maincorpus.getStructuralUnit("text").getProperty("id"); //$NON-NLS-1$ //$NON-NLS-2$
783 805
			int[] text_strucs = CQPSearchEngine.getCqiClient().cpos2Struc(text_id.getQualifiedName(), positions);
784 806
			String[] text_ids = CQPSearchEngine.getCqiClient().struc2Str(text_id.getQualifiedName(), text_strucs);
785
			
807

  
786 808
			String firstWordId = ids[0];
787 809
			String firstWordTextId = text_ids[0];
788 810
			if (clickedWordPosition >= 0 && clickedWordPosition < ids.length) {
789 811
				firstWordId = ids[clickedWordPosition];
790 812
				firstWordTextId = text_ids[clickedWordPosition];
791 813
			}
792
			
793
			
814

  
815

  
794 816
			EditionPanel panel = editor.getEditionPanel(0);
795 817
			Edition e = panel.getEdition();
796 818
			Project corpus = e.getText().getProject();
......
803 825
			Edition newEdition = newText.getEdition(e.getName()); // get the edition of the new text
804 826
			Page newPage = newEdition.getPageForWordId(firstWordId); // find out the page containing the word
805 827
			// System.out.println("page="+p+" current page="+panel.getCurrentPage());
806
			
828

  
807 829
			previousSelectedUnitIDS = Arrays.asList(ids);
808 830
			editor.addHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
809 831
			editor.addFontWeightWordsById(EditionPanel.WEIGHT_BOLD, previousSelectedUnitIDS);
810
			
832

  
811 833
			if (previousSelectedUnitIDS.size() > 0 && focus) {
812 834
				editor.setFocusedWordID(previousSelectedUnitIDS.get(0));
813 835
			}
......
823 845
		}
824 846
		return false;
825 847
	}
826
	
848

  
827 849
	protected void onCreateButtonSelected(SelectionEvent e) {
828 850
		// System.out.println("onCreateButtonSelected");
829 851
		int[] startend = getSelectionStartEndWordPositions();
......
831 853
			Log.info(NLS.bind(Messages.UnitToolbar_44, startend[0], startend[1]));
832 854
			Unite unite = UnitToolbar.this.vue.getCorpus().addUniteSaisie(typeCombo.getText(), startend[0], startend[1]);
833 855
			Structure structure = UnitToolbar.this.analecCorpus.getStructure();
834
			for (String prop : unite.getProps().keySet())
856
			for (String prop : unite.getProps().keySet()) {
835 857
				unite.getProps().put(prop, structure.getValeurParDefaut(unite.getClass(), unite.getType(), prop));
858
			}
836 859
			
837 860
			reloadIdentifiants();
838 861
			selectUniteInIdentifants(unite);
839 862
			// highlightUnite(unite, true, -1);
840
			
863

  
841 864
			deleteButton.setEnabled(true);
842 865
			editLeftButton.setEnabled(true);
843 866
			editButton.setEnabled(true);
......
847 870
			setFocusInPropertiesView();
848 871
			fireIsDirty();
849 872
		}
850
		
873

  
851 874
		if (e != null) editor.updateWordStyles();
852 875
	}
853
	
876

  
854 877
	protected void onDeleteComboSelected(Object e) {
855 878
		int i = navigationField.getSelectionIndex();
856 879
		if (i <= 0) return;
857 880
		// System.out.println("Delete unite at i="+i);
858 881
		Unite unite = unites[i - 1];
859
		
882

  
860 883
		String id = navigationField.getText();
861
		
884

  
862 885
		ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
863 886
				"org.txm.annotation.urs.delete",
864 887
				NLS.bind(Messages.UnitToolbar_47, id),
865 888
				NLS.bind(Messages.UnitToolbar_48, id));
866 889
		if (dialog.open() == ConfirmDialog.CANCEL) return;
867
		
890

  
868 891
		// System.out.println("unite "+unite.toString());
869 892
		UnitToolbar.this.vue.getCorpus().supUnite(unite);
870 893
		reloadIdentifiants();
871
		
894

  
872 895
		i = typeCombo.getSelectionIndex();
873 896
		if (i > 0) {
874 897
			highlightType();
875 898
		}
876 899
		fireIsDirty();
877
		
900

  
878 901
		if (e != null) editor.updateWordStyles();
879 902
	}
880
	
903

  
881 904
	protected void onEditButtonSelected(SelectionEvent e) {
882 905
		onEditButtonSelected(e, 3);
883 906
	}
884
	
907

  
885 908
	protected void onEditButtonSelected(SelectionEvent e, int mode) {
886 909
		if (mode == 0) { // select unit, select words, click the edit button -> deprecated
887 910
			int i = navigationField.getSelectionIndex();
......
915 938
		fireIsDirty();
916 939
		if (e != null) editor.updateWordStyles();
917 940
	}
918
	
941

  
919 942
	/**
920 943
	 * called when the NavigationField changed its selection
921 944
	 * 
......
931 954
				previousSelectedUnitIDS = null; // release memory
932 955
			}
933 956
			highlightType();
934
			
957

  
935 958
			clearPropertiesView(); // unload the selected element if any
936 959
			createButton.setEnabled(false);
937 960
			deleteButton.setEnabled(false);
......
953 976
			// System.out.println("unite="+unite);
954 977
			// System.out.println("unite str="+uniteToWords(unite));
955 978
			pageChanged = highlightUnite(unite, true, -1);
956
			
979

  
957 980
			updatePropertiesView(unite);
958 981
			deleteButton.setEnabled(true);
959 982
			editLeftButton.setEnabled(true);
......
961 984
			editRightButton.setEnabled(true);
962 985
			// drop_b.setEnabled(true);
963 986
		}
964
		
987

  
965 988
		if (e != null && !pageChanged) editor.updateWordStyles();
966 989
	}
967
	
990

  
968 991
	protected void onTypecomboSelected(SelectionEvent e) {
969 992
		reloadIdentifiants();
970
		
993

  
971 994
		if (typeCombo.getSelectionIndex() > 0) {
972 995
			// String type = unitesAVoir[typeCombo.getSelectionIndex()-1];
973 996
			highlightType();
......
977 1000
			clearHighlight();
978 1001
			navigationField.setEnabled(false);
979 1002
		}
980
		
1003

  
981 1004
		createButton.setEnabled(false);
982 1005
		deleteButton.setEnabled(false);
983 1006
		editButton.setEnabled(false);
984 1007
		// drop_b.setEnabled(false);
985 1008
		if (e != null) editor.updateWordStyles();
986 1009
	}
987
	
1010

  
988 1011
	/**
989 1012
	 * reload the identifiants combo
990 1013
	 * 
......
997 1020
		navigationField.setIdentifiants(identifiants, type0, Unite.class);
998 1021
		navigationField.setSelectionIndex(0);
999 1022
	}
1000
	
1023

  
1001 1024
	public void reloadUnits() {
1002
		
1025

  
1003 1026
		typesUnitesAVoir = vue.getTypesUnitesAVoir();
1004 1027
		String[] items = new String[typesUnitesAVoir.length + 1];
1005 1028
		System.arraycopy(typesUnitesAVoir, 0, items, 1, typesUnitesAVoir.length);
......
1009 1032
			typeCombo.select(0);
1010 1033
		}
1011 1034
		typeCombo.layout();
1012
		
1035

  
1013 1036
		onTypecomboSelected(null);
1014 1037
	}
1015
	
1038

  
1016 1039
	protected void selectUniteInIdentifants(Unite unite) {
1017 1040
		for (int i = 0; i < unites.length; i++) {
1018 1041
			// System.out.println("VS "+unites[i]);
......
1022 1045
			}
1023 1046
		}
1024 1047
	}
1025
	
1048

  
1026 1049
	public void setEnable(boolean enable) {
1027 1050
		l.setEnabled(enable);
1028 1051
		typeCombo.setEnabled(enable);
......
1034 1057
		editRightButton.setEnabled(enable);
1035 1058
		// drop_b.setEnabled(enable);
1036 1059
	}
1037
	
1060

  
1038 1061
	@Override
1039 1062
	public void traiterEvent(Message e) {
1040 1063
		if (annotationArea.isDisposed()) return;
1041
		
1064

  
1042 1065
		if (e.getType().equals(TypeMessage.MODIF_STRUCTURE)) {
1043 1066
			// System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
1044 1067
			UnitToolbar.this.annotationArea.getDisplay().syncExec(new Runnable() {
1045
				
1068

  
1046 1069
				@Override
1047 1070
				public void run() {
1048 1071
					setEnable(!analecCorpus.isVide());
......
1053 1076
		else if (e.getType().equals(TypeMessage.MODIF_ELEMENT)) {
1054 1077
			// System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
1055 1078
			UnitToolbar.this.annotationArea.getDisplay().syncExec(new Runnable() {
1056
				
1079

  
1057 1080
				@Override
1058 1081
				public void run() {
1059 1082
					// reloadUnits();
......
1061 1084
			});
1062 1085
		}
1063 1086
	}
1064
	
1087

  
1065 1088
	protected synchronized boolean tryHighlightingUnitsWord(String id, org.txm.searchengine.cqp.corpus.CQPCorpus c) throws CqiClientException {
1066 1089
		EditionPanel panel = editor.getEditionPanel(0);
1067 1090
		if (panel == null) return false;
1068 1091
		if (id != null) {
1069
			
1092

  
1070 1093
		}
1071 1094
		QueryResult r = c.query(new CQLQuery("[_.text_id=\"" + panel.getEdition().getText().getName() + "\" & id=\"" + id + "\"]"), "TMP", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1072 1095
		List<Match> matches = r.getMatches();
......
1088 1111
			}
1089 1112
			i++;
1090 1113
		}
1091
		
1114

  
1092 1115
		if (matching_units.size() > 0) {
1093 1116
			// get index in matching_units of the current unit if any
1094 1117
			int iUnite = matching_units.indexOf(navigationField.getSelectionIndex() - 1);
1095
			
1118

  
1096 1119
			if (iUnite == -1) iUnite = 0; // current unit is not present, take the first in matching_units
1097 1120
			else iUnite = (iUnite + 1) % matching_units.size(); // take the next unit in matching_units
1098
			
1121

  
1099 1122
			iUnite = matching_units.get(iUnite); // get the real unit position in 'unites'
1100 1123
			navigationField.setSelectionIndex(iUnite + 1, false); // call onIndentifiantComboChanged(...)
1101
			
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff