1 11 package org.eclipse.team.internal.ui.wizards; 12 13 import java.io.File ; 14 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.window.Window; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.SelectionAdapter; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.graphics.Point; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.*; 27 import org.eclipse.team.internal.ui.*; 28 import org.eclipse.ui.PlatformUI; 29 30 public class ImportProjectSetMainPage extends TeamWizardPage { 31 Combo fileCombo; 32 String file = ""; Button browseButton; 34 Button addToWorkingSet; 35 Text workingSetField; 36 37 private boolean createWorkingSet = false; 38 private String workingSetName = ""; 40 private boolean haveBrowsed; 41 42 private boolean runInBackground = isRunInBackgroundPreferenceOn(); 43 44 47 public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) { 48 super(pageName, title, titleImage); 49 setDescription(TeamUIMessages.ImportProjectSetMainPage_description); 50 } 51 52 55 public void createControl(Composite parent) { 56 Composite composite = createComposite(parent, 1); 57 initializeDialogUnits(composite); 58 59 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.IMPORT_PROJECT_SET_PAGE); 61 62 Composite inner = new Composite(composite, SWT.NULL); 63 inner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 64 GridLayout layout = new GridLayout(); 65 layout.numColumns = 3; 66 layout.marginHeight = 0; 67 layout.marginWidth = 0; 68 inner.setLayout(layout); 69 70 createLabel(inner, TeamUIMessages.ImportProjectSetMainPage_Project_Set_File_Name__2); 71 72 fileCombo = createDropDownCombo(inner); 73 file = PsfFilenameStore.getSuggestedDefault(); 74 fileCombo.setItems(PsfFilenameStore.getHistory()); 75 fileCombo.setText(file); 76 fileCombo.addListener(SWT.Modify, new Listener() { 77 public void handleEvent(Event event) { 78 file = fileCombo.getText(); 79 updateEnablement(); 80 } 81 }); 82 83 browseButton = new Button(inner, SWT.PUSH); 84 browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); 85 GridData data = new GridData(); 86 data.horizontalAlignment = GridData.FILL; 87 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 88 data.widthHint = Math.max(widthHint, browseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 89 browseButton.setLayoutData(data); 90 browseButton.addListener(SWT.Selection, new Listener() { 91 public void handleEvent(Event event) { 92 FileDialog d = new FileDialog(getShell()); 93 d.setFilterExtensions(new String [] {"*.psf", "*"}); d.setFilterNames(new String [] {TeamUIMessages.ImportProjectSetMainPage_Project_Set_Files_2, TeamUIMessages.ImportProjectSetMainPage_allFiles}); String fileName= getFileName(); 96 if (fileName != null && fileName.length() > 0) { 97 int separator= fileName.lastIndexOf(System.getProperty ("file.separator").charAt (0)); if (separator != -1) { 99 fileName= fileName.substring(0, separator); 100 } 101 } else { 102 fileName= ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); 103 } 104 d.setFilterPath(fileName); 105 String f = d.open(); 106 if (f != null) { 107 fileCombo.setText(f); 108 file = f; 109 } 110 } 111 }); 112 113 addWorkingSetSection(composite); 114 115 Button runInBackgroundCheckbox = SWTUtils.createCheckBox(composite, TeamUIMessages.ImportProjectSetMainPage_runInBackground, 3); 116 117 runInBackgroundCheckbox.setSelection(isRunInBackgroundPreferenceOn()); 118 runInBackgroundCheckbox.addSelectionListener(new SelectionAdapter() { 119 public void widgetSelected(SelectionEvent e) { 120 runInBackground = !runInBackground; 121 } 122 }); 123 124 setControl(composite); 125 updateEnablement(); 126 Dialog.applyDialogFont(parent); 127 } 128 129 private void addWorkingSetSection(Composite composite) { 130 131 addToWorkingSet = new Button(composite, SWT.CHECK | SWT.LEFT); 132 addToWorkingSet.setText( TeamUIMessages.ImportProjectSetMainPage_AddToWorkingSet); 133 GridData data = new GridData(); 134 data.horizontalSpan = 2; 135 addToWorkingSet.setLayoutData(data); 136 137 addToWorkingSet.setSelection(false); 138 addToWorkingSet.addSelectionListener(new SelectionAdapter() { 139 public void widgetSelected(SelectionEvent e) { 140 createWorkingSet= !createWorkingSet; 141 updateEnablement(); 142 } 143 }); 144 145 Composite inner = new Composite(composite, SWT.NULL); 146 inner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 147 GridLayout layout = new GridLayout(); 148 layout.numColumns = 2; 149 layout.marginHeight = 0; 150 layout.marginWidth = 0; 151 inner.setLayout(layout); 152 153 workingSetField = createTextField(inner); 154 workingSetField.setEditable(false); 155 browseButton = new Button(inner, SWT.PUSH); 156 browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse); 157 data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 158 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 159 Point minSize = browseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); 160 data.widthHint = Math.max(widthHint, minSize.x); 161 browseButton.setLayoutData(data); 162 163 164 haveBrowsed = false; 166 browseButton.addSelectionListener(new SelectionAdapter() { 167 public void widgetSelected(SelectionEvent e) { 168 final WorkingSetsDialog dialog = new WorkingSetsDialog(getShell()); 170 haveBrowsed = true; 171 if (dialog.open() == Window.OK) 172 workingSetField.setText(dialog.getSelectedWorkingSet()); 173 174 updateEnablement(); 175 } 176 }); 177 updateEnablement(); 178 179 } 180 181 private boolean validateWorkingSetName() { 182 if (addToWorkingSet.getSelection()) { 183 workingSetName = workingSetField.getText(); 184 if (workingSetName.length() == 0) { 185 setMessage(TeamUIMessages.ImportProjectSetMainPage_workingSetNameEmpty, ERROR); 186 return false; 187 } 188 } 189 setMessage(null); 190 return true; 191 } 192 193 private void updateEnablement() { 194 boolean complete; 195 setMessage(null); 196 197 workingSetField.setEnabled(addToWorkingSet.getSelection()); 198 browseButton.setEnabled(addToWorkingSet.getSelection()); 199 200 if (file.length() == 0) { 201 setPageComplete(false); 202 return; 203 } else { 204 File f = new File (file); 206 if (!f.exists()) { 207 setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, ERROR); 208 setPageComplete(false); 209 return; 210 } else if (f.isDirectory()) { 211 setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, ERROR); 212 setPageComplete(false); 213 return; 214 } 215 } 216 217 if (addToWorkingSet.getSelection() && !haveBrowsed){ 220 setPageComplete(false); 221 return; 222 } 223 224 complete = validateWorkingSetName(); 225 226 setPageComplete(complete); 227 } 228 229 public String getFileName() { 230 return file; 231 } 232 233 public void setVisible(boolean visible) { 234 super.setVisible(visible); 235 if (visible) { 236 fileCombo.setFocus(); 237 } 238 } 239 240 243 public String getWorkingSetName() { 244 if (!createWorkingSet) return null; 245 return workingSetName; 246 } 247 248 private static boolean isRunInBackgroundPreferenceOn() { 249 return TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean( 250 IPreferenceIds.RUN_IMPORT_IN_BACKGROUND); 251 } 252 253 public boolean isRunInBackgroundOn() { 254 return runInBackground; 255 } 256 } 257 | Popular Tags |