509cfef021134ff4e448b42c87dccf3acd064f6f
[phpeclipse.git] / net.sourceforge.phpeclipse / src / com / xaraya / wizard / XarayaModuleFilePage.java
1 package com.xaraya.wizard;
2
3 import org.eclipse.jface.viewers.IStructuredSelection;
4 import org.eclipse.jface.wizard.WizardPage;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.layout.GridData;
7 import org.eclipse.swt.layout.GridLayout;
8 import org.eclipse.swt.widgets.Button;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Event;
11 import org.eclipse.swt.widgets.Group;
12 import org.eclipse.swt.widgets.Label;
13 import org.eclipse.swt.widgets.Listener;
14 import org.eclipse.swt.widgets.Text;
15
16 public class XarayaModuleFilePage extends WizardPage implements Listener
17 {
18
19         IStructuredSelection selection;
20         
21         //Xaraya stuff
22         private Text modversionid;
23         private Text modversionversion;
24         private Text modversiondescription;
25         private Text modversionofficial;
26         private Text modversionauthor;
27         private Text modversioncontact;
28         private Text modversionsecurityschema;
29         private Text modversionclass;
30         private Text modversioncategory;
31
32         private Button officialButton;
33         private Button xarUserApi;
34         private Button xarUserGui;
35         private Button xarAdminApi;
36         private Button xarAdminGui;
37         
38         public XarayaModuleFilePage(String argument) {
39                 super(argument);
40                 setTitle(XarayaModuleMessages.getString("Xaraya.label.module"));
41                 setDescription(XarayaModuleMessages.getString("Xaraya.label.details"));
42                 setPageComplete(false);
43         }
44
45         public void createControl(Composite parent) {
46             // create the composite to hold the widgets
47                 GridData gd;
48                 Composite composite =  new Composite(parent, SWT.NULL);
49             // create the desired layout for this wizard page
50                 GridLayout gl = new GridLayout();
51                 int ncol = 4;
52                 gl.numColumns = ncol;
53                 composite.setLayout(gl);
54                 Group detailsgrp = new Group(composite, SWT.NULL);
55                 detailsgrp.setText(XarayaModuleMessages.getString("Xaraya.label.detailsgrp")/*"Module details"*/);
56                 detailsgrp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
57                 detailsgrp.setLayout(new GridLayout());
58
59                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionid")/*"modversionid"*/);                                
60                 modversionid = new Text(detailsgrp, SWT.BORDER);
61                 modversionid.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
62                 modversionid.addListener(SWT.KeyUp, this);
63                 modversionid.setFocus();
64                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionversion")/*"modversionversion"*/);                              
65                 modversionversion = new Text(detailsgrp, SWT.BORDER);
66                 modversionversion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
67                 modversionversion.addListener(SWT.KeyUp, this);
68                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionDescription")/*"modversionDescription"*/);                              
69                 modversiondescription = new Text(detailsgrp, SWT.BORDER);
70                 modversiondescription.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
71                 modversiondescription.addListener(SWT.KeyUp, this);
72         //      new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionofficial")/*"modversionofficial"*/);                            
73         //      modversionofficial = new Text(detailsgrp, SWT.BORDER);
74         //      modversionofficial.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
75         //      modversionofficial.addListener(SWT.KeyUp, this);
76                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionauthor")/*"modversionauthor"*/);                                
77                 modversionauthor = new Text(detailsgrp, SWT.BORDER);
78                 modversionauthor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79                 modversionauthor.addListener(SWT.KeyUp, this);
80                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversioncontact")/*"modversioncontact"*/);                              
81                 modversioncontact = new Text(detailsgrp, SWT.BORDER);
82                 modversioncontact.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
83                 modversioncontact.addListener(SWT.KeyUp, this);
84                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionsecurityschema")/*"modversionsecurityschema"*/);                                
85                 modversionsecurityschema = new Text(detailsgrp, SWT.BORDER);
86                 modversionsecurityschema.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
87                 modversionsecurityschema.addListener(SWT.KeyUp, this);
88                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversionclass")/*"modversionclass"*/);                          
89                 modversionclass = new Text(detailsgrp, SWT.BORDER);
90                 modversionclass.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
91                 modversionclass.addListener(SWT.KeyUp, this);
92                 new Label (detailsgrp, SWT.NONE).setText(XarayaModuleMessages.getString("Xaraya.label.modversioncategory")/*"modversioncategory"*/);                            
93                 modversioncategory = new Text(detailsgrp, SWT.BORDER);
94                 modversioncategory.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
95                 modversioncategory.addListener(SWT.KeyUp, this);
96                 
97                 Composite compo = new Composite(composite, SWT.NONE);
98                 gl = new GridLayout();
99                 ncol = 1;
100                 gl.numColumns = ncol;
101                 compo.setLayout(gl);
102                 
103                 //Group officialgrp = new Group(composite, SWT.NONE);
104                 Group officialgrp = new Group(compo, SWT.NONE);
105                 officialgrp.setText(XarayaModuleMessages.getString("Xaraya.label.officialgrp")/*"Module details"*/);
106                 officialgrp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
107                 officialgrp.setLayout(new GridLayout());
108
109                 officialButton = new Button(officialgrp, SWT.CHECK);
110                 officialButton.setText(XarayaModuleMessages.getString("Xaraya.label.official"));
111                 gd = new GridData(GridData.FILL_HORIZONTAL);
112                 //gd.horizontalSpan = ncol;
113                 officialButton.setLayoutData(gd);
114                 officialButton.setSelection(false);
115                 
116                 //Group autoGensgrp = new Group(composite, SWT.NONE);
117                 Group autoGensgrp = new Group(compo, SWT.NONE);
118                 autoGensgrp.setText(XarayaModuleMessages.getString("Xaraya.label.autoGensgrp"));
119                 autoGensgrp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
120                 autoGensgrp.setLayout(new GridLayout());
121
122                 xarUserApi = new Button(autoGensgrp, SWT.CHECK);
123                 xarUserApi.setText(XarayaModuleMessages.getString("Xaraya.label.xarUserApi"));
124                 gd = new GridData(GridData.FILL_HORIZONTAL);
125                 gd.horizontalSpan = ncol;
126                 xarUserApi.setLayoutData(gd);
127                 xarUserApi.setSelection(false);
128                 xarUserGui = new Button(autoGensgrp, SWT.CHECK);
129                 xarUserGui.setText(XarayaModuleMessages.getString("Xaraya.label.xarUserGui"));
130                 gd = new GridData(GridData.FILL_HORIZONTAL);
131                 gd.horizontalSpan = ncol;
132                 xarUserGui.setLayoutData(gd);
133                 xarUserGui.setSelection(false);
134                 xarAdminApi = new Button(autoGensgrp, SWT.CHECK);
135                 xarAdminApi.setText(XarayaModuleMessages.getString("Xaraya.label.xarAdminApi"));
136                 gd = new GridData(GridData.FILL_HORIZONTAL);
137                 gd.horizontalSpan = ncol;
138                 xarAdminApi.setLayoutData(gd);
139                 xarAdminApi.setSelection(false);
140                 xarAdminGui = new Button(autoGensgrp, SWT.CHECK);
141                 xarAdminGui.setText(XarayaModuleMessages.getString("Xaraya.label.xarAdminGui"));
142                 gd = new GridData(GridData.FILL_HORIZONTAL);
143                 gd.horizontalSpan = ncol;
144                 xarAdminGui.setLayoutData(gd);
145                 xarAdminGui.setSelection(false);
146
147             // set the composite as the control for this page
148                 setControl(composite);          
149                 addListeners();
150         }
151         
152         private void addListeners()
153         {
154                 officialButton.addListener(SWT.Selection, this);
155                 xarUserApi.addListener(SWT.Selection, this);
156                 xarUserGui.addListener(SWT.Selection, this);
157                 xarAdminApi.addListener(SWT.Selection, this);
158                 xarAdminGui.addListener(SWT.Selection, this);
159         }
160
161         public void handleEvent(Event event) {
162                 setPageComplete(validatePage());
163         }
164
165 //      public boolean canFlipToNextPage()
166 //      {
167 //              if (getErrorMessage() != null) return false;
168 //              if (isPageComplete() && validatePage()) {
169 //                      saveDataToModel();
170 //                      return true;
171 //              } 
172 //              return false;
173 //      }
174         public boolean canFinish(){
175                 if (isPageComplete() /*&& validatePage()*/) {
176                         saveDataToModel();
177                         return true;
178                 } 
179                 return false;           
180         }
181
182
183
184         private boolean validateText(Text input){
185                 String buf = input.getText();
186                 if ((buf!=null) 
187                         &&  (buf.trim().length() >0)) return true;
188                 else return false;      
189         }
190         public boolean isNumeric(Text input) {
191                 //there is something in the field to check..
192                 StringBuffer buf = new StringBuffer(input.getText());
193                 for (int i=0; i < buf.length(); i++){
194                         if (!( Character.isDigit(buf.charAt(i)) //is it a number
195                                 || (buf.charAt(i) == '.')  //is it a decimal point
196                                 || (buf.charAt(i) == '_'))) //is it an under_score (incase of 1_2)
197                                 return false;
198                 }
199                 return true;
200         }
201                         
202         private boolean validatePage()  {
203                 StringBuffer buf = new StringBuffer();
204                 if (!validateText(modversionid)) buf.append("Id field incomplete");
205                 else if (!isNumeric(modversionid)) buf.append("Id field must be numeric");
206                 else if (!validateText(modversionversion)) buf.append("Version field incomplete");
207                 else if (!isNumeric(modversionversion)) buf.append("Version must be numeric");
208                 else if (!validateText(modversiondescription)) buf.append("Description field incomplete");
209                 else if (!validateText(modversionauthor)) buf.append("Author field incomplete");
210                 else if (!validateText(modversioncontact)) buf.append("Contact field incomplete");
211                 else if (!validateText(modversionsecurityschema)) buf.append("Security schema field incomplete");
212                 else if (!validateText(modversionclass)) buf.append("Class field incomplete");
213                 else if (!validateText(modversioncategory)) buf.append("Category field incomplete");
214                 if (buf.length() == 0) {
215                         //setErrorMessage("Module ready for creation");
216                         setErrorMessage(null); 
217                         return true;
218                 }       
219                 setErrorMessage(buf.toString());
220                 return false;           
221         }
222
223         public void saveDataToModel()
224         {
225                 XarayaVersionModel.setModversionid(modversionid.getText());
226                 XarayaVersionModel.setModversionversion(modversionversion.getText());
227                 XarayaVersionModel.setModversiondescription(modversiondescription.getText());
228                 XarayaVersionModel.setModversionauthor(modversionauthor.getText());
229                 XarayaVersionModel.setModversioncontact(modversioncontact.getText());
230                 XarayaVersionModel.setModversionsecurityschema(modversionsecurityschema.getText());
231                 XarayaVersionModel.setModversionclass(modversionclass.getText());
232                 XarayaVersionModel.setModversioncategory(modversioncategory.getText());
233                 XarayaVersionModel.setUserApi(xarUserApi.getSelection());
234                 XarayaVersionModel.setUserGui(xarUserGui.getSelection());
235                 XarayaVersionModel.setAdminApi(xarAdminApi.getSelection());
236                 XarayaVersionModel.setAdminGui(xarAdminGui.getSelection());
237                 XarayaVersionModel.setModversionofficial(
238                         (officialButton.getSelection()) ? "1" : "0");
239                 XarayaVersionModel.setModversionadmin(
240                         (xarAdminGui.getSelection()) ? "1" : "0" );
241                 XarayaVersionModel.setModversionuser( 
242                         (xarUserGui.getSelection()) ? "1" : "0" );
243                 }
244 }
245