|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 11-22
Link Here
|
| 11 |
package org.eclipse.team.internal.ui.wizards; |
11 |
package org.eclipse.team.internal.ui.wizards; |
| 12 |
|
12 |
|
| 13 |
import java.io.File; |
13 |
import java.io.File; |
|
|
14 |
import java.lang.reflect.InvocationTargetException; |
| 15 |
import java.net.MalformedURLException; |
| 16 |
import java.net.URL; |
| 14 |
|
17 |
|
|
|
18 |
import org.eclipse.compare.internal.Utilities; |
| 15 |
import org.eclipse.core.resources.ResourcesPlugin; |
19 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
20 |
import org.eclipse.core.runtime.OperationCanceledException; |
| 16 |
import org.eclipse.jface.dialogs.Dialog; |
21 |
import org.eclipse.jface.dialogs.Dialog; |
| 17 |
import org.eclipse.jface.dialogs.IDialogConstants; |
22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 18 |
import org.eclipse.jface.resource.ImageDescriptor; |
23 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 19 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.SWT; |
|
|
25 |
import org.eclipse.swt.dnd.Clipboard; |
| 26 |
import org.eclipse.swt.dnd.TextTransfer; |
| 20 |
import org.eclipse.swt.events.SelectionAdapter; |
27 |
import org.eclipse.swt.events.SelectionAdapter; |
| 21 |
import org.eclipse.swt.events.SelectionEvent; |
28 |
import org.eclipse.swt.events.SelectionEvent; |
| 22 |
import org.eclipse.swt.layout.GridData; |
29 |
import org.eclipse.swt.layout.GridData; |
|
Lines 32-45
Link Here
|
| 32 |
String file = ""; //$NON-NLS-1$ |
39 |
String file = ""; //$NON-NLS-1$ |
| 33 |
Button browseButton; |
40 |
Button browseButton; |
| 34 |
|
41 |
|
|
|
42 |
String urlString = ""; //$NON-NLS-1$ |
| 43 |
Combo urlCombo; |
| 44 |
|
| 45 |
// input type radios |
| 46 |
private Button fileInputButton; |
| 47 |
private Button urlInputButton; |
| 48 |
|
| 49 |
// input type |
| 50 |
public static final int InputType_file = 0; |
| 51 |
public static final int InputType_URL = 1; |
| 52 |
private int inputType = InputType_file; |
| 53 |
|
| 35 |
private boolean runInBackground = isRunInBackgroundPreferenceOn(); |
54 |
private boolean runInBackground = isRunInBackgroundPreferenceOn(); |
| 36 |
// a wizard shouldn't be in an error state until the state has been modified by the user |
55 |
// a wizard shouldn't be in an error state until the state has been modified by the user |
| 37 |
private int messageType = NONE; |
56 |
private int messageType = NONE; |
| 38 |
private WorkingSetGroup workingSetGroup; |
57 |
private WorkingSetGroup workingSetGroup; |
| 39 |
|
58 |
|
| 40 |
public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) { |
59 |
private PsfFilenameStore psfFilenameStore = PsfFilenameStore.getInstance(); |
|
|
60 |
private PsfUrlStore psfUrlStore = PsfUrlStore.getInstance(); |
| 61 |
|
| 62 |
public ImportProjectSetMainPage(String pageName, String title, |
| 63 |
ImageDescriptor titleImage) { |
| 41 |
super(pageName, title, titleImage); |
64 |
super(pageName, title, titleImage); |
| 42 |
setDescription(TeamUIMessages.ImportProjectSetMainPage_description); |
65 |
setDescription(TeamUIMessages.ImportProjectSetMainPage_description); |
|
|
66 |
} |
| 67 |
|
| 68 |
private void setInputType(int inputTypeSelected) { |
| 69 |
this.inputType = inputTypeSelected; |
| 70 |
// reset the message type and give the user fresh chance to input |
| 71 |
// correct data |
| 72 |
messageType = NONE; |
| 73 |
// update controls |
| 74 |
fileInputButton.setSelection(inputType == InputType_file); |
| 75 |
fileCombo.setEnabled(inputType == InputType_file); |
| 76 |
browseButton.setEnabled(inputType == InputType_file); |
| 77 |
urlInputButton.setSelection(inputType == InputType_URL); |
| 78 |
urlCombo.setEnabled(inputType == InputType_URL); |
| 79 |
// validate field |
| 80 |
if (inputType == InputType_file) |
| 81 |
updateFileEnablement(); |
| 82 |
if (inputType == InputType_URL) |
| 83 |
updateUrlEnablement(); |
| 84 |
|
| 43 |
} |
85 |
} |
| 44 |
|
86 |
|
| 45 |
/* |
87 |
/* |
|
Lines 60-80
Link Here
|
| 60 |
layout.marginWidth = 0; |
102 |
layout.marginWidth = 0; |
| 61 |
inner.setLayout(layout); |
103 |
inner.setLayout(layout); |
| 62 |
|
104 |
|
| 63 |
createLabel(inner, TeamUIMessages.ImportProjectSetMainPage_Project_Set_File_Name__2); |
105 |
fileInputButton = new Button(inner, SWT.RADIO); |
|
|
106 |
fileInputButton |
| 107 |
.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_File); |
| 108 |
fileInputButton.setEnabled(true); |
| 109 |
fileInputButton.addSelectionListener(new SelectionAdapter() { |
| 110 |
public void widgetSelected(SelectionEvent e) { |
| 111 |
setInputType(InputType_file); |
| 112 |
} |
| 113 |
}); |
| 64 |
|
114 |
|
| 65 |
fileCombo = createDropDownCombo(inner); |
115 |
fileCombo = createDropDownCombo(inner); |
| 66 |
file = PsfFilenameStore.getSuggestedDefault(); |
116 |
file = psfFilenameStore.getSuggestedDefault(); |
| 67 |
fileCombo.setItems(PsfFilenameStore.getHistory()); |
117 |
fileCombo.setItems(psfFilenameStore.getHistory()); |
| 68 |
fileCombo.setText(file); |
118 |
fileCombo.setText(file); |
| 69 |
fileCombo.addListener(SWT.Modify, new Listener() { |
119 |
fileCombo.addListener(SWT.Modify, new Listener() { |
| 70 |
public void handleEvent(Event event) { |
120 |
public void handleEvent(Event event) { |
| 71 |
file = fileCombo.getText(); |
121 |
file = fileCombo.getText(); |
| 72 |
updateEnablement(); |
122 |
updateFileEnablement(); |
| 73 |
} |
123 |
} |
| 74 |
}); |
124 |
}); |
| 75 |
|
125 |
|
| 76 |
browseButton = new Button(inner, SWT.PUSH); |
126 |
browseButton = new Button(inner, SWT.PUSH); |
| 77 |
browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); |
127 |
browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); |
|
|
128 |
|
| 129 |
urlInputButton = new Button(inner, SWT.RADIO); |
| 130 |
urlInputButton |
| 131 |
.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_Url); |
| 132 |
urlInputButton.addSelectionListener(new SelectionAdapter() { |
| 133 |
public void widgetSelected(SelectionEvent e) { |
| 134 |
setInputType(InputType_URL); |
| 135 |
} |
| 136 |
}); |
| 137 |
urlCombo = createDropDownCombo(inner); |
| 138 |
urlString = psfUrlStore.getSuggestedDefault(); |
| 139 |
urlCombo.setItems(psfUrlStore.getHistory()); |
| 140 |
urlCombo.setText(urlString); |
| 141 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
| 142 |
gd.horizontalSpan = 2; |
| 143 |
urlCombo.setLayoutData(gd); |
| 144 |
urlCombo.addListener(SWT.Modify, new Listener() { |
| 145 |
public void handleEvent(Event event) { |
| 146 |
urlString = urlCombo.getText(); |
| 147 |
updateUrlEnablement(); |
| 148 |
} |
| 149 |
}); |
| 150 |
|
| 78 |
GridData data = new GridData(); |
151 |
GridData data = new GridData(); |
| 79 |
data.horizontalAlignment = GridData.FILL; |
152 |
data.horizontalAlignment = GridData.FILL; |
| 80 |
int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); |
153 |
int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); |
|
Lines 115-126
Link Here
|
| 115 |
}); |
188 |
}); |
| 116 |
|
189 |
|
| 117 |
setControl(composite); |
190 |
setControl(composite); |
| 118 |
updateEnablement(); |
191 |
setDefaultInputType(); |
| 119 |
Dialog.applyDialogFont(parent); |
192 |
Dialog.applyDialogFont(parent); |
| 120 |
// future messages will be of type error |
|
|
| 121 |
messageType = ERROR; |
| 122 |
} |
193 |
} |
| 123 |
|
194 |
|
|
|
195 |
private void setDefaultInputType() { |
| 196 |
// check for clipboard contents |
| 197 |
Control c = getControl(); |
| 198 |
if (c != null) { |
| 199 |
Clipboard clipboard = new Clipboard(c.getDisplay()); |
| 200 |
Object o = clipboard.getContents(TextTransfer.getInstance()); |
| 201 |
clipboard.dispose(); |
| 202 |
if (o instanceof String) { |
| 203 |
try { |
| 204 |
URL url = new URL((String) o); |
| 205 |
if (url != null) { |
| 206 |
setInputType(InputType_URL); |
| 207 |
urlCombo.setText((String) o); |
| 208 |
return; |
| 209 |
} |
| 210 |
} catch (MalformedURLException e) { |
| 211 |
// ignore, it's not and URL |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
setInputType(InputType_file); |
| 216 |
} |
| 217 |
|
| 124 |
private void addWorkingSetSection(Composite composite) { |
218 |
private void addWorkingSetSection(Composite composite) { |
| 125 |
workingSetGroup = new WorkingSetGroup( |
219 |
workingSetGroup = new WorkingSetGroup( |
| 126 |
composite, |
220 |
composite, |
|
Lines 129-137
Link Here
|
| 129 |
"org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */}); //$NON-NLS-1$ |
223 |
"org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */}); //$NON-NLS-1$ |
| 130 |
} |
224 |
} |
| 131 |
|
225 |
|
| 132 |
private void updateEnablement() { |
226 |
private void updateUrlEnablement() { |
|
|
227 |
boolean complete = false; |
| 228 |
setMessage(null); |
| 229 |
setErrorMessage(null); |
| 230 |
|
| 231 |
if (urlString.length() == 0) { |
| 232 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyURL, |
| 233 |
messageType); |
| 234 |
complete = false; |
| 235 |
} else { |
| 236 |
|
| 237 |
try { |
| 238 |
new URL(urlString); |
| 239 |
// the URL is correct, we can clear the error message |
| 240 |
complete = true; |
| 241 |
} catch (MalformedURLException e) { |
| 242 |
messageType = ERROR; |
| 243 |
setMessage(TeamUIMessages.ImportProjectSetDialog_malformed_url, |
| 244 |
messageType); |
| 245 |
complete = false; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
if (complete) { |
| 250 |
setErrorMessage(null); |
| 251 |
setDescription(TeamUIMessages.ImportProjectSetMainPage_description); |
| 252 |
} |
| 253 |
|
| 254 |
setPageComplete(complete); |
| 255 |
} |
| 256 |
|
| 257 |
private void updateFileEnablement() { |
| 133 |
boolean complete = false; |
258 |
boolean complete = false; |
| 134 |
setMessage(null); |
259 |
setMessage(null); |
|
|
260 |
setErrorMessage(null); |
| 135 |
|
261 |
|
| 136 |
if (file.length() == 0) { |
262 |
if (file.length() == 0) { |
| 137 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyFile, messageType); |
263 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyFile, messageType); |
|
Lines 141-154
Link Here
|
| 141 |
// See if the file exists |
267 |
// See if the file exists |
| 142 |
File f = new File(file); |
268 |
File f = new File(file); |
| 143 |
if (!f.exists()) { |
269 |
if (!f.exists()) { |
|
|
270 |
messageType = ERROR; |
| 144 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, messageType); |
271 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, messageType); |
| 145 |
setPageComplete(false); |
272 |
setPageComplete(false); |
| 146 |
return; |
273 |
return; |
| 147 |
} else if (f.isDirectory()) { |
274 |
} else if (f.isDirectory()) { |
|
|
275 |
messageType = ERROR; |
| 148 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, messageType); |
276 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, messageType); |
| 149 |
setPageComplete(false); |
277 |
setPageComplete(false); |
| 150 |
return; |
278 |
return; |
| 151 |
} else if (!ProjectSetImporter.isValidProjectSetFile(file)) { |
279 |
} else if (!ProjectSetImporter.isValidProjectSetFile(file)) { |
|
|
280 |
messageType = ERROR; |
| 152 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType); |
281 |
setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType); |
| 153 |
setPageComplete(false); |
282 |
setPageComplete(false); |
| 154 |
return; |
283 |
return; |
|
Lines 168-173
Link Here
|
| 168 |
return file; |
297 |
return file; |
| 169 |
} |
298 |
} |
| 170 |
|
299 |
|
|
|
300 |
public String getUrl() { |
| 301 |
return urlString; |
| 302 |
} |
| 303 |
|
| 171 |
public void setVisible(boolean visible) { |
304 |
public void setVisible(boolean visible) { |
| 172 |
super.setVisible(visible); |
305 |
super.setVisible(visible); |
| 173 |
if (visible) { |
306 |
if (visible) { |
|
Lines 193-196
Link Here
|
| 193 |
public boolean isRunInBackgroundOn() { |
326 |
public boolean isRunInBackgroundOn() { |
| 194 |
return runInBackground; |
327 |
return runInBackground; |
| 195 |
} |
328 |
} |
|
|
329 |
|
| 330 |
public int getInputType() { |
| 331 |
return inputType; |
| 332 |
} |
| 333 |
|
| 334 |
public String getURLContents() { |
| 335 |
try { |
| 336 |
PsfUrlStore.getInstance().remember(urlString); |
| 337 |
String urlContent = Utilities.getURLContents(new URL(urlString), |
| 338 |
getContainer()); |
| 339 |
if (ProjectSetImporter.isValidProjectSetString(urlContent)) { |
| 340 |
return urlContent; |
| 341 |
} else { |
| 342 |
messageType = ERROR; |
| 343 |
setMessage( |
| 344 |
TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, |
| 345 |
messageType); |
| 346 |
setPageComplete(false); |
| 347 |
return null; |
| 348 |
} |
| 349 |
} catch (OperationCanceledException e) { // ignore |
| 350 |
} catch (InterruptedException e) { // ignore |
| 351 |
} catch (InvocationTargetException e) { |
| 352 |
messageType = ERROR; |
| 353 |
setMessage( |
| 354 |
TeamUIMessages.ImportProjectSetMainPage_The_given_URL_cannot_be_loaded, |
| 355 |
messageType); |
| 356 |
setPageComplete(false); |
| 357 |
} catch (MalformedURLException e) { |
| 358 |
// ignore as we tested it with modify listener on combo |
| 359 |
} |
| 360 |
return null; |
| 361 |
} |
| 196 |
} |
362 |
} |