Révision 3225
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/toolbar/UnitToolbar.java (revision 3225) | ||
---|---|---|
794 | 794 |
editor.addHighlightWordsById(selected_unit_color, previousSelectedUnitIDS); |
795 | 795 |
editor.addFontWeightWordsById(EditionPanel.WEIGHT_BOLD, previousSelectedUnitIDS); |
796 | 796 |
|
797 |
if (previousSelectedUnitIDS.size() > 0 && focus) editor.setFocusedWordID(previousSelectedUnitIDS.get(0)); |
|
797 |
if (previousSelectedUnitIDS.size() > 0 && focus) { |
|
798 |
editor.setFocusedWordID(previousSelectedUnitIDS.get(0)); |
|
799 |
} |
|
800 |
Page cp = panel.getCurrentPage(); |
|
798 | 801 |
// System.out.println("Word page= "+p+" current="+panel.getCurrentPage()); |
799 |
if (panel.getCurrentText() != newText) { // text changed
|
|
802 |
if (!panel.getCurrentText().equals(newText)) { // text changed
|
|
800 | 803 |
// System.out.println("TEXT CHANGED"); |
801 | 804 |
editor.setText(newText, false); // don't refresh right now |
802 | 805 |
editor.goToPage(p.getName()); |
803 | 806 |
} |
804 |
else if (panel.getCurrentPage() != p) { // do we need to change page ?
|
|
807 |
else if (!cp.equals(p)) { // do we need to change page ?
|
|
805 | 808 |
editor.goToPage(p.getName()); |
806 | 809 |
} |
807 | 810 |
else { // just reload the page to highlight words |
... | ... | |
1095 | 1098 |
|
1096 | 1099 |
Unite unite = unites[iUnite]; |
1097 | 1100 |
int offset = start - unite.getDeb(); // to select the right page when the unit words overlap with 2 pages |
1098 |
highlightUnite(unite, true, offset);
|
|
1101 |
highlightUnite(unite, false, offset);
|
|
1099 | 1102 |
|
1100 | 1103 |
updatePropertiesView(unite); |
1101 | 1104 |
|
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/search/URSSearchEngine.java (revision 3225) | ||
---|---|---|
61 | 61 |
@Override |
62 | 62 |
public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception { |
63 | 63 |
|
64 |
ArrayList<Element> elements = findAllInCorpus(0, URSCorpora.getCorpus(corpus), corpus, Unite.class, query.getQueryString());
|
|
64 |
ArrayList<Element> elements = findAllInCorpus(0, URSCorpora.getCorpus(corpus), corpus, query.getQueryString()); |
|
65 | 65 |
ArrayList<URSMatch> matches = new ArrayList<URSMatch>(); |
66 | 66 |
for (Element e : elements) { |
67 |
matches.add(new URSMatch(e.getUnite0().getDeb(), e.getUnite0().getFin())); |
|
67 |
matches.add(new URSMatch(e, e.getUnite0().getDeb(), e.getUnite0().getFin()));
|
|
68 | 68 |
} |
69 | 69 |
return new URSSelection(query, matches); |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
static String[] getFilterParameters(String URSQL) { |
73 | 73 |
|
74 |
String clazz = "U"; |
|
74 | 75 |
String type = ""; |
75 | 76 |
String prop = ""; |
76 | 77 |
String value = ""; |
77 | 78 |
|
78 | 79 |
if (URSQL == null) return new String[] {type, prop, value}; |
79 | 80 |
|
81 |
int clazzidx = URSQL.indexOf("/"); //TODO parse query to find out which URS Element use (U/R/S/E) |
|
80 | 82 |
int atidx = URSQL.indexOf("@"); |
81 | 83 |
int equalidx = URSQL.indexOf("="); |
82 | 84 |
|
... | ... | |
94 | 96 |
type = URSQL; |
95 | 97 |
} |
96 | 98 |
// println(["'"+type+"'", "'"+prop+"'", "'"+value+"'"]) |
97 |
|
|
98 |
return new String[] {type, prop, value}; |
|
99 |
Boolean mustmatch = equalidx <= 0 || '!' != URSQL.charAt(equalidx-1); |
|
100 |
|
|
101 |
return new String[] {clazz, type, mustmatch.toString(), prop, value}; |
|
99 | 102 |
} |
100 | 103 |
|
101 |
static ArrayList<Element> findAllInCorpus(int debug, Corpus analecCorpus, CorpusBuild corpus, Class elemClazz, String URSQL) {
|
|
104 |
static ArrayList<Element> findAllInCorpus(int debug, Corpus analecCorpus, CorpusBuild corpus, String URSQL) { |
|
102 | 105 |
String[] params = getFilterParameters(URSQL); |
103 | 106 |
if (debug >= 2) Log.finer("PARAMS=$params"); |
104 |
return findAllInCorpus(debug, analecCorpus, corpus, elemClazz, params[0], params[1], params[2]);
|
|
107 |
return findAllInCorpus(debug, analecCorpus, corpus, params[0], params[1], params[2], Boolean.parseBoolean(params[3]), params[4]);
|
|
105 | 108 |
} |
109 |
|
|
110 |
static ArrayList<Element> findAllInCorpus(int debug, Corpus analecCorpus, CorpusBuild corpus, String clazzString, String typeRegex, String propName, boolean valueMustMatch, String valueRegex) { |
|
111 |
Class<? extends Element> clazz = Unite.class; |
|
112 |
if ("R".equals(clazzString)) { |
|
113 |
clazz = Relation.class; |
|
114 |
} else if ("S".equals(clazzString)) { |
|
115 |
clazz = Schema.class; |
|
116 |
} else if ("E".equals(clazzString)) { |
|
117 |
clazz = Element.class; |
|
118 |
} |
|
119 |
return findAllInCorpus(debug, analecCorpus, corpus, clazz, typeRegex, propName, valueMustMatch, valueRegex); |
|
120 |
} |
|
106 | 121 |
|
107 |
static ArrayList<Element> findAllInCorpus(int debug, Corpus analecCorpus, CorpusBuild corpus, Class elemClazz, String typeRegex, String propName, String valueRegex) {
|
|
122 |
static ArrayList<Element> findAllInCorpus(int debug, Corpus analecCorpus, CorpusBuild corpus, Class<? extends Element> elemClazz, String typeRegex, String propName, boolean valueMustMatch, String valueRegex) {
|
|
108 | 123 |
ArrayList<Element> allElements = new ArrayList<Element>(); |
109 | 124 |
|
110 | 125 |
if (elemClazz != null) { |
... | ... | |
120 | 135 |
allElements.addAll(analecCorpus.getTousSchemas()); |
121 | 136 |
} |
122 | 137 |
|
123 |
return filterElements(debug, allElements, corpus, typeRegex, propName, valueRegex); |
|
138 |
return filterElements(debug, allElements, corpus, typeRegex, propName, valueMustMatch, valueRegex);
|
|
124 | 139 |
} |
125 | 140 |
|
126 | 141 |
/** |
... | ... | |
206 | 221 |
return selectedUnits; |
207 | 222 |
} |
208 | 223 |
|
209 |
static ArrayList<Element> filterElements(int debug, ArrayList<Element> allElements, CorpusBuild corpus, String typeRegex, String propName, String valueRegex) { |
|
210 |
if (debug >= 2) Log.finer("filtering "+allElements.size()+" elements with typeRegex='$typeRegex' propName='$propName' and valueRegex='$valueRegex'"); |
|
224 |
static ArrayList<Element> filterElements(int debug, ArrayList<Element> allElements, CorpusBuild corpus, String typeRegex, String propName, boolean valueMustMatch, String valueRegex) {
|
|
225 |
if (debug >= 2) Log.finer("filtering "+allElements.size()+" elements with typeRegex='$typeRegex' propName='$propName' and valueRegex"+(valueMustMatch?"":"!")+"='$valueRegex'");
|
|
211 | 226 |
|
212 | 227 |
if (corpus != null) { |
213 | 228 |
allElements = filterUniteByInclusion(debug, allElements, corpus.getMatches(), true, 0); |
... | ... | |
225 | 240 |
allElements = filteredElements; |
226 | 241 |
} |
227 | 242 |
if (debug >= 2) Log.finer(" type step result: "+allElements.size()); |
228 |
|
|
243 |
|
|
229 | 244 |
if (propName != null && propName.length() > 0) { |
230 | 245 |
ArrayList<Element> filteredElements = new ArrayList<Element>(); |
231 | 246 |
if (valueRegex != null && valueRegex.length() > 0) { // select only elements with the prop&value |
232 | 247 |
Pattern pattern = Pattern.compile(valueRegex); |
233 | 248 |
for (Element element : allElements) { |
234 | 249 |
String value = element.getProp(propName); |
235 |
if (value != null && pattern.matcher(value).matches()) { |
|
250 |
if (value != null && pattern.matcher(value).matches() == valueMustMatch) {
|
|
236 | 251 |
filteredElements.add(element); |
237 | 252 |
} |
238 | 253 |
} |
... | ... | |
262 | 277 |
|
263 | 278 |
@Override |
264 | 279 |
public String getValueForProperty(Match match, SearchEngineProperty property) { |
265 |
// TODO Auto-generated method stub |
|
280 |
if (match instanceof URSMatch) { |
|
281 |
return ((URSMatch) match).getValue(property.getName()); |
|
282 |
} |
|
266 | 283 |
return null; |
267 | 284 |
} |
268 | 285 |
|
269 | 286 |
@Override |
270 | 287 |
public List<String> getValuesForProperty(Match match, SearchEngineProperty property) { |
271 |
// TODO Auto-generated method stub |
|
272 |
return null; |
|
288 |
ArrayList<String> a = new ArrayList<String>(); |
|
289 |
a.add(getValueForProperty(match, property)); |
|
290 |
return a; |
|
273 | 291 |
} |
274 | 292 |
|
275 | 293 |
} |
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/search/URSMatch.java (revision 3225) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.txm.objects.Match2P; |
4 | 4 |
|
5 |
import visuAnalec.elements.Element; |
|
6 |
|
|
5 | 7 |
public class URSMatch extends Match2P { |
6 | 8 |
|
7 |
public URSMatch(int start, int end) { |
|
9 |
Element element; |
|
10 |
|
|
11 |
public URSMatch(Element element, int start, int end) { |
|
8 | 12 |
super(start, end); |
13 |
this.element = element; |
|
9 | 14 |
} |
10 | 15 |
|
16 |
public String getValue(String property) { |
|
17 |
return this.element.getProp(property); |
|
18 |
} |
|
19 |
|
|
11 | 20 |
} |
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/view/PropertyField.java (revision 3225) | ||
---|---|---|
1 |
package org.txm.annotation.urs.view; |
|
2 |
|
|
3 |
import java.text.Collator; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.Locale; |
|
6 |
|
|
7 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
|
8 |
import org.eclipse.jface.fieldassist.ComboContentAdapter; |
|
9 |
import org.eclipse.jface.fieldassist.TXMAutoCompleteField; |
|
10 |
import org.eclipse.swt.SWT; |
|
11 |
import org.eclipse.swt.events.KeyEvent; |
|
12 |
import org.eclipse.swt.events.KeyListener; |
|
13 |
import org.eclipse.swt.events.ModifyEvent; |
|
14 |
import org.eclipse.swt.events.ModifyListener; |
|
15 |
import org.eclipse.swt.events.SelectionEvent; |
|
16 |
import org.eclipse.swt.events.SelectionListener; |
|
17 |
import org.eclipse.swt.graphics.Color; |
|
18 |
import org.eclipse.swt.layout.GridData; |
|
19 |
import org.eclipse.swt.widgets.Combo; |
|
20 |
import org.eclipse.swt.widgets.Composite; |
|
21 |
import org.eclipse.swt.widgets.Label; |
|
22 |
|
|
23 |
import visuAnalec.elements.Element; |
|
24 |
|
|
25 |
public class PropertyField extends Composite { |
|
26 |
|
|
27 |
String property; |
|
28 |
ElementPropertiesView view; |
|
29 |
boolean first = true; |
|
30 |
|
|
31 |
public void reinitialiseModify() { |
|
32 |
first = true; |
|
33 |
} |
|
34 |
|
|
35 |
public PropertyField(Composite parent, int style, String property, ElementPropertiesView view) { |
|
36 |
|
|
37 |
super(parent, style); |
|
38 |
this.property = property; |
|
39 |
this.view = view; |
|
40 |
|
|
41 |
label = new Label(this, SWT.None); |
|
42 |
label.setText(property); |
|
43 |
|
|
44 |
GridData lData = new GridData(GridData.FILL, GridData.CENTER, false, false); |
|
45 |
lData.minimumWidth = 75; |
|
46 |
lData.widthHint = 75; |
|
47 |
label.setLayoutData(lData); |
|
48 |
|
|
49 |
t = new Combo(this, SWT.BORDER); |
|
50 |
t.setToolTipText(property); |
|
51 |
GridData tData = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
52 |
tData.minimumWidth = 150; |
|
53 |
tData.widthHint = 150; |
|
54 |
t.setLayoutData(tData); |
|
55 |
|
|
56 |
t.addModifyListener(new ModifyListener() { |
|
57 |
|
|
58 |
@Override |
|
59 |
public void modifyText(ModifyEvent e) { |
|
60 |
if (e.widget.isDisposed()) return; |
|
61 |
if (first) { |
|
62 |
first = false; |
|
63 |
return; |
|
64 |
} |
|
65 |
|
|
66 |
t.setBackground(new Color(t.getDisplay(),255,0,0)); |
|
67 |
} |
|
68 |
}); |
|
69 |
t.addSelectionListener(new SelectionListener() { |
|
70 |
@Override |
|
71 |
public void widgetSelected(SelectionEvent e) { |
|
72 |
if (!(e.widget instanceof Combo)) return; |
|
73 |
view.saveFieldValue(PropertyField.this); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
78 |
|
|
79 |
} |
|
80 |
}); |
|
81 |
// t.addKeyListener(allControlsKeyListener); |
|
82 |
t.addKeyListener(new KeyListener() { |
|
83 |
@Override |
|
84 |
public void keyReleased(KeyEvent e) { |
|
85 |
if (!(e.widget instanceof Combo)) return; |
|
86 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
|
87 |
// System.out.println("w:"+e.widget+" key pressed2."); |
|
88 |
|
|
89 |
view.saveFieldValue(PropertyField.this); |
|
90 |
|
|
91 |
} |
|
92 |
// else if (e.keyCode == SWT.DEL) { |
|
93 |
// String value =((Combo) e.widget).getText(); |
|
94 |
// System.out.println("DEL prop="+textWidgets.get(e.widget)+" value="+value); |
|
95 |
// } |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void keyPressed(KeyEvent e) { } |
|
100 |
}); |
|
101 |
} |
|
102 |
Label label; |
|
103 |
Combo t; |
|
104 |
|
|
105 |
public void setItems(PropertyField t, Element newElement) { |
|
106 |
|
|
107 |
String[] items = view.getAnalecVue().getValeursChamp(newElement.getClass(), newElement.getType(), t.getToolTipText()); |
|
108 |
|
|
109 |
Arrays.sort(items, Collator.getInstance(Locale.getDefault())); |
|
110 |
t.getCombo().setItems(items); |
|
111 |
KeyStroke keys = KeyStroke.getInstance(SWT.CONTROL, SWT.SPACE); |
|
112 |
new TXMAutoCompleteField(t.getCombo(), new ComboContentAdapter(), items, keys); |
|
113 |
} |
|
114 |
|
|
115 |
public String getToolTipText() { |
|
116 |
return t.getToolTipText(); |
|
117 |
} |
|
118 |
|
|
119 |
public void setText(String value) { |
|
120 |
t.setText(value); |
|
121 |
} |
|
122 |
|
|
123 |
public boolean setFocus() { |
|
124 |
return t.setFocus(); |
|
125 |
} |
|
126 |
|
|
127 |
public void update() { |
|
128 |
super.update(); |
|
129 |
label.update(); |
|
130 |
t.update(); |
|
131 |
} |
|
132 |
|
|
133 |
public void setToolTipText(String title) { |
|
134 |
this.getCombo().setToolTipText(title); |
|
135 |
} |
|
136 |
|
|
137 |
public Combo getCombo() { |
|
138 |
return t; |
|
139 |
} |
|
140 |
|
|
141 |
public String getProperty() { |
|
142 |
|
|
143 |
return property; |
|
144 |
} |
|
145 |
|
|
146 |
public String getText() { |
|
147 |
|
|
148 |
return t.getText(); |
|
149 |
} |
|
150 |
|
|
151 |
} |
|
0 | 152 |
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/view/ElementPropertiesView.java (revision 3225) | ||
---|---|---|
1 | 1 |
package org.txm.annotation.urs.view; |
2 | 2 |
|
3 |
import java.text.Collator; |
|
4 | 3 |
import java.util.ArrayList; |
5 |
import java.util.Arrays; |
|
6 | 4 |
import java.util.LinkedHashMap; |
7 |
import java.util.Locale; |
|
8 | 5 |
|
9 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
|
10 |
import org.eclipse.jface.fieldassist.ComboContentAdapter; |
|
11 |
import org.eclipse.jface.fieldassist.TXMAutoCompleteField; |
|
12 | 6 |
import org.eclipse.swt.SWT; |
13 | 7 |
import org.eclipse.swt.events.DisposeEvent; |
14 | 8 |
import org.eclipse.swt.events.DisposeListener; |
15 |
import org.eclipse.swt.events.KeyEvent; |
|
16 |
import org.eclipse.swt.events.KeyListener; |
|
17 | 9 |
import org.eclipse.swt.events.SelectionEvent; |
18 | 10 |
import org.eclipse.swt.events.SelectionListener; |
11 |
import org.eclipse.swt.graphics.Color; |
|
19 | 12 |
import org.eclipse.swt.layout.GridData; |
20 | 13 |
import org.eclipse.swt.layout.GridLayout; |
21 | 14 |
import org.eclipse.swt.layout.RowData; |
22 | 15 |
import org.eclipse.swt.layout.RowLayout; |
23 |
import org.eclipse.swt.widgets.Combo; |
|
24 | 16 |
import org.eclipse.swt.widgets.Composite; |
25 | 17 |
import org.eclipse.swt.widgets.Control; |
26 | 18 |
import org.eclipse.swt.widgets.Display; |
27 |
import org.eclipse.swt.widgets.Label; |
|
28 | 19 |
import org.eclipse.swt.widgets.ToolBar; |
29 | 20 |
import org.eclipse.swt.widgets.ToolItem; |
30 | 21 |
import org.eclipse.ui.IWorkbenchPage; |
... | ... | |
46 | 37 |
import visuAnalec.vue.Vue; |
47 | 38 |
|
48 | 39 |
public class ElementPropertiesView extends ViewPart { |
49 |
|
|
40 |
|
|
50 | 41 |
public static final String ID = ElementPropertiesView.class.getName(); |
51 |
|
|
52 |
private LinkedHashMap<Combo, String> textWidgets = new LinkedHashMap<Combo, String>(); |
|
42 |
|
|
43 |
private LinkedHashMap<String, PropertyField> textWidgets = new LinkedHashMap<String, PropertyField>(); |
|
44 |
private String[][] properties; |
|
45 |
|
|
53 | 46 |
Element element; |
54 | 47 |
URSAnnotationToolbar toolbar; |
55 |
|
|
48 |
|
|
56 | 49 |
private ToolBar buttons; |
57 | 50 |
private Composite fields; |
58 | 51 |
private ToolItem firstButton; |
... | ... | |
60 | 53 |
private ToolItem nextButton; |
61 | 54 |
private ToolItem lastButton; |
62 | 55 |
RowData cData = new RowData(); |
63 |
private GridData lData; |
|
64 |
private GridData tData; |
|
65 |
|
|
56 |
|
|
66 | 57 |
private Corpus analecCorpus; |
67 | 58 |
private Vue vue; |
68 | 59 |
private CorpusListener corpusListener = new CorpusListener() { |
... | ... | |
76 | 67 |
if (fields == null || fields.isDisposed()) return; |
77 | 68 |
|
78 | 69 |
if (e.getType() == TypeMessage.MODIF_STRUCTURE) { |
79 |
needUpdate = true; |
|
80 | 70 |
loadElement(corpus, analecCorpus, element, toolbar); |
71 |
} else if (e.getType() == TypeMessage.CORPUS_SAVED) { |
|
72 |
for (PropertyField c : textWidgets.values()) { |
|
73 |
if (c.isDisposed()) continue; |
|
74 |
c.setForeground(null); |
|
75 |
c.update(); |
|
76 |
} |
|
81 | 77 |
} |
82 | 78 |
} |
83 | 79 |
}); |
84 | 80 |
|
85 | 81 |
} |
86 | 82 |
}; |
87 |
|
|
88 |
private boolean needUpdate = false; |
|
89 |
|
|
83 |
|
|
90 | 84 |
private org.txm.searchengine.cqp.corpus.CQPCorpus corpus; |
91 |
|
|
92 |
// private KeyListener allControlsKeyListener; |
|
93 |
|
|
85 |
|
|
86 |
// private KeyListener allControlsKeyListener;
|
|
87 |
|
|
94 | 88 |
public static void closeView() { |
95 | 89 |
try { |
96 | 90 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
97 | 91 |
ElementPropertiesView view = (ElementPropertiesView) page.findView(ElementPropertiesView.ID); |
98 |
|
|
92 |
|
|
99 | 93 |
// close Element View if opened |
100 | 94 |
if (view != null) { |
101 | 95 |
view = (ElementPropertiesView) page.showView(ElementPropertiesView.ID); |
102 | 96 |
page.hideView(view); |
103 | 97 |
} |
104 |
|
|
98 |
|
|
105 | 99 |
return; |
106 | 100 |
} catch (PartInitException e1) { |
107 | 101 |
System.out.println("Part initialisation error: "+e1.getLocalizedMessage()); |
... | ... | |
129 | 123 |
} |
130 | 124 |
return null; |
131 | 125 |
} |
132 |
|
|
126 |
|
|
133 | 127 |
@Override |
134 | 128 |
public void createPartControl(Composite parent) { |
135 |
|
|
129 |
|
|
136 | 130 |
GridLayout layout = new GridLayout(); |
137 | 131 |
parent.setLayout(layout); |
138 | 132 |
|
... | ... | |
190 | 184 |
@Override |
191 | 185 |
public void widgetDefaultSelected(SelectionEvent e) { } |
192 | 186 |
}); |
193 |
|
|
187 |
|
|
194 | 188 |
fields = new Composite(parent, SWT.NONE); |
195 | 189 |
GridData fields_gdata = new GridData(GridData.FILL, GridData.FILL, true, true); |
196 | 190 |
fields.setLayoutData(fields_gdata); |
... | ... | |
199 | 193 |
|
200 | 194 |
// GridDatas to use when a new field is added |
201 | 195 |
cData.width = 325; |
202 |
lData = new GridData(GridData.FILL, GridData.CENTER, false, false); |
|
203 |
lData.minimumWidth = 75; |
|
204 |
lData.widthHint = 75; |
|
205 |
tData = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
206 |
tData.minimumWidth = 150; |
|
207 |
tData.widthHint = 150; |
|
208 |
|
|
196 |
|
|
209 | 197 |
parent.addDisposeListener(new DisposeListener() { |
210 | 198 |
@Override |
211 | 199 |
public void widgetDisposed(DisposeEvent e) { |
212 | 200 |
try { |
213 | 201 |
if (element != null) { // save previous unit changes |
214 |
for (Combo t : new ArrayList<Combo>(textWidgets.keySet())) { |
|
215 |
if (!t.isDisposed()) {
|
|
216 |
saveFieldValue(t);
|
|
217 |
}
|
|
202 |
|
|
203 |
for (PropertyField c : textWidgets.values()) {
|
|
204 |
if (c.isDisposed()) continue;
|
|
205 |
saveFieldValue(c);
|
|
218 | 206 |
} |
219 | 207 |
} |
220 | 208 |
} catch(Exception ex) { ex.printStackTrace();} |
221 | 209 |
} |
222 |
}); |
|
210 |
});
|
|
223 | 211 |
} |
224 |
|
|
212 |
|
|
225 | 213 |
public void unloadElement(Corpus analecCorpus, URSAnnotationToolbar toolbar) { |
226 |
|
|
214 |
|
|
227 | 215 |
if (this.element != null) { // save previous unit changes |
228 |
for (Combo t : new ArrayList<Combo>(textWidgets.keySet())) { |
|
229 |
if (!t.isDisposed()) { |
|
230 |
saveFieldValue(t); |
|
231 |
} |
|
216 |
for (PropertyField c : textWidgets.values()) { |
|
217 |
if (c.isDisposed()) continue; |
|
218 |
saveFieldValue(c); |
|
232 | 219 |
} |
233 | 220 |
} |
234 | 221 |
|
... | ... | |
237 | 224 |
} |
238 | 225 |
|
239 | 226 |
clear(); |
240 |
this.needUpdate = true; |
|
241 | 227 |
this.setPartName("Element"); |
242 | 228 |
this.setContentDescription("No annotation selected"); |
243 | 229 |
} |
244 | 230 |
|
245 | 231 |
public synchronized void loadElement(org.txm.searchengine.cqp.corpus.CQPCorpus corpus, Corpus analecCorpus, Element newElement, URSAnnotationToolbar toolbar) { |
246 |
|
|
232 |
|
|
247 | 233 |
if (this.element != null) { // save previous unit changes |
248 |
ArrayList<Combo> widgets = new ArrayList<>(textWidgets.keySet()); // vue.setValue will modify this list if an Analec event is fired |
|
249 |
for (Combo t : widgets) {
|
|
250 |
if (!t.isDisposed()) saveFieldValue(t);
|
|
251 |
if (!t.isDisposed()) t.setText("");
|
|
234 |
|
|
235 |
for (PropertyField c : textWidgets.values()) {
|
|
236 |
if (c.isDisposed()) continue;
|
|
237 |
if (!c.isDisposed()) saveFieldValue(c);
|
|
252 | 238 |
} |
253 | 239 |
} |
254 |
|
|
240 |
|
|
255 | 241 |
if (this.analecCorpus != null) { // remove corpus listener from previous corpus |
256 | 242 |
this.analecCorpus.removeEventListener(corpusListener); |
257 | 243 |
} |
258 |
|
|
244 |
|
|
245 |
clear(); |
|
246 |
|
|
259 | 247 |
this.corpus = corpus; |
260 | 248 |
this.analecCorpus = analecCorpus; |
261 | 249 |
this.analecCorpus.addEventListener(corpusListener); |
262 | 250 |
this.vue = URSCorpora.getVue(analecCorpus); |
263 |
|
|
264 |
if (this.needUpdate || this.element == null || (!this.element.getType().equals(newElement.getType()))) { // no need to rebuild the widgets |
|
265 |
needUpdate = false; |
|
266 |
clear(); // remove all previous widgets |
|
267 |
|
|
268 |
String[][] props = vue.getChamps(newElement.getClass(), newElement.getType()); |
|
269 |
for (int l = 0 ; l < props.length ; l++) |
|
270 |
for (String p : props[l]) { // the first is the prop names |
|
271 |
|
|
272 |
Composite c = new Composite(fields, SWT.NONE); |
|
273 |
c.setLayoutData(cData); |
|
274 |
c.setLayout(new GridLayout(2, false)); |
|
275 |
Label label = new Label(c, SWT.None); |
|
276 |
label.setText(p); |
|
277 |
label.setLayoutData(lData); |
|
278 |
|
|
279 |
Combo t = new Combo(c, SWT.BORDER); |
|
280 |
t.setLayoutData(tData); |
|
281 |
textWidgets.put(t, p); |
|
282 |
setItems(t, newElement); |
|
283 |
t.addSelectionListener(new SelectionListener() { |
|
284 |
@Override |
|
285 |
public void widgetSelected(SelectionEvent e) { |
|
286 |
if (!(e.widget instanceof Combo)) return; |
|
287 |
|
|
288 |
// System.out.println("w:"+e.widget+" selected."); |
|
289 |
saveFieldValue((Combo)e.widget); |
|
290 |
} |
|
291 |
|
|
292 |
@Override |
|
293 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
294 |
|
|
295 |
} |
|
296 |
}); |
|
297 |
// t.addKeyListener(allControlsKeyListener); |
|
298 |
t.addKeyListener(new KeyListener() { |
|
299 |
@Override |
|
300 |
public void keyReleased(KeyEvent e) { |
|
301 |
if (!(e.widget instanceof Combo)) return; |
|
302 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
|
303 |
// System.out.println("w:"+e.widget+" key pressed2."); |
|
304 |
|
|
305 |
saveFieldValue((Combo)e.widget); |
|
306 |
} |
|
307 |
// else if (e.keyCode == SWT.DEL) { |
|
308 |
// String value =((Combo) e.widget).getText(); |
|
309 |
// System.out.println("DEL prop="+textWidgets.get(e.widget)+" value="+value); |
|
310 |
// } |
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public void keyPressed(KeyEvent e) { } |
|
315 |
}); |
|
316 |
|
|
317 |
} |
|
318 |
fields.layout(); |
|
319 |
fields.getParent().layout(); |
|
251 |
|
|
252 |
//if (this.element == null || (!this.element.getType().equals(newElement.getType()))) { // no need to rebuild the widgets |
|
253 |
//clear(); // remove all previous widgets |
|
254 |
String[][] props = vue.getChamps(newElement.getClass(), newElement.getType()); |
|
255 |
for (int l = 0 ; l < props.length ; l++) { |
|
256 |
for (String p : props[l]) { // the first is the prop names |
|
257 |
|
|
258 |
PropertyField c = new PropertyField(fields, SWT.NONE, p, this); |
|
259 |
|
|
260 |
c.setLayoutData(cData); |
|
261 |
c.setLayout(new GridLayout(2, false)); |
|
262 |
c.setItems(c, newElement); |
|
263 |
|
|
264 |
textWidgets.put(p, c); |
|
265 |
} |
|
320 | 266 |
} |
321 |
|
|
267 |
|
|
268 |
fields.layout(); |
|
269 |
fields.getParent().layout(); |
|
270 |
|
|
271 |
//} |
|
272 |
|
|
322 | 273 |
Log.fine("Refreshing unit properties view with: "+newElement); |
323 | 274 |
this.toolbar = toolbar; |
324 | 275 |
this.element = newElement; |
325 |
for (Combo t : new ArrayList<Combo>(textWidgets.keySet())) { |
|
326 |
if (newElement.getProps().get(textWidgets.get(t)) != null) { |
|
327 |
t.setText(newElement.getProps().get(textWidgets.get(t))); |
|
276 |
for (PropertyField t : new ArrayList<PropertyField>(textWidgets.values())) { |
|
277 |
if (newElement.getProps().get(t.getToolTipText()) != null) { |
|
278 |
String newValue = newElement.getProps().get(t.getToolTipText()); |
|
279 |
String oldValue = t.getText(); |
|
280 |
//System.out.println("new="+newValue+" old="+oldValue+" differs? "+(!newValue.equals(t.getText()))); |
|
281 |
if (!newValue.equals(oldValue)) { |
|
282 |
t.setText(newValue); |
|
283 |
} |
|
328 | 284 |
} |
329 | 285 |
} |
330 | 286 |
|
... | ... | |
342 | 298 |
} |
343 | 299 |
this.setContentDescription(""); |
344 | 300 |
} |
345 |
|
|
346 |
protected void saveFieldValue(Combo t) {
|
|
347 |
if (toolbar == null || toolbar.isDisposed()) return; |
|
301 |
|
|
302 |
protected void saveFieldValue(PropertyField c) {
|
|
303 |
if (toolbar == null || toolbar.isDisposed() || c.isDisposed()) return;
|
|
348 | 304 |
|
349 |
String newVal = t.getText().trim();
|
|
350 |
String v = ElementPropertiesView.this.vue.getValeurChamp(ElementPropertiesView.this.element, textWidgets.get(t));
|
|
305 |
String newVal = c.getCombo().getText().trim();
|
|
306 |
String v = ElementPropertiesView.this.vue.getValeurChamp(ElementPropertiesView.this.element, c.getToolTipText());
|
|
351 | 307 |
if (!v.equals(newVal) && v != null) { |
352 |
ElementPropertiesView.this.vue.setValeurChamp(ElementPropertiesView.this.element, textWidgets.get(t), newVal); |
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
ElementPropertiesView.this.vue.setValeurChamp(ElementPropertiesView.this.element, c.getProperty(), newVal); |
|
353 | 312 |
ElementPropertiesView.this.analecCorpus.isModifie(); |
354 |
if (toolbar != null && !toolbar.isDisposed()) this.toolbar.fireIsDirty(); |
|
313 |
if (toolbar != null && !toolbar.isDisposed()) this.toolbar.fireIsDirty(); // the Analec corpus should be saved |
|
314 |
|
|
315 |
if (!c.isDisposed()) { |
|
316 |
c.setBackground(new Color(c.getDisplay(), 255,0,0)); |
|
317 |
c.update(); |
|
318 |
} |
|
355 | 319 |
} |
356 | 320 |
} |
357 | 321 |
|
358 |
private void setItems(Combo t, Element newElement) { |
|
359 |
String[] items = vue.getValeursChamp(newElement.getClass(), newElement.getType(), textWidgets.get(t)); |
|
360 |
String lang = null; |
|
361 |
|
|
362 |
Arrays.sort(items, Collator.getInstance(Locale.getDefault())); |
|
363 |
t.setItems(items); |
|
364 |
KeyStroke keys = KeyStroke.getInstance(SWT.CONTROL, SWT.SPACE); |
|
365 |
new TXMAutoCompleteField(t, new ComboContentAdapter(), items, keys); |
|
366 |
} |
|
322 |
|
|
367 | 323 |
public Element getCurrentElement() { |
368 | 324 |
return element; |
369 | 325 |
} |
370 |
|
|
326 |
|
|
371 | 327 |
public Corpus getCurrentAnalecCorpus() { |
372 | 328 |
return analecCorpus; |
373 | 329 |
} |
374 |
|
|
330 |
|
|
375 | 331 |
public void setFocusOnProperty() { |
376 |
for (Combo w : textWidgets.keySet()) {
|
|
332 |
for (PropertyField w : textWidgets.values()) {
|
|
377 | 333 |
w.setFocus(); |
378 | 334 |
return; |
379 | 335 |
} |
380 | 336 |
} |
381 |
|
|
337 |
|
|
382 | 338 |
public void clear() { |
383 | 339 |
Control[] children = fields.getChildren(); |
384 | 340 |
for (int i = 0 ; i < children.length ; i++) { |
385 | 341 |
children[i].dispose(); |
386 | 342 |
} |
387 |
textWidgets.clear(); |
|
343 |
if (textWidgets != null) textWidgets.clear();
|
|
388 | 344 |
fields.layout(); |
389 | 345 |
} |
390 | 346 |
@Override |
... | ... | |
392 | 348 |
// TODO Auto-generated method stub |
393 | 349 |
|
394 | 350 |
} |
351 |
public Vue getAnalecVue() { |
|
352 |
|
|
353 |
return vue; |
|
354 |
} |
|
395 | 355 |
} |
Formats disponibles : Unified diff