27 |
27 |
//
|
28 |
28 |
package org.txm.rcp.actions;
|
29 |
29 |
|
30 |
|
import java.io.File;
|
31 |
|
import java.io.FileNotFoundException;
|
32 |
|
import java.io.IOException;
|
33 |
|
import java.io.UnsupportedEncodingException;
|
34 |
|
import java.util.ArrayList;
|
35 |
|
import java.util.List;
|
36 |
|
import java.util.Properties;
|
37 |
|
|
38 |
30 |
import org.eclipse.jface.dialogs.Dialog;
|
39 |
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
40 |
31 |
import org.eclipse.jface.dialogs.MessageDialog;
|
41 |
32 |
import org.eclipse.swt.SWT;
|
42 |
|
import org.eclipse.swt.custom.ScrolledComposite;
|
43 |
|
import org.eclipse.swt.events.ControlAdapter;
|
44 |
|
import org.eclipse.swt.events.ControlEvent;
|
45 |
33 |
import org.eclipse.swt.events.SelectionEvent;
|
46 |
34 |
import org.eclipse.swt.events.SelectionListener;
|
47 |
35 |
import org.eclipse.swt.graphics.Font;
|
48 |
36 |
import org.eclipse.swt.graphics.FontData;
|
49 |
|
import org.eclipse.swt.graphics.Rectangle;
|
50 |
37 |
import org.eclipse.swt.layout.GridData;
|
51 |
38 |
import org.eclipse.swt.layout.GridLayout;
|
52 |
|
import org.eclipse.swt.widgets.Button;
|
53 |
|
import org.eclipse.swt.widgets.Combo;
|
54 |
39 |
import org.eclipse.swt.widgets.Composite;
|
55 |
40 |
import org.eclipse.swt.widgets.Control;
|
56 |
41 |
import org.eclipse.swt.widgets.Display;
|
57 |
|
import org.eclipse.swt.widgets.Event;
|
58 |
|
import org.eclipse.swt.widgets.FileDialog;
|
59 |
42 |
import org.eclipse.swt.widgets.Label;
|
60 |
|
import org.eclipse.swt.widgets.Listener;
|
61 |
43 |
import org.eclipse.swt.widgets.Shell;
|
62 |
44 |
import org.eclipse.swt.widgets.TabFolder;
|
63 |
45 |
import org.eclipse.swt.widgets.TabItem;
|
... | ... | |
65 |
47 |
import org.txm.core.messages.TXMCoreMessages;
|
66 |
48 |
import org.txm.rcp.messages.TXMUIMessages;
|
67 |
49 |
import org.txm.rcp.swt.widget.PartitionComposer;
|
68 |
|
import org.txm.rcp.swt.widget.QueryWidget;
|
69 |
|
import org.txm.searchengine.cqp.CQPSearchEngine;
|
70 |
|
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
|
|
50 |
import org.txm.rcp.swt.widget.structures.AdvancedPartitionPanel;
|
|
51 |
import org.txm.rcp.swt.widget.structures.CrossedPartitionPanel;
|
|
52 |
import org.txm.rcp.swt.widget.structures.SimplePartitionPanel;
|
71 |
53 |
import org.txm.searchengine.cqp.corpus.CQPCorpus;
|
72 |
54 |
import org.txm.searchengine.cqp.corpus.Partition;
|
73 |
|
import org.txm.searchengine.cqp.corpus.StructuralUnit;
|
74 |
|
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
|
75 |
|
import org.txm.utils.io.IOUtils;
|
76 |
55 |
import org.txm.utils.logger.Log;
|
77 |
56 |
|
78 |
|
// TODO: Auto-generated Javadoc
|
79 |
57 |
/**
|
80 |
58 |
* Allow the user to choose between 3 mode to create a Partition Simple : choose
|
81 |
59 |
* a structural unit and a property Assisted : choose a structural unit and a
|
... | ... | |
86 |
64 |
*/
|
87 |
65 |
public class CreatePartitionDialog extends Dialog {
|
88 |
66 |
|
89 |
|
// For the "simple" tab
|
90 |
|
/** The selected structural unit. */
|
91 |
|
private StructuralUnit selectedStructuralUnit;
|
92 |
|
|
93 |
|
/** The selected structural unit property. */
|
94 |
|
private StructuralUnitProperty selectedStructuralUnitProperty;
|
95 |
|
|
96 |
67 |
/** The corpus. */
|
97 |
68 |
private CQPCorpus corpus;
|
98 |
69 |
|
99 |
|
// for the "advanced" tab
|
100 |
|
/** The queries. */
|
101 |
|
private List<QueryWidget> queries = new ArrayList<>();
|
102 |
|
|
103 |
|
/** The part names. */
|
104 |
|
private List<Text> partNames = new ArrayList<>();
|
105 |
|
|
106 |
|
/** The queries string. */
|
107 |
|
List<String> queriesString = new ArrayList<>();
|
108 |
|
|
109 |
|
/** The is simple selected. */
|
110 |
|
private boolean isSimpleSelected = true;
|
111 |
|
|
112 |
|
/** The is assisted selected. */
|
113 |
|
private boolean isAssistedSelected = false;
|
114 |
|
|
115 |
|
/** The is advanced selected. */
|
116 |
|
private boolean isAdvancedSelected = false;
|
117 |
|
|
118 |
|
/** The name. */
|
119 |
|
private String name;
|
120 |
|
|
121 |
70 |
/** The name text. */
|
122 |
71 |
private Text nameText;
|
123 |
72 |
|
124 |
|
/** The composite for assisted. */
|
125 |
|
private PartitionComposer compositeForAssisted;
|
126 |
|
|
127 |
|
/** The structural units combo. */
|
128 |
|
private Combo structuralUnitsCombo;
|
129 |
|
|
130 |
|
/** The structural units final. */
|
131 |
|
private List<StructuralUnit> structuralUnitsFinal;
|
132 |
|
|
133 |
|
/** The property combo. */
|
134 |
|
private Combo propertyCombo;
|
135 |
|
|
136 |
73 |
/** The partition. */
|
137 |
74 |
private Partition partition;
|
138 |
75 |
|
139 |
|
/** The composite for advanced. */
|
140 |
|
private Composite compositeForAdvanced;
|
|
76 |
private SimplePartitionPanel simplePanel;
|
|
77 |
private PartitionComposer compositeForAssisted;
|
|
78 |
private CrossedPartitionPanel crossedPanel;
|
|
79 |
private AdvancedPartitionPanel advancedPartitionPanel;
|
141 |
80 |
|
142 |
|
/** The scroll composite. */
|
143 |
|
private ScrolledComposite scrollComposite;
|
|
81 |
private TabItem selectedTab;
|
|
82 |
|
|
83 |
private TabItem simpleTab;
|
|
84 |
private TabItem assistedTab;
|
|
85 |
private TabItem crossedTab;
|
|
86 |
private TabItem advancedTab;
|
144 |
87 |
|
145 |
88 |
/**
|
146 |
89 |
* Instantiates a new creates the partition dialog.
|
... | ... | |
153 |
96 |
super(parentShell);
|
154 |
97 |
this.corpus = corpus;
|
155 |
98 |
this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
|
156 |
|
|
157 |
99 |
}
|
158 |
100 |
|
159 |
101 |
/*
|
... | ... | |
187 |
129 |
defaultFont.setStyle(SWT.BOLD);
|
188 |
130 |
Font newf = new Font(Display.getCurrent(), defaultFont);
|
189 |
131 |
nameLabel.setText(TXMUIMessages.ampNameColon);
|
190 |
|
nameLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
|
191 |
|
false, false));
|
|
132 |
nameLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
|
192 |
133 |
nameLabel.setFont(newf);
|
193 |
134 |
|
194 |
135 |
nameText = new Text(c, SWT.BORDER);
|
... | ... | |
202 |
143 |
// First tab
|
203 |
144 |
// --------------------------------------------------------
|
204 |
145 |
|
205 |
|
TabItem simpleTab = new TabItem(tabFolder, SWT.NONE);
|
206 |
|
|
|
146 |
simpleTab = new TabItem(tabFolder, SWT.NONE);
|
207 |
147 |
simpleTab.setText(TXMUIMessages.simple);
|
|
148 |
simplePanel = new SimplePartitionPanel(tabFolder, SWT.NONE, corpus);
|
|
149 |
simpleTab.setControl(simplePanel);
|
208 |
150 |
|
209 |
|
Composite composite = new Composite(tabFolder, SWT.NONE);
|
210 |
|
simpleTab.setControl(composite);
|
211 |
|
|
212 |
|
GridLayout layout = new GridLayout(2, false);
|
213 |
|
composite.setLayout(layout);
|
214 |
|
|
215 |
|
// StructuralUnit
|
216 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
217 |
|
|
218 |
|
Label structureLabel = new Label(composite, SWT.NONE);
|
219 |
|
structureLabel.setText(TXMUIMessages.ampStructureColon);
|
220 |
|
structureLabel.setLayoutData(new GridData(GridData.END,
|
221 |
|
GridData.CENTER, false, false));
|
222 |
|
|
223 |
|
structuralUnitsCombo = new Combo(composite, SWT.READ_ONLY);
|
224 |
|
structuralUnitsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
|
225 |
|
true, false));
|
226 |
|
|
227 |
|
List<StructuralUnit> structuralUnits = null;
|
228 |
|
try {
|
229 |
|
structuralUnits = corpus.getOrderedStructuralUnits();
|
230 |
|
}
|
231 |
|
catch (CqiClientException e) {
|
232 |
|
Log.severe(TXMCoreMessages.bind(TXMCoreMessages.error_errorP0, Log.toString(e)));
|
233 |
|
return null;
|
234 |
|
}
|
235 |
|
structuralUnitsFinal = new ArrayList<>();
|
236 |
|
for (StructuralUnit unit : structuralUnits) {
|
237 |
|
if (unit.getName().equals("txmcorpus")) continue; // ignore txmcorpus structure //$NON-NLS-1$
|
238 |
|
|
239 |
|
if (unit.getOrderedProperties() != null
|
240 |
|
&& unit.getOrderedProperties().size() != 0) {
|
241 |
|
/*
|
242 |
|
* if ((unit.getName().equals("text") &&
|
243 |
|
* unit.getProperties().size() > 3)) //$NON-NLS-1$ {
|
244 |
|
* structuralUnitsCombo.add(unit.getName());
|
245 |
|
* structuralUnitsFinal.add(unit); } else
|
246 |
|
* if (!unit.getName().equals("text")) //$NON-NLS-1$ {
|
247 |
|
*/
|
248 |
|
structuralUnitsCombo.add(unit.getName());
|
249 |
|
structuralUnitsFinal.add(unit);
|
250 |
|
// }
|
251 |
|
}
|
252 |
|
}
|
253 |
|
|
254 |
|
if (structuralUnitsCombo.getItemCount() == 0) {
|
255 |
|
this.getButton(IDialogConstants.OK_ID).setEnabled(false);
|
256 |
|
}
|
257 |
|
else {
|
258 |
|
structuralUnitsCombo.select(0);
|
259 |
|
String[] items = structuralUnitsCombo.getItems();
|
260 |
|
for (int i = 0; i < items.length; i++) {
|
261 |
|
if (items[i].equals("text")) //$NON-NLS-1$
|
262 |
|
{
|
263 |
|
structuralUnitsCombo.select(i);
|
264 |
|
break;
|
265 |
|
}
|
266 |
|
}
|
267 |
|
selectedStructuralUnit = structuralUnitsFinal.get(0);
|
268 |
|
}
|
269 |
|
// combo.setSize (200, 200);
|
270 |
|
|
271 |
|
// StructuralUnitProperty
|
272 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
273 |
|
|
274 |
|
Label propertyLabel = new Label(composite, SWT.NONE);
|
275 |
|
propertyLabel.setText(TXMUIMessages.ampPropertyColon);
|
276 |
|
propertyLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER,
|
277 |
|
false, false));
|
278 |
|
|
279 |
|
propertyCombo = new Combo(composite, SWT.READ_ONLY);
|
280 |
|
propertyCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
|
281 |
|
true, false));
|
282 |
|
// combo.setSize (200, 200);
|
283 |
|
structuralUnitsCombo.addSelectionListener(new SelectionListener() {
|
284 |
|
|
285 |
|
@Override
|
286 |
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
287 |
|
|
288 |
|
@Override
|
289 |
|
public void widgetSelected(SelectionEvent event) {
|
290 |
|
|
291 |
|
reloadProperties();
|
292 |
|
}
|
293 |
|
});
|
294 |
|
|
295 |
|
for (StructuralUnitProperty property : structuralUnitsFinal.get(0).getOrderedProperties()) {
|
296 |
|
if (!(structuralUnitsFinal.get(0).getName().equals("text") && //$NON-NLS-1$
|
297 |
|
(property.getName().equals("project") || property.getName().equals("base")))) //$NON-NLS-1$ //$NON-NLS-2$
|
298 |
|
propertyCombo.add(property.getName());
|
299 |
|
}
|
300 |
|
propertyCombo.select(0);
|
301 |
|
selectedStructuralUnitProperty = selectedStructuralUnit.getOrderedProperties()
|
302 |
|
.get(0);
|
303 |
|
|
304 |
|
propertyCombo.addSelectionListener(new SelectionListener() {
|
305 |
|
|
306 |
|
@Override
|
307 |
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
308 |
|
|
309 |
|
@Override
|
310 |
|
public void widgetSelected(SelectionEvent event) {
|
311 |
|
|
312 |
|
selectedStructuralUnitProperty = selectedStructuralUnit
|
313 |
|
.getOrderedProperties().get(propertyCombo.getSelectionIndex());
|
314 |
|
}
|
315 |
|
});
|
316 |
|
|
317 |
|
reloadProperties();
|
318 |
|
|
319 |
151 |
// Second Tab : assisted mode
|
320 |
|
TabItem assistedTab = new TabItem(tabFolder, SWT.NONE);
|
321 |
|
|
|
152 |
assistedTab = new TabItem(tabFolder, SWT.NONE);
|
322 |
153 |
assistedTab.setText(TXMUIMessages.assisted);
|
323 |
|
|
324 |
154 |
compositeForAssisted = new PartitionComposer(tabFolder, SWT.NONE, this.corpus);
|
325 |
155 |
assistedTab.setControl(compositeForAssisted);
|
326 |
156 |
|
327 |
|
// Third tab: avanced mode
|
328 |
|
// --------------------------------------------------------
|
|
157 |
// Second Tab : crossed mode
|
|
158 |
crossedTab = new TabItem(tabFolder, SWT.NONE);
|
|
159 |
crossedTab.setText("Crossed");
|
|
160 |
crossedPanel = new CrossedPartitionPanel(tabFolder, SWT.NONE, this.corpus);
|
|
161 |
crossedTab.setControl(crossedPanel);
|
329 |
162 |
|
330 |
|
TabItem advancedTab = new TabItem(tabFolder, SWT.NONE);
|
|
163 |
// Last tab: advanced mode
|
|
164 |
advancedTab = new TabItem(tabFolder, SWT.NONE);
|
331 |
165 |
advancedTab.setText(TXMUIMessages.advanced);
|
|
166 |
advancedPartitionPanel = new AdvancedPartitionPanel(tabFolder, SWT.NONE, this.corpus);
|
|
167 |
advancedTab.setControl(advancedPartitionPanel);
|
332 |
168 |
|
333 |
|
Composite advanceContainer = new Composite(tabFolder, SWT.NONE);
|
334 |
|
GridLayout advanceLayout = new GridLayout(2, false);
|
335 |
|
advanceContainer.setLayout(advanceLayout);
|
336 |
|
advancedTab.setControl(advanceContainer);
|
|
169 |
selectedTab = simpleTab;
|
337 |
170 |
|
338 |
|
scrollComposite = new ScrolledComposite(advanceContainer, SWT.V_SCROLL | SWT.BORDER);
|
339 |
|
scrollComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
|
340 |
|
|
341 |
|
Button plusButton = new Button(advanceContainer, SWT.NONE);
|
342 |
|
plusButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER, GridData.FILL, false, false));
|
343 |
|
plusButton.setText("+"); //$NON-NLS-1$
|
344 |
|
plusButton.addListener(SWT.Selection, new Listener() {
|
345 |
|
|
346 |
|
@Override
|
347 |
|
public void handleEvent(Event event) {
|
348 |
|
|
349 |
|
addQueryField();
|
350 |
|
}
|
351 |
|
});
|
352 |
|
|
353 |
|
// TODO enable when specified
|
354 |
|
// Button importButton = new Button(advanceContainer, SWT.NONE);
|
355 |
|
// importButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER,
|
356 |
|
// GridData.FILL, false, false));
|
357 |
|
// importButton.setText("Import from properties file..."); //$NON-NLS-1$
|
358 |
|
// importButton.addListener(SWT.Selection, new Listener() {
|
359 |
|
// @Override
|
360 |
|
// public void handleEvent(Event event) {
|
361 |
|
// FileDialog d = new FileDialog(event.display.getActiveShell());
|
362 |
|
// d.setFilterExtensions(new String[] {"*.properties"});
|
363 |
|
// d.setText("Select a properties file containing CQL queries");
|
364 |
|
// String path = d.open();
|
365 |
|
// if (path != null) {
|
366 |
|
// Properties props = new Properties();
|
367 |
|
// try {
|
368 |
|
// props.load(IOUtils.getReader(new File(path)));
|
369 |
|
// for (Object key : props.keySet()) {
|
370 |
|
// String value = props.getProperty(key.toString());
|
371 |
|
// QueryWidget qw = addQueryField(key.toString().substring(0, Math.min(20, key.toString().length())), value);
|
372 |
|
// }
|
373 |
|
// } catch (Exception e) {
|
374 |
|
// // TODO Auto-generated catch block
|
375 |
|
// e.printStackTrace();
|
376 |
|
// }
|
377 |
|
// }
|
378 |
|
//
|
379 |
|
// }
|
380 |
|
// });
|
381 |
|
|
382 |
|
compositeForAdvanced = new Composite(scrollComposite, SWT.NONE);
|
383 |
|
GridLayout layoutForAdvanced = new GridLayout(3, false);
|
384 |
|
compositeForAdvanced.setLayout(layoutForAdvanced);
|
385 |
|
|
386 |
|
scrollComposite.setContent(compositeForAdvanced);
|
387 |
|
scrollComposite.setExpandVertical(true);
|
388 |
|
scrollComposite.setExpandHorizontal(true);
|
389 |
|
scrollComposite.addControlListener(new ControlAdapter() {
|
390 |
|
|
391 |
|
@Override
|
392 |
|
public void controlResized(ControlEvent e) {
|
393 |
|
|
394 |
|
Rectangle r = scrollComposite.getClientArea();
|
395 |
|
scrollComposite.setMinSize(compositeForAdvanced.computeSize(
|
396 |
|
r.width, SWT.DEFAULT));
|
397 |
|
}
|
398 |
|
});
|
399 |
|
|
400 |
|
createAdvancedQueryField();
|
401 |
|
|
402 |
171 |
// check the state of the OK button according to the change of tab
|
403 |
172 |
// --------------------------------
|
404 |
173 |
|
... | ... | |
410 |
179 |
@Override
|
411 |
180 |
public void widgetSelected(SelectionEvent e) {
|
412 |
181 |
|
413 |
|
// record the tab currently in use
|
414 |
|
if (tabFolder.getSelectionIndex() == 0) {
|
415 |
|
isSimpleSelected = true;
|
416 |
|
isAssistedSelected = false;
|
417 |
|
isAdvancedSelected = false;
|
418 |
|
}
|
419 |
|
else if (tabFolder.getSelectionIndex() == 1) {
|
420 |
|
isSimpleSelected = false;
|
421 |
|
isAssistedSelected = true;
|
422 |
|
isAdvancedSelected = false;
|
423 |
|
}
|
424 |
|
else {
|
425 |
|
isSimpleSelected = false;
|
426 |
|
isAssistedSelected = false;
|
427 |
|
isAdvancedSelected = true;
|
428 |
|
}
|
|
182 |
selectedTab = tabFolder.getSelection()[0];
|
429 |
183 |
}
|
430 |
184 |
});
|
431 |
185 |
|
432 |
186 |
return tabFolder;
|
433 |
187 |
}
|
434 |
|
|
435 |
|
/**
|
436 |
|
* Reload properties.
|
437 |
|
*/
|
438 |
|
private void reloadProperties() {
|
439 |
188 |
|
440 |
|
List<StructuralUnitProperty> properties = null;
|
441 |
|
selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo
|
442 |
|
.getSelectionIndex());
|
443 |
|
|
444 |
|
properties = selectedStructuralUnit.getOrderedProperties();
|
445 |
|
propertyCombo.removeAll();
|
446 |
|
for (StructuralUnitProperty property : properties) {
|
447 |
|
/*
|
448 |
|
* if (!(selectedStructuralUnit.getName().equals("text") &&
|
449 |
|
* //$NON-NLS-1$ (property.getName().equals("id") || //$NON-NLS-1$
|
450 |
|
* property.getName().equals("base") || //$NON-NLS-1$
|
451 |
|
* property.getName().equals("project")))) //$NON-NLS-1$
|
452 |
|
*/
|
453 |
|
if (selectedStructuralUnit.getName().equals("text") && //$NON-NLS-1$
|
454 |
|
(property.getName().equals("project") || property.getName().equals("base"))) continue; // ignore technical properties //$NON-NLS-1$ //$NON-NLS-2$
|
455 |
|
propertyCombo.add(property.getName());
|
456 |
|
}
|
457 |
|
if (propertyCombo.getItemCount() > 0) {
|
458 |
|
propertyCombo.select(0);
|
459 |
|
String[] items = propertyCombo.getItems();
|
460 |
|
for (int i = 0; i < items.length; i++)
|
461 |
|
if (items[i].equals("id")) //$NON-NLS-1$
|
462 |
|
{
|
463 |
|
propertyCombo.select(i);
|
464 |
|
break;
|
465 |
|
}
|
466 |
|
selectedStructuralUnitProperty = selectedStructuralUnit
|
467 |
|
.getOrderedProperties().get(0);
|
468 |
|
// this.getButton(IDialogConstants.OK_ID).setEnabled(true);
|
469 |
|
}
|
470 |
|
}
|
471 |
|
|
472 |
|
/**
|
473 |
|
* Return true if no query is currently given in the "advanced" tab (ie if
|
474 |
|
* all Text field opened are empty).
|
475 |
|
*
|
476 |
|
* @return true, if successful
|
477 |
|
*/
|
478 |
|
private boolean noquery() {
|
479 |
|
|
480 |
|
for (QueryWidget query : queries) {
|
481 |
|
if (query.getText().length() == 0)
|
482 |
|
return true;
|
483 |
|
}
|
484 |
|
return false;
|
485 |
|
}
|
486 |
|
|
487 |
|
/**
|
488 |
|
* Creates the advanced query field.
|
489 |
|
*
|
490 |
|
*/
|
491 |
|
private void createAdvancedQueryField() {
|
492 |
|
|
493 |
|
addQueryField();
|
494 |
|
Rectangle r = scrollComposite.getClientArea();
|
495 |
|
scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width,
|
496 |
|
SWT.DEFAULT));
|
497 |
|
}
|
498 |
|
|
499 |
|
/**
|
500 |
|
* Adds the query field.
|
501 |
|
*
|
502 |
|
*/
|
503 |
|
private QueryWidget addQueryField() {
|
504 |
|
|
505 |
|
return addQueryField(null, null);
|
506 |
|
}
|
507 |
|
|
508 |
|
/**
|
509 |
|
* Adds the query field.
|
510 |
|
*
|
511 |
|
* @param name the query name
|
512 |
|
* @param value the query
|
513 |
|
*/
|
514 |
|
private QueryWidget addQueryField(String name, String value) {
|
515 |
|
|
516 |
|
final Text advancedPartLabel = new Text(compositeForAdvanced, SWT.BORDER);
|
517 |
|
advancedPartLabel.setText(TXMUIMessages.part
|
518 |
|
+ (partNames.size() + 1));
|
519 |
|
advancedPartLabel.setLayoutData(new GridData(GridData.FILL,
|
520 |
|
GridData.CENTER, false, false));
|
521 |
|
if (name != null && name.length() > 0) {
|
522 |
|
advancedPartLabel.setText(name);
|
523 |
|
}
|
524 |
|
partNames.add(advancedPartLabel);
|
525 |
|
|
526 |
|
final QueryWidget queryText;
|
527 |
|
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), CQPSearchEngine.getEngine());
|
528 |
|
queryText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
|
529 |
|
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
|
530 |
|
// gridData.widthHint = convertHeightInCharsToPixels(20);
|
531 |
|
queryText.setLayoutData(gridData);
|
532 |
|
queries.add(queryText);
|
533 |
|
if (value != null) {
|
534 |
|
queryText.setText(value);
|
535 |
|
}
|
536 |
|
final Button minusButton = new Button(compositeForAdvanced, SWT.NONE);
|
537 |
|
minusButton.setText("-"); //$NON-NLS-1$
|
538 |
|
// minusButton.setData(queryText);
|
539 |
|
minusButton.addListener(SWT.Selection, new Listener() {
|
540 |
|
|
541 |
|
@Override
|
542 |
|
public void handleEvent(Event event) {
|
543 |
|
|
544 |
|
queries.remove(queryText);
|
545 |
|
partNames.remove(advancedPartLabel);
|
546 |
|
advancedPartLabel.dispose();
|
547 |
|
queryText.dispose();
|
548 |
|
minusButton.dispose();
|
549 |
|
compositeForAdvanced.layout(true);
|
550 |
|
}
|
551 |
|
});
|
552 |
|
Rectangle r = scrollComposite.getClientArea();
|
553 |
|
scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width,
|
554 |
|
SWT.DEFAULT));
|
555 |
|
scrollComposite.update();
|
556 |
|
scrollComposite.layout();
|
557 |
|
compositeForAdvanced.update();
|
558 |
|
compositeForAdvanced.layout();
|
559 |
|
|
560 |
|
return queryText;
|
561 |
|
}
|
562 |
|
|
563 |
189 |
/*
|
564 |
190 |
* (non-Javadoc)
|
565 |
191 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
|
... | ... | |
567 |
193 |
@Override
|
568 |
194 |
protected void okPressed() {
|
569 |
195 |
|
570 |
|
if (isAdvancedSelected() && noquery()) {
|
|
196 |
if (selectedTab == advancedTab && advancedPartitionPanel.isQueriesSet()) {
|
571 |
197 |
MessageDialog.openError(getShell(),
|
572 |
198 |
TXMUIMessages.invalidQuery,
|
573 |
199 |
TXMUIMessages.queriesCannotBeLeftEmpty);
|
574 |
200 |
return;
|
575 |
201 |
}
|
576 |
202 |
|
577 |
|
/*
|
578 |
|
* if (isAssistedSelected) {
|
579 |
|
* if (compositeForAssisted.hasUnassigned()) {
|
580 |
|
* System.out.println(Messages.CreatePartitionDialog_11);
|
581 |
|
* return;
|
582 |
|
* }
|
583 |
|
* }
|
584 |
|
*/
|
585 |
|
|
586 |
|
for (QueryWidget query : queries) {
|
587 |
|
queriesString.add(query.getQueryString());
|
588 |
|
query.memorize();
|
589 |
|
}
|
590 |
203 |
partition = createPartition();
|
591 |
204 |
super.okPressed();
|
592 |
205 |
}
|
593 |
|
|
594 |
|
/**
|
595 |
|
* Tell if the user is using the "advanced" tab.
|
596 |
|
*
|
597 |
|
* @return true, if is advanced selected
|
598 |
|
*/
|
599 |
|
public boolean isAdvancedSelected() {
|
600 |
206 |
|
601 |
|
return isAdvancedSelected;
|
602 |
|
}
|
603 |
|
|
604 |
207 |
/**
|
605 |
|
* Gets the structural unit.
|
606 |
|
*
|
607 |
|
* @return the structural unit
|
608 |
|
*/
|
609 |
|
public StructuralUnit getStructuralUnit() {
|
610 |
|
|
611 |
|
if (isAdvancedSelected())
|
612 |
|
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
613 |
|
return selectedStructuralUnit;
|
614 |
|
}
|
615 |
|
|
616 |
|
/**
|
617 |
|
* Gets the structural unit property.
|
618 |
|
*
|
619 |
|
* @return the structural unit property
|
620 |
|
*/
|
621 |
|
public StructuralUnitProperty getStructuralUnitProperty() {
|
622 |
|
|
623 |
|
if (isAdvancedSelected())
|
624 |
|
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
625 |
|
return selectedStructuralUnitProperty;
|
626 |
|
}
|
627 |
|
|
628 |
|
/**
|
629 |
|
* Gets the queries.
|
630 |
|
*
|
631 |
|
* @return the queries
|
632 |
|
*/
|
633 |
|
public List<String> getQueries() {
|
634 |
|
|
635 |
|
if (!isAdvancedSelected())
|
636 |
|
throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
|
637 |
|
return queriesString;
|
638 |
|
}
|
639 |
|
|
640 |
|
|
641 |
|
/**
|
642 |
208 |
* Creates the partition.
|
643 |
209 |
*
|
644 |
210 |
* @return the partition
|
... | ... | |
649 |
215 |
|
650 |
216 |
String name = nameText.getText();
|
651 |
217 |
|
652 |
|
// Simple mode
|
653 |
|
if (isSimpleSelected) {
|
|
218 |
if (selectedTab == simpleTab) { // Simple mode
|
654 |
219 |
|
655 |
|
StructuralUnit structuralUnit = this.structuralUnitsFinal.get(this.structuralUnitsCombo.getSelectionIndex());
|
656 |
|
StructuralUnitProperty property = structuralUnit.getProperty(this.propertyCombo.getText());
|
657 |
|
try {
|
658 |
|
|
659 |
|
// auto-naming if needed
|
660 |
|
if (name.isEmpty()) {
|
661 |
|
name = property.asFullNameString();
|
662 |
|
}
|
663 |
|
|
664 |
|
partition = new Partition(corpus);
|
665 |
|
partition.setParameters(name, property, null);
|
666 |
|
}
|
667 |
|
catch (Exception e) {
|
668 |
|
org.txm.utils.logger.Log.printStackTrace(e);
|
669 |
|
return null;
|
670 |
|
}
|
|
220 |
partition = simplePanel.createPartition(name);
|
671 |
221 |
}
|
672 |
|
// Assisted mode
|
673 |
|
else if (isAssistedSelected) {
|
|
222 |
else if (selectedTab == assistedTab) { // Assisted mode
|
674 |
223 |
|
675 |
224 |
// auto-naming if needed
|
676 |
225 |
if (name.isEmpty()) {
|
... | ... | |
680 |
229 |
|
681 |
230 |
partition = this.compositeForAssisted.createPartition(name);
|
682 |
231 |
}
|
683 |
|
// Advanced mode
|
684 |
|
else if (isAdvancedSelected) {
|
685 |
|
try {
|
686 |
|
|
687 |
|
// auto-naming if needed
|
688 |
|
if (name.isEmpty()) {
|
689 |
|
name = "partition" + (this.corpus.getPartitions().size() + 1); //$NON-NLS-1$
|
690 |
|
Log.info(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
|
691 |
|
}
|
692 |
|
|
693 |
|
partition = new Partition(this.corpus);
|
694 |
|
partition.setParameters(name, this.getQueries(), this.getAdvancePartNames());
|
695 |
|
}
|
696 |
|
catch (Exception e) {
|
697 |
|
org.txm.utils.logger.Log.printStackTrace(e);
|
698 |
|
return null;
|
699 |
|
}
|
|
232 |
else if (selectedTab == crossedTab) { // Advanced mode
|
|
233 |
|
|
234 |
partition = crossedPanel.createPartition(name);
|
700 |
235 |
}
|
|
236 |
else if (selectedTab == advancedTab) { // Advanced mode
|
|
237 |
|
|
238 |
partition = advancedPartitionPanel.createPartition(name);
|
|
239 |
}
|
701 |
240 |
|
702 |
241 |
// Error
|
703 |
242 |
if (partition == null) {
|
... | ... | |
709 |
248 |
}
|
710 |
249 |
|
711 |
250 |
/**
|
712 |
|
* Gets the advance part names.
|
713 |
|
*
|
714 |
|
* @return the advance part names
|
715 |
|
*/
|
716 |
|
private List<String> getAdvancePartNames() {
|
717 |
|
|
718 |
|
ArrayList<String> values = new ArrayList<>();
|
719 |
|
int count = 0;
|
720 |
|
for (Text t : partNames) {
|
721 |
|
String name = t.getText().trim();
|
722 |
|
if (name.length() == 0)
|
723 |
|
name = TXMUIMessages.part + count++;
|
724 |
|
values.add(name);
|
725 |
|
}
|
726 |
|
return values;
|
727 |
|
}
|
728 |
|
|
729 |
|
/**
|
730 |
251 |
* Gets the partition.
|
731 |
252 |
*
|
732 |
253 |
* @return the partition
|