2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package oic.simulator.serviceprovider.view.dialogs;
19 import oic.simulator.serviceprovider.Activator;
20 import oic.simulator.serviceprovider.utils.Constants;
21 import oic.simulator.serviceprovider.utils.Utility;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.wizard.IWizardPage;
25 import org.eclipse.jface.wizard.WizardPage;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.ModifyEvent;
28 import org.eclipse.swt.events.ModifyListener;
29 import org.eclipse.swt.events.SelectionAdapter;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Display;
36 import org.eclipse.swt.widgets.Group;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Text;
40 public class SimpleResourceBasicDetailsPage extends WizardPage {
42 private Text resNameTxt;
43 private Text resUriTxt;
44 private Text resTypeTxt;
45 private Button observeBtn;
47 private String resName;
48 private String resURI;
49 private String resType;
50 private boolean observable;
52 protected SimpleResourceBasicDetailsPage() {
53 super("Basic Details");
57 public void createControl(Composite parent) {
58 setPageComplete(false);
59 setTitle(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
60 setMessage(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
62 Composite container = new Composite(parent, SWT.NONE);
63 GridLayout gridLayout = new GridLayout();
64 container.setLayout(gridLayout);
65 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
66 container.setLayoutData(gd);
68 Group resDetGrp = new Group(container, SWT.NONE);
69 resDetGrp.setText("Resource Details");
70 gridLayout = new GridLayout(4, false);
71 resDetGrp.setLayout(gridLayout);
72 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
73 resDetGrp.setLayoutData(gd);
75 Label resNameLbl = new Label(resDetGrp, SWT.NULL);
76 resNameLbl.setText(Constants.RESOURCE_NAME);
78 resNameLbl.setLayoutData(gd);
80 resNameTxt = new Text(resDetGrp, SWT.BORDER);
82 gd.horizontalAlignment = SWT.FILL;
83 gd.grabExcessHorizontalSpace = true;
84 gd.horizontalSpan = 3;
85 resNameTxt.setLayoutData(gd);
86 resNameTxt.setFocus();
88 Label resUriLbl = new Label(resDetGrp, SWT.NULL);
89 resUriLbl.setText(Constants.RESOURCE_URI);
91 resUriTxt = new Text(resDetGrp, SWT.BORDER);
93 gd.horizontalSpan = 3;
94 gd.horizontalAlignment = SWT.FILL;
95 gd.grabExcessHorizontalSpace = true;
96 resUriTxt.setLayoutData(gd);
98 Label resTypeLbl = new Label(resDetGrp, SWT.NULL);
99 resTypeLbl.setText(Constants.RESOURCE_TYPE);
101 resTypeTxt = new Text(resDetGrp, SWT.BORDER);
103 gd.horizontalSpan = 3;
104 gd.horizontalAlignment = SWT.FILL;
105 gd.grabExcessHorizontalSpace = true;
106 resTypeTxt.setLayoutData(gd);
108 Group otherOptionsGrp = new Group(container, SWT.NONE);
109 otherOptionsGrp.setText("Other options");
110 gridLayout = new GridLayout();
111 otherOptionsGrp.setLayout(gridLayout);
112 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
113 otherOptionsGrp.setLayoutData(gd);
115 observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
116 observeBtn.setText("Observable");
117 observeBtn.setSelection(true);
122 setControl(container);
125 private void addUiListeners() {
127 resUriTxt.addModifyListener(new ModifyListener() {
129 public void modifyText(ModifyEvent arg0) {
130 resURI = resUriTxt.getText();
131 if (null == resURI) {
135 getWizard().getContainer().updateButtons();
139 resNameTxt.addModifyListener(new ModifyListener() {
141 public void modifyText(ModifyEvent arg0) {
142 resName = resNameTxt.getText();
143 getWizard().getContainer().updateButtons();
147 resTypeTxt.addModifyListener(new ModifyListener() {
149 public void modifyText(ModifyEvent arg0) {
150 resType = resTypeTxt.getText();
151 getWizard().getContainer().updateButtons();
155 observeBtn.addSelectionListener(new SelectionAdapter() {
157 public void widgetSelected(SelectionEvent e) {
158 observable = observeBtn.getSelection();
164 public boolean canFlipToNextPage() {
165 if (null == resName || null == resURI || null == resType) {
168 resName = resName.trim();
169 resURI = resURI.trim();
170 resType = resType.trim();
171 if (resName.length() < 1 || resURI.length() < 1 || resType.length() < 1) {
178 public IWizardPage getNextPage() {
179 if (!Utility.isUriValid(resURI)) {
180 MessageDialog.openError(Display.getDefault().getActiveShell(),
181 "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
185 // Checking whether the uri is used by any other resource.
186 if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
188 .openError(getShell(), "Resource URI in use",
189 "Entered resource URI is in use. Please try a different one.");
190 // TODO: Instead of MessageDialog, errors may be shown on wizard
195 return ((CreateResourceWizard) getWizard())
196 .getSimpleResourceAddAttributePage();
199 public String getResName() {
203 public String getResURI() {
207 public String getResType() {
211 public boolean isObservable() {