1 package com.bull.eclipse.jonas; 2 3 7 8 import java.io.File ; 9 10 import org.eclipse.core.runtime.CoreException; 11 import org.eclipse.swt.SWT; 12 import org.eclipse.swt.events.SelectionAdapter; 13 import org.eclipse.swt.events.SelectionEvent; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.layout.GridLayout; 16 import org.eclipse.swt.widgets.Button; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.FileDialog; 20 import org.eclipse.swt.widgets.Label; 21 import org.eclipse.swt.widgets.Text; 22 23 public class JonasProjectGeneralPropertyPage implements JonasPluginResources { 24 25 private Button isJonasProjectCheck; 26 private Button exportSourceCheck; 27 private Text webpathText; 28 private Text warLocationText; 29 private Text webDirText; 30 private Text srcDirText; 31 private Text srcEJBDirText; 32 33 34 35 private JonasProjectPropertyPage page; 36 37 private static final int TEXT_FIELD_WIDTH = 200; 38 39 public JonasProjectGeneralPropertyPage(JonasProjectPropertyPage page) { 40 this.page = page; 41 } 42 43 44 47 protected Control createContents(Composite parent) { 48 Composite composite = new Composite(parent, SWT.NULL); 49 50 composite.setLayout(new GridLayout()); 51 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 52 53 createIsJonasProjectGroup(composite); 54 56 createWebNameGroup(composite); 57 createWebSrcGroup(composite); 58 createWebpathGroup(composite); 59 61 createWarLocationGroup(composite); 62 63 createEJBpathGroup(composite); 64 65 return composite; 66 } 67 68 public void createIsJonasProjectGroup(Composite parent) { 69 Composite isJonasProjectGroup = new Composite(parent,SWT.NONE); 70 GridLayout layout = new GridLayout(); 71 layout.numColumns = 3; 72 isJonasProjectGroup.setLayout(layout); 73 isJonasProjectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 74 75 isJonasProjectCheck = new Button(isJonasProjectGroup, SWT.CHECK | SWT.LEFT); 77 isJonasProjectCheck.setText(PROPERTIES_PAGE_PROJECT_ISJONASPROJECT_LABEL); 78 isJonasProjectCheck.setEnabled(true); 79 80 try { 81 isJonasProjectCheck.setSelection(page.getJavaProject().getProject().hasNature(JonasLauncherPlugin.NATURE_ID)); 82 } catch (CoreException ex) { 83 JonasLauncherPlugin.log(ex.getMessage()); 84 } 85 } 86 87 public void createWebNameGroup(Composite parent) { 88 Composite webnameGroup = new Composite(parent,SWT.NONE); 89 GridLayout layout = new GridLayout(); 90 layout.numColumns = 3; 91 webnameGroup.setLayout(layout); 92 webnameGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 93 94 Label webnameLabel = new Label(webnameGroup,SWT.NONE); 96 webnameLabel.setText(WIZARD_PROJECT_WEBNAME_LABEL); 97 webnameLabel.setEnabled(true); 98 99 webDirText = new Text(webnameGroup, SWT.BORDER); 101 GridData data = new GridData(GridData.FILL_HORIZONTAL); 102 data.widthHint = TEXT_FIELD_WIDTH; 103 webDirText.setLayoutData(data); 105 webDirText.setText(this.getwebDir()); 106 webDirText.setEnabled(true); 107 } 108 109 public void createWebSrcGroup(Composite parent) { 110 Composite websrcGroup = new Composite(parent,SWT.NONE); 111 GridLayout layout = new GridLayout(); 112 layout.numColumns = 3; 113 websrcGroup.setLayout(layout); 114 websrcGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 115 116 117 Label websrcLabel = new Label(websrcGroup,SWT.NONE); 119 websrcLabel.setText(WIZARD_PROJECT_WEBSRC_LABEL); 120 websrcLabel.setEnabled(true); 121 122 srcDirText = new Text(websrcGroup, SWT.BORDER); 124 GridData data1 = new GridData(GridData.FILL_HORIZONTAL); 125 data1.widthHint = TEXT_FIELD_WIDTH; 126 srcDirText.setLayoutData(data1); 128 srcDirText.setText(this.getsrcDir()); 129 srcDirText.setEnabled(true); 130 } 131 132 133 public void createWebpathGroup(Composite parent) { 134 Composite webpathGroup = new Composite(parent,SWT.NONE); 135 GridLayout layout = new GridLayout(); 136 layout.numColumns = 3; 137 webpathGroup.setLayout(layout); 138 webpathGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 139 140 Label webpathLabel = new Label(webpathGroup,SWT.NONE); 142 webpathLabel.setText(WIZARD_PROJECT_WEBPATH_LABEL); 143 webpathLabel.setEnabled(true); 144 145 webpathText = new Text(webpathGroup, SWT.BORDER); 147 GridData data = new GridData(GridData.FILL_HORIZONTAL); 148 data.widthHint = TEXT_FIELD_WIDTH; 149 webpathText.setLayoutData(data); 151 webpathText.setText(this.getWebPath()); 152 webpathText.setEnabled(true); 153 154 } 155 156 157 158 public void createWarLocationGroup(Composite parent) { 159 Composite warLocationGroup = new Composite(parent,SWT.NONE); 160 GridLayout layout = new GridLayout(); 161 layout.numColumns = 3; 162 warLocationGroup.setLayout(layout); 163 warLocationGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 164 165 Label warLocationLabel = new Label(warLocationGroup,SWT.NONE); 167 warLocationLabel.setText(WIZARD_PROJECT_WARLOCATION_LABEL); 168 warLocationLabel.setEnabled(true); 169 170 warLocationText = new Text(warLocationGroup, SWT.BORDER); 172 GridData data = new GridData(GridData.FILL_HORIZONTAL); 173 data.widthHint = TEXT_FIELD_WIDTH; 174 warLocationText.setLayoutData(data); 175 warLocationText.setText(this.getWarLocation()); 176 warLocationText.setEnabled(true); 177 178 Button browseButton = new Button(warLocationGroup, SWT.PUSH); 179 browseButton.setText(BROWSE_BUTTON_LABEL); 180 browseButton.addSelectionListener(new SelectionAdapter() { 181 public void widgetSelected(SelectionEvent evt) { 182 String newValue = warFieldChange(); 183 if (newValue != null) { 184 warLocationText.setText(newValue); 185 } 186 } 187 }); 188 189 browseButton.setEnabled(true); 190 191 exportSourceCheck = new Button(warLocationGroup, SWT.CHECK | SWT.LEFT); 192 exportSourceCheck.setText(WIZARD_PROJECT_EXPORTSOURCE_LABEL); 193 data = new GridData(); 194 data.horizontalSpan = 3; 195 exportSourceCheck.setLayoutData(data); 196 exportSourceCheck.setEnabled(true); 197 exportSourceCheck.setSelection(this.getExportSource()); 198 } 199 200 public void createEJBpathGroup(Composite parent) { 201 Composite ejbpathGroup = new Composite(parent,SWT.NONE); 202 GridLayout layout = new GridLayout(); 203 layout.numColumns = 3; 204 ejbpathGroup.setLayout(layout); 205 ejbpathGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 206 207 Label ejbpathLabel = new Label(ejbpathGroup,SWT.NONE); 209 ejbpathLabel.setText(WIZARD_PROJECT_EJBSRC_LABEL); 210 ejbpathLabel.setEnabled(true); 211 212 srcEJBDirText = new Text(ejbpathGroup, SWT.BORDER); 214 GridData data = new GridData(GridData.FILL_HORIZONTAL); 215 data.widthHint = TEXT_FIELD_WIDTH; 216 srcEJBDirText.setLayoutData(data); 218 srcEJBDirText.setText(this.getSrcEJBDir()); 219 srcEJBDirText.setEnabled(true); 220 221 } 222 223 protected String getWebPath() { 224 String result = ""; 225 try { 226 JonasProject prj = page.getJonasProject(); 227 if(prj != null) 228 result = prj.getWebContext(); 229 } catch (CoreException ex) { 230 } 232 return result; 233 } 234 235 protected String getWarLocation() { 236 String result = ""; 237 try { 238 JonasProject prj = page.getJonasProject(); 239 if(prj != null) { 240 result = prj.getWarLocation(); 241 if (result.trim().equals("")) 242 result = prj.getWebContext() + ".war"; 243 } 244 } catch (CoreException ex) { 245 } 247 return result; 248 } 249 250 protected String getwebDir() { 251 String result = ""; 252 try { 253 JonasProject prj = page.getJonasProject(); 254 if(prj != null) { 255 result = prj.getWebdirName(); 256 } 259 } catch (CoreException ex) { 260 } 262 return result; 263 } 264 265 protected String getsrcDir() { 266 String result = ""; 267 try { 268 JonasProject prj = page.getJonasProject(); 269 if(prj != null) { 270 result = prj.getSrcDir(); 271 } 274 } catch (CoreException ex) { 275 } 277 return result; 278 } 279 280 protected String getSrcEJBDir() { 281 String result = ""; 282 try { 283 JonasProject prj = page.getJonasProject(); 284 if(prj != null) { 285 result = prj.getSrcEJBDir(); 286 } 289 } catch (CoreException ex) { 290 } 292 return result; 293 } 294 295 protected boolean getExportSource() { 296 boolean result = false; 297 try { 298 JonasProject prj = page.getJonasProject(); 299 if(prj != null) 300 result = prj.getExportSource(); 301 } catch (CoreException ex) { 302 } 304 return result; 305 } 306 307 308 311 public boolean performOk() { 312 try { 313 if(isJonasProjectCheck.getSelection()) { 314 JonasProject.addJonasNature(page.getJavaProject()); 315 JonasProject prj = page.getJonasProject(); 316 prj.setWebContext(webpathText.getText()); 318 prj.setWebdirName(webDirText.getText()); 319 prj.setSrcDir(srcDirText.getText()); 320 prj.setWarLocation(warLocationText.getText()); 321 prj.setExportSource(exportSourceCheck.getSelection()); 323 prj.setSrcEJBDir(srcEJBDirText.getText()); 324 prj.saveProperties(); 325 } else { 326 JonasProject.removeJonasNature(page.getJavaProject()); 328 } 329 } catch (Exception ex) { 330 JonasLauncherPlugin.log(ex.getMessage()); 331 } 332 333 return true; 334 } 335 336 337 338 protected String warFieldChange() { 339 File f = new File (warLocationText.getText()); 340 if (!f.exists()) 341 f = null; 342 File d = getFile(f); 343 if (d == null) 344 return null; 345 346 return d.getAbsolutePath(); 347 } 348 349 public boolean isJonasProjectChecked() { 350 return isJonasProjectCheck.getSelection(); 351 } 352 353 356 private File getFile(File startingDirectory) { 357 358 FileDialog dialog = new FileDialog(page.getShell(), SWT.OPEN); 359 if (startingDirectory != null) 360 dialog.setFileName(startingDirectory.getPath()); 361 String file = dialog.open(); 364 if (file != null) { 365 file = file.trim(); 366 if (file.length() > 0) 367 return new File (file); 368 } 369 370 return null; 371 } 372 373 } 374 | Popular Tags |