/
ParameterDialog.java
4713 lines (4170 loc) · 137 KB
/
ParameterDialog.java
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2004, 2007 Actuate Corporation.
* 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:
* Actuate Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.birt.report.designer.ui.dialogs;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.birt.core.data.DataTypeUtil;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.format.DateFormatter;
import org.eclipse.birt.core.format.NumberFormatter;
import org.eclipse.birt.core.format.StringFormatter;
import org.eclipse.birt.report.data.adapter.api.AdapterException;
import org.eclipse.birt.report.data.adapter.api.DataAdapterUtil;
import org.eclipse.birt.report.designer.data.ui.util.SelectValueFetcher;
import org.eclipse.birt.report.designer.internal.ui.data.DataService;
import org.eclipse.birt.report.designer.internal.ui.dialogs.ImportValueDialog;
import org.eclipse.birt.report.designer.internal.ui.dialogs.SelectionChoiceDialog;
import org.eclipse.birt.report.designer.internal.ui.dialogs.expression.ExpressionButton;
import org.eclipse.birt.report.designer.internal.ui.dialogs.expression.ExpressionEditor;
import org.eclipse.birt.report.designer.internal.ui.dialogs.expression.IExpressionHelper;
import org.eclipse.birt.report.designer.internal.ui.dialogs.helper.DefaultParameterDialogControlTypeHelper;
import org.eclipse.birt.report.designer.internal.ui.dialogs.helper.IDialogHelper;
import org.eclipse.birt.report.designer.internal.ui.dialogs.helper.IDialogHelperProvider;
import org.eclipse.birt.report.designer.internal.ui.expressions.ExpressionContextFactoryImpl;
import org.eclipse.birt.report.designer.internal.ui.expressions.IExpressionContextFactory;
import org.eclipse.birt.report.designer.internal.ui.expressions.IExpressionConverter;
import org.eclipse.birt.report.designer.internal.ui.swt.custom.ITableAreaModifier;
import org.eclipse.birt.report.designer.internal.ui.swt.custom.TableArea;
import org.eclipse.birt.report.designer.internal.ui.util.DataUtil;
import org.eclipse.birt.report.designer.internal.ui.util.ExceptionHandler;
import org.eclipse.birt.report.designer.internal.ui.util.ExpressionButtonUtil;
import org.eclipse.birt.report.designer.internal.ui.util.ExpressionButtonUtil.ExpressionHelper;
import org.eclipse.birt.report.designer.internal.ui.util.ExpressionUtility;
import org.eclipse.birt.report.designer.internal.ui.util.IHelpContextIds;
import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;
import org.eclipse.birt.report.designer.internal.ui.util.WidgetUtil;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.IReportGraphicConstants;
import org.eclipse.birt.report.designer.ui.ReportPlatformUIImages;
import org.eclipse.birt.report.designer.ui.parameters.ParameterUtil;
import org.eclipse.birt.report.designer.ui.views.ElementAdapterManager;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.ChoiceSetFactory;
import org.eclipse.birt.report.designer.util.DEUtil;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.Expression;
import org.eclipse.birt.report.model.api.ExpressionHandle;
import org.eclipse.birt.report.model.api.ExpressionType;
import org.eclipse.birt.report.model.api.FormatValueHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ReportItemHandle;
import org.eclipse.birt.report.model.api.ResultSetColumnHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.SelectionChoiceHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.VariableElementHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.birt.report.model.api.elements.structures.FormatValue;
import org.eclipse.birt.report.model.api.elements.structures.SelectionChoice;
import org.eclipse.birt.report.model.api.metadata.IChoice;
import org.eclipse.birt.report.model.api.metadata.IChoiceSet;
import org.eclipse.birt.report.model.api.util.ParameterValidationUtil;
import org.eclipse.birt.report.model.api.util.StringUtil;
import org.eclipse.birt.report.model.elements.interfaces.IScalarParameterModel;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import com.ibm.icu.util.ULocale;
/**
* The dialog used to create or edit a parameter
*/
public class ParameterDialog extends BaseTitleAreaDialog
{
private static final String NULL_VALUE = Messages.getString( "ParameterDialog.Value.Null" ); //$NON-NLS-1$
private static final String EMPTY_VALUE = Messages.getString( "ParameterDialog.Value.Empty" ); //$NON-NLS-1$
private static final String CHOICE_NO_DEFAULT = Messages.getString( "ParameterDialog.Choice.NoDefault" ); //$NON-NLS-1$
private static final String CHOICE_DISPLAY_TEXT = Messages.getString( "ParameterDialog.Choice.DisplayText" ); //$NON-NLS-1$
private static final String CHOICE_VALUE_COLUMN = Messages.getString( "ParameterDialog.Choice.ValueColumn" ); //$NON-NLS-1$
private static final String CHOICE_ASCENDING = Messages.getString( "ParameterDialog.Choice.ASCENDING" ); //$NON-NLS-1$
private static final String CHOICE_DESCENDING = Messages.getString( "ParameterDialog.Choice.DESCENDING" ); //$NON-NLS-1$
private static final String CHOICE_SELECT_VALUE = Messages.getString( "ParameterDialog.Choice.SelectValue" ); //$NON-NLS-1$
private static final String GROUP_MORE_OPTION = Messages.getString( "ParameterDialog.Group.MoreOption" ); //$NON-NLS-1$
private static final String LABEL_NAME = Messages.getString( "ParameterDialog.Label.Name" ); //$NON-NLS-1$
private static final String LABEL_DATETIME_PROMPT = Messages.getFormattedString( "ParameterDialog.datetime.prompt", new String[]{"yyyy-MM-dd HH:mm:ss.SSS"} ); //$NON-NLS-1$ //$NON-NLS-2$
private static final String LABEL_DATE_PROMPT = Messages.getFormattedString( "ParameterDialog.date.prompt", new String[]{"yyyy-MM-dd"} ); //$NON-NLS-1$ //$NON-NLS-2$
private static final String LABEL_TIME_PROMPT = Messages.getFormattedString( "ParameterDialog.time.prompt", new String[]{"hh:mm:ss"} ); //$NON-NLS-1$ //$NON-NLS-2$
private static final String LABEL_PROMPT_TEXT = Messages.getString( "ParameterDialog.Label.PromptText" ); //$NON-NLS-1$
private static final String LABEL_PARAM_DATA_TYPE = Messages.getString( "ParameterDialog.Label.DataType" ); //$NON-NLS-1$
private static final String LABEL_DISPALY_TYPE = Messages.getString( "ParameterDialog.Label.DisplayType" ); //$NON-NLS-1$
private static final String LABEL_DEFAULT_VALUE = Messages.getString( "ParameterDialog.Label.DefaultValue" ); //$NON-NLS-1$
private static final String LABEL_HELP_TEXT = Messages.getString( "ParameterDialog.Label.HelpText" ); //$NON-NLS-1$
private static final String LABEL_LIST_OF_VALUE = Messages.getString( "ParameterDialog.Label.ListOfValue" ); //$NON-NLS-1$
private static final String LABEL_SORT_GROUP = Messages.getString( "ParameterDialog.Label.SortGroup" ); //$NON-NLS-1$
private static final String LABEL_VALUES = Messages.getString( "ParameterDialog.Label.Value" ); //$NON-NLS-1$
private static final String LABEL_FORMAT = Messages.getString( "ParameterDialog.Label.Format" ); //$NON-NLS-1$
private static final String LABEL_LIST_LIMIT = Messages.getString( "ParameterDialog.Label.Listlimit" ); //$NON-NLS-1$
private static final String LABEL_NULL = ParameterUtil.LABEL_NULL;
private static final String LABEL_SELECT_DISPLAY_TEXT = Messages.getString( "ParameterDialog.Label.SelectDisplayText" ); //$NON-NLS-1$
private static final String LABEL_SELECT_VALUE_COLUMN = Messages.getString( "ParameterDialog.Label.SelectValueColumn" ); //$NON-NLS-1$
private static final String LABEL_SELECT_DATA_SET = Messages.getString( "ParameterDialog.Label.SelectDataSet" ); //$NON-NLS-1$
private static final String LABEL_PREVIEW = Messages.getString( "ParameterDialog.Label.Preview" ); //$NON-NLS-1$
private static final String LABEL_SORT_KEY = Messages.getString( "ParameterDialog.Label.SortKey" ); //$NON-NLS-1$
private static final String LABEL_SORT_DIRECTION = Messages.getString( "ParameterDialog.Label.SortDirection" ); //$NON-NLS-1$
private static final String CHECKBOX_ISREQUIRED = Messages.getString( "ParameterDialog.CheckBox.IsRequired" ); //$NON-NLS-1$
private static final String CHECKBOX_DO_NOT_ECHO = Messages.getString( "ParameterDialog.CheckBox.DoNotEchoInput" ); //$NON-NLS-1$
private static final String CHECKBOX_HIDDEN = Messages.getString( "ParameterDialog.CheckBox.Hidden" ); //$NON-NLS-1$
private static final String CHECKBOX_DISTINCT = Messages.getString( "ParameterDialog.CheckBox.Distinct" ); //$NON-NLS-1$
private static final String BUTTON_LABEL_CHANGE_FORMAT = Messages.getString( "ParameterDialog.Button.ChangeFormat" ); //$NON-NLS-1$
private static final String BUTTON_LABEL_IMPORT = Messages.getString( "ParameterDialog.Button.ImportValue" ); //$NON-NLS-1$
private static final String BUTTON_LABEL_SET_DEFAULT = Messages.getString( "ParameterDialog.Button.SetDefault" ); //$NON-NLS-1$
private static final String BUTTON_LABEL_REMOVE_DEFAULT = Messages.getString( "ParameterDialog.Button.RemoveDefault" ); //$NON-NLS-1$
private static final String BUTTON_CREATE_DATA_SET = Messages.getString( "ParameterDialog.Button.CreateDataSet" ); //$NON-NLS-1$
private static final String RADIO_DYNAMIC = Messages.getString( "ParameterDialog.Radio.Dynamic" ); //$NON-NLS-1$
private static final String CHECK_ALLOW_MULTI = Messages.getString( "ParameterDialog.Check.AllowMulti" ); //$NON-NLS-1$
private static final String RADIO_STATIC = Messages.getString( "ParameterDialog.Radio.Static" ); //$NON-NLS-1$
private static final String ERROR_TITLE_INVALID_LIST_LIMIT = Messages.getString( "ParameterDialog.ErrorTitle.InvalidListLimit" ); //$NON-NLS-1$
private static final String ERROR_MSG_CANNOT_BE_BLANK = Messages.getString( "ParameterDialog.ErrorMessage.CanootBeBlank" ); //$NON-NLS-1$
private static final String ERROR_MSG_CANNOT_BE_NULL = Messages.getString( "ParameterDialog.ErrorMessage.CanootBeNull" ); //$NON-NLS-1$
private static final String ERROR_MSG_DUPLICATED_VALUE = Messages.getString( "ParameterDialog.ErrorMessage.DuplicatedValue" ); //$NON-NLS-1$
private static final String ERROR_MSG_DUPLICATED_LABEL = Messages.getString( "ParameterDialog.ErrorMessage.DuplicatedLabel" ); //$NON-NLS-1$
private static final String ERROR_MSG_DUPLICATED_LABELKEY = Messages.getString( "ParameterDialog.ErrorMessage.DuplicatedLabelKey" ); //$NON-NLS-1$
private static final String ERROR_MSG_MISMATCH_DATA_TYPE = Messages.getString( "ParameterDialog.ErrorMessage.MismatchDataType" ); //$NON-NLS-1$
private static final String ERROR_MSG_DUPLICATED_NAME = Messages.getString( "ParameterDialog.ErrorMessage.DuplicatedName" ); //$NON-NLS-1$
private static final String ERROR_MSG_NAME_IS_EMPTY = Messages.getString( "ParameterDialog.ErrorMessage.EmptyName" ); //$NON-NLS-1$
private static final String ERROR_MSG_NO_AVAILABLE_COLUMN = Messages.getString( "ParameterDialog.ErrorMessage.NoAvailableColumn" ); //$NON-NLS-1$
private static final String ERROR_MSG_VALUE_COLUMN_EMPTY = Messages.getString( "ParameterDialog.ErrorMessage.ValueColumnEmpty" ); //$NON-NLS-1$
private static final String ERROR_MSG_INVALID_LIST_LIMIT = Messages.getString( "ParameterDialog.ErrorMessage.InvalidListLimit" ); //$NON-NLS-1$
private static final String FLAG_DEFAULT = Messages.getString( "ParameterDialog.Flag.Default" ); //$NON-NLS-1$
private static final String COLUMN_VALUE = Messages.getString( "ParameterDialog.Column.Value" ); //$NON-NLS-1$
private static final String COLUMN_DISPLAY_TEXT = Messages.getString( "ParameterDialog.Column.DisplayText" ); //$NON-NLS-1$
private static final String COLUMN_DISPLAY_TEXT_KEY = Messages.getString( "ParameterDialog.Column.DisplayTextKey" ); //$NON-NLS-1$
private static final String COLUMN_IS_DEFAULT = Messages.getString( "ParameterDialog.Column.Default" ); //$NON-NLS-1$
private static final String BOOLEAN_TRUE = Messages.getString( "ParameterDialog.Boolean.True" ); //$NON-NLS-1$
private static final String BOOLEAN_FALSE = Messages.getString( "ParameterDialog.Boolean.False" ); //$NON-NLS-1$
public static final String PARAM_CONTROL_LIST = DesignChoiceConstants.PARAM_CONTROL_LIST_BOX
+ "/List"; //$NON-NLS-1$
public static final String PARAM_CONTROL_COMBO = DesignChoiceConstants.PARAM_CONTROL_LIST_BOX
+ "/Combo"; //$NON-NLS-1$
public static final String DISPLAY_NAME_CONTROL_LIST = Messages.getString( "ParameterDialog.DisplayLabel.List" ); //$NON-NLS-1$
public static final String DISPLAY_NAME_CONTROL_COMBO = Messages.getString( "ParameterDialog.DisplayLabel.Combo" ); //$NON-NLS-1$
private static final String NONE_DISPLAY_TEXT = Messages.getString( "ParameterDialog.Label.None" ); //$NON-NLS-1$
private static final Image DEFAULT_ICON = ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_DEFAULT );
private static final Image NOT_DEFAULT_ICON = ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_DEFAULT_NOT );
public static final String CONTROLTYPE_VALUE = "controltype";//$NON-NLS-1$
public static final String DATATYPE_VALUE = "datatype";//$NON-NLS-1$
public static final String STATIC_VALUE = "static";//$NON-NLS-1$
public static final String HELPER_KEY_CONTROLTYPE = "controlType";//$NON-NLS-1$
public static final String HELPER_KEY_STARTPOINT = "autoSuggestStartPoint";//$NON-NLS-1$
public static final String CONTROLTYPE_INPUTVALUE = "controltypeinput"; //$NON-NLS-1$
public static final String STARTPOINT_INPUTVALUE = "startpointinput"; //$NON-NLS-1$
public static final String STARTPOINT_VALUE = "startpoint"; //$NON-NLS-1$
private boolean allowMultiValueVisible = true;
private HashMap dirtyProperties = new HashMap( 5 );
private ArrayList choiceList = new ArrayList( );
private Map<SelectionChoice,SelectionChoice> editChoiceMap = new HashMap<SelectionChoice,SelectionChoice>();
private static final IChoiceSet DATA_TYPE_CHOICE_SET = DEUtil.getMetaDataDictionary( )
.getElement( ReportDesignConstants.SCALAR_PARAMETER_ELEMENT )
.getProperty( ScalarParameterHandle.DATA_TYPE_PROP )
.getAllowedChoices( );
private static final double DEFAULT_PREVIEW_NUMBER = 1234.56;
private static final int DEFAULT_PREVIEW_INTEGER = 123456;
private ScalarParameterHandle inputParameter;
private boolean loading = true;
private Text nameEditor, promptTextEditor, helpTextEditor, formatField;
// Prompt message line
private Label promptMessageLine;
// Error message line
// private CLabel errorMessageLine;
// Check boxes
private Button isRequired, doNotEcho, isHidden, distinct;
// Push buttons
private Button importValue, changeDefault, changeFormat, createDataSet;
// Radio buttons
private Button dynamicRadio, staticRadio;
private Button allowMultiChoice;
// Combo chooser for static
private Combo dataTypeChooser;
private CCombo defaultValueChooser;
// Combo chooser for dynamic
private Combo dataSetChooser, columnChooser, displayTextChooser,
sortKeyChooser, sortDirectionChooser;
// Label
private Label sortKeyLabel, sortDirectionLabel;
private CLabel previewLabel;
private TableViewer valueTable;
private String lastDataType, lastControlType;
private String formatCategroy, formatPattern;
private ULocale formatLocale;
private List<Expression> defaultValueList;
private Composite valueArea, sorttingArea;
private List columnList;
private TableArea staticTableArea;
private IDialogHelper controlTypeHelper;
private IDialogHelper startPointTypeHelper;
private IStructuredContentProvider contentProvider = new IStructuredContentProvider( ) {
public void dispose( )
{
}
public void inputChanged( Viewer viewer, Object oldInput,
Object newInput )
{
}
public Object[] getElements( Object inputElement )
{
ArrayList list = ( (ArrayList) inputElement );
ArrayList elementsList = (ArrayList) list.clone( );
return elementsList.toArray( );
}
};
private ITableLabelProvider labelProvider = new ITableLabelProvider( ) {
public Image getColumnImage( Object element, int columnIndex )
{
if ( valueTable.getColumnProperties( ).length == 5
&& columnIndex == 1 )
{
SelectionChoice choice = ( (SelectionChoice) element );
if ( isDefaultChoice( choice ) )
{
return DEFAULT_ICON;
}
else
return NOT_DEFAULT_ICON;
}
return null;
}
public String getColumnText( Object element, int columnIndex )
{
SelectionChoice choice = ( (SelectionChoice) element );
final int valueIndex = valueTable.getColumnProperties( ).length - 3;
String text = null;
if ( valueTable.getColumnProperties( ).length == 5
&& columnIndex == 1 )
{
if ( isDefaultChoice( choice ) )
{
text = FLAG_DEFAULT;
}
}
else if ( columnIndex == valueIndex )
{
text = choice.getValue( );
if ( text == null )
text = NULL_VALUE;
else if ( text.equals( "" ) ) //$NON-NLS-1$
text = EMPTY_VALUE;
}
else if ( columnIndex == valueIndex + 1 )
{
text = choice.getLabel( );
if ( text == null )
return ""; //$NON-NLS-1$
}
else if ( columnIndex == valueIndex + 2 )
{
text = choice.getLabelResourceKey( );
}
if ( text == null )
{
text = ""; //$NON-NLS-1$
}
return text;
}
public void addListener( ILabelProviderListener listener )
{
}
public void dispose( )
{
}
public boolean isLabelProperty( Object element, String property )
{
return false;
}
public void removeListener( ILabelProviderListener listener )
{
}
};
private final ITableAreaModifier tableAreaModifier = new ITableAreaModifier( ) {
public boolean editItem( final Object element )
{
final SelectionChoice oldChoice = (SelectionChoice) element;
final SelectionChoice tempChoice = cloneSelectionChoice(oldChoice);
String oldVal = oldChoice.getValue( );
boolean isDefault = isDefaultChoice( oldChoice );
SelectionChoiceDialog dialog = new SelectionChoiceDialog( Messages.getString( "ParameterDialog.SelectionDialog.Edit" ), canBeNull( ), canUseEmptyValue( ) ); //$NON-NLS-1$
dialog.setInput( tempChoice );
dialog.setValidator( new SelectionChoiceDialog.ISelectionChoiceValidator( ) {
public String validate( String displayLableKey,
String displayLabel, String value )
{
return validateChoice( oldChoice,
displayLableKey,
displayLabel,
value );
}
} );
if ( dialog.open( ) == Dialog.OK )
{
// choice.setValue( convertToStandardFormat( choice.getValue( )
// ) );
// oldChoice.setValue( tempChoice.getValue( ) );
editChoiceMap.put(tempChoice, oldChoice);
choiceList.set(choiceList.indexOf(oldChoice), tempChoice);
if ( isDefault )
{
changeDefaultValue( oldVal, tempChoice.getValue( ) );
}
return true;
}
return false;
}
private SelectionChoice cloneSelectionChoice(SelectionChoice choice)
{
SelectionChoice tempChoice = StructureFactory.createSelectionChoice( );
tempChoice.setValue(choice.getValue());
tempChoice.setLabel(choice.getLabel());
tempChoice.setLabelResourceKey(choice.getLabelResourceKey());
return tempChoice;
}
public boolean newItem( )
{
SelectionChoice choice = StructureFactory.createSelectionChoice( );
SelectionChoiceDialog dialog = new SelectionChoiceDialog( Messages.getString( "ParameterDialog.SelectionDialog.New" ), canBeNull( ), canUseEmptyValue( ) ); //$NON-NLS-1$
dialog.setInput( choice );
dialog.setValidator( new SelectionChoiceDialog.ISelectionChoiceValidator( ) {
public String validate( String displayLabelKey,
String displayLabel, String value )
{
return validateChoice( null,
displayLabelKey,
displayLabel,
value );
}
} );
if ( dialog.open( ) == Dialog.OK )
{
// choice.setValue( convertToStandardFormat( choice.getValue( )
// ) );
// choice.setValue( choice.getValue( ) );
choiceList.add( choice );
return true;
}
return false;
}
public boolean removeItem( Object[] elements )
{
for ( int i = 0; i < elements.length; i++ )
{
if ( isDefaultChoice( (SelectionChoice) elements[i] ) )
{
removeDefaultValue( ( (SelectionChoice) elements[i] ).getValue( ) );
}
choiceList.remove( elements[i] );
}
return true;
}
public boolean removeItemAll( )
{
choiceList.clear( );
if ( defaultValueList != null && defaultValueList.size( ) > 0 )
{
defaultValueList.clear( );
valueTable.refresh( );
}
return true;
}
};
protected IStructuredContentProvider tableContentProvider = new IStructuredContentProvider( ) {
public void dispose( )
{
}
public Object[] getElements( Object inputElement )
{
if ( inputElement == null )
{
return new Object[0];
}
else if ( inputElement instanceof List )
{
return ( (List) inputElement ).toArray( );
}
return null;
}
public void inputChanged( Viewer viewer, Object oldInput,
Object newInput )
{
}
};
protected ITableLabelProvider tableLableProvier = new ITableLabelProvider( ) {
public void addListener( ILabelProviderListener listener )
{
}
public void dispose( )
{
}
public Image getColumnImage( Object element, int columnIndex )
{
return null;
}
public String getColumnText( Object element, int columnIndex )
{
if ( columnIndex == 0 )
{
if ( element instanceof Expression )
{
String value = ( (Expression) element ).getStringExpression( );
if ( value == null )
return NULL_VALUE;
else if ( value.equals( "" ) ) //$NON-NLS-1$
return EMPTY_VALUE;
}
return element.toString( );
}
return ""; //$NON-NLS-1$
}
public boolean isLabelProperty( Object element, String property )
{
return false;
}
public void removeListener( ILabelProviderListener listener )
{
}
};
private Text listLimit;
private Composite displayArea;
private boolean isInitialized;
private TableViewer defaultValueViewer;
private Button delBtn;
private Button editBtn;
private Button delAllBtn;
private Group valuesDefineSection;
private Button addButton;
private Composite rightPart;
/**
* Create a new parameter dialog with given title under the active shell
*
* @param title
* the title of the dialog
*/
public ParameterDialog( String title )
{
this( UIUtil.getDefaultShell( ), title );
}
/**
* Create a new parameter dialog with given title under the specified shell
*
* @param parentShell
* the parent shell of the dialog
* @param title
* the title of the dialog
*/
public ParameterDialog( Shell parentShell, String title )
{
super( parentShell );
this.title = title;
}
public ParameterDialog( Shell parentShell, String title,
boolean allowMultiValueVisible )
{
this( parentShell, title );
this.allowMultiValueVisible = allowMultiValueVisible;
}
protected Control createDialogArea( Composite parent )
{
setMessage( Messages.getString( "ParameterDialog.message" ) ); //$NON-NLS-1$
ScrolledComposite scrollContent = new ScrolledComposite( (Composite) super.createDialogArea( parent ),
SWT.H_SCROLL | SWT.V_SCROLL );
scrollContent.setAlwaysShowScrollBars( false );
scrollContent.setExpandHorizontal( true );
scrollContent.setMinWidth( 600 );
scrollContent.setLayout( new FillLayout( ) );
scrollContent.setLayoutData( new GridData( GridData.FILL_BOTH ) );
displayArea = new Composite( scrollContent, SWT.NONE );
Composite topComposite = new Composite( displayArea, SWT.NONE );
topComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
topComposite.setLayout( new GridLayout( 2, false ) );
createPropertiesSection( topComposite );
createDisplayOptionsSection( topComposite );
createValuesDefineSection( displayArea );
displayArea.setLayout( new GridLayout( ) );
Point size = displayArea.computeSize( SWT.DEFAULT, SWT.DEFAULT );
displayArea.setSize( size );
scrollContent.setContent( displayArea );
UIUtil.bindHelp( parent, IHelpContextIds.PARAMETER_DIALOG_ID );
return scrollContent;
}
private void createPropertiesSection( Composite composite )
{
Composite propertiesSection = new Composite( composite, SWT.NONE );
propertiesSection.setLayout( new GridLayout( ) );
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
gd.widthHint = 200;
propertiesSection.setLayoutData( gd );
createLabel( propertiesSection, LABEL_NAME );
nameEditor = new Text( propertiesSection, SWT.BORDER );
nameEditor.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
nameEditor.addModifyListener( new ModifyListener( ) {
public void modifyText( ModifyEvent e )
{
updateMessageLine( );
}
} );
createLabel( propertiesSection, LABEL_PROMPT_TEXT );
promptTextEditor = new Text( propertiesSection, SWT.BORDER );
promptTextEditor.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
createLabel( propertiesSection, LABEL_PARAM_DATA_TYPE );
dataTypeChooser = new Combo( propertiesSection, SWT.READ_ONLY
| SWT.DROP_DOWN );
dataTypeChooser.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
dataTypeChooser.setItems( ChoiceSetFactory.getDisplayNamefromChoiceSet( DATA_TYPE_CHOICE_SET ) );
dataTypeChooser.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
changeDataType( );
updateCheckBoxArea( );
refreshColumns( true );
// Reset control type status
handleControlTypeSelectionEvent( );
}
} );
createLabel( propertiesSection, LABEL_DISPALY_TYPE );
createControlTypeChooser( propertiesSection );
}
private void createControlTypeChooser( Composite propertiesSection )
{
IDialogHelperProvider helperProvider = (IDialogHelperProvider) ElementAdapterManager.getAdapter( this,
IDialogHelperProvider.class );
if ( helperProvider != null )
{
controlTypeHelper = helperProvider.createHelper( this,
HELPER_KEY_CONTROLTYPE );
}
if ( controlTypeHelper == null )
{
controlTypeHelper = new DefaultParameterDialogControlTypeHelper( );
}
controlTypeHelper.setContainer( this );
controlTypeHelper.createContent( propertiesSection );
controlTypeHelper.getControl( )
.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
controlTypeHelper.addListener( SWT.Selection, new Listener( ) {
public void handleEvent( Event event )
{
handleControlTypeSelectionEvent( );
}
} );
}
private void createDisplayOptionsSection( Composite composite )
{
Group displayOptionSection = new Group( composite, SWT.NONE );
displayOptionSection.setText( GROUP_MORE_OPTION );
displayOptionSection.setLayout( new GridLayout( 2, false ) );
displayOptionSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
createLabel( displayOptionSection, LABEL_HELP_TEXT );
helpTextEditor = new Text( displayOptionSection, SWT.BORDER );
helpTextEditor.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
createLabel( displayOptionSection, LABEL_FORMAT );
Composite formatSection = new Composite( displayOptionSection, SWT.NONE );
formatSection.setLayout( UIUtil.createGridLayoutWithoutMargin( 2, false ) );
formatSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
formatField = new Text( formatSection, SWT.BORDER
| SWT.SINGLE
| SWT.READ_ONLY );
GridData fFgd = new GridData( GridData.FILL_HORIZONTAL );
fFgd.minimumWidth = 180;
formatField.setLayoutData( fFgd );
changeFormat = new Button( formatSection, SWT.PUSH );
changeFormat.setText( BUTTON_LABEL_CHANGE_FORMAT );
setButtonLayoutData( changeFormat );
changeFormat.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
popupFormatBuilder( true );
}
} );
createLabel( displayOptionSection, null );
Group previewArea = new Group( displayOptionSection, SWT.NONE );
previewArea.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
previewArea.setLayout( UIUtil.createGridLayoutWithoutMargin( ) );
previewArea.setText( LABEL_PREVIEW );
previewLabel = new CLabel( previewArea, SWT.NONE );
previewLabel.setAlignment( SWT.CENTER );
previewLabel.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
// start create list limitation area
createLabel( displayOptionSection, LABEL_LIST_LIMIT );
Composite limitArea = new Composite( displayOptionSection, SWT.NULL );
GridLayout layout = new GridLayout( 2, false );
layout.marginWidth = 0;
layout.marginHeight = 0;
limitArea.setLayout( layout );
GridData data = new GridData( GridData.FILL_HORIZONTAL );
data.verticalSpan = 1;
limitArea.setLayoutData( data );
listLimit = new Text( limitArea, SWT.BORDER );
data = new GridData( );
data.widthHint = 80;
listLimit.setLayoutData( data );
listLimit.addVerifyListener( new VerifyListener( ) {
public void verifyText( VerifyEvent e )
{
e.doit = ( "0123456789\0\b\u007f".indexOf( e.character ) != -1 ); //$NON-NLS-1$
}
} );
Label values = new Label( limitArea, SWT.NULL );
values.setText( Messages.getString( "ParameterDialog.Label.values" ) ); //$NON-NLS-1$
values.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
// end
createLabel( displayOptionSection, null ); // Dummy
Composite checkBoxArea = new Composite( displayOptionSection, SWT.NONE );
checkBoxArea.setLayout( UIUtil.createGridLayoutWithoutMargin( 2, false ) );
checkBoxArea.setLayoutData( new GridData( GridData.FILL_BOTH ) );
isRequired = new Button( checkBoxArea, SWT.CHECK );
isRequired.setText( CHECKBOX_ISREQUIRED );
addCheckBoxListener( isRequired, CHECKBOX_ISREQUIRED );
doNotEcho = new Button( checkBoxArea, SWT.CHECK );
doNotEcho.setText( CHECKBOX_DO_NOT_ECHO );
addCheckBoxListener( doNotEcho, CHECKBOX_DO_NOT_ECHO );
isHidden = new Button( checkBoxArea, SWT.CHECK );
isHidden.setText( CHECKBOX_HIDDEN );
addCheckBoxListener( isHidden, CHECKBOX_HIDDEN );
distinct = new Button( checkBoxArea, SWT.CHECK );
distinct.setText( CHECKBOX_DISTINCT );
distinct.setSelection( false );
addCheckBoxListener( distinct, CHECKBOX_DISTINCT );
createStartPointSection( displayOptionSection );
}
private void createStartPointSection( Group displayOptionSection )
{
IDialogHelperProvider helperProvider = (IDialogHelperProvider) ElementAdapterManager.getAdapter( this,
IDialogHelperProvider.class );
if ( helperProvider != null )
{
startPointTypeHelper = helperProvider.createHelper( this,
HELPER_KEY_STARTPOINT );
}
if ( startPointTypeHelper != null )
{
startPointTypeHelper.createContent( displayOptionSection );
GridData data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
startPointTypeHelper.getControl( ).setLayoutData( data );
startPointTypeHelper.addListener( SWT.Modify, new Listener( ) {
public void handleEvent( Event event )
{
startPointTypeHelper.update( false );
}
} );
}
}
private void hideStartPointSection( boolean hide )
{
if ( startPointTypeHelper != null
&& startPointTypeHelper.getControl( ) != null )
{
GridData gd = (GridData) startPointTypeHelper.getControl( )
.getLayoutData( );
gd.exclude = hide;
startPointTypeHelper.getControl( ).setVisible( !hide );
startPointTypeHelper.getControl( ).getParent( ).layout( );
if ( !hide )
startPointTypeHelper.update( true );
}
}
private void createValuesDefineSection( Composite composite )
{
valuesDefineSection = new Group( composite, SWT.NONE );
valuesDefineSection.setText( LABEL_LIST_OF_VALUE );
valuesDefineSection.setLayout( new GridLayout( 2, false ) );
valuesDefineSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
Composite choiceArea = new Composite( valuesDefineSection, SWT.NONE );
choiceArea.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
choiceArea.setLayout( UIUtil.createGridLayoutWithoutMargin( 4, true ) );
staticRadio = new Button( choiceArea, SWT.RADIO );
staticRadio.setText( RADIO_STATIC );
GridData gd = new GridData( );
gd.widthHint = Math.max( staticRadio.computeSize( SWT.DEFAULT,
SWT.DEFAULT ).x, 100 );
gd.horizontalIndent = 40;
staticRadio.setLayoutData( gd );
staticRadio.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
if ( staticRadio.getSelection( ) )
switchParamterType( );
}
} );
dynamicRadio = new Button( choiceArea, SWT.RADIO );
dynamicRadio.setText( RADIO_DYNAMIC );
dynamicRadio.setLayoutData( new GridData( ) );
dynamicRadio.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
if ( dynamicRadio.getSelection( ) )
switchParamterType( );
}
} );
allowMultiChoice = new Button( choiceArea, SWT.CHECK );
allowMultiChoice.setText( CHECK_ALLOW_MULTI );
gd = new GridData( );
gd.horizontalSpan = 2;
gd.horizontalAlignment = SWT.END;
gd.grabExcessHorizontalSpace = true;
allowMultiChoice.setLayoutData( gd );
allowMultiChoice.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
// keep one value of default value list when switch from allow
// to disallow
if ( isStatic( ) && !allowMultiChoice.getSelection( ) )
{
if ( defaultValueList != null
&& defaultValueList.size( ) > 0 )
{
Expression expression = getFirstDefaultValue( );
defaultValueList.clear( );
defaultValueList.add( expression );
valueTable.refresh( );
}
// Switch from multiple selection to single selection.
// Deselect all if more than one item is selected.
Table table = staticTableArea.getTableViewer( ).getTable( );
if ( table.getSelectionCount( ) > 1 )
{
table.deselectAll( );
updateStaticTableButtons( );
}
}
initDefaultValueViewer( );
}
} );
valueArea = new Composite( valuesDefineSection, SWT.NONE );
valueArea.setLayout( UIUtil.createGridLayoutWithoutMargin( 2, false ) );
gd = new GridData( GridData.FILL_BOTH );
gd.minimumHeight = 320;
gd.widthHint = 550;
gd.horizontalSpan = 2;