Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / SingleTextInputDialog.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.TrayDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.swt.widgets.Text;
30
31 /**
32  * This class shows a dialog for filtering logs based on severity levels.
33  */
34 public class SingleTextInputDialog extends TrayDialog {
35
36     private Text   txt;
37     private String value;
38     private String lblTxt;
39     private String shellTitle;
40
41     public SingleTextInputDialog(Shell shell, String title, String lblTxt) {
42         super(shell);
43         shellTitle = title;
44         this.lblTxt = lblTxt;
45     }
46
47     @Override
48     protected void configureShell(Shell shell) {
49         super.configureShell(shell);
50     }
51
52     @Override
53     protected Control createDialogArea(Composite parent) {
54         Composite composite = (Composite) super.createDialogArea(parent);
55         getShell().setText(shellTitle);
56
57         Composite content = new Composite(parent, SWT.NULL);
58         GridLayout gridLayout = new GridLayout();
59         content.setLayout(gridLayout);
60         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
61         content.setLayoutData(gd);
62
63         Label lbl = new Label(content, SWT.NONE);
64         lbl.setText(lblTxt);
65
66         txt = new Text(content, SWT.BORDER);
67         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
68         txt.setLayoutData(gd);
69         txt.addModifyListener(new ModifyListener() {
70
71             @Override
72             public void modifyText(ModifyEvent e) {
73                 value = txt.getText();
74             }
75         });
76
77         return composite;
78     }
79
80     @Override
81     protected void okPressed() {
82         if (null != value) {
83             value = value.trim();
84             if (value.length() > 0) {
85                 close();
86                 return;
87             }
88         }
89         txt.setFocus();
90     }
91
92     @Override
93     public boolean isHelpAvailable() {
94         return false;
95     }
96
97     public String getValue() {
98         return value;
99     }
100 }