Simulator Plug-ins: Bug fixing and enhancements.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / AddAttributeDialog.java
1 package oic.simulator.serviceprovider.view.dialogs;
2
3 import java.util.Iterator;
4 import java.util.Set;
5
6 import oic.simulator.serviceprovider.model.AttributeHelper;
7 import oic.simulator.serviceprovider.utils.Constants;
8
9 import org.eclipse.jface.dialogs.MessageDialog;
10 import org.eclipse.jface.dialogs.TitleAreaDialog;
11 import org.eclipse.jface.window.Window;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.custom.CCombo;
14 import org.eclipse.swt.events.SelectionAdapter;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.swt.graphics.Rectangle;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Event;
25 import org.eclipse.swt.widgets.Group;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.List;
28 import org.eclipse.swt.widgets.Listener;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.swt.widgets.Text;
31 import org.oic.simulator.AttributeProperty.Type;
32
33 public class AddAttributeDialog extends TitleAreaDialog {
34
35     private Text                 attNameTxt;
36     private Text                 minRangeTxt;
37     private Text                 maxRangeTxt;
38     private CCombo               attTypeCmb;
39     private Text                 dflValueTxt;
40     private Button               rangeBtn;
41     private Button               cusValuesBtn;
42     private Button               noneBtn;
43     private Button               addBtn;
44     private Button               remBtn;
45     private Label                minLbl;
46     private Label                maxLbl;
47     private List                 customValuesList;
48     private Text                 detail;
49
50     private AttributeHelper      attHelper;
51
52     private AttributeHelper      attClone;
53
54     private Set<AttributeHelper> attributes;
55
56     private final String         defaultMessage   = "Name, Type, and Default Value fields "
57                                                           + "are mandatory.\n\nRange and custom fields allow to set the valid "
58                                                           + "values of the attribute.\n\n";
59     private final String         msgForBoolType   = "Possible attribute values of Bool are "
60                                                           + "true and false.\nSo range and custom options are disabled.";
61     private final String         msgForIntType    = "Valid values for Int type can either be "
62                                                           + "of range type (Ex: 1 - 10) or custom values (Ex: 10, 20, 50, and 100).\n";
63     private final String         msgForDoubleType = "Valid values for Double type can either be "
64                                                           + "of range type (Ex: 18.0 - 22.0) or custom values (Ex: 1.5, 2.5, 3.9, 4.8, etc).\n";
65     private final String         msgForStringType = "For String type, range option is not"
66                                                           + "applicable. Hence it is disabled.\n\n"
67                                                           + "Custom option is available to provide the valid values.\n\n"
68                                                           + "Ex: low, mid, high, etc.";
69
70     private Set<String>          attValueTypes;
71
72     private boolean              editOperation;
73
74     public AddAttributeDialog(Shell parentShell, AttributeHelper att,
75             Set<String> attValueTypes, Set<AttributeHelper> attributes) {
76         super(parentShell);
77         if (null == att) {
78             att = new AttributeHelper();
79         } else {
80             attClone = att.clone();
81             System.out.println("Cloned attribute's data:" + attClone);
82             editOperation = true;
83         }
84         attHelper = att;
85         this.attValueTypes = attValueTypes;
86         this.attributes = attributes;
87     }
88
89     @Override
90     public void create() {
91         super.create();
92         setTitle("Add Attribute");
93         setMessage("Fill the details for creating an attribute");
94     }
95
96     @Override
97     protected Control createDialogArea(Composite parent) {
98         Composite compLayout = (Composite) super.createDialogArea(parent);
99         Composite container = new Composite(compLayout, SWT.NONE);
100         container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
101         GridLayout layout = new GridLayout(5, false);
102         /*
103          * layout.verticalSpacing = 10; layout.marginTop = 10;
104          */
105         container.setLayout(layout);
106
107         Label attNameLbl = new Label(container, SWT.NULL);
108         attNameLbl.setText("Attribute Name:");
109
110         attNameTxt = new Text(container, SWT.BORDER);
111         GridData gd = new GridData();
112         gd.horizontalAlignment = SWT.FILL;
113         gd.horizontalSpan = 4;
114         gd.grabExcessHorizontalSpace = true;
115         attNameTxt.setLayoutData(gd);
116
117         Label attTypeLbl = new Label(container, SWT.NULL);
118         attTypeLbl.setText("Attribute Type:");
119
120         attTypeCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
121         gd = new GridData();
122         gd.grabExcessHorizontalSpace = true;
123         gd.horizontalSpan = 4;
124         gd.horizontalAlignment = SWT.FILL;
125         attTypeCmb.setLayoutData(gd);
126         initTypes();
127
128         Group valuesGrp = new Group(container, SWT.NULL);
129         valuesGrp.setText("Attribute Values");
130         gd = new GridData();
131         gd.verticalIndent = 10;
132         gd.horizontalSpan = 3;
133         gd.grabExcessHorizontalSpace = true;
134         gd.horizontalAlignment = SWT.FILL;
135         gd.grabExcessVerticalSpace = true;
136         gd.verticalAlignment = SWT.FILL;
137         valuesGrp.setLayoutData(gd);
138         layout = new GridLayout(4, false);
139         valuesGrp.setLayout(layout);
140
141         rangeBtn = new Button(valuesGrp, SWT.RADIO);
142         rangeBtn.setText("Range");
143         gd = new GridData();
144         gd.horizontalSpan = 4;
145         rangeBtn.setLayoutData(gd);
146
147         minLbl = new Label(valuesGrp, SWT.NONE);
148         minLbl.setText("Min:");
149         gd = new GridData();
150         gd.horizontalIndent = 25;
151         minLbl.setLayoutData(gd);
152
153         minRangeTxt = new Text(valuesGrp, SWT.BORDER);
154         gd = new GridData();
155         gd.widthHint = 70;
156         minRangeTxt.setLayoutData(gd);
157
158         maxLbl = new Label(valuesGrp, SWT.NONE);
159         maxLbl.setText("Max:");
160         gd = new GridData();
161         gd.horizontalIndent = 25;
162         maxLbl.setLayoutData(gd);
163
164         maxRangeTxt = new Text(valuesGrp, SWT.BORDER);
165         gd = new GridData();
166         gd.widthHint = 70;
167         maxRangeTxt.setLayoutData(gd);
168
169         cusValuesBtn = new Button(valuesGrp, SWT.RADIO);
170         cusValuesBtn.setText("Custom");
171         gd = new GridData();
172         gd.horizontalSpan = 4;
173         cusValuesBtn.setLayoutData(gd);
174
175         Composite cusValuesComp = new Composite(valuesGrp, SWT.NONE);
176         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
177         gd.horizontalSpan = 4;
178         cusValuesComp.setLayoutData(gd);
179         layout = new GridLayout(2, false);
180         cusValuesComp.setLayout(layout);
181
182         customValuesList = new List(cusValuesComp, SWT.BORDER | SWT.MULTI
183                 | SWT.V_SCROLL);
184         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
185         gd.heightHint = 75;
186         gd.horizontalIndent = 25;
187         customValuesList.setLayoutData(gd);
188
189         Composite cusValuesActionsComp = new Composite(cusValuesComp, SWT.NONE);
190         layout = new GridLayout();
191         cusValuesActionsComp.setLayout(layout);
192         gd = new GridData();
193         gd.verticalAlignment = SWT.TOP;
194         cusValuesActionsComp.setLayoutData(gd);
195
196         addBtn = new Button(cusValuesActionsComp, SWT.PUSH);
197         addBtn.setText("Add");
198         gd = new GridData();
199         gd.widthHint = 70;
200         addBtn.setLayoutData(gd);
201
202         remBtn = new Button(cusValuesActionsComp, SWT.PUSH);
203         remBtn.setText("Remove");
204         gd = new GridData();
205         gd.widthHint = 70;
206         remBtn.setLayoutData(gd);
207         remBtn.setEnabled(false);
208
209         noneBtn = new Button(valuesGrp, SWT.RADIO);
210         noneBtn.setText("None");
211         gd = new GridData();
212         gd.horizontalSpan = 4;
213         noneBtn.setLayoutData(gd);
214
215         Composite detailsComp = new Composite(container, SWT.NULL);
216         detailsComp.setLayout(new GridLayout());
217         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
218         gd.horizontalSpan = 2;
219         gd.widthHint = 100;
220         detailsComp.setLayoutData(gd);
221
222         Label lbl = new Label(detailsComp, SWT.NULL);
223         lbl.setText("Details");
224
225         Group detailsGrp = new Group(detailsComp, SWT.NULL);
226         detailsGrp.setLayout(new GridLayout());
227         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
228         detailsGrp.setLayoutData(gd);
229
230         detail = new Text(detailsGrp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
231                 | SWT.WRAP | SWT.V_SCROLL);
232         detail.setBackground(detailsGrp.getBackground());
233         detail.setText(defaultMessage);
234         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
235         detail.setLayoutData(gd);
236
237         Label dflValueLbl = new Label(container, SWT.NULL);
238         dflValueLbl.setText("Default value");
239
240         dflValueTxt = new Text(container, SWT.BORDER);
241         gd = new GridData();
242         gd.horizontalSpan = 4;
243         gd.grabExcessHorizontalSpace = true;
244         gd.horizontalAlignment = SWT.FILL;
245         dflValueTxt.setLayoutData(gd);
246
247         setUiListeners();
248
249         if (editOperation) {
250             initData();
251             attNameTxt.setFocus();
252         } else {
253             setInitialSelection();
254         }
255
256         return compLayout;
257     }
258
259     private void initTypes() {
260         if (null != attValueTypes && attValueTypes.size() > 0) {
261             Iterator<String> itr = attValueTypes.iterator();
262             while (itr.hasNext()) {
263                 attTypeCmb.add(itr.next());
264             }
265         }
266     }
267
268     private void setInitialSelection() {
269         enable(false);
270         rangeOptionSelected(false);
271         customOptionSelected(false);
272     }
273
274     private void initData() {
275         if (editOperation) {
276             // Populate the UI controls with the data.
277             attNameTxt.setText(attHelper.getAttributeName());
278             attTypeCmb.select(attTypeCmb.indexOf(attHelper.getAttributeType()));
279             updateControls();
280             dflValueTxt.setText(attHelper.getAttributeDflValue());
281             Type valuesType = attHelper.getValidValuesType();
282             /*
283              * if (valuesType == Type.UNKNOWN) { noneBtn.setSelection(true); }
284              * else
285              */if (valuesType == Type.RANGE) {
286                 rangeBtn.setSelection(true);
287                 noneBtn.setSelection(false);
288                 rangeOptionSelected(true);
289                 minRangeTxt.setText(attHelper.getMin());
290                 maxRangeTxt.setText(attHelper.getMax());
291             } else if (valuesType == Type.VALUESET) {
292                 cusValuesBtn.setSelection(true);
293                 noneBtn.setSelection(false);
294                 customOptionSelected(true);
295                 Set<String> allowedValues = attHelper.getAllowedValues();
296                 customValuesList.setItems(allowedValues.toArray(new String[1]));
297             }
298         }
299     }
300
301     private void setUiListeners() {
302         rangeBtn.addSelectionListener(new SelectionAdapter() {
303             @Override
304             public void widgetSelected(SelectionEvent e) {
305                 rangeOptionSelected(true);
306                 customOptionSelected(false);
307                 minRangeTxt.setFocus();
308             }
309         });
310
311         cusValuesBtn.addSelectionListener(new SelectionAdapter() {
312             @Override
313             public void widgetSelected(SelectionEvent e) {
314                 addBtn.setFocus();
315                 rangeOptionSelected(false);
316                 customOptionSelected(true);
317             }
318         });
319
320         noneBtn.addSelectionListener(new SelectionAdapter() {
321             @Override
322             public void widgetSelected(SelectionEvent e) {
323                 rangeOptionSelected(false);
324                 customOptionSelected(false);
325             }
326         });
327
328         attTypeCmb.addSelectionListener(new SelectionAdapter() {
329             @Override
330             public void widgetSelected(SelectionEvent e) {
331                 updateControls();
332             }
333         });
334
335         minRangeTxt.addListener(SWT.Verify, new Listener() {
336             @Override
337             public void handleEvent(Event e) {
338                 String string = e.text;
339                 System.out.println(string);
340                 char[] chars = new char[string.length()];
341                 string.getChars(0, chars.length, chars, 0);
342                 for (int i = 0; i < chars.length; i++) {
343                     if (!(('0' <= chars[i] && chars[i] <= '9')
344                             || chars[i] == '-' || chars[i] == '+')) {
345                         if (attTypeCmb.getText().equals(Constants.INT)) {
346                             e.doit = false;
347                             return;
348                         } else if (attTypeCmb.getText()
349                                 .equals(Constants.DOUBLE)) {
350                             if (!(chars[i] == '.')) {
351                                 e.doit = false;
352                                 return;
353                             }
354                         }
355                     }
356                 }
357                 // attHelper.setMin(minRangeTxt.getText() + string);
358             }
359         });
360
361         maxRangeTxt.addListener(SWT.Verify, new Listener() {
362             @Override
363             public void handleEvent(Event e) {
364                 String string = e.text;
365                 char[] chars = new char[string.length()];
366                 string.getChars(0, chars.length, chars, 0);
367                 for (int i = 0; i < chars.length; i++) {
368                     if (!(('0' <= chars[i] && chars[i] <= '9')
369                             || chars[i] == '-' || chars[i] == '+')) {
370                         if (attTypeCmb.getText().equals(Constants.INT)) {
371                             e.doit = false;
372                             return;
373                         } else if (attTypeCmb.getText()
374                                 .equals(Constants.DOUBLE)) {
375                             if (!(chars[i] == '.')) {
376                                 e.doit = false;
377                                 return;
378                             }
379                         }
380                     }
381                 }
382                 // attHelper.setMax(maxRangeTxt.getText() + string);
383             }
384         });
385
386         addBtn.addSelectionListener(new SelectionAdapter() {
387             @Override
388             public void widgetSelected(SelectionEvent e) {
389                 SingleTextInputDialog dialog = new SingleTextInputDialog(
390                         getShell(), "Add Attribute Value", "Attribute Value");
391                 if (dialog.open() == Window.OK) {
392                     System.out.println(dialog.getValue());
393                     String value = dialog.getValue();
394                     String type = attTypeCmb.getText();
395                     if (!attHelper.isValueValid(value, type)) {
396                         MessageDialog.openError(getParentShell(),
397                                 "Invalid value", "Attribute value is invalid.");
398                     } else if (attHelper.isAllowedValueExist(
399                             customValuesList.getItems(), value)) {
400                         MessageDialog.openError(getParentShell(),
401                                 "Duplicate value",
402                                 "Attribute value already exists.");
403                     } else {
404                         customValuesList.add(value);
405                         customValuesList.deselectAll();
406                         customValuesList.select(customValuesList.getItemCount() - 1);
407                         customValuesList.showSelection();
408                         remBtn.setEnabled(true);
409                         // attHelper.addValueToAllowedValues(value);
410                     }
411                 }
412             }
413         });
414
415         remBtn.addSelectionListener(new SelectionAdapter() {
416             @Override
417             public void widgetSelected(SelectionEvent e) {
418                 int[] selection = customValuesList.getSelectionIndices();
419                 // String[] selectionStr = customValuesList.getSelection();
420                 if (null != selection && selection.length > 0) {
421                     customValuesList.remove(selection);
422                     /*
423                      * for (String selected : selectionStr) {
424                      * attHelper.removeValueFromAllowedValues(selected); }
425                      */
426                 }
427
428                 changeRemBtnVisibility();
429             }
430         });
431
432         customValuesList.addSelectionListener(new SelectionAdapter() {
433             @Override
434             public void widgetSelected(SelectionEvent e) {
435                 changeRemBtnVisibility();
436             }
437         });
438     }
439
440     private void updateControls() {
441         rangeBtn.setSelection(false);
442         cusValuesBtn.setSelection(false);
443         noneBtn.setSelection(true);
444
445         cleanRangeAndCustomValues();
446         dflValueTxt.setText("");
447
448         String selected = attTypeCmb.getText();
449         // attHelper.setAttributeType(selected);
450
451         if (selected.equals(Constants.INT)) {
452             enable(true);
453             rangeOptionSelected(false);
454             customOptionSelected(false);
455             detail.setText(defaultMessage + msgForIntType);
456         } else if (selected.equals(Constants.DOUBLE)) {
457             enable(true);
458             rangeOptionSelected(false);
459             customOptionSelected(false);
460             detail.setText(defaultMessage + msgForDoubleType);
461         } else if (selected.equals(Constants.BOOL)) {
462             // noneBtn.setSelection(true);
463             enable(false);
464             rangeOptionSelected(false);
465             customOptionSelected(false);
466             detail.setText(defaultMessage + msgForBoolType);
467         } else if (selected.equals(Constants.STRING)) {
468             rangeBtn.setEnabled(false);
469             rangeOptionSelected(false);
470             cusValuesBtn.setEnabled(true);
471             noneBtn.setEnabled(true);
472             // cusValuesBtn.setSelection(true);
473             detail.setText(defaultMessage + msgForStringType);
474         } else {
475             // noneBtn.setSelection(true);
476             enable(false);
477             rangeOptionSelected(false);
478             customOptionSelected(false);
479             detail.setText(defaultMessage);
480         }
481     }
482
483     private void changeRemBtnVisibility() {
484         if (cusValuesBtn.isEnabled() && cusValuesBtn.getSelection()) {
485             int[] selection = customValuesList.getSelectionIndices();
486             if (null != selection && selection.length > 0) {
487                 remBtn.setEnabled(true);
488             } else {
489                 remBtn.setEnabled(false);
490             }
491         } else {
492             remBtn.setEnabled(false);
493         }
494     }
495
496     private void enable(boolean enable) {
497         rangeBtn.setEnabled(enable);
498         cusValuesBtn.setEnabled(enable);
499         noneBtn.setEnabled(enable);
500     }
501
502     private void rangeOptionSelected(boolean enable) {
503         minRangeTxt.setEnabled(enable);
504         maxRangeTxt.setEnabled(enable);
505         minLbl.setEnabled(enable);
506         maxLbl.setEnabled(enable);
507     }
508
509     private void customOptionSelected(boolean enable) {
510         customValuesList.setEnabled(enable);
511         addBtn.setEnabled(enable);
512         changeRemBtnVisibility();
513     }
514
515     private void cleanRangeAndCustomValues() {
516         cleanRangeValues();
517         cleanCustomValues();
518     }
519
520     private void cleanRangeValues() {
521         minRangeTxt.setText("");
522         maxRangeTxt.setText("");
523     }
524
525     private void cleanCustomValues() {
526         customValuesList.removeAll();
527     }
528
529     public AttributeHelper getAttHelper() {
530         return attHelper;
531     }
532
533     public AttributeHelper getAttClone() {
534         return attClone;
535     }
536
537     @Override
538     protected void okPressed() {
539         // Attribute Name
540         String attName = attNameTxt.getText();
541         if (null == attName || attName.isEmpty()) {
542             MessageDialog.openError(getParentShell(),
543                     "Mandatory field is empty",
544                     "Please fill the attribute name.");
545             attNameTxt.setFocus();
546             return;
547         }
548         attName = attName.trim();
549         if (attName.length() < 1) {
550             MessageDialog.openError(getParentShell(),
551                     "Mandatory field is empty", "Attribute name is invalid.");
552             attNameTxt.setFocus();
553             return;
554         }
555         attHelper.setAttributeName(attName);
556
557         // Duplicate check for attribute name if this is not editing operation
558         if (!editOperation) {
559             if (!attributes.isEmpty()) {
560                 Iterator<AttributeHelper> itr = attributes.iterator();
561                 AttributeHelper att;
562                 while (itr.hasNext()) {
563                     att = itr.next();
564                     if (att.getAttributeName().equals(attName)) {
565                         MessageDialog
566                                 .openError(
567                                         getParentShell(),
568                                         "Duplicate Attribute",
569                                         "Another attribute with the same attribute name exist. Please enter a new attribute name.");
570                         attNameTxt.setFocus();
571                         return;
572                     }
573                 }
574             }
575         }
576
577         // Attribute Type
578         String attType = attTypeCmb.getText();
579         if (null == attType || attType.isEmpty()) {
580             MessageDialog.openError(getParentShell(),
581                     "Mandatory field is empty",
582                     "Please select an attribute type.");
583             return;
584         }
585         attHelper.setAttributeType(attType);
586
587         // Attribute values
588         if (rangeBtn.isEnabled() && rangeBtn.getSelection()) { // Range option
589             String min = minRangeTxt.getText();
590             String max = maxRangeTxt.getText();
591             if (null == min && null == max) {
592                 MessageDialog
593                         .openError(getParentShell(), "Range is empty",
594                                 "Please enter the minimum and maximum value of the range.");
595                 minRangeTxt.setFocus();
596                 return;
597             }
598             if (null == min || null == max) {
599                 String msg;
600                 msg = "Please enter the "
601                         + ((null == min) ? "minimum value" : "maximum value")
602                         + "of the range.";
603                 MessageDialog
604                         .openError(getParentShell(), "Range is empty", msg);
605                 ((null == min) ? minRangeTxt : maxRangeTxt).setFocus();
606                 return;
607             }
608             if (min.isEmpty() && max.isEmpty()) {
609                 MessageDialog
610                         .openError(getParentShell(), "Range is empty",
611                                 "Please enter the minimum and maximum value of the range.");
612                 minRangeTxt.setFocus();
613                 return;
614             }
615             if (min.isEmpty()) {
616                 MessageDialog.openError(getParentShell(), "Range is empty",
617                         "Please enter the minimum value for the range.");
618                 minRangeTxt.setFocus();
619                 return;
620             }
621             if (max.isEmpty()) {
622                 MessageDialog.openError(getParentShell(), "Range is empty",
623                         "Please enter the maximum value for the range.");
624                 maxRangeTxt.setFocus();
625                 return;
626             }
627
628             if (!min.isEmpty() && !max.isEmpty()
629                     && !attHelper.isRangeValid(min, max, attType)) {
630                 MessageDialog.openError(getParentShell(), "Invalid range",
631                         "Range is invalid.");
632                 maxRangeTxt.setFocus();
633                 return;
634             }
635             attHelper.setValidValuesType(Type.RANGE);
636             attHelper.setMin(min);
637             attHelper.setMax(max);
638
639             if (editOperation) {
640                 // Remove all existing custom values
641                 attHelper.setAllowedValues(null);
642             }
643         } else if (cusValuesBtn.isEnabled() && cusValuesBtn.getSelection()) {
644             String[] cusItems = customValuesList.getItems();
645             if (null == cusItems || cusItems.length < 1) {
646                 MessageDialog.openError(getParentShell(),
647                         "Custom list is empty.",
648                         "No values are added to the custom list.");
649                 maxRangeTxt.setFocus();
650                 return;
651             }
652             attHelper.setValidValuesType(Type.VALUESET);
653             attHelper.setAllowedValuesByArray(cusItems);
654
655             if (editOperation) {
656                 // Remove min and max values
657                 attHelper.setMin(null);
658                 attHelper.setMax(null);
659             }
660         } else if (noneBtn.isEnabled() && noneBtn.getSelection()) {
661             attHelper.setValidValuesType(Type.UNKNOWN);
662             if (editOperation) {
663                 // Remove min, max and custom values
664                 attHelper.setAllowedValues(null);
665                 attHelper.setMin(null);
666                 attHelper.setMax(null);
667             }
668         }
669
670         // Attribute Default Value
671         String attDflValue = dflValueTxt.getText();
672         if (null == attDflValue || attDflValue.isEmpty()) {
673             MessageDialog.openError(getParentShell(),
674                     "Mandatory field is empty",
675                     "Please enter a default value for the attribute.");
676             dflValueTxt.setFocus();
677             return;
678         }
679         attDflValue = attDflValue.trim();
680         if (attDflValue.length() < 1
681                 || !attHelper.isValueValid(attDflValue, attType)) {
682             MessageDialog.openError(getParentShell(), "Invalid value",
683                     "Default value is invalid.");
684             dflValueTxt.setFocus();
685             return;
686         }
687         if (!attHelper.isDefaultValueValid(attDflValue)) {
688             MessageDialog.openError(getParentShell(), "Invalid value",
689                     "Default value is not in the valid values.");
690             dflValueTxt.setFocus();
691             return;
692         }
693
694         attHelper.setAttributeDflValue(attDflValue.toLowerCase());
695
696         close();
697     }
698
699     @Override
700     public boolean isHelpAvailable() {
701         return false;
702     }
703
704     /*
705      * @Override protected Point getInitialSize() { Point curSize =
706      * super.getInitialSize(); return new Point(curSize.x, curSize.y + 200); }
707      */
708
709     @Override
710     protected Point getInitialLocation(Point initialSize) {
711         Rectangle shellBounds = Display.getDefault().getActiveShell()
712                 .getBounds();
713         Point dialogSize = getInitialSize();
714
715         return new Point(
716                 shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
717                 shellBounds.y + (shellBounds.height - dialogSize.y) / 2);
718     }
719 }