1 package oic.simulator.serviceprovider.view.dialogs;
3 import java.util.HashSet;
6 import oic.simulator.serviceprovider.Activator;
7 import oic.simulator.serviceprovider.utils.Constants;
8 import oic.simulator.serviceprovider.utils.Utility;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.window.Window;
12 import org.eclipse.jface.wizard.IWizardPage;
13 import org.eclipse.jface.wizard.WizardPage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.ModifyEvent;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Group;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.List;
27 import org.eclipse.swt.widgets.Text;
29 public class SimpleResourceBasicDetailsPage extends WizardPage {
31 private Text resNameTxt;
32 private Text resUriTxt;
33 private List resTypeslist;
34 private Button addToListBtn;
35 private Button remFromListBtn;
36 private Button observeBtn;
37 // private Button startBtn;
39 private String resName;
40 private String resURI;
41 private Set<String> resTypes;
42 private boolean observable;
44 // private boolean start;
46 protected SimpleResourceBasicDetailsPage() {
47 super("Basic Details");
48 resTypes = new HashSet<String>();
52 public void createControl(Composite parent) {
53 setPageComplete(false);
54 setTitle(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
55 setMessage(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
57 Composite container = new Composite(parent, SWT.NONE);
58 GridLayout gridLayout = new GridLayout();
59 container.setLayout(gridLayout);
60 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
61 container.setLayoutData(gd);
63 Group resDetGrp = new Group(container, SWT.NONE);
64 resDetGrp.setText("Resource Details");
65 gridLayout = new GridLayout(4, false);
66 resDetGrp.setLayout(gridLayout);
67 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
68 resDetGrp.setLayoutData(gd);
70 Label resNameLbl = new Label(resDetGrp, SWT.NULL);
71 resNameLbl.setText(Constants.RESOURCE_NAME);
73 resNameLbl.setLayoutData(gd);
75 resNameTxt = new Text(resDetGrp, SWT.BORDER);
77 // gd.widthHint = 300;
78 gd.horizontalAlignment = SWT.FILL;
79 gd.grabExcessHorizontalSpace = true;
80 gd.horizontalSpan = 3;
81 resNameTxt.setLayoutData(gd);
82 resNameTxt.setFocus();
84 Label resUriLbl = new Label(resDetGrp, SWT.NULL);
85 resUriLbl.setText(Constants.RESOURCE_URI);
87 resUriTxt = new Text(resDetGrp, SWT.BORDER);
89 // gd.widthHint = 300;
90 gd.horizontalSpan = 3;
91 gd.horizontalAlignment = SWT.FILL;
92 gd.grabExcessHorizontalSpace = true;
93 resUriTxt.setLayoutData(gd);
95 * Composite resTypesComp = new Composite(compContent, SWT.NONE);
96 * gridLayout = new GridLayout(3, false);
97 * resTypesComp.setLayout(gridLayout); gd = new GridData();
98 * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
99 * SWT.FILL; resTypesComp.setLayoutData(gd);
102 Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
103 resTypesLbl.setText(Constants.RESOURCE_TYPES);
105 resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
108 gd.grabExcessHorizontalSpace = true;
109 gd.horizontalAlignment = SWT.FILL;
110 gd.horizontalSpan = 2;
112 /* gd.widthHint = 200; */
113 resTypeslist.setLayoutData(gd);
114 // resTypeslist.setBackground(new Color());
116 Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
117 gridLayout = new GridLayout();
118 resTypesActionsComp.setLayout(gridLayout);
120 gd.verticalAlignment = SWT.TOP;
122 * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
125 resTypesActionsComp.setLayoutData(gd);
127 addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
128 addToListBtn.setText("Add");
131 addToListBtn.setLayoutData(gd);
133 remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
134 remFromListBtn.setText("Remove");
137 remFromListBtn.setLayoutData(gd);
138 remFromListBtn.setEnabled(false);
140 Group otherOptionsGrp = new Group(container, SWT.NONE);
141 otherOptionsGrp.setText("Other options");
142 gridLayout = new GridLayout();
143 otherOptionsGrp.setLayout(gridLayout);
144 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
145 otherOptionsGrp.setLayoutData(gd);
147 observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
148 observeBtn.setText("Observable");
149 observeBtn.setSelection(true);
153 * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
154 * startBtn.setText("Start the resource immediately after creation");
155 * startBtn.setSelection(true);
159 setControl(container);
162 private void addUiListeners() {
164 resUriTxt.addModifyListener(new ModifyListener() {
166 public void modifyText(ModifyEvent arg0) {
167 resURI = resUriTxt.getText();
168 if (null == resURI) {
172 getWizard().getContainer().updateButtons();
176 resNameTxt.addModifyListener(new ModifyListener() {
178 public void modifyText(ModifyEvent arg0) {
179 resName = resNameTxt.getText();
180 getWizard().getContainer().updateButtons();
184 addToListBtn.addSelectionListener(new SelectionAdapter() {
186 public void widgetSelected(SelectionEvent e) {
187 SingleTextInputDialog dialog = new SingleTextInputDialog(
188 getShell(), "Add Resource Type", "Resource Type");
189 if (dialog.open() == Window.OK) {
190 System.out.println(dialog.getValue());
191 String resType = dialog.getValue();
193 if (resTypes.contains(resType)) {
194 MessageDialog.openError(Display.getDefault()
195 .getActiveShell(), "Duplicate value",
196 "value already exist.");
199 resTypeslist.add(resType);
200 resTypeslist.deselectAll();
201 resTypeslist.select(resTypeslist.getItemCount() - 1);
202 resTypeslist.showSelection();
203 remFromListBtn.setEnabled(true);
205 resTypes.add(resType);
207 getWizard().getContainer().updateButtons();
212 remFromListBtn.addSelectionListener(new SelectionAdapter() {
214 public void widgetSelected(SelectionEvent e) {
215 int[] selection = resTypeslist.getSelectionIndices();
216 String[] selectionStr = resTypeslist.getSelection();
217 if (null != selection && selection.length > 0) {
218 resTypeslist.remove(selection);
219 for (String selected : selectionStr) {
220 resTypes.remove(selected);
225 getWizard().getContainer().updateButtons();
229 resTypeslist.addSelectionListener(new SelectionAdapter() {
231 public void widgetSelected(SelectionEvent e) {
236 observeBtn.addSelectionListener(new SelectionAdapter() {
238 public void widgetSelected(SelectionEvent e) {
239 observable = observeBtn.getSelection();
244 private void changeVisibility() {
245 int[] selection = resTypeslist.getSelectionIndices();
246 if (null != selection && selection.length > 0) {
247 remFromListBtn.setEnabled(true);
249 remFromListBtn.setEnabled(false);
254 public boolean canFlipToNextPage() {
255 if (null == resName || null == resURI || resTypes.size() < 1) {
258 resName = resName.trim();
259 resURI = resURI.trim();
260 if (resName.length() < 1 || resURI.length() < 1) {
267 public IWizardPage getNextPage() {
268 if (!Utility.isUriValid(resURI)) {
269 MessageDialog.openError(Display.getDefault().getActiveShell(),
270 "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
274 // Checking whether the uri is used by any other resource.
275 if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
277 .openError(getShell(), "Resource URI in use",
278 "Entered resource URI is in use. Please try a different one.");
279 // TODO: Instead of MessageDialog, errors may be shown on wizard
284 return ((CreateResourceWizard) getWizard())
285 .getSimpleResourceAddAttributePage();
288 public String getResName() {
292 public String getResURI() {
296 public Set<String> getResTypes() {
300 public boolean isObservable() {