Révision 3976

TXM/trunk/bundles/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/ComputeSubCorpus.java (revision 3976)
34 34
import org.eclipse.core.runtime.IProgressMonitor;
35 35
import org.eclipse.core.runtime.IStatus;
36 36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.jface.dialogs.MessageDialog;
37 38
import org.eclipse.jface.viewers.IStructuredSelection;
38 39
import org.eclipse.jface.window.Window;
39 40
import org.eclipse.osgi.util.NLS;
......
171 172
						monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100);
172 173
						final Subcorpus subcorpus;
173 174
						
174
						if (d.isAdvancedSelected() || d.isAssistedSelected()) {
175
						if (d.getMode() == 1 || d.getMode() == 2 || d.getMode() == 3) {
176
							
177
							// test if a query has been set
178
							if (d.getQuery().length() == 0) {
179
								Log.warning(TXMUIMessages.queryCannotBeLeftEmpty);
180
								return Status.CANCEL_STATUS;
181
							}
182
							
175 183
							CQLQuery q = new CQLQuery(d.getQuery());
176 184
							
177 185
							// System.out.println(NLS.bind(TXMUIMessages.computeSubCorpusOnP0QueryColonP1, corpus.getName(), q.getQueryString()));
178
							
179 186
							subcorpus = corpus.createSubcorpus(q, d.getName());
180 187
						}
181 188
						else {
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/SimpleSubcorpusPanel.java (revision 3976)
4 4
import java.util.Collections;
5 5
import java.util.List;
6 6

  
7
import org.apache.commons.lang.StringUtils;
7 8
import org.eclipse.jface.dialogs.IDialogConstants;
8 9
import org.eclipse.jface.viewers.ArrayContentProvider;
9 10
import org.eclipse.jface.viewers.ISelection;
......
29 30
import org.txm.searchengine.cqp.corpus.query.SubcorpusCQLQuery;
30 31
import org.txm.utils.logger.Log;
31 32

  
33
import cern.colt.Arrays;
34

  
32 35
public class SimpleSubcorpusPanel extends Composite {
33 36

  
34 37
	public StructuralUnit selectedStructuralUnit;
......
200 203
	 */
201 204
	protected void reloadProperties() {
202 205

  
203
		selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo
204
				.getSelectionIndex());
206
		selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo.getSelectionIndex());
205 207

  
206 208
		selectableStructuralUnitProperties = 
207 209
				new ArrayList<StructuralUnitProperty>(selectedStructuralUnit.getOrderedProperties());
......
242 244
		return query.getQueryString();
243 245
	}
244 246

  
247
	public String getGeneratedName() {
248

  
249
		return structuralUnitsCombo.getText()+"@"+propertyCombo.getText() + "="+StringUtils.join(valueCombo.getList().getSelection(), ", ");
250
	}
251

  
245 252
}
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreateSubcorpusDialog.java (revision 3976)
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
}
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/messages/TXMUIMessages.java (revision 3976)
278 278
	public static String contextColon;
279 279
	
280 280
	public static String contextsDisplayOptions;
281
	
282
	public static String contexts;
281 283

  
282 284

  
283 285
	public static String contextSize;
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages.properties (revision 3976)
527 527
downloadingTheP0File=Downloading file {0}...
528 528
noTextInCorpusColonP0=** No {0} text in the corpus.
529 529
contextsDisplayOptions=Contexts display options
530
contexts=Contexts
530 531
errorWhileComputingCorpusSummary=** Error while computing corpus properties
531 532
selectValuesToAssignColon=Select the values to assign\: 
532 533
CopingFilesP0=Copying files\: {0}
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages_fr.properties (revision 3976)
528 528
downloadingTheP0File=Téléchargement du fichier {0}...
529 529
noTextInCorpusColonP0=** Aucun texte {0} dans le corpus.
530 530
contextsDisplayOptions=Options d'affichage des contextes
531
contexts=Contextes
531 532
errorWhileComputingCorpusSummary=** Erreur lors du calcul des propriétés du corpus
532 533
selectValuesToAssignColon=Sélectionner les valeurs à affecter \: 
533 534
CopingFilesP0=Copie des fichiers \: {0}

Formats disponibles : Unified diff