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