Révision 3977
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreateSubcorpusDialog.java (revision 3977) | ||
---|---|---|
48 | 48 |
import org.eclipse.swt.widgets.TabItem; |
49 | 49 |
import org.eclipse.swt.widgets.Text; |
50 | 50 |
import org.txm.rcp.messages.TXMUIMessages; |
51 |
import org.txm.rcp.swt.widget.ComplexSubcorpusPanel;
|
|
52 |
import org.txm.rcp.swt.widget.ContextsSubcorpusPanel;
|
|
53 |
import org.txm.rcp.swt.widget.QueryWidget;
|
|
51 |
import org.txm.rcp.swt.widget.structures.AdvancedSubcorpusPanel;
|
|
52 |
import org.txm.rcp.swt.widget.structures.ComplexSubcorpusPanel;
|
|
53 |
import org.txm.rcp.swt.widget.structures.ContextsSubcorpusPanel;
|
|
54 | 54 |
import org.txm.rcp.swt.widget.structures.SimpleSubcorpusPanel; |
55 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
56 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
57 | 55 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
58 | 56 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
59 | 57 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
... | ... | |
65 | 63 |
* query to build the sub-corpus @ author mdecorde. |
66 | 64 |
*/ |
67 | 65 |
public class CreateSubcorpusDialog extends Dialog { |
68 |
// For the "simple" tab |
|
69 |
/** The selected structural unit. */ |
|
70 |
// private StructuralUnit selectedStructuralUnit; |
|
71 |
// List<StructuralUnitProperty> selectableStructuralUnitProperties = null; |
|
72 |
/** The selected structural unit property. */ |
|
73 |
// private StructuralUnitProperty selectedStructuralUnitProperty; |
|
74 | 66 |
|
75 |
/** The selected values. */ |
|
76 |
// private List<String> selectedValues; |
|
77 |
|
|
78 |
// For the assisted tab |
|
79 |
/** The simple and complex panels. */ |
|
80 |
SimpleSubcorpusPanel simplePanel; |
|
81 |
|
|
82 |
ComplexSubcorpusPanel complexPanel; |
|
83 |
|
|
84 |
ContextsSubcorpusPanel contextsPanel; |
|
85 |
|
|
86 |
// For the "advanced" tab |
|
87 |
/** The query text. */ |
|
88 |
private QueryWidget queryText; |
|
89 |
|
|
90 |
/** The query string. */ |
|
91 |
private String queryString; |
|
92 |
|
|
93 |
// for both tab |
|
67 |
// for all tabs |
|
94 | 68 |
/** The name. */ |
95 |
private Text name; |
|
69 |
private Text nameField;
|
|
96 | 70 |
|
97 | 71 |
/** The name string. */ |
98 | 72 |
private String nameString; |
... | ... | |
100 | 74 |
/** The corpus. */ |
101 | 75 |
private CQPCorpus corpus; |
102 | 76 |
|
103 |
/** The assisted selected. */
|
|
104 |
private int subcorpusMode = 0;
|
|
77 |
/** The selected subcorpus mode */
|
|
78 |
private TabItem subcorpusMode = null;
|
|
105 | 79 |
|
80 |
private TabItem simpleTab; |
|
81 |
private TabItem complexTab; |
|
82 |
private TabItem contextsTab; |
|
83 |
private TabItem advancedTab; |
|
84 |
|
|
85 |
SimpleSubcorpusPanel simplePanel; |
|
86 |
ComplexSubcorpusPanel complexPanel; |
|
87 |
ContextsSubcorpusPanel contextsPanel; |
|
88 |
AdvancedSubcorpusPanel advancedPanel; |
|
89 |
|
|
90 |
/** The query string. */ |
|
91 |
private String queryString; |
|
92 |
|
|
106 | 93 |
/** |
107 | 94 |
* Instantiates a new creates the subcorpus dialog. |
108 | 95 |
* |
... | ... | |
126 | 113 |
newShell.setMinimumSize(300, 300); |
127 | 114 |
} |
128 | 115 |
|
129 |
/** The structural units final. */ |
|
130 |
List<StructuralUnit> structuralUnitsFinal; |
|
131 |
|
|
132 |
/** The structural units combo. */ |
|
133 |
Combo structuralUnitsCombo; |
|
134 |
|
|
135 |
/** The property combo. */ |
|
136 |
Combo propertyCombo; |
|
137 |
|
|
138 |
/** The value combo. */ |
|
139 |
org.eclipse.swt.widgets.List valueCombo; |
|
140 |
|
|
141 | 116 |
/* |
142 | 117 |
* (non-Javadoc) |
143 | 118 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
... | ... | |
146 | 121 |
protected Control createDialogArea(Composite parent) { |
147 | 122 |
|
148 | 123 |
Composite inclosing = new Composite(parent, SWT.NONE); |
149 |
// TODO : we just put a composite into another composite. Everything |
|
150 |
// should be directly put into parent |
|
124 |
|
|
151 | 125 |
GridLayout layout4inclosing = new GridLayout(1, true); |
152 | 126 |
layout4inclosing.verticalSpacing = 0; |
153 | 127 |
layout4inclosing.horizontalSpacing = 0; |
... | ... | |
164 | 138 |
nameLabel.setText(TXMUIMessages.ampNameColon); |
165 | 139 |
nameLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
166 | 140 |
|
167 |
name = new Text(nameComposite, SWT.BORDER); |
|
168 |
name.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
|
141 |
nameField = new Text(nameComposite, SWT.BORDER);
|
|
142 |
nameField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
|
|
169 | 143 |
|
170 | 144 |
// Param panel |
171 | 145 |
final TabFolder tabFolder = new TabFolder(inclosing, SWT.NONE); |
172 | 146 |
tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); |
173 | 147 |
|
174 | 148 |
// First tab |
175 |
TabItem simpleTab = new TabItem(tabFolder, SWT.NONE);
|
|
149 |
simpleTab = new TabItem(tabFolder, SWT.NONE); |
|
176 | 150 |
simpleTab.setText(TXMUIMessages.simple); |
177 | 151 |
simplePanel = new SimpleSubcorpusPanel(tabFolder, SWT.NONE, this.getButton(IDialogConstants.OK_ID), corpus); |
178 | 152 |
simpleTab.setControl(simplePanel); |
179 | 153 |
|
180 | 154 |
// Second tab: assisted mode |
181 |
TabItem secondTab = new TabItem(tabFolder, SWT.NONE);
|
|
182 |
secondTab.setText(TXMUIMessages.assisted);
|
|
155 |
complexTab = new TabItem(tabFolder, SWT.NONE);
|
|
156 |
complexTab.setText(TXMUIMessages.assisted);
|
|
183 | 157 |
this.complexPanel = new ComplexSubcorpusPanel(tabFolder, SWT.NONE, this.corpus); |
184 |
secondTab.setControl(complexPanel);
|
|
158 |
complexTab.setControl(complexPanel);
|
|
185 | 159 |
|
186 | 160 |
// Third tab: assisted mode |
187 |
TabItem thirdTab = new TabItem(tabFolder, SWT.NONE);
|
|
188 |
thirdTab.setText(TXMUIMessages.contexts);
|
|
161 |
contextsTab = new TabItem(tabFolder, SWT.NONE);
|
|
162 |
contextsTab.setText(TXMUIMessages.contexts);
|
|
189 | 163 |
this.contextsPanel = new ContextsSubcorpusPanel(tabFolder, SWT.NONE, this.corpus); |
190 |
thirdTab.setControl(contextsPanel);
|
|
164 |
contextsTab.setControl(contextsPanel);
|
|
191 | 165 |
|
192 | 166 |
// Third tab: advanced mode |
193 |
TabItem advancedTab = new TabItem(tabFolder, SWT.NONE);
|
|
167 |
advancedTab = new TabItem(tabFolder, SWT.NONE); |
|
194 | 168 |
advancedTab.setText(TXMUIMessages.advanced); |
169 |
|
|
170 |
this.advancedPanel = new AdvancedSubcorpusPanel(tabFolder, SWT.NONE, this.corpus); |
|
171 |
advancedTab.setControl(advancedPanel); |
|
172 |
|
|
173 |
subcorpusMode = simpleTab; |
|
195 | 174 |
|
196 |
Composite compositeForAdvanced = new Composite(tabFolder, SWT.NONE); |
|
197 |
advancedTab.setControl(compositeForAdvanced); |
|
198 |
|
|
199 |
GridLayout layoutForAdvanced = new GridLayout(3, false); |
|
200 |
compositeForAdvanced.setLayout(layoutForAdvanced); |
|
201 |
|
|
202 |
Label advancedPartLabel = new Label(compositeForAdvanced, SWT.NONE); |
|
203 |
advancedPartLabel.setText(TXMUIMessages.ampQuery); |
|
204 |
advancedPartLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
205 |
|
|
206 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), CQPSearchEngine.getEngine()); |
|
207 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
|
208 |
GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); |
|
209 |
gridData.widthHint = convertHeightInCharsToPixels(20); |
|
210 |
queryText.setLayoutData(gridData); |
|
211 |
|
|
212 | 175 |
// check the state of the OK button according to the change of tab |
213 | 176 |
// -------------------------------- |
214 | 177 |
|
... | ... | |
220 | 183 |
@Override |
221 | 184 |
public void widgetSelected(SelectionEvent e) { |
222 | 185 |
|
223 |
subcorpusMode = tabFolder.getSelectionIndex();
|
|
186 |
subcorpusMode = tabFolder.getSelection()[0];
|
|
224 | 187 |
} |
225 | 188 |
}); |
226 | 189 |
|
227 | 190 |
return tabFolder; |
228 | 191 |
} |
229 | 192 |
|
230 |
|
|
231 |
|
|
232 | 193 |
@Override |
233 | 194 |
public Button getButton(int id) { |
195 |
|
|
234 | 196 |
return super.getButton(id); |
235 | 197 |
} |
236 | 198 |
|
... | ... | |
241 | 203 |
@Override |
242 | 204 |
protected void okPressed() { |
243 | 205 |
|
244 |
// auto-naming if needed |
|
245 |
if (name.getText().length() == 0) { |
|
206 |
if (nameField.getText().length() == 0) { // auto-naming if needed |
|
246 | 207 |
String autoName = "subcorpus"; //$NON-NLS-1$ |
247 | 208 |
|
248 | 209 |
// Advanced mode |
249 |
if (subcorpusMode == 0) {
|
|
210 |
if (subcorpusMode == simpleTab) {
|
|
250 | 211 |
autoName = this.simplePanel.getGeneratedName(); |
251 | 212 |
} |
252 |
// Assisted mode (structure@property=1st_value) |
|
253 |
else if (subcorpusMode == 1) { |
|
213 |
else if (subcorpusMode == complexTab) { // Assisted mode (structure@property=1st_value) |
|
254 | 214 |
autoName = this.complexPanel.getGeneratedName(); |
255 | 215 |
} |
256 |
else if (subcorpusMode == 2) {
|
|
216 |
else if (subcorpusMode == contextsTab) {
|
|
257 | 217 |
autoName = this.contextsPanel.getGeneratedName(); |
258 | 218 |
} |
259 |
else if (subcorpusMode == 3) {
|
|
219 |
else if (subcorpusMode == advancedTab) {
|
|
260 | 220 |
autoName += "" + (this.corpus.getSubcorpora().size() + 1); //$NON-NLS-1$ |
261 | 221 |
} else { |
262 | 222 |
autoName = this.complexPanel.getGeneratedName(); |
... | ... | |
264 | 224 |
|
265 | 225 |
Log.info(NLS.bind(TXMUIMessages.noSubcorpusNameWasSpecifiedWeveGeneratedOneP0, autoName)); |
266 | 226 |
|
267 |
name.setText(autoName); |
|
227 |
nameField.setText(autoName);
|
|
268 | 228 |
} |
269 | 229 |
|
270 |
if (subcorpusMode == 1) { |
|
271 |
|
|
230 |
if (subcorpusMode == complexTab) { |
|
272 | 231 |
// System.out.println("1 "+queryString); |
273 | 232 |
queryString = this.complexPanel.getQueryFieldValue(); |
274 | 233 |
// System.out.println("2 "+queryString); |
... | ... | |
280 | 239 |
return; |
281 | 240 |
} |
282 | 241 |
} |
283 |
|
|
284 |
} else if (subcorpusMode == 2) { |
|
285 |
|
|
242 |
} else if (subcorpusMode == contextsTab) { |
|
286 | 243 |
queryString = this.contextsPanel.getQueryString(); |
287 |
} else if (subcorpusMode == 3) { |
|
288 |
|
|
289 |
queryString = queryText.getQueryString(); |
|
244 |
} else if (subcorpusMode == advancedTab) { |
|
245 |
queryString = advancedPanel.getQueryString(); |
|
290 | 246 |
} |
291 | 247 |
|
292 |
nameString = name.getText(); |
|
248 |
nameString = nameField.getText();
|
|
293 | 249 |
super.okPressed(); |
294 | 250 |
} |
295 | 251 |
|
... | ... | |
299 | 255 |
* @return the structural unit |
300 | 256 |
*/ |
301 | 257 |
public StructuralUnit getStructuralUnit() { |
302 |
if (subcorpusMode == 3) { |
|
258 |
|
|
259 |
if (subcorpusMode == advancedTab) { |
|
303 | 260 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab); |
304 | 261 |
} |
305 | 262 |
return simplePanel.selectedStructuralUnit; |
... | ... | |
311 | 268 |
* @return the structural unit property |
312 | 269 |
*/ |
313 | 270 |
public StructuralUnitProperty getStructuralUnitProperty() { |
314 |
if (subcorpusMode == 2 || subcorpusMode == 3) { |
|
271 |
|
|
272 |
if (subcorpusMode == contextsTab || subcorpusMode == advancedTab) { |
|
315 | 273 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab); |
316 | 274 |
} |
317 | 275 |
return simplePanel.selectedStructuralUnitProperty; |
... | ... | |
323 | 281 |
* @return the values |
324 | 282 |
*/ |
325 | 283 |
public List<String> getValues() { |
326 |
if (subcorpusMode == 2 || subcorpusMode == 3) { |
|
284 |
|
|
285 |
if (subcorpusMode == contextsTab || subcorpusMode == advancedTab) { |
|
327 | 286 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab); |
328 | 287 |
} |
329 | 288 |
return simplePanel.selectedValues; |
... | ... | |
335 | 294 |
* @return the query |
336 | 295 |
*/ |
337 | 296 |
public String getQuery() { |
338 |
if (subcorpusMode == 0 ) { |
|
297 |
|
|
298 |
if (subcorpusMode == simpleTab) { |
|
339 | 299 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab); |
340 | 300 |
} |
341 | 301 |
return queryString; |
... | ... | |
347 | 307 |
* @return the name |
348 | 308 |
*/ |
349 | 309 |
public String getName() { |
310 |
|
|
350 | 311 |
return nameString; |
351 | 312 |
} |
352 | 313 |
|
... | ... | |
356 | 317 |
* @return the sub corpus name |
357 | 318 |
*/ |
358 | 319 |
public String getSubCorpusName() { |
359 |
return name.getText(); |
|
320 |
|
|
321 |
return nameField.getText(); |
|
360 | 322 |
} |
361 | 323 |
|
362 |
public int getMode() {
|
|
363 |
|
|
364 |
return subcorpusMode; |
|
324 |
public boolean isQueryBased() {
|
|
325 |
|
|
326 |
return subcorpusMode == complexTab || subcorpusMode == contextsTab || subcorpusMode == advancedTab;
|
|
365 | 327 |
} |
366 | 328 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/ComplexSubcorpusPanel.java (revision 3977) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
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.rcp.swt.widget; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.LinkedHashSet; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.apache.commons.lang.StringUtils; |
|
36 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
37 |
import org.eclipse.jface.viewers.ISelection; |
|
38 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
39 |
import org.eclipse.jface.viewers.ListViewer; |
|
40 |
import org.eclipse.swt.SWT; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.events.SelectionListener; |
|
43 |
import org.eclipse.swt.layout.GridData; |
|
44 |
import org.eclipse.swt.layout.GridLayout; |
|
45 |
import org.eclipse.swt.widgets.Button; |
|
46 |
import org.eclipse.swt.widgets.Combo; |
|
47 |
import org.eclipse.swt.widgets.Composite; |
|
48 |
import org.eclipse.swt.widgets.Group; |
|
49 |
import org.eclipse.swt.widgets.Label; |
|
50 |
import org.eclipse.swt.widgets.Text; |
|
51 |
import org.txm.core.messages.TXMCoreMessages; |
|
52 |
import org.txm.rcp.messages.TXMUIMessages; |
|
53 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
54 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
55 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
56 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
57 |
|
|
58 |
// TODO: Auto-generated Javadoc |
|
59 |
/** |
|
60 |
* The Class ComplexSubcorpusPanel. |
|
61 |
*/ |
|
62 |
public class ComplexSubcorpusPanel extends Composite { |
|
63 |
|
|
64 |
/** The self. */ |
|
65 |
ComplexSubcorpusPanel self; |
|
66 |
|
|
67 |
/** The corpus. */ |
|
68 |
CQPCorpus corpus; |
|
69 |
|
|
70 |
/** The query. */ |
|
71 |
String query; |
|
72 |
|
|
73 |
/** The btn area. */ |
|
74 |
Composite parent, partArea, firstArea, dispoArea, btnArea; |
|
75 |
|
|
76 |
/** The structuralunits. */ |
|
77 |
List<StructuralUnit> structuralunits; |
|
78 |
|
|
79 |
/** The structural units properties. */ |
|
80 |
HashMap<StructuralUnit, List<StructuralUnitProperty>> structuralUnitsProperties = new HashMap<>(); |
|
81 |
|
|
82 |
/** The query items. */ |
|
83 |
ArrayList<QueryItem> queryItems = new ArrayList<>(); |
|
84 |
|
|
85 |
/** The queries panel. */ |
|
86 |
Composite queriesPanel; |
|
87 |
|
|
88 |
/** The query field. */ |
|
89 |
Text queryField; |
|
90 |
|
|
91 |
/** The and btn. */ |
|
92 |
Button andBtn; |
|
93 |
|
|
94 |
/** |
|
95 |
* Instantiates a new complex subcorpus panel. |
|
96 |
* |
|
97 |
* @param parent the parent |
|
98 |
* @param style the style |
|
99 |
* @param corpus the corpus |
|
100 |
*/ |
|
101 |
public ComplexSubcorpusPanel(Composite parent, int style, CQPCorpus corpus) { |
|
102 |
super(parent, style); |
|
103 |
self = this; |
|
104 |
this.setLayout(new GridLayout(3, false)); |
|
105 |
this.corpus = corpus; |
|
106 |
|
|
107 |
try { |
|
108 |
this.structuralunits = new ArrayList<>(corpus.getOrderedStructuralUnits()); |
|
109 |
for (int i = 0; i < this.structuralunits.size(); i++) { |
|
110 |
if (this.structuralunits.get(i).getName().equals("txmcorpus")) { //$NON-NLS-1$ |
|
111 |
this.structuralunits.remove(i); |
|
112 |
i--; |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
catch (CqiClientException e) { |
|
117 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
118 |
} |
|
119 |
|
|
120 |
for (StructuralUnit su : this.structuralunits) { |
|
121 |
List<StructuralUnitProperty> properties = new ArrayList<>(su.getOrderedProperties()); |
|
122 |
if (su.getName().equals("text")) { //$NON-NLS-1$ |
|
123 |
for (int i = 0; i < properties.size(); i++) { |
|
124 |
if (properties.get(i).getName().equals("base") || //$NON-NLS-1$ |
|
125 |
properties.get(i).getName().equals("project")) { //$NON-NLS-1$ |
|
126 |
properties.remove(i); |
|
127 |
i--; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
structuralUnitsProperties.put(su, properties); |
|
132 |
} |
|
133 |
|
|
134 |
Label firstStep = new Label(this, SWT.NONE); |
|
135 |
firstStep.setText(TXMUIMessages.oneConfigure); |
|
136 |
firstStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
137 |
firstStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
138 |
|
|
139 |
Group andorGroup = new Group(this, SWT.SHADOW_ETCHED_IN); |
|
140 |
andorGroup.setText(TXMUIMessages.match); |
|
141 |
andorGroup.setLayout(new GridLayout(2, false)); |
|
142 |
andorGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1)); |
|
143 |
|
|
144 |
andBtn = new Button(andorGroup, SWT.RADIO); |
|
145 |
andBtn.setText(TXMUIMessages.allCriteria); |
|
146 |
andBtn.setSelection(true); |
|
147 |
|
|
148 |
Button orBtn = new Button(andorGroup, SWT.RADIO); |
|
149 |
orBtn.setText(TXMUIMessages.someCriteria); |
|
150 |
orBtn.setSelection(false); |
|
151 |
|
|
152 |
queriesPanel = new Composite(this, SWT.NONE); |
|
153 |
queriesPanel.setLayout(new GridLayout(1, false)); |
|
154 |
queriesPanel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1)); |
|
155 |
QueryItem item = new QueryItem(queriesPanel, SWT.NONE); |
|
156 |
item.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
157 |
queryItems.add(item); |
|
158 |
// choix OU / ET |
|
159 |
// 3 combos : struc, prop, value |
|
160 |
// Add/Rmv contrainte |
|
161 |
// affichage requete |
|
162 |
|
|
163 |
Label secondStep = new Label(this, SWT.NONE); |
|
164 |
secondStep.setText(TXMUIMessages.twoGenerateTheQuery); |
|
165 |
secondStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
166 |
secondStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
167 |
|
|
168 |
Label l = new Label(this, SWT.NONE); |
|
169 |
l.setText(TXMUIMessages.query); |
|
170 |
|
|
171 |
queryField = new Text(this, SWT.BORDER); |
|
172 |
queryField.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
173 |
|
|
174 |
Button refreshBtn = new Button(this, SWT.PUSH); |
|
175 |
refreshBtn.setText(TXMUIMessages.refreshTheQuery); |
|
176 |
refreshBtn.addSelectionListener(new SelectionListener() { |
|
177 |
|
|
178 |
@Override |
|
179 |
public void widgetSelected(SelectionEvent e) { |
|
180 |
updateQueryField(); |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
184 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
185 |
|
|
186 |
} |
|
187 |
}); |
|
188 |
|
|
189 |
// first init |
|
190 |
updateQueryField(); |
|
191 |
} |
|
192 |
|
|
193 |
public void updateQueryField() { |
|
194 |
queryField.setText(getQueryString()); |
|
195 |
queryField.update(); |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Update display. |
|
200 |
*/ |
|
201 |
public void updateDisplay() { |
|
202 |
firstArea.layout(); |
|
203 |
dispoArea.layout(); |
|
204 |
partArea.layout(); |
|
205 |
btnArea.layout(); |
|
206 |
parent.layout(); |
|
207 |
parent.getParent().layout(); |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Gets the query string. |
|
212 |
* |
|
213 |
* @return the query string |
|
214 |
*/ |
|
215 |
public String getQueryString() { |
|
216 |
|
|
217 |
LinkedHashSet<String> parts = new LinkedHashSet<>(); // to avoid duplicates |
|
218 |
for (QueryItem item : queryItems) { |
|
219 |
|
|
220 |
String query = ""; //$NON-NLS-1$ |
|
221 |
|
|
222 |
String prop = item.selectedSup.getFullName(); |
|
223 |
IStructuredSelection sel = item.valueCombo.getStructuredSelection(); |
|
224 |
String value = StringUtils.join(sel.toList(), "|"); //$NON-NLS-1$ |
|
225 |
|
|
226 |
int test = item.testCombo.getSelectionIndex(); |
|
227 |
|
|
228 |
if (test == 0) // is |
|
229 |
query = " _."+ prop + "=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
230 |
else if (test == 1) // is not |
|
231 |
query = " _."+ prop + "!=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
232 |
else if (test == 2) // contains |
|
233 |
query = " _."+ prop + "=\".*" + value + ".*\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
234 |
else // does not contain |
|
235 |
query = " _."+ prop + "!=\".*" + value + ".*\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
236 |
|
|
237 |
parts.add(query); |
|
238 |
} |
|
239 |
|
|
240 |
String sep = " | "; //$NON-NLS-1$ |
|
241 |
if (andBtn.getSelection()) { |
|
242 |
sep = " & "; //$NON-NLS-1$ |
|
243 |
} |
|
244 |
|
|
245 |
return "["+ StringUtils.join(parts, sep)+"] expand to "+queryItems.get(queryItems.size() - 1).structCombo.getText(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
246 |
|
|
247 |
} |
|
248 |
|
|
249 |
public String getQueryFieldValue() { |
|
250 |
String query = this.queryField.getText(); |
|
251 |
if (query == null || query.length() == 0) { |
|
252 |
query = getQueryString(); |
|
253 |
} |
|
254 |
return query; |
|
255 |
} |
|
256 |
|
|
257 |
public String getGeneratedName() { |
|
258 |
|
|
259 |
LinkedHashSet<String> parts = new LinkedHashSet<>(); |
|
260 |
|
|
261 |
for (QueryItem queryItem : queryItems) { |
|
262 |
|
|
263 |
String testString = "="; //$NON-NLS-1$ |
|
264 |
int test = queryItem.testCombo.getSelectionIndex(); |
|
265 |
if (test == 0) // is |
|
266 |
testString = "="; //$NON-NLS-1$ |
|
267 |
else if (test == 1) // is not |
|
268 |
testString = "!="; //$NON-NLS-1$ |
|
269 |
else if (test == 2) // contains |
|
270 |
testString = " contains "; //$NON-NLS-1$ |
|
271 |
else // does not contain |
|
272 |
testString = " does not contains"; //$NON-NLS-1$ |
|
273 |
|
|
274 |
String generated = queryItem.selectedSup.asFullNameString() + testString + queryItem.valueCombo.getList().getSelection()[0]; |
|
275 |
parts.add(generated); |
|
276 |
} |
|
277 |
|
|
278 |
String sep = " | "; //$NON-NLS-1$ |
|
279 |
if (andBtn.getSelection()) |
|
280 |
sep = " & "; //$NON-NLS-1$ |
|
281 |
|
|
282 |
return StringUtils.join(parts, sep); |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* The Class QueryItem. |
|
287 |
*/ |
|
288 |
class QueryItem extends Composite { |
|
289 |
|
|
290 |
/** The struct combo. */ |
|
291 |
Combo structCombo; |
|
292 |
|
|
293 |
/** The prop combo. */ |
|
294 |
Combo propCombo; |
|
295 |
|
|
296 |
/** The test combo. */ |
|
297 |
Combo testCombo; |
|
298 |
|
|
299 |
/** The value combo. */ |
|
300 |
ListViewer valueCombo; |
|
301 |
|
|
302 |
/** The sups. */ |
|
303 |
List<StructuralUnitProperty> sups; |
|
304 |
|
|
305 |
/** The selected sup. */ |
|
306 |
StructuralUnitProperty selectedSup; |
|
307 |
|
|
308 |
/** The selected su. */ |
|
309 |
StructuralUnit selectedSu; |
|
310 |
|
|
311 |
/** |
|
312 |
* Instantiates a new query item. |
|
313 |
* |
|
314 |
* @param parent the parent |
|
315 |
* @param style the style |
|
316 |
*/ |
|
317 |
public QueryItem(Composite parent, int style) { |
|
318 |
super(parent, style); |
|
319 |
|
|
320 |
this.setLayout(new GridLayout(7, false)); |
|
321 |
|
|
322 |
// structure choice |
|
323 |
Label l = new Label(this, SWT.None); |
|
324 |
l.setText(TXMCoreMessages.common_structure); |
|
325 |
|
|
326 |
structCombo = new Combo(this, SWT.READ_ONLY); |
|
327 |
structCombo.addSelectionListener(new SelectionListener() { |
|
328 |
|
|
329 |
@Override |
|
330 |
public void widgetSelected(SelectionEvent e) { |
|
331 |
for (QueryItem item : queryItems) |
|
332 |
item.refreshProps(); |
|
333 |
} |
|
334 |
|
|
335 |
@Override |
|
336 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
337 |
}); |
|
338 |
|
|
339 |
int i_text = 0, i = 0; |
|
340 |
for (StructuralUnit su : structuralunits) { |
|
341 |
structCombo.add(su.getName()); |
|
342 |
if (su.getName().equals("text")) i_text = i; //$NON-NLS-1$ |
|
343 |
i++; |
|
344 |
} |
|
345 |
|
|
346 |
if (structuralunits.size() > 0) { |
|
347 |
structCombo.select(i_text); |
|
348 |
} |
|
349 |
|
|
350 |
propCombo = new Combo(this, SWT.READ_ONLY); |
|
351 |
propCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
352 |
propCombo.addSelectionListener(new SelectionListener() { |
|
353 |
|
|
354 |
@Override |
|
355 |
public void widgetSelected(SelectionEvent e) { |
|
356 |
refreshValues(); |
|
357 |
} |
|
358 |
|
|
359 |
@Override |
|
360 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
361 |
}); |
|
362 |
|
|
363 |
testCombo = new Combo(this, SWT.READ_ONLY); |
|
364 |
testCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
365 |
testCombo.add("is"); //$NON-NLS-1$ |
|
366 |
testCombo.add("is not"); //$NON-NLS-1$ |
|
367 |
testCombo.add(TXMUIMessages.contains); |
|
368 |
testCombo.add(TXMUIMessages.doesNotContain); |
|
369 |
testCombo.select(0); |
|
370 |
|
|
371 |
valueCombo = new ListViewer(this, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL); |
|
372 |
valueCombo.setContentProvider(new ArrayContentProvider()); |
|
373 |
GridData data = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
374 |
data.heightHint = testCombo.getItemHeight(); |
|
375 |
valueCombo.getList().setLayoutData(data); |
|
376 |
if (structuralunits.size() > 0) { |
|
377 |
refreshProps(); |
|
378 |
} |
|
379 |
|
|
380 |
Button btnAdd = new Button(this, SWT.PUSH); |
|
381 |
btnAdd.setText("+"); //$NON-NLS-1$ |
|
382 |
btnAdd.addSelectionListener(new SelectionListener() { |
|
383 |
|
|
384 |
@Override |
|
385 |
public void widgetSelected(SelectionEvent e) { |
|
386 |
// System.out.println("add constraint"); |
|
387 |
QueryItem item = new QueryItem(queriesPanel, SWT.NONE); |
|
388 |
item.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
389 |
queryItems.add(item); |
|
390 |
ComplexSubcorpusPanel.this.layout(); |
|
391 |
// System.out.println(getQueryString()); |
|
392 |
} |
|
393 |
|
|
394 |
@Override |
|
395 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
396 |
}); |
|
397 |
|
|
398 |
Button btnRmv = new Button(this, SWT.PUSH); |
|
399 |
btnRmv.setText("-"); //$NON-NLS-1$ |
|
400 |
btnRmv.addSelectionListener(new SelectionListener() { |
|
401 |
|
|
402 |
@Override |
|
403 |
public void widgetSelected(SelectionEvent e) { |
|
404 |
if (queryItems.size() > 1) { |
|
405 |
QueryItem.this.dispose(); |
|
406 |
queryItems.remove(QueryItem.this); |
|
407 |
ComplexSubcorpusPanel.this.layout(); |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
@Override |
|
412 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
413 |
}); |
|
414 |
} |
|
415 |
|
|
416 |
/** |
|
417 |
* Refresh props. |
|
418 |
*/ |
|
419 |
private void refreshProps() { |
|
420 |
propCombo.removeAll(); |
|
421 |
selectedSu = structuralunits.get(structCombo.getSelectionIndex()); |
|
422 |
sups = structuralUnitsProperties.get(selectedSu); |
|
423 |
|
|
424 |
for (StructuralUnitProperty sup : sups) |
|
425 |
propCombo.add(sup.getName()); |
|
426 |
|
|
427 |
if (sups.size() > 0) { |
|
428 |
selectedSup = sups.get(0); |
|
429 |
propCombo.select(0); |
|
430 |
refreshValues(); |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
434 |
/** |
|
435 |
* Refresh values. |
|
436 |
*/ |
|
437 |
private void refreshValues() { |
|
438 |
|
|
439 |
selectedSup = sups.get(propCombo.getSelectionIndex()); |
|
440 |
try { |
|
441 |
valueCombo.setInput(selectedSup.getOrderedValues()); |
|
442 |
} |
|
443 |
catch (CqiClientException e1) { |
|
444 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
445 |
} |
|
446 |
if (valueCombo.getList().getItemCount() > 0) |
|
447 |
valueCombo.getList().select(0); |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* Gets the structural unit. |
|
452 |
* |
|
453 |
* @return the structural unit |
|
454 |
*/ |
|
455 |
public StructuralUnit getStructuralUnit() { |
|
456 |
return null; |
|
457 |
} |
|
458 |
} |
|
459 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/ComplexSubcorpusPanel.java (revision 3977) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
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.rcp.swt.widget.structures; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.LinkedHashSet; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.apache.commons.lang.StringUtils; |
|
36 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
37 |
import org.eclipse.jface.viewers.ISelection; |
|
38 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
39 |
import org.eclipse.jface.viewers.ListViewer; |
|
40 |
import org.eclipse.swt.SWT; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.events.SelectionListener; |
|
43 |
import org.eclipse.swt.layout.GridData; |
|
44 |
import org.eclipse.swt.layout.GridLayout; |
|
45 |
import org.eclipse.swt.widgets.Button; |
|
46 |
import org.eclipse.swt.widgets.Combo; |
|
47 |
import org.eclipse.swt.widgets.Composite; |
|
48 |
import org.eclipse.swt.widgets.Group; |
|
49 |
import org.eclipse.swt.widgets.Label; |
|
50 |
import org.eclipse.swt.widgets.Text; |
|
51 |
import org.txm.core.messages.TXMCoreMessages; |
|
52 |
import org.txm.rcp.messages.TXMUIMessages; |
|
53 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
54 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
55 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
56 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
57 |
|
|
58 |
// TODO: Auto-generated Javadoc |
|
59 |
/** |
|
60 |
* The Class ComplexSubcorpusPanel. |
|
61 |
*/ |
|
62 |
public class ComplexSubcorpusPanel extends Composite { |
|
63 |
|
|
64 |
/** The self. */ |
|
65 |
|
|
66 |
/** The corpus. */ |
|
67 |
CQPCorpus corpus; |
|
68 |
|
|
69 |
/** The query. */ |
|
70 |
String query; |
|
71 |
|
|
72 |
/** The btn area. */ |
|
73 |
Composite parent, partArea, firstArea, dispoArea, btnArea; |
|
74 |
|
|
75 |
/** The structuralunits. */ |
|
76 |
List<StructuralUnit> structuralunits; |
|
77 |
|
|
78 |
/** The structural units properties. */ |
|
79 |
HashMap<StructuralUnit, List<StructuralUnitProperty>> structuralUnitsProperties = new HashMap<>(); |
|
80 |
|
|
81 |
/** The query items. */ |
|
82 |
ArrayList<QueryItem> queryItems = new ArrayList<>(); |
|
83 |
|
|
84 |
/** The queries panel. */ |
|
85 |
Composite queriesPanel; |
|
86 |
|
|
87 |
/** The query field. */ |
|
88 |
Text queryField; |
|
89 |
|
|
90 |
/** The and btn. */ |
|
91 |
Button andBtn; |
|
92 |
|
|
93 |
/** |
|
94 |
* Instantiates a new complex subcorpus panel. |
|
95 |
* |
|
96 |
* @param parent the parent |
|
97 |
* @param style the style |
|
98 |
* @param corpus the corpus |
|
99 |
*/ |
|
100 |
public ComplexSubcorpusPanel(Composite parent, int style, CQPCorpus corpus) { |
|
101 |
super(parent, style); |
|
102 |
this.setLayout(new GridLayout(3, false)); |
|
103 |
this.corpus = corpus; |
|
104 |
|
|
105 |
try { |
|
106 |
this.structuralunits = new ArrayList<>(corpus.getOrderedStructuralUnits()); |
|
107 |
for (int i = 0; i < this.structuralunits.size(); i++) { |
|
108 |
if (this.structuralunits.get(i).getName().equals("txmcorpus")) { //$NON-NLS-1$ |
|
109 |
this.structuralunits.remove(i); |
|
110 |
i--; |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
catch (CqiClientException e) { |
|
115 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
116 |
} |
|
117 |
|
|
118 |
for (StructuralUnit su : this.structuralunits) { |
|
119 |
List<StructuralUnitProperty> properties = new ArrayList<>(su.getOrderedProperties()); |
|
120 |
if (su.getName().equals("text")) { //$NON-NLS-1$ |
|
121 |
for (int i = 0; i < properties.size(); i++) { |
|
122 |
if (properties.get(i).getName().equals("base") || //$NON-NLS-1$ |
|
123 |
properties.get(i).getName().equals("project")) { //$NON-NLS-1$ |
|
124 |
properties.remove(i); |
|
125 |
i--; |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
structuralUnitsProperties.put(su, properties); |
|
130 |
} |
|
131 |
|
|
132 |
Label firstStep = new Label(this, SWT.NONE); |
|
133 |
firstStep.setText(TXMUIMessages.oneConfigure); |
|
134 |
firstStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
135 |
firstStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
136 |
|
|
137 |
Group andorGroup = new Group(this, SWT.SHADOW_ETCHED_IN); |
|
138 |
andorGroup.setText(TXMUIMessages.match); |
|
139 |
andorGroup.setLayout(new GridLayout(2, false)); |
|
140 |
andorGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1)); |
|
141 |
|
|
142 |
andBtn = new Button(andorGroup, SWT.RADIO); |
|
143 |
andBtn.setText(TXMUIMessages.allCriteria); |
|
144 |
andBtn.setSelection(true); |
|
145 |
|
|
146 |
Button orBtn = new Button(andorGroup, SWT.RADIO); |
|
147 |
orBtn.setText(TXMUIMessages.someCriteria); |
|
148 |
orBtn.setSelection(false); |
|
149 |
|
|
150 |
queriesPanel = new Composite(this, SWT.NONE); |
|
151 |
queriesPanel.setLayout(new GridLayout(1, false)); |
|
152 |
queriesPanel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1)); |
|
153 |
QueryItem item = new QueryItem(queriesPanel, SWT.NONE); |
|
154 |
item.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
155 |
queryItems.add(item); |
|
156 |
// choix OU / ET |
|
157 |
// 3 combos : struc, prop, value |
|
158 |
// Add/Rmv contrainte |
|
159 |
// affichage requete |
|
160 |
|
|
161 |
Label secondStep = new Label(this, SWT.NONE); |
|
162 |
secondStep.setText(TXMUIMessages.twoGenerateTheQuery); |
|
163 |
secondStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
164 |
secondStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
165 |
|
|
166 |
Label l = new Label(this, SWT.NONE); |
|
167 |
l.setText(TXMUIMessages.query); |
|
168 |
|
|
169 |
queryField = new Text(this, SWT.BORDER); |
|
170 |
queryField.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
171 |
|
|
172 |
Button refreshBtn = new Button(this, SWT.PUSH); |
|
173 |
refreshBtn.setText(TXMUIMessages.refreshTheQuery); |
|
174 |
refreshBtn.addSelectionListener(new SelectionListener() { |
|
175 |
|
|
176 |
@Override |
|
177 |
public void widgetSelected(SelectionEvent e) { |
|
178 |
updateQueryField(); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
183 |
|
|
184 |
} |
|
185 |
}); |
|
186 |
|
|
187 |
// first init |
|
188 |
updateQueryField(); |
|
189 |
} |
|
190 |
|
|
191 |
public void updateQueryField() { |
|
192 |
queryField.setText(getQueryString()); |
|
193 |
queryField.update(); |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* Update display. |
|
198 |
*/ |
|
199 |
public void updateDisplay() { |
|
200 |
firstArea.layout(); |
|
201 |
dispoArea.layout(); |
|
202 |
partArea.layout(); |
|
203 |
btnArea.layout(); |
|
204 |
parent.layout(); |
|
205 |
parent.getParent().layout(); |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Gets the query string. |
|
210 |
* |
|
211 |
* @return the query string |
|
212 |
*/ |
|
213 |
public String getQueryString() { |
|
214 |
|
|
215 |
LinkedHashSet<String> parts = new LinkedHashSet<>(); // to avoid duplicates |
|
216 |
for (QueryItem item : queryItems) { |
|
217 |
|
|
218 |
String query = ""; //$NON-NLS-1$ |
|
219 |
|
|
220 |
String prop = item.selectedSup.getFullName(); |
|
221 |
IStructuredSelection sel = item.valueCombo.getStructuredSelection(); |
|
222 |
String value = StringUtils.join(sel.toList(), "|"); //$NON-NLS-1$ |
|
223 |
|
|
224 |
int test = item.testCombo.getSelectionIndex(); |
|
225 |
|
|
226 |
if (test == 0) // is |
|
227 |
query = " _."+ prop + "=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
228 |
else if (test == 1) // is not |
|
229 |
query = " _."+ prop + "!=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
230 |
else if (test == 2) // contains |
|
231 |
query = " _."+ prop + "=\".*" + value + ".*\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
232 |
else // does not contain |
|
233 |
query = " _."+ prop + "!=\".*" + value + ".*\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
234 |
|
|
235 |
parts.add(query); |
|
236 |
} |
|
237 |
|
|
238 |
String sep = " | "; //$NON-NLS-1$ |
|
239 |
if (andBtn.getSelection()) { |
|
240 |
sep = " & "; //$NON-NLS-1$ |
|
241 |
} |
|
242 |
|
|
243 |
return "["+ StringUtils.join(parts, sep)+"] expand to "+queryItems.get(queryItems.size() - 1).structCombo.getText(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
244 |
|
|
245 |
} |
|
246 |
|
|
247 |
public String getQueryFieldValue() { |
|
248 |
String query = this.queryField.getText(); |
|
249 |
if (query == null || query.length() == 0) { |
|
250 |
query = getQueryString(); |
|
251 |
} |
|
252 |
return query; |
|
253 |
} |
|
254 |
|
|
255 |
public String getGeneratedName() { |
|
256 |
|
|
257 |
LinkedHashSet<String> parts = new LinkedHashSet<>(); |
|
258 |
|
|
259 |
for (QueryItem queryItem : queryItems) { |
|
260 |
|
|
261 |
String testString = "="; //$NON-NLS-1$ |
|
262 |
int test = queryItem.testCombo.getSelectionIndex(); |
|
263 |
if (test == 0) // is |
|
264 |
testString = "="; //$NON-NLS-1$ |
|
265 |
else if (test == 1) // is not |
|
266 |
testString = "!="; //$NON-NLS-1$ |
|
267 |
else if (test == 2) // contains |
|
268 |
testString = " contains "; //$NON-NLS-1$ |
|
269 |
else // does not contain |
|
270 |
testString = " does not contains"; //$NON-NLS-1$ |
|
271 |
|
|
272 |
String generated = queryItem.selectedSup.asFullNameString() + testString + queryItem.valueCombo.getList().getSelection()[0]; |
|
273 |
parts.add(generated); |
|
274 |
} |
|
275 |
|
|
276 |
String sep = " | "; //$NON-NLS-1$ |
|
277 |
if (andBtn.getSelection()) |
|
278 |
sep = " & "; //$NON-NLS-1$ |
|
279 |
|
|
280 |
return StringUtils.join(parts, sep); |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* The Class QueryItem. |
|
285 |
*/ |
|
286 |
class QueryItem extends Composite { |
|
287 |
|
|
288 |
/** The struct combo. */ |
|
289 |
Combo structCombo; |
|
290 |
|
|
291 |
/** The prop combo. */ |
|
292 |
Combo propCombo; |
|
293 |
|
|
294 |
/** The test combo. */ |
|
295 |
Combo testCombo; |
|
296 |
|
|
297 |
/** The value combo. */ |
|
298 |
ListViewer valueCombo; |
|
299 |
|
|
300 |
/** The sups. */ |
|
301 |
List<StructuralUnitProperty> sups; |
|
302 |
|
|
303 |
/** The selected sup. */ |
|
304 |
StructuralUnitProperty selectedSup; |
|
305 |
|
|
306 |
/** The selected su. */ |
|
307 |
StructuralUnit selectedSu; |
|
308 |
|
|
309 |
/** |
|
310 |
* Instantiates a new query item. |
|
311 |
* |
|
312 |
* @param parent the parent |
|
313 |
* @param style the style |
|
314 |
*/ |
|
315 |
public QueryItem(Composite parent, int style) { |
|
316 |
super(parent, style); |
|
317 |
|
|
318 |
this.setLayout(new GridLayout(7, false)); |
|
319 |
|
|
320 |
// structure choice |
|
321 |
Label l = new Label(this, SWT.None); |
|
322 |
l.setText(TXMCoreMessages.common_structure); |
|
323 |
|
|
324 |
structCombo = new Combo(this, SWT.READ_ONLY); |
|
325 |
structCombo.addSelectionListener(new SelectionListener() { |
|
326 |
|
|
327 |
@Override |
|
328 |
public void widgetSelected(SelectionEvent e) { |
|
329 |
for (QueryItem item : queryItems) |
|
330 |
item.refreshProps(); |
|
331 |
} |
|
332 |
|
|
333 |
@Override |
|
334 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
335 |
}); |
|
336 |
|
|
337 |
int i_text = 0, i = 0; |
|
338 |
for (StructuralUnit su : structuralunits) { |
|
339 |
structCombo.add(su.getName()); |
|
340 |
if (su.getName().equals("text")) i_text = i; //$NON-NLS-1$ |
|
341 |
i++; |
|
342 |
} |
|
343 |
|
|
344 |
if (structuralunits.size() > 0) { |
|
345 |
structCombo.select(i_text); |
|
346 |
} |
|
347 |
|
|
348 |
propCombo = new Combo(this, SWT.READ_ONLY); |
|
349 |
propCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
350 |
propCombo.addSelectionListener(new SelectionListener() { |
|
351 |
|
|
352 |
@Override |
|
353 |
public void widgetSelected(SelectionEvent e) { |
|
354 |
refreshValues(); |
|
355 |
} |
|
356 |
|
|
357 |
@Override |
|
358 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
359 |
}); |
|
360 |
|
|
361 |
testCombo = new Combo(this, SWT.READ_ONLY); |
|
362 |
testCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
363 |
testCombo.add("is"); //$NON-NLS-1$ |
|
364 |
testCombo.add("is not"); //$NON-NLS-1$ |
|
365 |
testCombo.add(TXMUIMessages.contains); |
|
366 |
testCombo.add(TXMUIMessages.doesNotContain); |
|
367 |
testCombo.select(0); |
|
368 |
|
|
369 |
valueCombo = new ListViewer(this, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL); |
|
370 |
valueCombo.setContentProvider(new ArrayContentProvider()); |
|
371 |
GridData data = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
372 |
data.heightHint = testCombo.getItemHeight(); |
|
373 |
valueCombo.getList().setLayoutData(data); |
|
374 |
if (structuralunits.size() > 0) { |
|
375 |
refreshProps(); |
|
376 |
} |
|
377 |
|
|
378 |
Button btnAdd = new Button(this, SWT.PUSH); |
|
379 |
btnAdd.setText("+"); //$NON-NLS-1$ |
|
380 |
btnAdd.addSelectionListener(new SelectionListener() { |
|
381 |
|
|
382 |
@Override |
|
383 |
public void widgetSelected(SelectionEvent e) { |
|
384 |
// System.out.println("add constraint"); |
|
385 |
QueryItem item = new QueryItem(queriesPanel, SWT.NONE); |
|
386 |
item.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
387 |
queryItems.add(item); |
|
388 |
ComplexSubcorpusPanel.this.layout(); |
|
389 |
// System.out.println(getQueryString()); |
|
390 |
} |
|
391 |
|
|
392 |
@Override |
|
393 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
394 |
}); |
|
395 |
|
|
396 |
Button btnRmv = new Button(this, SWT.PUSH); |
|
397 |
btnRmv.setText("-"); //$NON-NLS-1$ |
|
398 |
btnRmv.addSelectionListener(new SelectionListener() { |
|
399 |
|
|
400 |
@Override |
|
401 |
public void widgetSelected(SelectionEvent e) { |
|
402 |
if (queryItems.size() > 1) { |
|
403 |
QueryItem.this.dispose(); |
|
404 |
queryItems.remove(QueryItem.this); |
|
405 |
ComplexSubcorpusPanel.this.layout(); |
|
406 |
} |
|
407 |
} |
|
408 |
|
|
409 |
@Override |
|
410 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
411 |
}); |
|
412 |
} |
|
413 |
|
|
414 |
/** |
|
415 |
* Refresh props. |
|
416 |
*/ |
|
417 |
private void refreshProps() { |
|
418 |
propCombo.removeAll(); |
|
419 |
selectedSu = structuralunits.get(structCombo.getSelectionIndex()); |
|
420 |
sups = structuralUnitsProperties.get(selectedSu); |
|
421 |
|
|
422 |
for (StructuralUnitProperty sup : sups) |
|
423 |
propCombo.add(sup.getName()); |
|
424 |
|
|
425 |
if (sups.size() > 0) { |
|
426 |
selectedSup = sups.get(0); |
|
427 |
propCombo.select(0); |
|
428 |
refreshValues(); |
|
429 |
} |
|
430 |
} |
|
431 |
|
|
432 |
/** |
|
433 |
* Refresh values. |
|
434 |
*/ |
|
435 |
private void refreshValues() { |
|
436 |
|
|
437 |
selectedSup = sups.get(propCombo.getSelectionIndex()); |
|
438 |
try { |
|
439 |
valueCombo.setInput(selectedSup.getOrderedValues()); |
|
440 |
} |
|
441 |
catch (CqiClientException e1) { |
|
442 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
443 |
} |
|
444 |
if (valueCombo.getList().getItemCount() > 0) |
|
445 |
valueCombo.getList().select(0); |
|
446 |
} |
|
447 |
|
|
448 |
/** |
|
449 |
* Gets the structural unit. |
|
450 |
* |
|
451 |
* @return the structural unit |
|
452 |
*/ |
|
453 |
public StructuralUnit getStructuralUnit() { |
|
454 |
return null; |
|
455 |
} |
|
456 |
} |
|
457 |
} |
|
0 | 458 |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/SimpleSubcorpusPanel.java (revision 3977) | ||
---|---|---|
5 | 5 |
import java.util.List; |
6 | 6 |
|
7 | 7 |
import org.apache.commons.lang.StringUtils; |
8 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
9 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
10 |
import org.eclipse.jface.viewers.ISelection; |
|
11 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
12 |
import org.eclipse.jface.viewers.ListViewer; |
|
13 | 8 |
import org.eclipse.swt.SWT; |
14 | 9 |
import org.eclipse.swt.events.SelectionEvent; |
15 | 10 |
import org.eclipse.swt.events.SelectionListener; |
... | ... | |
20 | 15 |
import org.eclipse.swt.widgets.Composite; |
21 | 16 |
import org.eclipse.swt.widgets.Label; |
22 | 17 |
import org.txm.core.messages.TXMCoreMessages; |
23 |
import org.txm.rcp.actions.CreateSubcorpusDialog; |
|
24 | 18 |
import org.txm.rcp.messages.TXMUIMessages; |
25 | 19 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
26 | 20 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
... | ... | |
30 | 24 |
import org.txm.searchengine.cqp.corpus.query.SubcorpusCQLQuery; |
31 | 25 |
import org.txm.utils.logger.Log; |
32 | 26 |
|
33 |
import cern.colt.Arrays; |
|
34 |
|
|
35 | 27 |
public class SimpleSubcorpusPanel extends Composite { |
36 | 28 |
|
37 | 29 |
public StructuralUnit selectedStructuralUnit; |
TXM/trunk/bundles/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/ComputeSubCorpus.java (revision 3977) | ||
---|---|---|
172 | 172 |
monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100); |
173 | 173 |
final Subcorpus subcorpus; |
174 | 174 |
|
175 |
if (d.getMode() == 1 || d.getMode() == 2 || d.getMode() == 3) {
|
|
175 |
if (d.isQueryBased()) {
|
|
176 | 176 |
|
177 | 177 |
// test if a query has been set |
178 | 178 |
if (d.getQuery().length() == 0) { |
TXM/trunk/bundles/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/editor/SubcorpusEditor.java (revision 3977) | ||
---|---|---|
26 | 26 |
import org.txm.rcp.editors.listeners.ComputeKeyListener; |
27 | 27 |
import org.txm.rcp.messages.TXMUIMessages; |
28 | 28 |
import org.txm.rcp.swt.widget.AssistedChoiceQueryWidget; |
29 |
import org.txm.rcp.swt.widget.ComplexSubcorpusPanel; |
|
29 |
import org.txm.rcp.swt.widget.structures.ComplexSubcorpusPanel;
|
|
30 | 30 |
import org.txm.rcp.swt.widget.structures.SimpleSubcorpusPanel; |
31 | 31 |
import org.txm.rcp.views.corpora.CorporaView; |
32 | 32 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
Formats disponibles : Unified diff