1 16 package org.apache.axis.tool.codegen.eclipse.ui; 17 18 import java.io.File ; 19 import java.lang.reflect.Method ; 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 import java.net.URLClassLoader ; 23 import java.util.Vector ; 24 25 import org.apache.axis.tool.codegen.eclipse.plugin.CodegenWizardPlugin; 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.events.SelectionListener; 32 import org.eclipse.swt.layout.GridData; 33 import org.eclipse.swt.layout.GridLayout; 34 import org.eclipse.swt.widgets.Button; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.swt.widgets.DirectoryDialog; 37 import org.eclipse.swt.widgets.Label; 38 import org.eclipse.swt.widgets.Table; 39 import org.eclipse.swt.widgets.TableColumn; 40 import org.eclipse.swt.widgets.TableItem; 41 import org.eclipse.swt.widgets.Text; 42 43 public class JavaSourceSelectionPage extends AbstractWizardPage{ 44 45 46 private Text javaClassFileLocationBox; 47 private Text javaClassNameBox; 48 private Button searchDeclaredMethodsCheckBox; 49 50 private Table table; 51 52 private boolean dirty; 53 54 public JavaSourceSelectionPage() { 55 super("page4"); 56 } 57 58 protected void initializeDefaultSettings() { 59 settings.put(JAVA_CLASS_NAME, ""); 60 settings.put(JAVA_CLASS_LOCATION_NAME, ""); 61 } 62 63 68 public int getPageType() { 69 return JAVA_2_WSDL_TYPE; 70 } 71 72 77 public void createControl(Composite parent) { 78 Composite container = new Composite(parent, SWT.NULL); 79 GridLayout layout = new GridLayout(); 80 container.setLayout(layout); 81 layout.numColumns = 3; 82 layout.verticalSpacing = 9; 83 84 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 85 86 Label label = new Label(container, SWT.NULL); 87 label.setText(CodegenWizardPlugin 88 .getResourceString("page4.javafilelocation.label")); 89 90 javaClassFileLocationBox = new Text(container, SWT.BORDER); 91 javaClassFileLocationBox.setLayoutData(gd); 92 javaClassFileLocationBox.setText(settings.get(JAVA_CLASS_LOCATION_NAME)); 93 javaClassFileLocationBox.addModifyListener(new ModifyListener(){ 94 public void modifyText(ModifyEvent e){ 95 handleLocationTextChange(); 96 } 97 }); 98 99 100 Button browseButton = new Button(container, SWT.PUSH); 101 browseButton.setText(CodegenWizardPlugin 102 .getResourceString("general.browse")); 103 browseButton.addSelectionListener(new SelectionAdapter() { 104 public void widgetSelected(SelectionEvent e) { 105 handleDirectoryBrowse(); 106 } 107 }); 108 109 label = new Label(container, SWT.NULL); 110 label.setText(CodegenWizardPlugin 111 .getResourceString("page4.classname.label")); 112 113 gd = new GridData(GridData.FILL_HORIZONTAL); 114 javaClassNameBox = new Text(container,SWT.BORDER); 115 javaClassNameBox.setLayoutData(gd); 116 javaClassNameBox.setText(settings.get(JAVA_CLASS_NAME)); 117 javaClassNameBox.addModifyListener(new ModifyListener(){ 118 public void modifyText(ModifyEvent e){ 119 handleClassNameTextChange(); 120 } 121 }); 122 123 Button searchButton = new Button(container, SWT.PUSH); 124 searchButton.setText(CodegenWizardPlugin 125 .getResourceString("general.search")); 126 searchButton.addSelectionListener(new SelectionAdapter() { 127 public void widgetSelected(SelectionEvent e) { 128 updateTable(); 129 } 130 }); 131 gd = new GridData(GridData.FILL_HORIZONTAL); 133 gd.horizontalSpan = 3; 134 135 searchDeclaredMethodsCheckBox = new Button(container,SWT.CHECK); 136 searchDeclaredMethodsCheckBox.setLayoutData(gd); 137 searchDeclaredMethodsCheckBox.setText("List Declared Methods Only"); 138 searchDeclaredMethodsCheckBox.addSelectionListener(new SelectionListener(){ 139 public void widgetSelected(SelectionEvent e){ 140 updateDirtyStatus(true); } 142 public void widgetDefaultSelected(SelectionEvent e){} 143 }); 144 145 gd = new GridData(GridData.FILL_BOTH); 146 gd.horizontalSpan=3; 147 gd.verticalSpan=5; 148 table = new Table(container,SWT.SINGLE|SWT.FULL_SELECTION|SWT.CHECK); 149 table.setLinesVisible(true); 150 table.setHeaderVisible(true); 151 table.setLayoutData(gd); 152 declareColumn(table,20,""); 153 declareColumn(table,100,"Method Name"); 154 declareColumn(table,100,"Return Type"); 155 declareColumn(table,100,"Parameter Count"); 156 table.setVisible(false); 157 158 setPageComplete(false); 159 160 if (restoredFromPreviousSettings){ 161 handleLocationTextChange(); 162 handleClassNameTextChange(); 163 } 164 165 setControl(container); 166 167 } 168 169 private void declareColumn(Table table, int width,String colName){ 170 TableColumn column = new TableColumn(table,SWT.NONE); 171 column.setWidth(width); 172 column.setText(colName); 173 } 174 178 private void handleDirectoryBrowse() { 179 DirectoryDialog fileDialog = new DirectoryDialog(this.getShell()); 180 String dirName = fileDialog.open(); 181 if (dirName != null) { 182 javaClassFileLocationBox.setText(dirName); 183 } 184 185 } 186 187 private void handleLocationTextChange(){ 188 String locationText = javaClassFileLocationBox.getText(); 189 settings.put(JAVA_CLASS_LOCATION_NAME,locationText); 190 if (locationText==null || "".equals(locationText.trim())){ 191 updateStatus("Class file location needs to be specified!"); 192 }else{ 193 updateStatus(null); 194 } 195 } 196 197 private void handleClassNameTextChange(){ 198 String className = javaClassNameBox.getText(); 199 settings.put(JAVA_CLASS_NAME,className); 200 if (className==null || "".equals(className.trim())){ 201 updateStatus("Fully qualified class name needs to be specified!"); 202 }else if(className.endsWith(".")){ 203 updateStatus("Class name is not properly terminated!"); 204 }else{ 205 updateStatus(null); 206 } 207 } 208 209 public String getClassName(){ 210 return javaClassNameBox.getText(); 211 } 212 213 public String getClassLocation(){ 214 return javaClassFileLocationBox.getText(); 215 } 216 217 public Vector getSelectedMethods(){ 218 Vector list = new Vector (); 219 TableItem[] items = table.getItems(); 220 int itemLength = items.length; 221 for(int i=0;i<itemLength;i++){ 222 if(items[i].getChecked()){ 223 list.add(items[i].getText(1)); } 225 } 226 return list; 227 } 228 229 private void updateTable() { 230 try { 232 String classFileLocation = this.getClassLocation(); 233 URL classFileURL = new File (classFileLocation).toURL(); 234 ClassLoader loader = new URLClassLoader (new URL [] { classFileURL }); 235 236 Class clazz = loader.loadClass(getClassName()); 237 Method [] methods = null; 238 239 if (searchDeclaredMethodsCheckBox.getSelection()){ 240 methods = clazz.getDeclaredMethods(); 241 }else{ 242 methods = clazz.getMethods(); 243 } 244 245 int methodCount = methods.length; 246 if (methodCount > 0) { 247 table.removeAll(); 248 TableItem[] items = new TableItem[methodCount]; for (int i = 0 ; i < methodCount; i++){ 250 items[i] = new TableItem(table, SWT.NONE); 251 items[i].setText(1,methods[i].getName()); 252 items[i].setText(2,methods[i].getReturnType().getName()); 253 items[i].setText(3,methods[i].getParameterTypes().length+""); 254 items[i].setChecked(true); } 256 table.setVisible(true); 257 258 updateDirtyStatus(false); 260 updateStatus(null); 261 } 262 263 } catch (MalformedURLException e) { 264 updateStatus("Error : invalid location " +e.getMessage()); 265 } catch (ClassNotFoundException e) { 266 updateStatus("Error : Class not found " + e.getMessage()); 267 } 268 } 269 270 private void updateDirtyStatus(boolean status){ 271 dirty = status; 272 if (table.isVisible()){ 273 table.setEnabled(!status); 274 } 275 setPageComplete(!status); 276 } 277 } 278 | Popular Tags |