1 24 package org.objectweb.dolphin.dialogs; 25 26 import org.eclipse.jface.dialogs.Dialog; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Control; 35 import org.eclipse.swt.widgets.DirectoryDialog; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Shell; 38 import org.eclipse.swt.widgets.Text; 39 import org.objectweb.dolphin.resources.DolphinResourcesManagment; 40 41 45 public class DialogWorkspace extends Dialog{ 46 private String text =""; 47 48 57 public DialogWorkspace(Shell parentShell) { 58 super(parentShell); 59 } 60 61 65 private String queryFile() { 66 DirectoryDialog dialog= new DirectoryDialog(new Shell(), SWT.OPEN); 67 dialog.setText("Switch Workspace"); String path= dialog.open(); 69 if (path != null && path.length() > 0) 70 return path; 71 return null; 72 } 73 74 77 public Control createDialogArea(Composite parent){ 78 Composite composite = (Composite) super.createDialogArea(parent); 79 GridLayout grid = new GridLayout(2,true); 80 composite.setLayout(grid); 81 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 82 83 Label old = new Label(composite, SWT.BOLD); 84 old.setText("Old workspace : "+DolphinResourcesManagment.getWorkspace()); 85 gd.horizontalSpan=2; 86 old.setLayoutData(gd); 87 gd = new GridData(GridData.FILL_HORIZONTAL); 88 89 Label label = new Label(composite, SWT.BOLD); 91 label.setText("Select the new workspace :"); 92 gd.horizontalSpan=2; 93 label.setLayoutData(gd); 94 95 gd = new GridData(GridData.FILL_HORIZONTAL); 97 final Text textField = new Text(composite,SWT.BORDER); 98 textField.setBounds(10,10,300,20); 99 textField.setLayoutData(gd); 100 gd = new GridData(GridData.FILL_HORIZONTAL); 101 Button button = new Button(composite,SWT.PUSH); 102 button.setText("Browse"); 103 button.addSelectionListener(new SelectionAdapter() { 104 public void widgetSelected(SelectionEvent e) { 105 text = queryFile(); 106 textField.setText(text); 107 } 108 }); 109 button.setLayoutData(gd); 110 111 112 return composite; 113 } 114 115 119 protected void okPressed() { 120 DolphinResourcesManagment.setWorkspace(text); 121 super.okPressed(); 122 } 123 124 125 126 127 } 128 | Popular Tags |