Revision 2628

tmp/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreatePartitionDialog.java (revision 2628)
72 72
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
73 73
import org.txm.utils.io.IOUtils;
74 74
import org.txm.utils.logger.Log;
75

  
75 76
// TODO: Auto-generated Javadoc
76 77
/**
77 78
 * Allow the user to choose between 3 mode to create a Partition Simple : choose
78 79
 * a structural unit and a property Assisted : choose a structural unit and a
79 80
 * property, then dispatch them into parts Advanced : user define the queries to
80
 * build the parts 
81
 * build the parts
81 82
 * 
82 83
 * @author mdecorde.
83 84
 */
84 85
public class CreatePartitionDialog extends Dialog {
85

  
86
	
86 87
	// For the "simple" tab
87 88
	/** The selected structural unit. */
88 89
	private StructuralUnit selectedStructuralUnit;
89

  
90
	
90 91
	/** The selected structural unit property. */
91 92
	private StructuralUnitProperty selectedStructuralUnitProperty;
92

  
93
	
93 94
	/** The corpus. */
94 95
	private CQPCorpus corpus;
95

  
96
	
96 97
	// for the "advanced" tab
97 98
	/** The queries. */
98
	private List<QueryWidget> queries = new ArrayList<QueryWidget>();
99

  
99
	private List<QueryWidget> queries = new ArrayList<>();
100
	
100 101
	/** The part names. */
101
	private List<Text> partNames = new ArrayList<Text>();
102

  
102
	private List<Text> partNames = new ArrayList<>();
103
	
103 104
	/** The queries string. */
104
	List<String> queriesString = new ArrayList<String>();
105

  
105
	List<String> queriesString = new ArrayList<>();
106
	
106 107
	/** The is simple selected. */
107 108
	private boolean isSimpleSelected = true;
108

  
109
	
109 110
	/** The is assisted selected. */
110 111
	private boolean isAssistedSelected = false;
111

  
112
	
112 113
	/** The is advanced selected. */
113 114
	private boolean isAdvancedSelected = false;
114

  
115
	
115 116
	/** The name. */
116 117
	private String name;
117

  
118
	
118 119
	/** The name text. */
119 120
	private Text nameText;
120

  
121
	
121 122
	/** The composite for assisted. */
122 123
	private PartitionComposer compositeForAssisted;
123

  
124
	
124 125
	/** The structural units combo. */
125 126
	private Combo structuralUnitsCombo;
126

  
127
	
127 128
	/** The structural units final. */
128 129
	private List<StructuralUnit> structuralUnitsFinal;
129

  
130
	
130 131
	/** The property combo. */
131 132
	private Combo propertyCombo;
132

  
133
	
133 134
	/** The partition. */
134 135
	private Partition partition;
135

  
136
	
136 137
	/** The composite for advanced. */
137 138
	private Composite compositeForAdvanced;
138

  
139
	
139 140
	/** The scroll composite. */
140 141
	private ScrolledComposite scrollComposite;
141

  
142
	
142 143
	/**
143 144
	 * Instantiates a new creates the partition dialog.
144 145
	 *
......
149 150
		super(parentShell);
150 151
		this.corpus = corpus;
151 152
		this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
152

  
153
		
153 154
	}
154

  
155
	/* (non-Javadoc)
155
	
156
	/*
157
	 * (non-Javadoc)
156 158
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
157 159
	 */
158 160
	@Override
......
161 163
		newShell.setText(TXMUIMessages.createPartition);
162 164
		newShell.setMinimumSize(400, 400);
163 165
	}
164

  
165
	/* (non-Javadoc)
166
	
167
	/*
168
	 * (non-Javadoc)
166 169
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
167 170
	 */
168 171
	@Override
......
182 185
		nameLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
183 186
				false, false));
184 187
		nameLabel.setFont(newf);
185

  
188
		
186 189
		nameText = new Text(c, SWT.BORDER);
187 190
		GridData data = new GridData(GridData.FILL, GridData.FILL, true, false);
188 191
		data.horizontalSpan = 1;
189 192
		nameText.setLayoutData(data);
190

  
193
		
191 194
		final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
192 195
		tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
193 196
				true, true));
194 197
		// First tab
195 198
		// --------------------------------------------------------
196

  
199
		
197 200
		TabItem simpleTab = new TabItem(tabFolder, SWT.NONE);
198

  
201
		
199 202
		simpleTab.setText(TXMUIMessages.simple);
200

  
203
		
201 204
		Composite composite = new Composite(tabFolder, SWT.NONE);
202 205
		simpleTab.setControl(composite);
203

  
206
		
204 207
		GridLayout layout = new GridLayout(2, false);
205 208
		composite.setLayout(layout);
206

  
209
		
207 210
		// StructuralUnit
208 211
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209

  
212
		
210 213
		Label structureLabel = new Label(composite, SWT.NONE);
211 214
		structureLabel.setText(TXMUIMessages.ampStructureColon);
212 215
		structureLabel.setLayoutData(new GridData(GridData.END,
213 216
				GridData.CENTER, false, false));
214

  
217
		
215 218
		structuralUnitsCombo = new Combo(composite, SWT.READ_ONLY);
216 219
		structuralUnitsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
217 220
				true, false));
218

  
221
		
219 222
		List<StructuralUnit> structuralUnits = null;
220 223
		try {
221 224
			structuralUnits = corpus.getOrderedStructuralUnits();
222
		} catch (CqiClientException e) {
225
		}
226
		catch (CqiClientException e) {
223 227
			Log.severe(TXMCoreMessages.bind(TXMCoreMessages.error_error, Log.toString(e)));
224 228
			return null;
225 229
		}
226
		structuralUnitsFinal = new ArrayList<StructuralUnit>();
230
		structuralUnitsFinal = new ArrayList<>();
227 231
		for (StructuralUnit unit : structuralUnits) {
228 232
			if (unit.getName().equals("txmcorpus")) continue; // ignore txmcorpus structure //$NON-NLS-1$
229 233
			
......
241 245
				// }
242 246
			}
243 247
		}
244

  
248
		
245 249
		if (structuralUnitsCombo.getItemCount() == 0) {
246 250
			this.getButton(IDialogConstants.OK_ID).setEnabled(false);
247
		} else {
251
		}
252
		else {
248 253
			structuralUnitsCombo.select(0);
249 254
			String[] items = structuralUnitsCombo.getItems();
250
			for (int i = 0 ; i < items.length ; i++) {
255
			for (int i = 0; i < items.length; i++) {
251 256
				if (items[i].equals("text")) //$NON-NLS-1$
252 257
				{
253 258
					structuralUnitsCombo.select(i);
......
257 262
			selectedStructuralUnit = structuralUnitsFinal.get(0);
258 263
		}
259 264
		// combo.setSize (200, 200);
260

  
265
		
261 266
		// StructuralUnitProperty
262 267
		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263

  
268
		
264 269
		Label propertyLabel = new Label(composite, SWT.NONE);
265 270
		propertyLabel.setText(TXMUIMessages.ampPropertyColon);
266 271
		propertyLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER,
267 272
				false, false));
268

  
273
		
269 274
		propertyCombo = new Combo(composite, SWT.READ_ONLY);
270 275
		propertyCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
271 276
				true, false));
272 277
		// combo.setSize (200, 200);
273 278
		structuralUnitsCombo.addSelectionListener(new SelectionListener() {
279
			
274 280
			@Override
275
			public void widgetDefaultSelected(SelectionEvent e) {
276
			}
277

  
281
			public void widgetDefaultSelected(SelectionEvent e) {}
282
			
278 283
			@Override
279 284
			public void widgetSelected(SelectionEvent event) {
280 285
				reloadProperties();
281 286
			}
282 287
		});
283

  
288
		
284 289
		for (StructuralUnitProperty property : structuralUnitsFinal.get(0).getOrderedProperties()) {
285 290
			if (!(structuralUnitsFinal.get(0).getName().equals("text") &&  //$NON-NLS-1$
286 291
					(property.getName().equals("project") || property.getName().equals("base")))) //$NON-NLS-1$ //$NON-NLS-2$
......
288 293
		}
289 294
		propertyCombo.select(0);
290 295
		selectedStructuralUnitProperty = selectedStructuralUnit.getOrderedProperties()
291
		.get(0);
292

  
296
				.get(0);
297
		
293 298
		propertyCombo.addSelectionListener(new SelectionListener() {
299
			
294 300
			@Override
295
			public void widgetDefaultSelected(SelectionEvent e) {
296
			}
297

  
301
			public void widgetDefaultSelected(SelectionEvent e) {}
302
			
298 303
			@Override
299 304
			public void widgetSelected(SelectionEvent event) {
300 305
				selectedStructuralUnitProperty = selectedStructuralUnit
301
				.getOrderedProperties().get(propertyCombo.getSelectionIndex());
306
						.getOrderedProperties().get(propertyCombo.getSelectionIndex());
302 307
			}
303 308
		});
304

  
309
		
305 310
		reloadProperties();
306

  
311
		
307 312
		// Second Tab : assisted mode
308 313
		TabItem assistedTab = new TabItem(tabFolder, SWT.NONE);
309

  
314
		
310 315
		assistedTab.setText(TXMUIMessages.assisted);
311

  
316
		
312 317
		compositeForAssisted = new PartitionComposer(tabFolder, SWT.NONE,
313 318
				this.corpus);
314 319
		assistedTab.setControl(compositeForAssisted);
315

  
320
		
316 321
		// Third tab: avanced mode
317 322
		// --------------------------------------------------------
318

  
323
		
319 324
		TabItem advancedTab = new TabItem(tabFolder, SWT.NONE);
320 325
		advancedTab.setText(TXMUIMessages.advanced);
321

  
326
		
322 327
		Composite advanceContainer = new Composite(tabFolder, SWT.NONE);
323 328
		GridLayout advanceLayout = new GridLayout(2, false);
324 329
		advanceContainer.setLayout(advanceLayout);
325 330
		advancedTab.setControl(advanceContainer);
326

  
331
		
327 332
		scrollComposite = new ScrolledComposite(advanceContainer, SWT.V_SCROLL
328 333
				| SWT.BORDER);
329 334
		scrollComposite.setLayoutData(new GridData(GridData.FILL,
330 335
				GridData.FILL, true, true, 2, 1));
331

  
336
		
332 337
		Button plusButton = new Button(advanceContainer, SWT.NONE);
333 338
		plusButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER,
334 339
				GridData.FILL, false, false));
335 340
		plusButton.setText("+"); //$NON-NLS-1$
336 341
		plusButton.addListener(SWT.Selection, new Listener() {
342
			
337 343
			@Override
338 344
			public void handleEvent(Event event) {
339 345
				addQueryField();
340 346
			}
341 347
		});
342 348
		
343
		//TODO enable when specified
344
//		Button importButton = new Button(advanceContainer, SWT.NONE);
345
//		importButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER,
346
//				GridData.FILL, false, false));
347
//		importButton.setText("Import from properties file..."); //$NON-NLS-1$
348
//		importButton.addListener(SWT.Selection, new Listener() {
349
//			@Override
350
//			public void handleEvent(Event event) {
351
//				FileDialog d = new FileDialog(event.display.getActiveShell());
352
//				d.setFilterExtensions(new String[] {"*.properties"});
353
//				d.setText("Select a properties file containing CQL queries");
354
//				String path = d.open();
355
//				if (path != null) {
356
//					Properties props = new Properties();
357
//					try {
358
//						props.load(IOUtils.getReader(new File(path)));
359
//						for (Object key : props.keySet()) {
360
//							String value = props.getProperty(key.toString());
361
//							QueryWidget qw = addQueryField(key.toString().substring(0, Math.min(20, key.toString().length())), value);
362
//						}
363
//					} catch (Exception e) {
364
//						// TODO Auto-generated catch block
365
//						e.printStackTrace();
366
//					}
367
//				}
368
//				
369
//			}
370
//		});
371

  
349
		// TODO enable when specified
350
		// Button importButton = new Button(advanceContainer, SWT.NONE);
351
		// importButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER,
352
		// GridData.FILL, false, false));
353
		// importButton.setText("Import from properties file..."); //$NON-NLS-1$
354
		// importButton.addListener(SWT.Selection, new Listener() {
355
		// @Override
356
		// public void handleEvent(Event event) {
357
		// FileDialog d = new FileDialog(event.display.getActiveShell());
358
		// d.setFilterExtensions(new String[] {"*.properties"});
359
		// d.setText("Select a properties file containing CQL queries");
360
		// String path = d.open();
361
		// if (path != null) {
362
		// Properties props = new Properties();
363
		// try {
364
		// props.load(IOUtils.getReader(new File(path)));
365
		// for (Object key : props.keySet()) {
366
		// String value = props.getProperty(key.toString());
367
		// QueryWidget qw = addQueryField(key.toString().substring(0, Math.min(20, key.toString().length())), value);
368
		// }
369
		// } catch (Exception e) {
370
		// // TODO Auto-generated catch block
371
		// e.printStackTrace();
372
		// }
373
		// }
374
		//
375
		// }
376
		// });
377
		
372 378
		compositeForAdvanced = new Composite(scrollComposite, SWT.NONE);
373 379
		GridLayout layoutForAdvanced = new GridLayout(3, false);
374 380
		compositeForAdvanced.setLayout(layoutForAdvanced);
375

  
381
		
376 382
		scrollComposite.setContent(compositeForAdvanced);
377 383
		scrollComposite.setExpandVertical(true);
378 384
		scrollComposite.setExpandHorizontal(true);
379 385
		scrollComposite.addControlListener(new ControlAdapter() {
386
			
380 387
			@Override
381 388
			public void controlResized(ControlEvent e) {
382 389
				Rectangle r = scrollComposite.getClientArea();
......
384 391
						r.width, SWT.DEFAULT));
385 392
			}
386 393
		});
387

  
394
		
388 395
		createAdvancedQueryField();
389

  
396
		
390 397
		// check the state of the OK button according to the change of tab
391 398
		// --------------------------------
392

  
399
		
393 400
		tabFolder.addSelectionListener(new SelectionListener() {
401
			
394 402
			@Override
395
			public void widgetDefaultSelected(SelectionEvent e) {
396
			}
397

  
403
			public void widgetDefaultSelected(SelectionEvent e) {}
404
			
398 405
			@Override
399 406
			public void widgetSelected(SelectionEvent e) {
400 407
				// record the tab currently in use
......
402 409
					isSimpleSelected = true;
403 410
					isAssistedSelected = false;
404 411
					isAdvancedSelected = false;
405
				} else if (tabFolder.getSelectionIndex() == 1) {
412
				}
413
				else if (tabFolder.getSelectionIndex() == 1) {
406 414
					isSimpleSelected = false;
407 415
					isAssistedSelected = true;
408 416
					isAdvancedSelected = false;
409
				} else {
417
				}
418
				else {
410 419
					isSimpleSelected = false;
411 420
					isAssistedSelected = false;
412 421
					isAdvancedSelected = true;
413 422
				}
414 423
			}
415 424
		});
416

  
425
		
417 426
		return tabFolder;
418 427
	}
419

  
428
	
420 429
	/**
421 430
	 * Reload properties.
422 431
	 */
......
424 433
		List<StructuralUnitProperty> properties = null;
425 434
		selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo
426 435
				.getSelectionIndex());
427

  
436
		
428 437
		properties = selectedStructuralUnit.getOrderedProperties();
429 438
		propertyCombo.removeAll();
430 439
		for (StructuralUnitProperty property : properties) {
......
441 450
		if (propertyCombo.getItemCount() > 0) {
442 451
			propertyCombo.select(0);
443 452
			String[] items = propertyCombo.getItems();
444
			for(int i = 0 ; i < items.length ; i++)
453
			for (int i = 0; i < items.length; i++)
445 454
				if (items[i].equals("id")) //$NON-NLS-1$
446 455
				{
447 456
					propertyCombo.select(i);
448 457
					break;
449 458
				}
450 459
			selectedStructuralUnitProperty = selectedStructuralUnit
451
			.getOrderedProperties().get(0);
460
					.getOrderedProperties().get(0);
452 461
			// this.getButton(IDialogConstants.OK_ID).setEnabled(true);
453 462
		}
454 463
	}
455

  
464
	
456 465
	/**
457 466
	 * Return true if no query is currently given in the "advanced" tab (ie if
458 467
	 * all Text field opened are empty).
......
466 475
		}
467 476
		return false;
468 477
	}
469

  
478
	
470 479
	/**
471 480
	 * Creates the advanced query field.
472 481
	 *
......
478 487
		scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width,
479 488
				SWT.DEFAULT));
480 489
	}
481

  
490
	
482 491
	/**
483 492
	 * Adds the query field.
484 493
	 *
......
497 506
	private QueryWidget addQueryField(String name, String value) {
498 507
		final Text advancedPartLabel = new Text(compositeForAdvanced, SWT.BORDER);
499 508
		advancedPartLabel.setText(TXMUIMessages.part
500
				+ (partNames.size() + 1)); 
509
				+ (partNames.size() + 1));
501 510
		advancedPartLabel.setLayoutData(new GridData(GridData.FILL,
502 511
				GridData.CENTER, false, false));
503 512
		if (name != null && name.length() > 0) {
504 513
			advancedPartLabel.setText(name);
505 514
		}
506 515
		partNames.add(advancedPartLabel);
507

  
516
		
508 517
		final QueryWidget queryText;
509 518
		queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN);
510 519
		queryText.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
......
521 530
		minusButton.setText("-"); //$NON-NLS-1$
522 531
		// minusButton.setData(queryText);
523 532
		minusButton.addListener(SWT.Selection, new Listener() {
533
			
524 534
			@Override
525 535
			public void handleEvent(Event event) {
526 536
				queries.remove(queryText);
......
541 551
		
542 552
		return queryText;
543 553
	}
544

  
545
	/* (non-Javadoc)
554
	
555
	/*
556
	 * (non-Javadoc)
546 557
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
547 558
	 */
548 559
	@Override
549 560
	protected void okPressed() {
550
		if (nameText.getText().length() == 0) {
551
			if(isAdvancedSelected())
552
			{
553
				String name = "partition"+(this.corpus.getPartitions().size()+1); //$NON-NLS-1$
554
				nameText.setText(name);
555
				System.out.println(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
556
			}
557
			else if (isAssistedSelected)
558
			{
559
				String name = this.corpus.getName()+"_"+compositeForAssisted.getProperty().getFullName(); //$NON-NLS-1$
560
				nameText.setText(name);
561
				System.out.println(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
562
			}
563
			//return;
564
		}
565

  
561
		
566 562
		if (isAdvancedSelected() && noquery()) {
567 563
			MessageDialog.openError(getShell(),
568 564
					TXMUIMessages.invalidQuery,
569 565
					TXMUIMessages.queriesCannotBeLeftEmpty);
570 566
			return;
571 567
		}
572

  
573
		/*if (isAssistedSelected) {
574
			if (compositeForAssisted.hasUnassigned()) {
575
				System.out.println(Messages.CreatePartitionDialog_11);
576
				return;
577
			}
578
		}*/
579

  
568
		
569
		/*
570
		 * if (isAssistedSelected) {
571
		 * if (compositeForAssisted.hasUnassigned()) {
572
		 * System.out.println(Messages.CreatePartitionDialog_11);
573
		 * return;
574
		 * }
575
		 * }
576
		 */
577
		
580 578
		for (QueryWidget query : queries) {
581 579
			queriesString.add(query.getQueryString());
582 580
			query.memorize();
583 581
		}
584
		name = nameText.getText();
585
		partition = _getPartition();
582
		partition = createPartition();
586 583
		super.okPressed();
587 584
	}
588

  
585
	
589 586
	/**
590 587
	 * Tell if the user is using the "advanced" tab.
591 588
	 *
......
594 591
	public boolean isAdvancedSelected() {
595 592
		return isAdvancedSelected;
596 593
	}
597

  
594
	
598 595
	/**
599 596
	 * Gets the structural unit.
600 597
	 *
......
605 602
			throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
606 603
		return selectedStructuralUnit;
607 604
	}
608

  
605
	
609 606
	/**
610 607
	 * Gets the structural unit property.
611 608
	 *
......
616 613
			throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
617 614
		return selectedStructuralUnitProperty;
618 615
	}
619

  
616
	
620 617
	/**
621 618
	 * Gets the queries.
622 619
	 *
......
627 624
			throw new IllegalStateException(TXMUIMessages.cannotAskForTheSimpleTabWhenTheUserHasSelectedTheAdvancedTab);
628 625
		return queriesString;
629 626
	}
630

  
627
	
628
	
631 629
	/**
632
	 * Gets the name.
630
	 * Creates the partition.
633 631
	 *
634
	 * @return the name
635
	 */
636
	public String getName() {
637
		// if (!isAdvancedSelected()) throw new
638
		// IllegalStateException(Messages.CreatePartitionDialog_20);
639
		return name;
640
	}
641

  
642
	/**
643
	 * _get partition.
644
	 *
645 632
	 * @return the partition
646 633
	 */
647
	public Partition _getPartition() {
648
		Partition p = null;
634
	public Partition createPartition() {
635
		
636
		Partition partition = null;
637
		
638
		String name = nameText.getText();
639
		
640
		
641
		// Simple mode
649 642
		if (isSimpleSelected) {
643
			
644
			
650 645
			StructuralUnit structuralUnit = this.structuralUnitsFinal.get(this.structuralUnitsCombo.getSelectionIndex());
651 646
			StructuralUnitProperty property = structuralUnit.getProperty(this.propertyCombo.getText());
652 647
			try {
653
				p = new Partition(corpus);
654
				p.setParameters(getName(), property, null);
655
			} catch (Exception e) {
648
				
649
				// auto-naming if needed
650
				if (name.isEmpty()) {
651
					name = corpus.getName() + "_" + property.getFullName(); //$NON-NLS-1$
652
				}
653
				
654
				partition = new Partition(corpus);
655
				partition.setParameters(name, property, null);
656
			}
657
			catch (Exception e) {
656 658
				org.txm.utils.logger.Log.printStackTrace(e);
657 659
				return null;
658 660
			}
659 661
		}
662
		// Assisted mode
660 663
		else if (isAssistedSelected) {
661
			p = this.compositeForAssisted.getPartition(getName());
664
			
665
			// auto-naming if needed
666
			if (name.isEmpty()) {
667
				name = this.corpus.getName() + "_" + compositeForAssisted.getProperty().getFullName(); //$NON-NLS-1$
668
				Log.info(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
669
			}
670
			
671
			// FIXME: SJ: getPartition() calls a compute() so the compute is done 2 times when using Assisted Mode? need to check
672
			partition = this.compositeForAssisted.getPartition(name);
662 673
		}
674
		// Advanced mode
663 675
		else if (isAdvancedSelected) {
664 676
			try {
665
				p = new Partition(corpus);
666
				p.setParameters(getName(), getQueries(), getAdvancePartNames());
667
			} catch (Exception e) {
677
				
678
				// auto-naming if needed
679
				if (name.isEmpty()) {
680
					name = "partition" + (this.corpus.getPartitions().size() + 1); //$NON-NLS-1$
681
					Log.info(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
682
				}
683
				
684
				partition = new Partition(this.corpus);
685
				partition.setParameters(name, this.getQueries(), this.getAdvancePartNames());
686
			}
687
			catch (Exception e) {
668 688
				org.txm.utils.logger.Log.printStackTrace(e);
669 689
				return null;
670 690
			}
671 691
		}
672

  
673
		if (p == null) {
692
		
693
		// Error
694
		if (partition == null) {
674 695
			Log.severe(TXMUIMessages.noPartWasDefined);
675 696
			return null;
676 697
		}
677 698
		
678
		return p;
699
		return partition;
679 700
	}
680

  
701
	
681 702
	/**
682 703
	 * Gets the advance part names.
683 704
	 *
684 705
	 * @return the advance part names
685 706
	 */
686 707
	private List<String> getAdvancePartNames() {
687
		ArrayList<String> values = new ArrayList<String>();
708
		ArrayList<String> values = new ArrayList<>();
688 709
		int count = 0;
689
		for (Text t: partNames) {
710
		for (Text t : partNames) {
690 711
			String name = t.getText().trim();
691 712
			if (name.length() == 0)
692
				name = TXMUIMessages.part + count++; //$NON-NLS-1$
713
				name = TXMUIMessages.part + count++;
693 714
			values.add(name);
694 715
		}
695 716
		return values;
696 717
	}
697

  
718
	
698 719
	/**
699 720
	 * Gets the partition.
700 721
	 *
......
703 724
	public Partition getPartition() {
704 725
		return partition;
705 726
	}
706
}
727
}

Also available in: Unified diff