|
Lines 15-20
Link Here
|
| 15 |
import java.lang.reflect.InvocationTargetException; |
15 |
import java.lang.reflect.InvocationTargetException; |
| 16 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
| 17 |
|
17 |
|
|
|
18 |
import org.eclipse.core.commands.ExecutionException; |
| 18 |
import org.eclipse.core.resources.IFolder; |
19 |
import org.eclipse.core.resources.IFolder; |
| 19 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.core.resources.IResource; |
| 20 |
import org.eclipse.core.resources.IResourceStatus; |
21 |
import org.eclipse.core.resources.IResourceStatus; |
|
Lines 29-37
Link Here
|
| 29 |
import org.eclipse.core.runtime.Path; |
30 |
import org.eclipse.core.runtime.Path; |
| 30 |
import org.eclipse.core.runtime.Preferences; |
31 |
import org.eclipse.core.runtime.Preferences; |
| 31 |
import org.eclipse.core.runtime.SubProgressMonitor; |
32 |
import org.eclipse.core.runtime.SubProgressMonitor; |
| 32 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
|
|
| 33 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 34 |
import org.eclipse.jface.dialogs.MessageDialog; |
33 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
|
34 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 35 |
import org.eclipse.jface.viewers.IStructuredSelection; |
35 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 36 |
import org.eclipse.jface.wizard.WizardPage; |
36 |
import org.eclipse.jface.wizard.WizardPage; |
| 37 |
import org.eclipse.osgi.util.NLS; |
37 |
import org.eclipse.osgi.util.NLS; |
|
Lines 47-53
Link Here
|
| 47 |
import org.eclipse.swt.widgets.Listener; |
47 |
import org.eclipse.swt.widgets.Listener; |
| 48 |
import org.eclipse.swt.widgets.Shell; |
48 |
import org.eclipse.swt.widgets.Shell; |
| 49 |
import org.eclipse.ui.PlatformUI; |
49 |
import org.eclipse.ui.PlatformUI; |
| 50 |
import org.eclipse.ui.actions.WorkspaceModifyOperation; |
50 |
import org.eclipse.ui.ide.undo.CreateFolderOperation; |
| 51 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
51 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
| 52 |
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; |
52 |
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; |
| 53 |
import org.eclipse.ui.internal.ide.IIDEHelpContextIds; |
53 |
import org.eclipse.ui.internal.ide.IIDEHelpContextIds; |
|
Lines 62-509
Link Here
|
| 62 |
* <p> |
62 |
* <p> |
| 63 |
* Subclasses may extend |
63 |
* Subclasses may extend |
| 64 |
* <ul> |
64 |
* <ul> |
| 65 |
* <li><code>handleEvent</code></li> |
65 |
* <li><code>handleEvent</code></li> |
| 66 |
* </ul> |
66 |
* </ul> |
| 67 |
* </p> |
67 |
* </p> |
| 68 |
*/ |
68 |
*/ |
| 69 |
public class WizardNewFolderMainPage extends WizardPage implements Listener { |
69 |
public class WizardNewFolderMainPage extends WizardPage implements Listener { |
| 70 |
private static final int SIZING_CONTAINER_GROUP_HEIGHT = 250; |
70 |
private static final int SIZING_CONTAINER_GROUP_HEIGHT = 250; |
| 71 |
|
71 |
|
| 72 |
private IStructuredSelection currentSelection; |
72 |
private IStructuredSelection currentSelection; |
| 73 |
|
73 |
|
| 74 |
private IFolder newFolder; |
74 |
private IFolder newFolder; |
| 75 |
|
75 |
|
| 76 |
// link target location |
76 |
// link target location |
| 77 |
private IPath linkTargetPath; |
77 |
private IPath linkTargetPath; |
| 78 |
|
78 |
|
| 79 |
// widgets |
79 |
// widgets |
| 80 |
private ResourceAndContainerGroup resourceGroup; |
80 |
private ResourceAndContainerGroup resourceGroup; |
| 81 |
|
81 |
|
| 82 |
private Button advancedButton; |
82 |
private Button advancedButton; |
| 83 |
|
83 |
|
| 84 |
private CreateLinkedResourceGroup linkedResourceGroup; |
84 |
private CreateLinkedResourceGroup linkedResourceGroup; |
| 85 |
|
85 |
|
| 86 |
private Composite linkedResourceParent; |
86 |
private Composite linkedResourceParent; |
| 87 |
|
87 |
|
| 88 |
private Composite linkedResourceComposite; |
88 |
private Composite linkedResourceComposite; |
| 89 |
|
89 |
|
| 90 |
/** |
90 |
/** |
| 91 |
* Height of the "advanced" linked resource group. Set when the |
91 |
* Height of the "advanced" linked resource group. Set when the advanced |
| 92 |
* advanced group is first made visible. |
92 |
* group is first made visible. |
| 93 |
*/ |
93 |
*/ |
| 94 |
private int linkedResourceGroupHeight = -1; |
94 |
private int linkedResourceGroupHeight = -1; |
| 95 |
|
95 |
|
| 96 |
/** |
96 |
/** |
| 97 |
* First time the advanced group is validated. |
97 |
* First time the advanced group is validated. |
| 98 |
*/ |
98 |
*/ |
| 99 |
private boolean firstLinkCheck = true; |
99 |
private boolean firstLinkCheck = true; |
| 100 |
|
100 |
|
| 101 |
/** |
101 |
/** |
| 102 |
* Creates a new folder creation wizard page. If the initial resource selection |
102 |
* Creates a new folder creation wizard page. If the initial resource |
| 103 |
* contains exactly one container resource then it will be used as the default |
103 |
* selection contains exactly one container resource then it will be used as |
| 104 |
* container resource. |
104 |
* the default container resource. |
| 105 |
* |
105 |
* |
| 106 |
* @param pageName the name of the page |
106 |
* @param pageName |
| 107 |
* @param selection the current resource selection |
107 |
* the name of the page |
| 108 |
*/ |
108 |
* @param selection |
| 109 |
public WizardNewFolderMainPage(String pageName, |
109 |
* the current resource selection |
| 110 |
IStructuredSelection selection) { |
110 |
*/ |
| 111 |
super("newFolderPage1");//$NON-NLS-1$ |
111 |
public WizardNewFolderMainPage(String pageName, |
| 112 |
setTitle(pageName); |
112 |
IStructuredSelection selection) { |
| 113 |
setDescription(IDEWorkbenchMessages.WizardNewFolderMainPage_description); |
113 |
super("newFolderPage1");//$NON-NLS-1$ |
| 114 |
this.currentSelection = selection; |
114 |
setTitle(pageName); |
| 115 |
} |
115 |
setDescription(IDEWorkbenchMessages.WizardNewFolderMainPage_description); |
| 116 |
|
116 |
this.currentSelection = selection; |
| 117 |
/** |
117 |
} |
| 118 |
* Creates the widget for advanced options. |
118 |
|
| 119 |
* |
119 |
/** |
| 120 |
* @param parent the parent composite |
120 |
* Creates the widget for advanced options. |
| 121 |
*/ |
121 |
* |
| 122 |
protected void createAdvancedControls(Composite parent) { |
122 |
* @param parent |
| 123 |
Preferences preferences = ResourcesPlugin.getPlugin() |
123 |
* the parent composite |
| 124 |
.getPluginPreferences(); |
124 |
*/ |
| 125 |
|
125 |
protected void createAdvancedControls(Composite parent) { |
| 126 |
if (preferences.getBoolean(ResourcesPlugin.PREF_DISABLE_LINKING) == false) { |
126 |
Preferences preferences = ResourcesPlugin.getPlugin() |
| 127 |
linkedResourceParent = new Composite(parent, SWT.NONE); |
127 |
.getPluginPreferences(); |
| 128 |
linkedResourceParent.setFont(parent.getFont()); |
128 |
|
| 129 |
linkedResourceParent.setLayoutData(new GridData( |
129 |
if (preferences.getBoolean(ResourcesPlugin.PREF_DISABLE_LINKING) == false) { |
| 130 |
GridData.FILL_HORIZONTAL)); |
130 |
linkedResourceParent = new Composite(parent, SWT.NONE); |
| 131 |
GridLayout layout = new GridLayout(); |
131 |
linkedResourceParent.setFont(parent.getFont()); |
| 132 |
layout.marginHeight = 0; |
132 |
linkedResourceParent.setLayoutData(new GridData( |
| 133 |
layout.marginWidth = 0; |
133 |
GridData.FILL_HORIZONTAL)); |
| 134 |
linkedResourceParent.setLayout(layout); |
134 |
GridLayout layout = new GridLayout(); |
| 135 |
|
135 |
layout.marginHeight = 0; |
| 136 |
advancedButton = new Button(linkedResourceParent, SWT.PUSH); |
136 |
layout.marginWidth = 0; |
| 137 |
advancedButton.setFont(linkedResourceParent.getFont()); |
137 |
linkedResourceParent.setLayout(layout); |
| 138 |
advancedButton.setText(IDEWorkbenchMessages.showAdvanced); |
138 |
|
| 139 |
GridData data = setButtonLayoutData(advancedButton); |
139 |
advancedButton = new Button(linkedResourceParent, SWT.PUSH); |
| 140 |
data.horizontalAlignment = GridData.BEGINNING; |
140 |
advancedButton.setFont(linkedResourceParent.getFont()); |
| 141 |
advancedButton.setLayoutData(data); |
141 |
advancedButton.setText(IDEWorkbenchMessages.showAdvanced); |
| 142 |
advancedButton.addSelectionListener(new SelectionAdapter() { |
142 |
GridData data = setButtonLayoutData(advancedButton); |
| 143 |
public void widgetSelected(SelectionEvent e) { |
143 |
data.horizontalAlignment = GridData.BEGINNING; |
| 144 |
handleAdvancedButtonSelect(); |
144 |
advancedButton.setLayoutData(data); |
| 145 |
} |
145 |
advancedButton.addSelectionListener(new SelectionAdapter() { |
| 146 |
}); |
146 |
public void widgetSelected(SelectionEvent e) { |
| 147 |
} |
147 |
handleAdvancedButtonSelect(); |
| 148 |
linkedResourceGroup = new CreateLinkedResourceGroup(IResource.FOLDER, |
148 |
} |
| 149 |
new Listener() { |
149 |
}); |
| 150 |
public void handleEvent(Event e) { |
150 |
} |
| 151 |
setPageComplete(validatePage()); |
151 |
linkedResourceGroup = new CreateLinkedResourceGroup(IResource.FOLDER, |
| 152 |
firstLinkCheck = false; |
152 |
new Listener() { |
| 153 |
} |
153 |
public void handleEvent(Event e) { |
| 154 |
}, |
154 |
setPageComplete(validatePage()); |
| 155 |
new CreateLinkedResourceGroup.IStringValue() { |
155 |
firstLinkCheck = false; |
| 156 |
public String getValue() { |
156 |
} |
| 157 |
return resourceGroup.getResource(); |
157 |
}, new CreateLinkedResourceGroup.IStringValue() { |
| 158 |
} |
158 |
public String getValue() { |
| 159 |
public void setValue(String string) { |
159 |
return resourceGroup.getResource(); |
| 160 |
resourceGroup.setResource(string); |
160 |
} |
| 161 |
} |
161 |
|
| 162 |
}); |
162 |
public void setValue(String string) { |
| 163 |
} |
163 |
resourceGroup.setResource(string); |
| 164 |
|
164 |
} |
| 165 |
/** (non-Javadoc) |
165 |
}); |
| 166 |
* Method declared on IDialogPage. |
166 |
} |
| 167 |
*/ |
167 |
|
| 168 |
public void createControl(Composite parent) { |
168 |
/** |
| 169 |
initializeDialogUnits(parent); |
169 |
* (non-Javadoc) Method declared on IDialogPage. |
| 170 |
// top level group |
170 |
*/ |
| 171 |
Composite composite = new Composite(parent, SWT.NONE); |
171 |
public void createControl(Composite parent) { |
| 172 |
composite.setFont(parent.getFont()); |
172 |
initializeDialogUnits(parent); |
| 173 |
composite.setLayout(new GridLayout()); |
173 |
// top level group |
| 174 |
composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL |
174 |
Composite composite = new Composite(parent, SWT.NONE); |
| 175 |
| GridData.HORIZONTAL_ALIGN_FILL)); |
175 |
composite.setFont(parent.getFont()); |
| 176 |
|
176 |
composite.setLayout(new GridLayout()); |
| 177 |
PlatformUI.getWorkbench().getHelpSystem() |
177 |
composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL |
| 178 |
.setHelp(composite, IIDEHelpContextIds.NEW_FOLDER_WIZARD_PAGE); |
178 |
| GridData.HORIZONTAL_ALIGN_FILL)); |
| 179 |
|
179 |
|
| 180 |
resourceGroup = new ResourceAndContainerGroup( |
180 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, |
| 181 |
composite, |
181 |
IIDEHelpContextIds.NEW_FOLDER_WIZARD_PAGE); |
| 182 |
this, |
182 |
|
| 183 |
IDEWorkbenchMessages.WizardNewFolderMainPage_folderName, IDEWorkbenchMessages.WizardNewFolderMainPage_folderLabel, false, SIZING_CONTAINER_GROUP_HEIGHT); |
183 |
resourceGroup = new ResourceAndContainerGroup(composite, this, |
| 184 |
resourceGroup.setAllowExistingResources(false); |
184 |
IDEWorkbenchMessages.WizardNewFolderMainPage_folderName, |
| 185 |
createAdvancedControls(composite); |
185 |
IDEWorkbenchMessages.WizardNewFolderMainPage_folderLabel, |
| 186 |
initializePage(); |
186 |
false, SIZING_CONTAINER_GROUP_HEIGHT); |
| 187 |
validatePage(); |
187 |
resourceGroup.setAllowExistingResources(false); |
| 188 |
// Show description on opening |
188 |
createAdvancedControls(composite); |
| 189 |
setErrorMessage(null); |
189 |
initializePage(); |
| 190 |
setMessage(null); |
190 |
validatePage(); |
| 191 |
setControl(composite); |
191 |
// Show description on opening |
| 192 |
} |
192 |
setErrorMessage(null); |
| 193 |
|
193 |
setMessage(null); |
| 194 |
/** |
194 |
setControl(composite); |
| 195 |
* Creates a folder resource given the folder handle. |
195 |
} |
| 196 |
* |
196 |
|
| 197 |
* @param folderHandle the folder handle to create a folder resource for |
197 |
/** |
| 198 |
* @param monitor the progress monitor to show visual progress with |
198 |
* Creates a folder resource given the folder handle. |
| 199 |
* @exception CoreException if the operation fails |
199 |
* |
| 200 |
* @exception OperationCanceledException if the operation is canceled |
200 |
* @param folderHandle |
| 201 |
*/ |
201 |
* the folder handle to create a folder resource for |
| 202 |
protected void createFolder(IFolder folderHandle, IProgressMonitor monitor) |
202 |
* @param monitor |
| 203 |
throws CoreException { |
203 |
* the progress monitor to show visual progress with |
| 204 |
try { |
204 |
* @exception CoreException |
| 205 |
// Create the folder resource in the workspace |
205 |
* if the operation fails |
| 206 |
// Update: Recursive to create any folders which do not exist already |
206 |
* @exception OperationCanceledException |
| 207 |
if (!folderHandle.exists()) { |
207 |
* if the operation is canceled |
| 208 |
if (linkTargetPath != null) { |
208 |
* |
|
|
209 |
* @deprecated As of 3.3, use {@link #createNewFolder()} which uses the |
| 210 |
* undoable operation support. |
| 211 |
*/ |
| 212 |
protected void createFolder(IFolder folderHandle, IProgressMonitor monitor) |
| 213 |
throws CoreException { |
| 214 |
try { |
| 215 |
// Create the folder resource in the workspace |
| 216 |
// Update: Recursive to create any folders which do not exist |
| 217 |
// already |
| 218 |
if (!folderHandle.exists()) { |
| 219 |
if (linkTargetPath != null) { |
| 209 |
folderHandle.createLink(linkTargetPath, |
220 |
folderHandle.createLink(linkTargetPath, |
| 210 |
IResource.ALLOW_MISSING_LOCAL, monitor); |
221 |
IResource.ALLOW_MISSING_LOCAL, monitor); |
| 211 |
} else { |
222 |
} else { |
| 212 |
IPath path = folderHandle.getFullPath(); |
223 |
IPath path = folderHandle.getFullPath(); |
| 213 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
224 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace() |
| 214 |
int numSegments= path.segmentCount(); |
225 |
.getRoot(); |
| 215 |
if (numSegments > 2 && !root.getFolder(path.removeLastSegments(1)).exists()) { |
226 |
int numSegments = path.segmentCount(); |
| 216 |
// If the direct parent of the path doesn't exist, try to create the |
227 |
if (numSegments > 2 |
| 217 |
// necessary directories. |
228 |
&& !root.getFolder(path.removeLastSegments(1)) |
| 218 |
for (int i= numSegments - 2; i > 0; i--) { |
229 |
.exists()) { |
| 219 |
IFolder folder = root.getFolder(path.removeLastSegments(i)); |
230 |
// If the direct parent of the path doesn't exist, try |
| 220 |
if (!folder.exists()) { |
231 |
// to create the |
| 221 |
folder.create(false, true, monitor); |
232 |
// necessary directories. |
| 222 |
} |
233 |
for (int i = numSegments - 2; i > 0; i--) { |
| 223 |
} |
234 |
IFolder folder = root.getFolder(path |
| 224 |
} |
235 |
.removeLastSegments(i)); |
| 225 |
folderHandle.create(false, true, monitor); |
236 |
if (!folder.exists()) { |
| 226 |
} |
237 |
folder.create(false, true, monitor); |
| 227 |
} |
238 |
} |
| 228 |
} catch (CoreException e) { |
239 |
} |
| 229 |
// If the folder already existed locally, just refresh to get contents |
240 |
} |
| 230 |
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) { |
241 |
folderHandle.create(false, true, monitor); |
|
|
242 |
} |
| 243 |
} |
| 244 |
} catch (CoreException e) { |
| 245 |
// If the folder already existed locally, just refresh to get |
| 246 |
// contents |
| 247 |
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) { |
| 231 |
folderHandle.refreshLocal(IResource.DEPTH_INFINITE, |
248 |
folderHandle.refreshLocal(IResource.DEPTH_INFINITE, |
| 232 |
new SubProgressMonitor(monitor, 500)); |
249 |
new SubProgressMonitor(monitor, 500)); |
| 233 |
} else { |
250 |
} else { |
| 234 |
throw e; |
251 |
throw e; |
| 235 |
} |
252 |
} |
| 236 |
} |
253 |
} |
| 237 |
|
254 |
|
| 238 |
if (monitor.isCanceled()) { |
255 |
if (monitor.isCanceled()) { |
| 239 |
throw new OperationCanceledException(); |
256 |
throw new OperationCanceledException(); |
| 240 |
} |
257 |
} |
| 241 |
} |
258 |
} |
| 242 |
|
259 |
|
| 243 |
/** |
260 |
/** |
| 244 |
* Creates a folder resource handle for the folder with the given workspace path. |
261 |
* Creates a folder resource handle for the folder with the given workspace |
| 245 |
* This method does not create the folder resource; this is the responsibility |
262 |
* path. This method does not create the folder resource; this is the |
| 246 |
* of <code>createFolder</code>. |
263 |
* responsibility of <code>createFolder</code>. |
| 247 |
* |
264 |
* |
| 248 |
* @param folderPath the path of the folder resource to create a handle for |
265 |
* @param folderPath |
| 249 |
* @return the new folder resource handle |
266 |
* the path of the folder resource to create a handle for |
| 250 |
* @see #createFolder |
267 |
* @return the new folder resource handle |
| 251 |
*/ |
268 |
* @see #createFolder |
| 252 |
protected IFolder createFolderHandle(IPath folderPath) { |
269 |
*/ |
| 253 |
return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder( |
270 |
protected IFolder createFolderHandle(IPath folderPath) { |
| 254 |
folderPath); |
271 |
return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder( |
| 255 |
} |
272 |
folderPath); |
| 256 |
|
273 |
} |
| 257 |
/** |
274 |
|
| 258 |
* Creates the link target path if a link target has been specified. |
275 |
/** |
| 259 |
*/ |
276 |
* Creates the link target path if a link target has been specified. |
| 260 |
protected void createLinkTarget() { |
277 |
*/ |
| 261 |
String linkTarget = linkedResourceGroup.getLinkTarget(); |
278 |
protected void createLinkTarget() { |
| 262 |
if (linkTarget != null) { |
279 |
String linkTarget = linkedResourceGroup.getLinkTarget(); |
| 263 |
linkTargetPath = new Path(linkTarget); |
280 |
if (linkTarget != null) { |
| 264 |
} else { |
281 |
linkTargetPath = new Path(linkTarget); |
| 265 |
linkTargetPath = null; |
282 |
} else { |
| 266 |
} |
283 |
linkTargetPath = null; |
| 267 |
} |
284 |
} |
| 268 |
|
285 |
} |
| 269 |
/** |
286 |
|
| 270 |
* Creates a new folder resource in the selected container and with the selected |
287 |
/** |
| 271 |
* name. Creates any missing resource containers along the path; does nothing if |
288 |
* Creates a new folder resource in the selected container and with the |
| 272 |
* the container resources already exist. |
289 |
* selected name. Creates any missing resource containers along the path; |
| 273 |
* <p> |
290 |
* does nothing if the container resources already exist. |
| 274 |
* In normal usage, this method is invoked after the user has pressed Finish on |
291 |
* <p> |
| 275 |
* the wizard; the enablement of the Finish button implies that all controls on |
292 |
* In normal usage, this method is invoked after the user has pressed Finish |
| 276 |
* this page currently contain valid values. |
293 |
* on the wizard; the enablement of the Finish button implies that all |
| 277 |
* </p> |
294 |
* controls on this page currently contain valid values. |
| 278 |
* <p> |
295 |
* </p> |
| 279 |
* Note that this page caches the new folder once it has been successfully |
296 |
* <p> |
| 280 |
* created; subsequent invocations of this method will answer the same |
297 |
* Note that this page caches the new folder once it has been successfully |
| 281 |
* folder resource without attempting to create it again. |
298 |
* created; subsequent invocations of this method will answer the same |
| 282 |
* </p> |
299 |
* folder resource without attempting to create it again. |
| 283 |
* <p> |
300 |
* </p> |
| 284 |
* This method should be called within a workspace modify operation since |
301 |
* <p> |
| 285 |
* it creates resources. |
302 |
* This method should be called within a workspace modify operation since it |
| 286 |
* </p> |
303 |
* creates resources. |
| 287 |
* |
304 |
* </p> |
| 288 |
* @return the created folder resource, or <code>null</code> if the folder |
305 |
* |
| 289 |
* was not created |
306 |
* @return the created folder resource, or <code>null</code> if the folder |
| 290 |
*/ |
307 |
* was not created |
| 291 |
public IFolder createNewFolder() { |
308 |
*/ |
| 292 |
if (newFolder != null) { |
309 |
public IFolder createNewFolder() { |
|
|
310 |
if (newFolder != null) { |
| 293 |
return newFolder; |
311 |
return newFolder; |
| 294 |
} |
312 |
} |
| 295 |
|
313 |
|
| 296 |
// create the new folder and cache it if successful |
314 |
// create the new folder and cache it if successful |
| 297 |
final IPath containerPath = resourceGroup.getContainerFullPath(); |
315 |
final IPath containerPath = resourceGroup.getContainerFullPath(); |
| 298 |
IPath newFolderPath = containerPath.append(resourceGroup.getResource()); |
316 |
IPath newFolderPath = containerPath.append(resourceGroup.getResource()); |
| 299 |
final IFolder newFolderHandle = createFolderHandle(newFolderPath); |
317 |
final IFolder newFolderHandle = createFolderHandle(newFolderPath); |
| 300 |
|
318 |
|
| 301 |
createLinkTarget(); |
319 |
createLinkTarget(); |
| 302 |
WorkspaceModifyOperation op = new WorkspaceModifyOperation(createRule(newFolderHandle)) { |
320 |
IRunnableWithProgress op = new IRunnableWithProgress() { |
| 303 |
public void execute(IProgressMonitor monitor) throws CoreException { |
321 |
public void run(IProgressMonitor monitor) { |
| 304 |
try { |
322 |
CreateFolderOperation op = new CreateFolderOperation( |
| 305 |
monitor.beginTask(IDEWorkbenchMessages.WizardNewFolderCreationPage_progress, 2000); |
323 |
newFolderHandle, linkTargetPath, |
| 306 |
ContainerGenerator generator = new ContainerGenerator( |
324 |
IDEWorkbenchMessages.WizardNewFolderCreationPage_title); |
| 307 |
containerPath); |
325 |
try { |
| 308 |
generator.generateContainer(new SubProgressMonitor(monitor, |
326 |
PlatformUI.getWorkbench().getOperationSupport() |
| 309 |
1000)); |
327 |
.getOperationHistory().execute(op, monitor, |
| 310 |
createFolder(newFolderHandle, new SubProgressMonitor( |
328 |
new IAdaptable() { |
| 311 |
monitor, 1000)); |
329 |
public Object getAdapter(Class clazz) { |
| 312 |
} finally { |
330 |
if (clazz == Shell.class) { |
| 313 |
monitor.done(); |
331 |
return getContainer() |
| 314 |
} |
332 |
.getShell(); |
| 315 |
} |
333 |
} |
| 316 |
}; |
334 |
return null; |
| 317 |
|
335 |
} |
| 318 |
try { |
336 |
}); |
| 319 |
getContainer().run(true, true, op); |
337 |
} catch (ExecutionException e) { |
| 320 |
} catch (InterruptedException e) { |
338 |
IDEWorkbenchPlugin.log(e.getMessage(), e); |
| 321 |
return null; |
339 |
} |
| 322 |
} catch (InvocationTargetException e) { |
340 |
} |
| 323 |
if (e.getTargetException() instanceof CoreException) { |
341 |
}; |
| 324 |
ErrorDialog |
342 |
|
| 325 |
.openError( |
343 |
try { |
| 326 |
getContainer().getShell(), // Was Utilities.getFocusShell() |
344 |
getContainer().run(true, true, op); |
| 327 |
IDEWorkbenchMessages.WizardNewFolderCreationPage_errorTitle, |
345 |
} catch (InterruptedException e) { |
| 328 |
null, // no special message |
346 |
return null; |
| 329 |
((CoreException) e.getTargetException()) |
347 |
} catch (InvocationTargetException e) { |
| 330 |
.getStatus()); |
348 |
// ExecutionExceptions are handled above, but unexpected runtime |
| 331 |
} else { |
349 |
// exceptions and errors may still occur. |
| 332 |
// CoreExceptions are handled above, but unexpected runtime exceptions and errors may still occur. |
350 |
IDEWorkbenchPlugin.log(getClass(), |
| 333 |
|
351 |
"createNewFolder()", e.getTargetException()); //$NON-NLS-1$ |
| 334 |
IDEWorkbenchPlugin.log(getClass(), |
352 |
MessageDialog |
| 335 |
"createNewFolder()", e.getTargetException()); //$NON-NLS-1$ |
353 |
.openError( |
| 336 |
MessageDialog |
354 |
getContainer().getShell(), |
| 337 |
.openError( |
355 |
IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle, NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError, e.getTargetException().getMessage())); |
| 338 |
getContainer().getShell(), |
356 |
return null; |
| 339 |
IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle, NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError, e.getTargetException().getMessage())); |
357 |
} |
| 340 |
} |
358 |
|
| 341 |
return null; // ie.- one of the steps resulted in a core exception |
359 |
newFolder = newFolderHandle; |
| 342 |
} |
360 |
|
| 343 |
|
361 |
return newFolder; |
| 344 |
newFolder = newFolderHandle; |
362 |
} |
| 345 |
|
363 |
|
| 346 |
return newFolder; |
364 |
/** |
| 347 |
} |
365 |
* Shows/hides the advanced option widgets. |
| 348 |
|
366 |
*/ |
| 349 |
/** |
367 |
protected void handleAdvancedButtonSelect() { |
| 350 |
* Returns the scheduling rule to use when creating the resource at |
368 |
Shell shell = getShell(); |
| 351 |
* the given container path. The rule should be the creation rule for |
369 |
Point shellSize = shell.getSize(); |
| 352 |
* the top-most non-existing parent. |
370 |
Composite composite = (Composite) getControl(); |
| 353 |
* @param resource The resource being created |
371 |
|
| 354 |
* @return The scheduling rule for creating the given resource |
372 |
if (linkedResourceComposite != null) { |
| 355 |
* @since 3.1 |
373 |
linkedResourceComposite.dispose(); |
| 356 |
*/ |
374 |
linkedResourceComposite = null; |
| 357 |
private ISchedulingRule createRule(IResource resource) { |
375 |
composite.layout(); |
| 358 |
IResource parent = resource.getParent(); |
376 |
shell.setSize(shellSize.x, shellSize.y - linkedResourceGroupHeight); |
| 359 |
while (parent != null) { |
377 |
advancedButton.setText(IDEWorkbenchMessages.showAdvanced); |
| 360 |
if (parent.exists()) { |
378 |
} else { |
| 361 |
return resource.getWorkspace().getRuleFactory().createRule(resource); |
379 |
linkedResourceComposite = linkedResourceGroup |
|
|
380 |
.createContents(linkedResourceParent); |
| 381 |
if (linkedResourceGroupHeight == -1) { |
| 382 |
Point groupSize = linkedResourceComposite.computeSize( |
| 383 |
SWT.DEFAULT, SWT.DEFAULT, true); |
| 384 |
linkedResourceGroupHeight = groupSize.y; |
| 385 |
} |
| 386 |
shell.setSize(shellSize.x, shellSize.y + linkedResourceGroupHeight); |
| 387 |
composite.layout(); |
| 388 |
advancedButton.setText(IDEWorkbenchMessages.hideAdvanced); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* The <code>WizardNewFolderCreationPage</code> implementation of this |
| 394 |
* <code>Listener</code> method handles all events and enablements for |
| 395 |
* controls on this page. Subclasses may extend. |
| 396 |
*/ |
| 397 |
public void handleEvent(Event ev) { |
| 398 |
setPageComplete(validatePage()); |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 402 |
* Initializes this page's controls. |
| 403 |
*/ |
| 404 |
protected void initializePage() { |
| 405 |
Iterator it = currentSelection.iterator(); |
| 406 |
if (it.hasNext()) { |
| 407 |
Object next = it.next(); |
| 408 |
IResource selectedResource = null; |
| 409 |
if (next instanceof IResource) { |
| 410 |
selectedResource = (IResource) next; |
| 411 |
} else if (next instanceof IAdaptable) { |
| 412 |
selectedResource = (IResource) ((IAdaptable) next) |
| 413 |
.getAdapter(IResource.class); |
| 362 |
} |
414 |
} |
| 363 |
resource = parent; |
415 |
if (selectedResource != null) { |
| 364 |
parent = parent.getParent(); |
416 |
if (selectedResource.getType() == IResource.FILE) { |
| 365 |
} |
|
|
| 366 |
return resource.getWorkspace().getRoot(); |
| 367 |
} |
| 368 |
|
| 369 |
/** |
| 370 |
* Shows/hides the advanced option widgets. |
| 371 |
*/ |
| 372 |
protected void handleAdvancedButtonSelect() { |
| 373 |
Shell shell = getShell(); |
| 374 |
Point shellSize = shell.getSize(); |
| 375 |
Composite composite = (Composite) getControl(); |
| 376 |
|
| 377 |
if (linkedResourceComposite != null) { |
| 378 |
linkedResourceComposite.dispose(); |
| 379 |
linkedResourceComposite = null; |
| 380 |
composite.layout(); |
| 381 |
shell.setSize(shellSize.x, shellSize.y - linkedResourceGroupHeight); |
| 382 |
advancedButton.setText(IDEWorkbenchMessages.showAdvanced); |
| 383 |
} else { |
| 384 |
linkedResourceComposite = linkedResourceGroup |
| 385 |
.createContents(linkedResourceParent); |
| 386 |
if (linkedResourceGroupHeight == -1) { |
| 387 |
Point groupSize = linkedResourceComposite.computeSize( |
| 388 |
SWT.DEFAULT, SWT.DEFAULT, true); |
| 389 |
linkedResourceGroupHeight = groupSize.y; |
| 390 |
} |
| 391 |
shell.setSize(shellSize.x, shellSize.y + linkedResourceGroupHeight); |
| 392 |
composite.layout(); |
| 393 |
advancedButton.setText(IDEWorkbenchMessages.hideAdvanced); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* The <code>WizardNewFolderCreationPage</code> implementation of this |
| 399 |
* <code>Listener</code> method handles all events and enablements for controls |
| 400 |
* on this page. Subclasses may extend. |
| 401 |
*/ |
| 402 |
public void handleEvent(Event ev) { |
| 403 |
setPageComplete(validatePage()); |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Initializes this page's controls. |
| 408 |
*/ |
| 409 |
protected void initializePage() { |
| 410 |
Iterator it = currentSelection.iterator(); |
| 411 |
if (it.hasNext()) { |
| 412 |
Object next = it.next(); |
| 413 |
IResource selectedResource = null; |
| 414 |
if (next instanceof IResource) { |
| 415 |
selectedResource = (IResource) next; |
| 416 |
} else if (next instanceof IAdaptable) { |
| 417 |
selectedResource = (IResource) ((IAdaptable) next) |
| 418 |
.getAdapter(IResource.class); |
| 419 |
} |
| 420 |
if (selectedResource != null) { |
| 421 |
if (selectedResource.getType() == IResource.FILE) { |
| 422 |
selectedResource = selectedResource.getParent(); |
417 |
selectedResource = selectedResource.getParent(); |
| 423 |
} |
418 |
} |
| 424 |
if (selectedResource.isAccessible()) { |
419 |
if (selectedResource.isAccessible()) { |
| 425 |
resourceGroup.setContainerFullPath(selectedResource |
420 |
resourceGroup.setContainerFullPath(selectedResource |
| 426 |
.getFullPath()); |
421 |
.getFullPath()); |
| 427 |
} |
422 |
} |
| 428 |
} |
423 |
} |
| 429 |
} |
424 |
} |
| 430 |
|
425 |
|
| 431 |
setPageComplete(false); |
426 |
setPageComplete(false); |
| 432 |
} |
427 |
} |
| 433 |
|
428 |
|
| 434 |
/* |
429 |
/* |
| 435 |
* @see DialogPage.setVisible(boolean) |
430 |
* @see DialogPage.setVisible(boolean) |
| 436 |
*/ |
431 |
*/ |
| 437 |
public void setVisible(boolean visible) { |
432 |
public void setVisible(boolean visible) { |
| 438 |
super.setVisible(visible); |
433 |
super.setVisible(visible); |
| 439 |
if (visible) { |
434 |
if (visible) { |
| 440 |
resourceGroup.setFocus(); |
435 |
resourceGroup.setFocus(); |
| 441 |
} |
436 |
} |
| 442 |
} |
437 |
} |
| 443 |
|
438 |
|
| 444 |
/** |
439 |
/** |
| 445 |
* Checks whether the linked resource target is valid. |
440 |
* Checks whether the linked resource target is valid. Sets the error |
| 446 |
* Sets the error message accordingly and returns the status. |
441 |
* message accordingly and returns the status. |
| 447 |
* |
442 |
* |
| 448 |
* @return IStatus validation result from the CreateLinkedResourceGroup |
443 |
* @return IStatus validation result from the CreateLinkedResourceGroup |
| 449 |
*/ |
444 |
*/ |
| 450 |
protected IStatus validateLinkedResource() { |
445 |
protected IStatus validateLinkedResource() { |
| 451 |
IPath containerPath = resourceGroup.getContainerFullPath(); |
446 |
IPath containerPath = resourceGroup.getContainerFullPath(); |
| 452 |
IPath newFolderPath = containerPath.append(resourceGroup.getResource()); |
447 |
IPath newFolderPath = containerPath.append(resourceGroup.getResource()); |
| 453 |
IFolder newFolderHandle = createFolderHandle(newFolderPath); |
448 |
IFolder newFolderHandle = createFolderHandle(newFolderPath); |
| 454 |
IStatus status = linkedResourceGroup |
449 |
IStatus status = linkedResourceGroup |
| 455 |
.validateLinkLocation(newFolderHandle); |
450 |
.validateLinkLocation(newFolderHandle); |
| 456 |
|
451 |
|
| 457 |
if (status.getSeverity() == IStatus.ERROR) { |
452 |
if (status.getSeverity() == IStatus.ERROR) { |
| 458 |
if (firstLinkCheck) { |
453 |
if (firstLinkCheck) { |
| 459 |
setMessage(status.getMessage()); |
454 |
setMessage(status.getMessage()); |
| 460 |
} else { |
455 |
} else { |
| 461 |
setErrorMessage(status.getMessage()); |
456 |
setErrorMessage(status.getMessage()); |
| 462 |
} |
457 |
} |
| 463 |
} else if (status.getSeverity() == IStatus.WARNING) { |
458 |
} else if (status.getSeverity() == IStatus.WARNING) { |
| 464 |
setMessage(status.getMessage(), WARNING); |
459 |
setMessage(status.getMessage(), WARNING); |
| 465 |
setErrorMessage(null); |
460 |
setErrorMessage(null); |
| 466 |
} |
461 |
} |
| 467 |
return status; |
462 |
return status; |
| 468 |
} |
463 |
} |
| 469 |
|
464 |
|
| 470 |
/** |
465 |
/** |
| 471 |
* Returns whether this page's controls currently all contain valid |
466 |
* Returns whether this page's controls currently all contain valid values. |
| 472 |
* values. |
467 |
* |
| 473 |
* |
468 |
* @return <code>true</code> if all controls are valid, and |
| 474 |
* @return <code>true</code> if all controls are valid, and |
469 |
* <code>false</code> if at least one is invalid |
| 475 |
* <code>false</code> if at least one is invalid |
470 |
*/ |
| 476 |
*/ |
471 |
protected boolean validatePage() { |
| 477 |
protected boolean validatePage() { |
472 |
boolean valid = true; |
| 478 |
boolean valid = true; |
473 |
|
| 479 |
|
474 |
if (!resourceGroup.areAllValuesValid()) { |
| 480 |
if (!resourceGroup.areAllValuesValid()) { |
475 |
// if blank name then fail silently |
| 481 |
// if blank name then fail silently |
476 |
if (resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY |
| 482 |
if (resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY |
477 |
|| resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY) { |
| 483 |
|| resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY) { |
478 |
setMessage(resourceGroup.getProblemMessage()); |
| 484 |
setMessage(resourceGroup.getProblemMessage()); |
479 |
setErrorMessage(null); |
| 485 |
setErrorMessage(null); |
480 |
} else { |
| 486 |
} else { |
481 |
setErrorMessage(resourceGroup.getProblemMessage()); |
| 487 |
setErrorMessage(resourceGroup.getProblemMessage()); |
482 |
} |
| 488 |
} |
483 |
valid = false; |
| 489 |
valid = false; |
484 |
} |
| 490 |
} |
485 |
|
| 491 |
|
486 |
IStatus linkedResourceStatus = null; |
| 492 |
IStatus linkedResourceStatus = null; |
487 |
if (valid) { |
| 493 |
if (valid) { |
488 |
linkedResourceStatus = validateLinkedResource(); |
| 494 |
linkedResourceStatus = validateLinkedResource(); |
489 |
if (linkedResourceStatus.getSeverity() == IStatus.ERROR) { |
| 495 |
if (linkedResourceStatus.getSeverity() == IStatus.ERROR) { |
|
|
| 496 |
valid = false; |
490 |
valid = false; |
| 497 |
} |
491 |
} |
| 498 |
} |
492 |
} |
| 499 |
// validateLinkedResource sets messages itself |
493 |
// validateLinkedResource sets messages itself |
| 500 |
if (valid |
494 |
if (valid |
| 501 |
&& (linkedResourceStatus == null || linkedResourceStatus.isOK())) { |
495 |
&& (linkedResourceStatus == null || linkedResourceStatus.isOK())) { |
| 502 |
setMessage(null); |
496 |
setMessage(null); |
| 503 |
setErrorMessage(null); |
497 |
setErrorMessage(null); |
| 504 |
} |
498 |
} |
| 505 |
return valid; |
499 |
return valid; |
| 506 |
} |
500 |
} |
| 507 |
|
501 |
|
| 508 |
} |
502 |
} |
| 509 |
|
|
|