| 49 |
49 |
import org.eclipse.swt.widgets.Text;
|
| 50 |
50 |
import org.txm.rcp.messages.TXMUIMessages;
|
| 51 |
51 |
import org.txm.rcp.swt.widget.ComplexSubcorpusPanel;
|
|
52 |
import org.txm.rcp.swt.widget.ContextsSubcorpusPanel;
|
| 52 |
53 |
import org.txm.rcp.swt.widget.QueryWidget;
|
| 53 |
54 |
import org.txm.rcp.swt.widget.structures.SimpleSubcorpusPanel;
|
| 54 |
55 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
| ... | ... | |
| 70 |
71 |
// List<StructuralUnitProperty> selectableStructuralUnitProperties = null;
|
| 71 |
72 |
/** The selected structural unit property. */
|
| 72 |
73 |
// private StructuralUnitProperty selectedStructuralUnitProperty;
|
| 73 |
|
|
|
74 |
|
| 74 |
75 |
/** The selected values. */
|
| 75 |
76 |
// private List<String> selectedValues;
|
| 76 |
|
|
|
77 |
|
| 77 |
78 |
// For the assisted tab
|
| 78 |
79 |
/** The simple and complex panels. */
|
| 79 |
80 |
SimpleSubcorpusPanel simplePanel;
|
| 80 |
|
|
|
81 |
|
| 81 |
82 |
ComplexSubcorpusPanel complexPanel;
|
| 82 |
|
|
|
83 |
|
|
84 |
ContextsSubcorpusPanel contextsPanel;
|
|
85 |
|
| 83 |
86 |
// For the "advanced" tab
|
| 84 |
87 |
/** The query text. */
|
| 85 |
88 |
private QueryWidget queryText;
|
| 86 |
|
|
|
89 |
|
| 87 |
90 |
/** The query string. */
|
| 88 |
91 |
private String queryString;
|
| 89 |
|
|
|
92 |
|
| 90 |
93 |
// for both tab
|
| 91 |
94 |
/** The name. */
|
| 92 |
95 |
private Text name;
|
| 93 |
|
|
|
96 |
|
| 94 |
97 |
/** The name string. */
|
| 95 |
98 |
private String nameString;
|
| 96 |
|
|
|
99 |
|
| 97 |
100 |
/** The corpus. */
|
| 98 |
101 |
private CQPCorpus corpus;
|
| 99 |
|
|
| 100 |
|
/** The is advanced selected. */
|
| 101 |
|
private boolean isAdvancedSelected = false;
|
| 102 |
|
|
|
102 |
|
| 103 |
103 |
/** The assisted selected. */
|
| 104 |
|
private boolean assistedSelected = false;
|
| 105 |
|
|
|
104 |
private int subcorpusMode = 0;
|
|
105 |
|
| 106 |
106 |
/**
|
| 107 |
107 |
* Instantiates a new creates the subcorpus dialog.
|
| 108 |
108 |
*
|
| ... | ... | |
| 114 |
114 |
this.corpus = corpus;
|
| 115 |
115 |
this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
|
| 116 |
116 |
}
|
| 117 |
|
|
|
117 |
|
| 118 |
118 |
/*
|
| 119 |
119 |
* (non-Javadoc)
|
| 120 |
120 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
| ... | ... | |
| 125 |
125 |
newShell.setText(TXMUIMessages.createSubcorpus);
|
| 126 |
126 |
newShell.setMinimumSize(300, 300);
|
| 127 |
127 |
}
|
| 128 |
|
|
|
128 |
|
| 129 |
129 |
/** The structural units final. */
|
| 130 |
130 |
List<StructuralUnit> structuralUnitsFinal;
|
| 131 |
|
|
|
131 |
|
| 132 |
132 |
/** The structural units combo. */
|
| 133 |
133 |
Combo structuralUnitsCombo;
|
| 134 |
|
|
|
134 |
|
| 135 |
135 |
/** The property combo. */
|
| 136 |
136 |
Combo propertyCombo;
|
| 137 |
|
|
|
137 |
|
| 138 |
138 |
/** The value combo. */
|
| 139 |
139 |
org.eclipse.swt.widgets.List valueCombo;
|
| 140 |
|
|
|
140 |
|
| 141 |
141 |
/*
|
| 142 |
142 |
* (non-Javadoc)
|
| 143 |
143 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
| 144 |
144 |
*/
|
| 145 |
145 |
@Override
|
| 146 |
146 |
protected Control createDialogArea(Composite parent) {
|
| 147 |
|
|
|
147 |
|
| 148 |
148 |
Composite inclosing = new Composite(parent, SWT.NONE);
|
| 149 |
149 |
// TODO : we just put a composite into another composite. Everything
|
| 150 |
150 |
// should be directly put into parent
|
| ... | ... | |
| 153 |
153 |
layout4inclosing.horizontalSpacing = 0;
|
| 154 |
154 |
inclosing.setLayout(layout4inclosing);
|
| 155 |
155 |
inclosing.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
|
| 156 |
|
|
|
156 |
|
| 157 |
157 |
// name panel
|
| 158 |
158 |
Composite nameComposite = new Composite(inclosing, SWT.NONE);
|
| 159 |
159 |
nameComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
|
| 160 |
160 |
GridLayout layout4nameComposite = new GridLayout(2, false);
|
| 161 |
161 |
nameComposite.setLayout(layout4nameComposite);
|
| 162 |
|
|
|
162 |
|
| 163 |
163 |
Label nameLabel = new Label(nameComposite, SWT.NONE);
|
| 164 |
164 |
nameLabel.setText(TXMUIMessages.ampNameColon);
|
| 165 |
165 |
nameLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
|
| 166 |
|
|
|
166 |
|
| 167 |
167 |
name = new Text(nameComposite, SWT.BORDER);
|
| 168 |
168 |
name.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
|
| 169 |
|
|
|
169 |
|
| 170 |
170 |
// Param panel
|
| 171 |
171 |
final TabFolder tabFolder = new TabFolder(inclosing, SWT.NONE);
|
| 172 |
172 |
tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
|
| 173 |
|
|
|
173 |
|
| 174 |
174 |
// First tab
|
| 175 |
175 |
TabItem simpleTab = new TabItem(tabFolder, SWT.NONE);
|
| 176 |
176 |
simpleTab.setText(TXMUIMessages.simple);
|
| 177 |
177 |
simplePanel = new SimpleSubcorpusPanel(tabFolder, SWT.NONE, this.getButton(IDialogConstants.OK_ID), corpus);
|
| 178 |
178 |
simpleTab.setControl(simplePanel);
|
| 179 |
|
|
|
179 |
|
| 180 |
180 |
// Second tab: assisted mode
|
| 181 |
181 |
TabItem secondTab = new TabItem(tabFolder, SWT.NONE);
|
| 182 |
182 |
secondTab.setText(TXMUIMessages.assisted);
|
| 183 |
183 |
this.complexPanel = new ComplexSubcorpusPanel(tabFolder, SWT.NONE, this.corpus);
|
| 184 |
184 |
secondTab.setControl(complexPanel);
|
| 185 |
|
|
|
185 |
|
|
186 |
// Third tab: assisted mode
|
|
187 |
TabItem thirdTab = new TabItem(tabFolder, SWT.NONE);
|
|
188 |
thirdTab.setText(TXMUIMessages.contexts);
|
|
189 |
this.contextsPanel = new ContextsSubcorpusPanel(tabFolder, SWT.NONE, this.corpus);
|
|
190 |
thirdTab.setControl(contextsPanel);
|
|
191 |
|
| 186 |
192 |
// Third tab: advanced mode
|
| 187 |
193 |
TabItem advancedTab = new TabItem(tabFolder, SWT.NONE);
|
| 188 |
194 |
advancedTab.setText(TXMUIMessages.advanced);
|
| 189 |
|
|
|
195 |
|
| 190 |
196 |
Composite compositeForAdvanced = new Composite(tabFolder, SWT.NONE);
|
| 191 |
197 |
advancedTab.setControl(compositeForAdvanced);
|
| 192 |
|
|
|
198 |
|
| 193 |
199 |
GridLayout layoutForAdvanced = new GridLayout(3, false);
|
| 194 |
200 |
compositeForAdvanced.setLayout(layoutForAdvanced);
|
| 195 |
|
|
|
201 |
|
| 196 |
202 |
Label advancedPartLabel = new Label(compositeForAdvanced, SWT.NONE);
|
| 197 |
203 |
advancedPartLabel.setText(TXMUIMessages.ampQuery);
|
| 198 |
204 |
advancedPartLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
|
| 199 |
|
|
|
205 |
|
| 200 |
206 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), CQPSearchEngine.getEngine());
|
| 201 |
207 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
|
| 202 |
208 |
GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
| 203 |
209 |
gridData.widthHint = convertHeightInCharsToPixels(20);
|
| 204 |
210 |
queryText.setLayoutData(gridData);
|
| 205 |
|
|
|
211 |
|
| 206 |
212 |
// check the state of the OK button according to the change of tab
|
| 207 |
213 |
// --------------------------------
|
| 208 |
|
|
|
214 |
|
| 209 |
215 |
tabFolder.addSelectionListener(new SelectionListener() {
|
| 210 |
|
|
|
216 |
|
| 211 |
217 |
@Override
|
| 212 |
218 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
| 213 |
|
|
|
219 |
|
| 214 |
220 |
@Override
|
| 215 |
221 |
public void widgetSelected(SelectionEvent e) {
|
| 216 |
|
if (tabFolder.getSelectionIndex() == 0) {
|
| 217 |
|
isAdvancedSelected = false;
|
| 218 |
|
assistedSelected = false;
|
| 219 |
|
}
|
| 220 |
|
else if (tabFolder.getSelectionIndex() == 1) {
|
| 221 |
|
isAdvancedSelected = false;
|
| 222 |
|
assistedSelected = true;
|
| 223 |
|
}
|
| 224 |
|
else {
|
| 225 |
|
isAdvancedSelected = true;
|
| 226 |
|
assistedSelected = false;
|
| 227 |
|
}
|
|
222 |
|
|
223 |
subcorpusMode = tabFolder.getSelectionIndex();
|
| 228 |
224 |
}
|
| 229 |
225 |
});
|
| 230 |
|
|
|
226 |
|
| 231 |
227 |
return tabFolder;
|
| 232 |
228 |
}
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
|
229 |
|
|
230 |
|
|
231 |
|
| 236 |
232 |
@Override
|
| 237 |
233 |
public Button getButton(int id) {
|
| 238 |
234 |
return super.getButton(id);
|
| 239 |
235 |
}
|
| 240 |
|
|
|
236 |
|
| 241 |
237 |
/*
|
| 242 |
238 |
* (non-Javadoc)
|
| 243 |
239 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
|
| 244 |
240 |
*/
|
| 245 |
241 |
@Override
|
| 246 |
242 |
protected void okPressed() {
|
| 247 |
|
|
|
243 |
|
| 248 |
244 |
// auto-naming if needed
|
| 249 |
245 |
if (name.getText().length() == 0) {
|
| 250 |
246 |
String autoName = "subcorpus"; //$NON-NLS-1$
|
| 251 |
|
|
|
247 |
|
| 252 |
248 |
// Advanced mode
|
| 253 |
|
if (isAdvancedSelected()) {
|
| 254 |
|
autoName += "" + (this.corpus.getSubcorpora().size() + 1); //$NON-NLS-1$
|
|
249 |
if (subcorpusMode == 0) {
|
|
250 |
autoName = this.simplePanel.getGeneratedName();
|
| 255 |
251 |
}
|
| 256 |
252 |
// Assisted mode (structure@property=1st_value)
|
| 257 |
|
else if (assistedSelected) {
|
|
253 |
else if (subcorpusMode == 1) {
|
| 258 |
254 |
autoName = this.complexPanel.getGeneratedName();
|
| 259 |
255 |
}
|
| 260 |
|
// Simple mode (structure@property=1st_value)
|
| 261 |
|
else {
|
| 262 |
|
autoName = getStructuralUnitProperty().asFullNameString() + "=" + getValues().get(0); //$NON-NLS-1$
|
|
256 |
else if (subcorpusMode == 2) {
|
|
257 |
autoName = this.contextsPanel.getGeneratedName();
|
|
258 |
}
|
|
259 |
else if (subcorpusMode == 3) {
|
|
260 |
autoName += "" + (this.corpus.getSubcorpora().size() + 1); //$NON-NLS-1$
|
|
261 |
} else {
|
|
262 |
autoName = this.complexPanel.getGeneratedName();
|
| 263 |
263 |
}
|
| 264 |
264 |
|
| 265 |
265 |
Log.info(NLS.bind(TXMUIMessages.noSubcorpusNameWasSpecifiedWeveGeneratedOneP0, autoName));
|
| 266 |
|
|
|
266 |
|
| 267 |
267 |
name.setText(autoName);
|
| 268 |
268 |
}
|
| 269 |
|
|
| 270 |
|
// test if a query has been set
|
| 271 |
|
if ((isAdvancedSelected()) && queryText.getText().length() == 0) {
|
| 272 |
|
MessageDialog.openError(getShell(), TXMUIMessages.invalidQuery, TXMUIMessages.queryCannotBeLeftEmpty);
|
| 273 |
|
return;
|
| 274 |
|
}
|
| 275 |
|
|
| 276 |
|
queryString = queryText.getQueryString();
|
| 277 |
|
// queryText.memorize();
|
| 278 |
|
|
| 279 |
|
if (assistedSelected) {
|
|
269 |
|
|
270 |
if (subcorpusMode == 1) {
|
|
271 |
|
| 280 |
272 |
// System.out.println("1 "+queryString);
|
| 281 |
273 |
queryString = this.complexPanel.getQueryFieldValue();
|
| 282 |
274 |
// System.out.println("2 "+queryString);
|
| ... | ... | |
| 288 |
280 |
return;
|
| 289 |
281 |
}
|
| 290 |
282 |
}
|
|
283 |
|
|
284 |
} else if (subcorpusMode == 2) {
|
|
285 |
|
|
286 |
queryString = this.contextsPanel.getQueryString();
|
|
287 |
} else if (subcorpusMode == 3) {
|
|
288 |
|
|
289 |
queryString = queryText.getQueryString();
|
| 291 |
290 |
}
|
| 292 |
|
|
|
291 |
|
| 293 |
292 |
nameString = name.getText();
|
| 294 |
293 |
super.okPressed();
|
| 295 |
294 |
}
|
| 296 |
|
|
|
295 |
|
| 297 |
296 |
/**
|
| 298 |
|
* Tell if the user is using the "advanced" tab.
|
| 299 |
|
*
|
| 300 |
|
* @return true, if is advanced selected
|
| 301 |
|
*/
|
| 302 |
|
public boolean isAdvancedSelected() {
|
| 303 |
|
return isAdvancedSelected;
|
| 304 |
|
}
|
| 305 |
|
|
| 306 |
|
/**
|
| 307 |
|
* Tell if the user is using the "assisted" tab.
|
| 308 |
|
*
|
| 309 |
|
* @return true, if is assisted selected
|
| 310 |
|
*/
|
| 311 |
|
public boolean isAssistedSelected() {
|
| 312 |
|
return assistedSelected;
|
| 313 |
|
}
|
| 314 |
|
|
| 315 |
|
/**
|
| 316 |
297 |
* Gets the structural unit.
|
| 317 |
298 |
*
|
| 318 |
299 |
* @return the structural unit
|
| 319 |
300 |
*/
|
| 320 |
301 |
public StructuralUnit getStructuralUnit() {
|
| 321 |
|
if (isAdvancedSelected()) {
|
|
302 |
if (subcorpusMode == 3) {
|
| 322 |
303 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
| 323 |
304 |
}
|
| 324 |
305 |
return simplePanel.selectedStructuralUnit;
|
| 325 |
306 |
}
|
| 326 |
|
|
|
307 |
|
| 327 |
308 |
/**
|
| 328 |
309 |
* Gets the structural unit property.
|
| 329 |
310 |
*
|
| 330 |
311 |
* @return the structural unit property
|
| 331 |
312 |
*/
|
| 332 |
313 |
public StructuralUnitProperty getStructuralUnitProperty() {
|
| 333 |
|
if (isAdvancedSelected()) {
|
|
314 |
if (subcorpusMode == 2 || subcorpusMode == 3) {
|
| 334 |
315 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
| 335 |
316 |
}
|
| 336 |
317 |
return simplePanel.selectedStructuralUnitProperty;
|
| 337 |
318 |
}
|
| 338 |
|
|
|
319 |
|
| 339 |
320 |
/**
|
| 340 |
321 |
* Gets the values.
|
| 341 |
322 |
*
|
| 342 |
323 |
* @return the values
|
| 343 |
324 |
*/
|
| 344 |
325 |
public List<String> getValues() {
|
| 345 |
|
if (isAdvancedSelected()) {
|
|
326 |
if (subcorpusMode == 2 || subcorpusMode == 3) {
|
| 346 |
327 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
| 347 |
328 |
}
|
| 348 |
329 |
return simplePanel.selectedValues;
|
| 349 |
330 |
}
|
| 350 |
|
|
|
331 |
|
| 351 |
332 |
/**
|
| 352 |
333 |
* Gets the query.
|
| 353 |
334 |
*
|
| 354 |
335 |
* @return the query
|
| 355 |
336 |
*/
|
| 356 |
337 |
public String getQuery() {
|
| 357 |
|
if (isAdvancedSelected() == false && isAssistedSelected() == false) {
|
|
338 |
if (subcorpusMode == 0 ) {
|
| 358 |
339 |
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
| 359 |
340 |
}
|
| 360 |
341 |
return queryString;
|
| 361 |
342 |
}
|
| 362 |
|
|
|
343 |
|
| 363 |
344 |
/**
|
| 364 |
345 |
* Gets the name.
|
| 365 |
346 |
*
|
| ... | ... | |
| 368 |
349 |
public String getName() {
|
| 369 |
350 |
return nameString;
|
| 370 |
351 |
}
|
| 371 |
|
|
|
352 |
|
| 372 |
353 |
/**
|
| 373 |
354 |
* Gets the sub corpus name.
|
| 374 |
355 |
*
|
| ... | ... | |
| 377 |
358 |
public String getSubCorpusName() {
|
| 378 |
359 |
return name.getText();
|
| 379 |
360 |
}
|
|
361 |
|
|
362 |
public int getMode() {
|
|
363 |
|
|
364 |
return subcorpusMode;
|
|
365 |
}
|
| 380 |
366 |
}
|