Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 29630976bacd5f4edd92aef7a043542808791001 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
 *   Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr - Bug 493756
 *   
 *****************************************************************************/

package org.eclipse.papyrus.customization.nattableconfiguration.pages;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper;
import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisIndexStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TableHeaderAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.MasterObjectAxisProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.SlaveObjectAxisProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.DisplayStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestyleFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.TableDisplayStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattabletester.JavaTableTester;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattabletester.NattabletesterFactory;
import org.eclipse.papyrus.infra.widgets.editors.BrowseFileEditor;
import org.eclipse.papyrus.infra.widgets.providers.FileExtensions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.Section;

/**
 * This page allows to edit the name, type and icon of a table
 */
public class EditGenericNattableConfigurationFieldsNattableWizardPage extends AbstractTableConfigurationWizardPage {

	/**
	 * The current configuration to modify.
	 */
	private final TableConfiguration configuration;

	/**
	 * Constructor.
	 *
	 * @param helper
	 *            The table configuration helper.
	 */
	public EditGenericNattableConfigurationFieldsNattableWizardPage(final TableConfigurationHelper helper) {
		super(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_pageName, helper);
		configuration = helper.getTableConfiguration();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(final Composite parent) {
		setPageComplete(isPageComplete());
		final Composite container = new Composite(parent, SWT.BORDER);
		container.setLayout(new GridLayout(1, false));
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		// Create the table group and its grid data
		final Group tableGroup = new Group(container, SWT.NONE);
		tableGroup.setLayout(new GridLayout(2, false));
		tableGroup.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_tableConfigurationLabel);
		final GridData tableGroupData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
		tableGroupData.horizontalSpan = 2;
		tableGroup.setLayoutData(tableGroupData);

		// Create the default name text of the table
		final Label labelDefaultName = new Label(tableGroup, SWT.NONE);
		labelDefaultName.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_defaultTableNameLabel);
		labelDefaultName.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text defaultName = new Text(tableGroup, SWT.BORDER);
		defaultName.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				if (!helper.getDefaultTableName().equals(defaultName.getText())) {
					helper.setDefaultTableName(defaultName.getText());
				}
				setPageComplete(isPageComplete());
			}
		});
		final GridData defaultNameLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		defaultNameLayoutData.minimumWidth = 200;
		defaultName.setLayoutData(defaultNameLayoutData);

		// Create the type text of the table
		final Label labelType = new Label(tableGroup, SWT.NONE);
		labelType.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_tableTypeLabel);
		labelType.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text type = new Text(tableGroup, SWT.BORDER);
		type.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				if (!helper.getTableType().equals(type.getText())) {
					helper.setTableType(type.getText());
				}
				setPageComplete(isPageComplete());
			}
		});
		final GridData typeLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		typeLayoutData.minimumWidth = 200;
		type.setLayoutData(typeLayoutData);

		// Create the description text of the table
		final Label labelDescription = new Label(tableGroup, SWT.NONE);
		labelDescription.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_descriptionLabel);
		labelDescription.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text description = new Text(tableGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		description.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				if (!helper.getTableConfigurationDescription().equals(description.getText())) {
					helper.setTableConfigurationDescription(description.getText());
				}
			}
		});
		final GridData descriptionLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		descriptionLayoutData.minimumWidth = 400;
		descriptionLayoutData.heightHint = 50;
		description.setLayoutData(descriptionLayoutData);

		// Create the icon browse editor for the icon of the table
		final BrowseFileEditor iconEditor = new BrowseFileEditor(tableGroup, SWT.NONE);
		iconEditor.setLabel(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_iconToUseLabel);
		iconEditor.setAllowFileSystem(false);
		iconEditor.setAllowWorkspace(true);

		// Get file extensions
		final Set<String> extensions = FileExtensions.imagesFilesExtensions.keySet();
		String[] str1 = extensions.toArray(new String[extensions.size()]);

		final Collection<String> extension2 = FileExtensions.imagesFilesExtensions.values();
		String[] str2 = extension2.toArray(new String[extensions.size()]);

		iconEditor.setFilters(str1, str2);

		iconEditor.getText().setEnabled(false);
		iconEditor.getText().addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				if (!configuration.getIconPath().equals(iconEditor.getText().getText())) {
					helper.setTableIcon(iconEditor.getText().getText());
				}
			}
		});
		final GridData iconGridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		iconGridData.horizontalSpan = 2;
		iconEditor.setLayoutData(iconGridData);

		// Create the combo for the table style (flat or tree)
		final Label labelAxisKind = new Label(tableGroup, SWT.NONE);
		labelAxisKind.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_axisKindLabel);
		final Composite styleComposite = new Composite(tableGroup, SWT.NONE);
		final GridLayout styleCompositeLayoutData = new GridLayout(2, false);
		styleCompositeLayoutData.marginWidth = 0;
		styleCompositeLayoutData.marginHeight = 0;
		styleComposite.setLayout(styleCompositeLayoutData);
		styleComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false));
		final Combo axisKindCombo = new Combo(styleComposite, SWT.NONE);
		final List<String> axisKindStyleList = new ArrayList<String>();
		axisKindStyleList.add(TableConfigurationHelper.AXIS_FLAT_STYLE);
		axisKindStyleList.add(TableConfigurationHelper.AXIS_TREE_STYLE);
		axisKindCombo.setItems((String[]) axisKindStyleList.toArray(new String[axisKindStyleList.size()]));
		final GridData axisKindLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		axisKindLayoutData.minimumWidth = 100;
		axisKindCombo.setLayoutData(axisKindLayoutData);

		// Create the combo for the column header style when this is a tree table
		final Combo treeAxisStyleCombo = new Combo(styleComposite, SWT.NONE);
		final List<String> treeAxisStyleList = new ArrayList<String>();
		treeAxisStyleList.add("Single header column"); //$NON-NLS-1$
		treeAxisStyleList.add("Multiple header column"); //$NON-NLS-1$
		treeAxisStyleCombo.setItems((String[]) treeAxisStyleList.toArray(new String[treeAxisStyleList.size()]));
		final GridData treeAxisStyleLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		treeAxisStyleLayoutData.minimumWidth = 200;
		treeAxisStyleCombo.setLayoutData(treeAxisStyleLayoutData);
		treeAxisStyleCombo.setVisible(false);

		// Manage the modification of the axis kind combo
		axisKindCombo.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// if this is flat, remove the possible table display value and hide the tree axis display style combo
				if (0 == axisKindCombo.getSelectionIndex()) {
					treeAxisStyleCombo.setVisible(false);
					TableDisplayStyle displayStyle = (TableDisplayStyle) configuration.getStyle(NattablestylePackage.eINSTANCE.getTableDisplayStyle());
					if (null != displayStyle) {
						configuration.getStyles().remove(displayStyle);
					}
				} else {
					// This is tree table, set visible the tree axis display style combo
					treeAxisStyleCombo.setVisible(true);
					treeAxisStyleCombo.select(0);
				}
			}
		});

		// Manage the modification of the tree axis display style combo
		treeAxisStyleCombo.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// Get the table display style (or create it if necessary)
				TableDisplayStyle displayStyle = (TableDisplayStyle) configuration.getStyle(NattablestylePackage.eINSTANCE.getTableDisplayStyle());
				if (null == displayStyle) {
					displayStyle = NattablestyleFactory.eINSTANCE.createTableDisplayStyle();
					configuration.getStyles().add(displayStyle);
				}

				// Set the correct value
				if (0 == treeAxisStyleCombo.getSelectionIndex()) {
					displayStyle.setDisplayStyle(DisplayStyle.HIERARCHIC_SINGLE_TREE_COLUMN);
				} else {
					displayStyle.setDisplayStyle(DisplayStyle.HIERARCHIC_MULTI_TREE_COLUMN);
				}
			}
		});

		// Create the description text of the table
		final Label labelJavaTableTester = new Label(tableGroup, SWT.NONE);
		labelJavaTableTester.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_javaTableTesterLabel);
		labelJavaTableTester.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text javaTableTester = new Text(tableGroup, SWT.BORDER);
		javaTableTester.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				JavaTableTester tableTester = configuration.getCreationTester() instanceof JavaTableTester ? (JavaTableTester) configuration.getCreationTester() : null;

				if (null == tableTester) {
					tableTester = NattabletesterFactory.eINSTANCE.createJavaTableTester();
					configuration.setCreationTester(tableTester);
				}

				tableTester.setTester(javaTableTester.getText());
			}
		});
		final GridData javaTableTesterLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		javaTableTesterLayoutData.minimumWidth = 600;
		javaTableTester.setLayoutData(javaTableTesterLayoutData);

		// Initialize the fields
		defaultName.setText(helper.getDefaultTableName());
		type.setText(helper.getTableType());
		description.setText(helper.getTableConfigurationDescription());
		if (null != configuration.getIconPath()) {
			iconEditor.getText().setText(configuration.getIconPath());
		}
		// Select the correct combo item corresponding to the current configuration
		TableDisplayStyle displayStyle = (TableDisplayStyle) configuration.getStyle(NattablestylePackage.eINSTANCE.getTableDisplayStyle());
		if (null != displayStyle) {
			axisKindCombo.select(1);
			if (DisplayStyle.HIERARCHIC_SINGLE_TREE_COLUMN.equals(displayStyle.getDisplayStyle())) {
				treeAxisStyleCombo.select(0);
			} else if (DisplayStyle.HIERARCHIC_MULTI_TREE_COLUMN.equals(displayStyle.getDisplayStyle())) {
				treeAxisStyleCombo.select(1);
			}
		} else {
			axisKindCombo.select(0);
		}
		if (configuration.getCreationTester() instanceof JavaTableTester) {
			javaTableTester.setText(((JavaTableTester) configuration.getCreationTester()).getTester());
		}

		// Create the rows and columns groups
		createRowsGroup(tableGroup);
		createColumnsGroup(tableGroup);

		// Create the master and slave groups
		createMasterGroup(tableGroup);
		createSlaveGroup(tableGroup);

		setControl(container); // should be a container composite here!
	}

	/**
	 * This allows to create the rows group and its fields.
	 * 
	 * @param parent
	 *            The parent composite.
	 */
	protected void createRowsGroup(final Composite parent) {

		// Create the rows composite
		final Composite rowsGroup = createSection(parent, Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_rowsManagementLabel);
		rowsGroup.setLayout(new GridLayout(4, false));

		// Create the index style combo
		final Label labelIndexStyle = new Label(rowsGroup, SWT.NONE);
		labelIndexStyle.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_indexStyleLabel);
		labelIndexStyle.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Combo rowsIndexStyleCombo = new Combo(rowsGroup, SWT.NONE);
		final List<String> indexStyleList = new ArrayList<String>();
		indexStyleList.add(AxisIndexStyle.ALPHABETIC.getName());
		indexStyleList.add(AxisIndexStyle.NUMERIC.getName());
		rowsIndexStyleCombo.setItems((String[]) indexStyleList.toArray(new String[indexStyleList.size()]));
		final GridData rowsIndexStyleLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
		rowsIndexStyleLayoutData.minimumWidth = 100;
		rowsIndexStyleCombo.setLayoutData(rowsIndexStyleLayoutData);
		rowsIndexStyleCombo.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				TableHeaderAxisConfiguration rowHeaderAxisConfiguration = configuration.getRowHeaderAxisConfiguration();
				if (null == rowHeaderAxisConfiguration) {
					rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration);
				}

				if (0 == rowsIndexStyleCombo.getSelectionIndex()) {
					rowHeaderAxisConfiguration.setIndexStyle(AxisIndexStyle.ALPHABETIC);
				} else {
					rowHeaderAxisConfiguration.setIndexStyle(AxisIndexStyle.NUMERIC);
				}
			}
		});

		// Create the display index checkbox
		final Label displayIndexLabel = new Label(rowsGroup, SWT.NONE);
		displayIndexLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayIndexLabel);
		displayIndexLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayIndexButton = new Button(rowsGroup, SWT.CHECK);
		displayIndexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayIndexButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(final SelectionEvent e) {
				TableHeaderAxisConfiguration rowHeaderAxisConfiguration = configuration.getRowHeaderAxisConfiguration();
				if (null == rowHeaderAxisConfiguration) {
					rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration);
				}

				rowHeaderAxisConfiguration.setDisplayIndex(displayIndexButton.getSelection());
			}
		});

		// Create the display label checkbox
		final Label displayLabelLabel = new Label(rowsGroup, SWT.NONE);
		displayLabelLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayLabelLabel);
		displayLabelLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayLabelButton = new Button(rowsGroup, SWT.CHECK);
		displayLabelButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayLabelButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(final SelectionEvent e) {
				TableHeaderAxisConfiguration rowHeaderAxisConfiguration = configuration.getRowHeaderAxisConfiguration();
				if (null == rowHeaderAxisConfiguration) {
					rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration);
				}

				rowHeaderAxisConfiguration.setDisplayLabel(displayLabelButton.getSelection());
			}
		});

		// Create the display filter checkbox
		final Label displayFilterLabel = new Label(rowsGroup, SWT.NONE);
		displayFilterLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayFilterLabel);
		displayFilterLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayFilterButton = new Button(rowsGroup, SWT.CHECK);
		displayFilterButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayFilterButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(final SelectionEvent e) {
				TableHeaderAxisConfiguration rowHeaderAxisConfiguration = configuration.getRowHeaderAxisConfiguration();
				if (null == rowHeaderAxisConfiguration) {
					rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration);
				}

				rowHeaderAxisConfiguration.setDisplayFilter(displayFilterButton.getSelection());
			}
		});

		// Initialize the fields
		// Select the correct combo item corresponding to the current configuration
		TableHeaderAxisConfiguration rowHeaderAxisConfiguration = configuration.getRowHeaderAxisConfiguration();
		if (null != rowHeaderAxisConfiguration) {
			if (AxisIndexStyle.ALPHABETIC.equals(rowHeaderAxisConfiguration.getIndexStyle())) {
				rowsIndexStyleCombo.select(0);
			} else {
				rowsIndexStyleCombo.select(1);
			}
			displayFilterButton.setSelection(rowHeaderAxisConfiguration.isDisplayFilter());
			displayIndexButton.setSelection(rowHeaderAxisConfiguration.isDisplayIndex());
			displayLabelButton.setSelection(rowHeaderAxisConfiguration.isDisplayLabel());
		} else {
			rowsIndexStyleCombo.select(1);
			displayFilterButton.setSelection(false);
			displayIndexButton.setSelection(true);
			displayLabelButton.setSelection(true);
		}
	}

	/**
	 * This allows to create the columns group and its fields.
	 * 
	 * @param parent
	 *            The parent composite.
	 */
	protected void createColumnsGroup(final Composite parent) {

		// Create the columns composite
		final Composite columnsGroup = createSection(parent, Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_columnsManagementLabel);
		columnsGroup.setLayout(new GridLayout(4, false));

		// Create the index style combo
		final Label labelIndexStyle = new Label(columnsGroup, SWT.NONE);
		labelIndexStyle.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_indexStyleLabel);
		labelIndexStyle.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Combo columnsIndexStyleCombo = new Combo(columnsGroup, SWT.NONE);
		final List<String> indexStyleList = new ArrayList<String>();
		indexStyleList.add(AxisIndexStyle.ALPHABETIC.getName());
		indexStyleList.add(AxisIndexStyle.NUMERIC.getName());
		columnsIndexStyleCombo.setItems((String[]) indexStyleList.toArray(new String[indexStyleList.size()]));
		final GridData columnsIndexStyleLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
		columnsIndexStyleLayoutData.minimumWidth = 100;
		columnsIndexStyleCombo.setLayoutData(columnsIndexStyleLayoutData);
		columnsIndexStyleCombo.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				TableHeaderAxisConfiguration columnHeaderAxisConfiguration = configuration.getColumnHeaderAxisConfiguration();
				if (null == columnHeaderAxisConfiguration) {
					columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration);
				}

				if (0 == columnsIndexStyleCombo.getSelectionIndex()) {
					columnHeaderAxisConfiguration.setIndexStyle(AxisIndexStyle.ALPHABETIC);
				} else {
					columnHeaderAxisConfiguration.setIndexStyle(AxisIndexStyle.NUMERIC);
				}
			}
		});

		// Create the display index checkbox
		final Label displayIndexLabel = new Label(columnsGroup, SWT.NONE);
		displayIndexLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayIndexLabel);
		displayIndexLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayIndexButton = new Button(columnsGroup, SWT.CHECK);
		displayIndexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayIndexButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(final SelectionEvent e) {
				TableHeaderAxisConfiguration columnHeaderAxisConfiguration = configuration.getColumnHeaderAxisConfiguration();
				if (null == columnHeaderAxisConfiguration) {
					columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration);
				}

				columnHeaderAxisConfiguration.setDisplayIndex(displayIndexButton.getSelection());
			}
		});

		// Create the display label checkbox
		final Label displayLabelLabel = new Label(columnsGroup, SWT.NONE);
		displayLabelLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayLabelLabel);
		displayLabelLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayLabelButton = new Button(columnsGroup, SWT.CHECK);
		displayLabelButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayLabelButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(final SelectionEvent e) {
				TableHeaderAxisConfiguration columnHeaderAxisConfiguration = configuration.getColumnHeaderAxisConfiguration();
				if (null == columnHeaderAxisConfiguration) {
					columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration);
				}

				columnHeaderAxisConfiguration.setDisplayLabel(displayLabelButton.getSelection());
			}
		});

		// Create the display filter checkbox
		final Label displayFilterLabel = new Label(columnsGroup, SWT.NONE);
		displayFilterLabel.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_displayFilterLabel);
		displayFilterLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button displayFilterButton = new Button(columnsGroup, SWT.CHECK);
		displayFilterButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		displayFilterButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				TableHeaderAxisConfiguration columnHeaderAxisConfiguration = configuration.getColumnHeaderAxisConfiguration();
				if (null == columnHeaderAxisConfiguration) {
					columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration();
					configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration);
				}

				columnHeaderAxisConfiguration.setDisplayFilter(displayFilterButton.getSelection());
			}
		});

		// Initialize the fields
		// Select the correct combo item corresponding to the current configuration
		TableHeaderAxisConfiguration columnHeaderAxisConfiguration = configuration.getColumnHeaderAxisConfiguration();
		if (null != columnHeaderAxisConfiguration) {
			if (AxisIndexStyle.NUMERIC.equals(columnHeaderAxisConfiguration.getIndexStyle())) {
				columnsIndexStyleCombo.select(1);
			} else {
				columnsIndexStyleCombo.select(0);
			}
			displayFilterButton.setSelection(columnHeaderAxisConfiguration.isDisplayFilter());
			displayIndexButton.setSelection(columnHeaderAxisConfiguration.isDisplayIndex());
			displayLabelButton.setSelection(columnHeaderAxisConfiguration.isDisplayLabel());
		} else {
			columnsIndexStyleCombo.select(0);
			displayFilterButton.setSelection(false);
			displayIndexButton.setSelection(true);
			displayLabelButton.setSelection(true);
		}
	}

	/**
	 * This allows to create the master group and its fields.
	 * 
	 * @param parent
	 *            The parent composite.
	 */
	protected void createMasterGroup(final Composite parent) {

		// Create the master group
		final Composite masterGroup = createSection(parent, Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_masterLabel);
		masterGroup.setLayout(new GridLayout(2, false));

		// Create the name text of the master
		final Label labelame = new Label(masterGroup, SWT.NONE);
		labelame.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_nameLabel);
		labelame.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text name = new Text(masterGroup, SWT.BORDER);
		name.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// Set the master name
				getOrCreateMasterObjectAxisProvider(configuration).setName(name.getText());
			}
		});
		final GridData nameLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		nameLayoutData.minimumWidth = 200;
		name.setLayoutData(nameLayoutData);

		// Create the description text of the master
		final Label labelDescription = new Label(masterGroup, SWT.NONE);
		labelDescription.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_descriptionLabel);
		labelDescription.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text description = new Text(masterGroup, SWT.BORDER | SWT.MULTI);
		description.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// Set the master description
				getOrCreateMasterObjectAxisProvider(configuration).setDescription(description.getText());
			}
		});
		final GridData descriptionLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		descriptionLayoutData.minimumWidth = 400;
		descriptionLayoutData.heightHint = 50;
		description.setLayoutData(descriptionLayoutData);

		// Create the disconnect slave checkbox for the master
		final Label labelDisconnectSlave = new Label(masterGroup, SWT.NONE);
		labelDisconnectSlave.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_disconnectSlaveLabel);
		labelDisconnectSlave.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Button disconnectSlave = new Button(masterGroup, SWT.CHECK);
		disconnectSlave.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(final SelectionEvent e) {
				// Set the disconnect slave
				getOrCreateMasterObjectAxisProvider(configuration).setDisconnectSlave(disconnectSlave.getSelection());
			};
		});

		// Initialize the fields
		MasterObjectAxisProvider master = getMasterObjectAxisProvider(configuration);
		if (null != master) {
			name.setText(master.getName());
			description.setText(master.getDescription());
			disconnectSlave.setSelection(master.isDisconnectSlave());
		}
	}

	/**
	 * This allows to create the slave group and its fields.
	 * 
	 * @param parent
	 *            The parent composite.
	 */
	protected void createSlaveGroup(final Composite parent) {
		// Create the slave group
		final Composite slaveGroup = createSection(parent, Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_slaveLabel);
		slaveGroup.setLayout(new GridLayout(2, false));

		// Create the name text for the slave
		final Label labelame = new Label(slaveGroup, SWT.NONE);
		labelame.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_nameLabel);
		labelame.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text name = new Text(slaveGroup, SWT.BORDER);
		name.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// Set the slave description
				getOrCreateSlaveObjectAxisProvider(configuration).setName(name.getText());
			}
		});
		final GridData nameLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		nameLayoutData.minimumWidth = 200;
		name.setLayoutData(nameLayoutData);

		// Create the description text for the slave
		final Label labelDescription = new Label(slaveGroup, SWT.NONE);
		labelDescription.setText(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_descriptionLabel);
		labelDescription.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		final Text description = new Text(slaveGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		description.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(final ModifyEvent e) {
				// Set the slave description
				getOrCreateSlaveObjectAxisProvider(configuration).setDescription(description.getText());
			}
		});
		final GridData descriptionLayoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false);
		descriptionLayoutData.minimumWidth = 400;
		descriptionLayoutData.heightHint = 50;
		description.setLayoutData(descriptionLayoutData);

		// Initialize the fields
		SlaveObjectAxisProvider slave = getSlaveObjectAxisProvider(configuration);
		if (null != slave) {
			name.setText(slave.getName());
			description.setText(slave.getDescription());
		}
	}

	/**
	 * This allows to create a section (which can be expand or collapse).
	 * 
	 * @param parent
	 *            The parent composite.
	 * @param sectionTitle
	 *            The section title.
	 * @return The created section.
	 */
	protected Composite createSection(final Composite parent, final String sectionTitle) {
		// Create a section to manage a better user-friendly interface
		final Section expandableCompoosite = new Section(parent, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
		expandableCompoosite.setText(sectionTitle);
		expandableCompoosite.setExpanded(true);
		expandableCompoosite.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
		expandableCompoosite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1));
		expandableCompoosite.addExpansionListener(new ExpansionAdapter() {
			@Override
			public void expansionStateChanged(final ExpansionEvent e) {
				expandableCompoosite.getParent().getParent().layout();
				expandableCompoosite.getParent().getParent().redraw();
			}
		});

		// Create the composite
		final Composite composite = new Composite(expandableCompoosite, SWT.NONE);
		expandableCompoosite.setClient(composite);

		return composite;
	}

	/**
	 * This allows to get the master axis provider of the configuration.
	 * 
	 * @param configuration
	 *            The current configuration.
	 * @return The master axis provider or <code>null</code> if not existing.
	 */
	protected MasterObjectAxisProvider getMasterObjectAxisProvider(final TableConfiguration configuration) {
		MasterObjectAxisProvider master = null;

		// Try to get an existing master axis provider
		if (0 < configuration.getRowAxisProviders().size()) {
			final Iterator<AbstractAxisProvider> rowAxisProvidersIterator = configuration.getRowAxisProviders().iterator();
			while (rowAxisProvidersIterator.hasNext() && null == master) {
				final AbstractAxisProvider axisProvider = rowAxisProvidersIterator.next();
				if (axisProvider instanceof MasterObjectAxisProvider) {
					master = (MasterObjectAxisProvider) axisProvider;
				}
			}
		}

		return master;
	}

	/**
	 * This allows to get the master axis provider of the configuration if existing or create it otherwise.
	 * 
	 * @param configuration
	 *            The current configuration.
	 * @return The got or created master axis provider.
	 */
	protected MasterObjectAxisProvider getOrCreateMasterObjectAxisProvider(final TableConfiguration configuration) {
		MasterObjectAxisProvider master = getMasterObjectAxisProvider(configuration);

		// The master doesn't exist, create it
		if (null == master) {
			master = NattableaxisproviderFactory.eINSTANCE.createMasterObjectAxisProvider();
			configuration.getRowAxisProviders().add(master);
		}

		// Set the master as default row axis provider if this is not already done
		if (null == configuration.getDefaultRowAxisProvider()) {
			configuration.setDefaultRowAxisProvider(master);
		}

		return master;
	}

	/**
	 * This allows to get the slave axis provider of the configuration.
	 * 
	 * @param configuration
	 *            The current configuration.
	 * @return The slave axis provider or <code>null</code> if not existing.
	 */
	protected SlaveObjectAxisProvider getSlaveObjectAxisProvider(final TableConfiguration configuration) {
		SlaveObjectAxisProvider slave = null;

		// Try to get an existing master axis provider
		if (0 < configuration.getRowAxisProviders().size()) {
			final Iterator<AbstractAxisProvider> columnAxisProvidersIterator = configuration.getColumnAxisProviders().iterator();
			while (columnAxisProvidersIterator.hasNext() && null == slave) {
				final AbstractAxisProvider axisProvider = columnAxisProvidersIterator.next();
				if (axisProvider instanceof SlaveObjectAxisProvider) {
					slave = (SlaveObjectAxisProvider) axisProvider;
				}
			}
		}

		return slave;
	}

	/**
	 * This allows to get the slave axis provider of the configuration if existing or create it otherwise.
	 * 
	 * @param configuration
	 *            The current configuration.
	 * @return The got or created slave axis provider.
	 */
	protected SlaveObjectAxisProvider getOrCreateSlaveObjectAxisProvider(final TableConfiguration configuration) {
		SlaveObjectAxisProvider slave = getSlaveObjectAxisProvider(configuration);

		// The master doesn't exist, create it
		if (null == slave) {
			slave = NattableaxisproviderFactory.eINSTANCE.createSlaveObjectAxisProvider();
			configuration.getColumnAxisProviders().add(slave);
		}

		// Set the master as default row axis provider if this is not already done
		if (null == configuration.getDefaultColumnAxisProvider()) {
			configuration.setDefaultColumnAxisProvider(slave);
		}

		return slave;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
	 */
	@Override
	public boolean isPageComplete() {
		boolean isComplete = true;
		final String name = helper.getDefaultTableName();
		final String type = helper.getTableType();
		String errorMessage = null;
		StringBuffer buffer = new StringBuffer();
		if (name.isEmpty()) {
			buffer.append(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_nameMustBeSetError);
		}

		if (type.isEmpty()) {
			buffer.append(Messages.EditGenericNattableConfigurationFieldsNattableWizardPage_typeMustBeSetError);
		}

		errorMessage = buffer.toString();
		if (errorMessage.isEmpty()) {
			setErrorMessage(null);
		} else {
			setErrorMessage(errorMessage.toString());
		}

		isComplete = !name.isEmpty() && !type.isEmpty();
		return isComplete;
	}

}

Back to the top