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;
9 import org.eclipse.jface.dialogs.MessageDialog;
10 import org.eclipse.jface.window.Window;
11 import org.eclipse.jface.wizard.IWizardPage;
12 import org.eclipse.jface.wizard.WizardPage;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.ModifyEvent;
15 import org.eclipse.swt.events.ModifyListener;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Group;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.List;
26 import org.eclipse.swt.widgets.Text;
28 public class SimpleResourceBasicDetailsPage extends WizardPage {
30 private Text resNameTxt;
31 private Text resUriTxt;
32 private List resTypeslist;
33 private Button addToListBtn;
34 private Button remFromListBtn;
35 private Button observeBtn;
36 // private Button startBtn;
38 private String resName;
39 private String resURI;
40 private Set<String> resTypes;
41 private boolean observable;
43 // private boolean start;
45 protected SimpleResourceBasicDetailsPage() {
46 super("Basic Details");
47 resTypes = new HashSet<String>();
51 public void createControl(Composite parent) {
52 setPageComplete(false);
53 setTitle(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
54 setMessage(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
56 Composite container = new Composite(parent, SWT.NONE);
57 GridLayout gridLayout = new GridLayout();
58 container.setLayout(gridLayout);
59 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
60 container.setLayoutData(gd);
62 Group resDetGrp = new Group(container, SWT.NONE);
63 resDetGrp.setText("Resource Details");
64 gridLayout = new GridLayout(4, false);
65 resDetGrp.setLayout(gridLayout);
66 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
67 resDetGrp.setLayoutData(gd);
69 Label resNameLbl = new Label(resDetGrp, SWT.NULL);
70 resNameLbl.setText(Constants.RESOURCE_NAME);
72 resNameLbl.setLayoutData(gd);
74 resNameTxt = new Text(resDetGrp, SWT.BORDER);
76 // gd.widthHint = 300;
77 gd.horizontalAlignment = SWT.FILL;
78 gd.grabExcessHorizontalSpace = true;
79 gd.horizontalSpan = 3;
80 resNameTxt.setLayoutData(gd);
81 resNameTxt.setFocus();
83 Label resUriLbl = new Label(resDetGrp, SWT.NULL);
84 resUriLbl.setText(Constants.RESOURCE_URI);
86 resUriTxt = new Text(resDetGrp, SWT.BORDER);
88 // gd.widthHint = 300;
89 gd.horizontalSpan = 3;
90 gd.horizontalAlignment = SWT.FILL;
91 gd.grabExcessHorizontalSpace = true;
92 resUriTxt.setLayoutData(gd);
94 * Composite resTypesComp = new Composite(compContent, SWT.NONE);
95 * gridLayout = new GridLayout(3, false);
96 * resTypesComp.setLayout(gridLayout); gd = new GridData();
97 * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
98 * SWT.FILL; resTypesComp.setLayoutData(gd);
101 Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
102 resTypesLbl.setText(Constants.RESOURCE_TYPES);
104 resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
107 gd.grabExcessHorizontalSpace = true;
108 gd.horizontalAlignment = SWT.FILL;
109 gd.horizontalSpan = 2;
111 /* gd.widthHint = 200; */
112 resTypeslist.setLayoutData(gd);
113 // resTypeslist.setBackground(new Color());
115 Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
116 gridLayout = new GridLayout();
117 resTypesActionsComp.setLayout(gridLayout);
119 gd.verticalAlignment = SWT.TOP;
121 * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
124 resTypesActionsComp.setLayoutData(gd);
126 addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
127 addToListBtn.setText("Add");
130 addToListBtn.setLayoutData(gd);
132 remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
133 remFromListBtn.setText("Remove");
136 remFromListBtn.setLayoutData(gd);
137 remFromListBtn.setEnabled(false);
139 Group otherOptionsGrp = new Group(container, SWT.NONE);
140 otherOptionsGrp.setText("Other options");
141 gridLayout = new GridLayout();
142 otherOptionsGrp.setLayout(gridLayout);
143 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
144 otherOptionsGrp.setLayoutData(gd);
146 observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
147 observeBtn.setText("Observable");
148 observeBtn.setSelection(true);
152 * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
153 * startBtn.setText("Start the resource immediately after creation");
154 * startBtn.setSelection(true);
158 setControl(container);
161 private void addUiListeners() {
163 resUriTxt.addModifyListener(new ModifyListener() {
165 public void modifyText(ModifyEvent arg0) {
166 resURI = resUriTxt.getText();
167 getWizard().getContainer().updateButtons();
171 resNameTxt.addModifyListener(new ModifyListener() {
173 public void modifyText(ModifyEvent arg0) {
174 resName = resNameTxt.getText();
175 getWizard().getContainer().updateButtons();
179 addToListBtn.addSelectionListener(new SelectionAdapter() {
181 public void widgetSelected(SelectionEvent e) {
182 SingleTextInputDialog dialog = new SingleTextInputDialog(
183 getShell(), "Add Resource Type", "Resource Type");
184 if (dialog.open() == Window.OK) {
185 System.out.println(dialog.getValue());
186 String resType = dialog.getValue();
188 if (resTypes.contains(resType)) {
189 MessageDialog.openError(Display.getDefault()
190 .getActiveShell(), "Duplicate value",
191 "value already exist.");
194 resTypeslist.add(resType);
195 resTypeslist.deselectAll();
196 resTypeslist.select(resTypeslist.getItemCount() - 1);
197 resTypeslist.showSelection();
198 remFromListBtn.setEnabled(true);
200 resTypes.add(resType);
202 getWizard().getContainer().updateButtons();
207 remFromListBtn.addSelectionListener(new SelectionAdapter() {
209 public void widgetSelected(SelectionEvent e) {
210 int[] selection = resTypeslist.getSelectionIndices();
211 String[] selectionStr = resTypeslist.getSelection();
212 if (null != selection && selection.length > 0) {
213 resTypeslist.remove(selection);
214 for (String selected : selectionStr) {
215 resTypes.remove(selected);
220 getWizard().getContainer().updateButtons();
224 resTypeslist.addSelectionListener(new SelectionAdapter() {
226 public void widgetSelected(SelectionEvent e) {
231 observeBtn.addSelectionListener(new SelectionAdapter() {
233 public void widgetSelected(SelectionEvent e) {
234 observable = observeBtn.getSelection();
239 * startBtn.addSelectionListener(new SelectionAdapter() {
241 * @Override public void widgetSelected(SelectionEvent e) { start =
242 * startBtn.getSelection(); } });
246 private void changeVisibility() {
247 int[] selection = resTypeslist.getSelectionIndices();
248 if (null != selection && selection.length > 0) {
249 remFromListBtn.setEnabled(true);
251 remFromListBtn.setEnabled(false);
256 public boolean canFlipToNextPage() {
257 if (null == resName || null == resURI || resTypes.size() < 1) {
260 resName = resName.trim();
261 resURI = resURI.trim();
262 if (resName.length() < 1 || resURI.length() < 1) {
269 public IWizardPage getNextPage() {
270 // Checking whether the uri is used by any other resource.
271 if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
273 .openError(getShell(), "Resource URI in use",
274 "Entered resource URI is in use. Please try a different one.");
275 // TODO: Instead of MessageDialog, errors may be shown on wizard
279 return ((CreateResourceWizard) getWizard())
280 .getSimpleResourceAddAttributePage();
283 public String getResName() {
287 public String getResURI() {
291 public Set<String> getResTypes() {
295 public boolean isObservable() {
300 * public boolean isStart() { return start; }