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