1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.fosstrak.llrp.commander.dialogs;
23
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Event;
33 import org.eclipse.swt.widgets.Listener;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.swt.widgets.Text;
36
37
38
39
40
41
42 public class AddFCDialog extends ConnectDialog {
43
44
45 private static final int VALUE_NAME = 0;
46
47
48 private static final int VALUE_IP = 1;
49
50
51 protected Button localAdapter;
52
53
54 private boolean isLocalAdapter = false;
55
56
57
58
59
60 public AddFCDialog(Shell aShell) {
61 super(aShell, "Add Adapter");
62 FIELDS = new String[] { "Adapter Name", "IP" };
63 DEFAULTS = new String [] { "AdapterName", "127.0.0.1" };
64 }
65
66
67
68
69 public String getName() {
70 return values[VALUE_NAME];
71 }
72
73
74
75
76
77
78 public boolean isLocalAdapter() {
79 return isLocalAdapter;
80 }
81
82
83
84
85 public String getIP() {
86 return values[VALUE_IP];
87 }
88
89 @Override
90 protected Control createContents(Composite parent) {
91 setLayout(parent);
92
93 addTextFields(parent);
94
95
96
97
98 GridData gridNoWidthHint = new GridData();
99 gridNoWidthHint.horizontalSpan = 3;
100
101 localAdapter = new Button(parent, SWT.CHECK);
102 localAdapter.setText("local Adapter");
103 localAdapter.setLayoutData(gridNoWidthHint);
104 localAdapter.setSelection(false);
105
106 addInvisibleButton(parent);
107 addOKButton(parent);
108 addCancelButton(parent);
109
110 parent.pack();
111 return parent;
112 }
113
114 @Override
115 protected void addOKButton(Composite parent) {
116 final Button btnOK = new Button(parent, SWT.PUSH);
117 btnOK.setText("OK");
118 btnOK.setLayoutData(gridLabel);
119
120 btnOK.addSelectionListener(new SelectionAdapter() {
121 public void widgetSelected(SelectionEvent e) {
122 for (int i=0; i<DEFAULTS.length; i++) {
123 values[i] = txts[i].getText();
124 }
125
126 isLocalAdapter = localAdapter.getSelection();
127
128 setReturnCode(Window.OK);
129 close();
130 }
131 });
132
133
134 registerTextFieldListeners(btnOK);
135 }
136
137 @Override
138 public Listener getListener(final Text txt, int offset, final Button ok) {
139 Listener listener = null;
140 switch (offset) {
141 case VALUE_NAME:
142 listener = new Listener() {
143 public void handleEvent(Event event) {
144 try {
145 if ((txt.getText() == null) || (txt.getText().length() < 3)) {
146 ok.setEnabled(false);
147 } else {
148 ok.setEnabled(true);
149 }
150 } catch (Exception e) {
151 ok.setEnabled(false);
152 }
153 }
154 };
155 break;
156 case VALUE_IP:
157
158 break;
159 }
160 return listener;
161 }
162 }
163