/** * Creates a new folder resource in the selected container and with the * selected name. Creates any missing resource containers along the path; * does nothing if the container resources already exist. * <p> * In normal usage, this method is invoked after the user has pressed Finish * on the wizard; the enablement of the Finish button implies that all * controls on this page currently contain valid values. * </p> * <p> * Note that this page caches the new folder once it has been successfully * created; subsequent invocations of this method will answer the same * folder resource without attempting to create it again. * </p> * <p> * This method should be called within a workspace modify operation since it * creates resources. * </p> * * @return the created folder resource, or <code>null</code> if the folder * was not created */ public IFolder createNewFolder(String containerName, String folderName, IProgressMonitor monitor) { // create the new folder and cache it if successful final IPath containerPath = new Path(containerName); IPath newFolderPath = containerPath.append(folderName); final IFolder newFolderHandle = createFolderHandle(newFolderPath); AbstractOperation op; op = new CreateFolderOperation(newFolderHandle, null, false, null, "New Folder"); try { op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); } catch (final ExecutionException e) { getContainer().getShell().getDisplay().syncExec( new Runnable() { public void run() { if (e.getCause() instanceof CoreException) { ErrorDialog.openError(getContainer().getShell(), "Creation Problems", null, ((CoreException) e.getCause()).getStatus()); } else { MessageDialog.openError(getContainer().getShell(), "Creation problems", NLS.bind("Eclipse Internal error: {0}", e.getCause().getMessage())); } } }); } return newFolderHandle; }
@Override protected IRunnableWithProgress createOperation(final IStatus[] errorStatus) { return monitor -> { final IResource[] resources = getActionResources().toArray(new IResource[getActionResources().size()]); // Rename is only valid for a single resource. This has already // been validated. if (resources.length == 1) { // check for overwrite final IWorkspaceRoot workspaceRoot = resources[0].getWorkspace().getRoot(); final IResource newResource = workspaceRoot.findMember(newPath); boolean go = true; if (newResource != null) { go = checkOverwrite(WorkbenchHelper.getShell(), newResource); } if (go) { final MoveResourcesOperation op = new MoveResourcesOperation(resources[0], newPath, IDEWorkbenchMessages.RenameResourceAction_operationTitle); op.setModelProviderIds(getModelProviderIds()); try { PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(WorkbenchHelper.getShell())); } catch (final ExecutionException e) { if (e.getCause() instanceof CoreException) { errorStatus[0] = ((CoreException) e.getCause()).getStatus(); } else { errorStatus[0] = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, getProblemsMessage(), e); } } } } }; }
protected IRunnableWithProgress createOperation(final IStatus[] errorStatus) { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { IResource[] resources = (IResource[]) getActionResources() .toArray(new IResource[getActionResources().size()]); // Rename is only valid for a single resource. This has already // been validated. if (resources.length == 1) { // check for overwrite IWorkspaceRoot workspaceRoot = resources[0].getWorkspace() .getRoot(); IResource newResource = workspaceRoot.findMember(newPath); boolean go = true; if (newResource != null) { go = checkOverwrite(shellProvider.getShell(), newResource); } if (go) { MoveResourcesOperation op = new MoveResourcesOperation( resources[0], newPath, IDEWorkbenchMessages.RenameResourceAction_operationTitle); op.setModelProviderIds(getModelProviderIds()); try { PlatformUI .getWorkbench() .getOperationSupport() .getOperationHistory() .execute( op, monitor, WorkspaceUndoUtil .getUIInfoAdapter(shellProvider.getShell())); } catch (ExecutionException e) { if (e.getCause() instanceof CoreException) { errorStatus[0] = ((CoreException) e.getCause()) .getStatus(); } else { errorStatus[0] = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, getProblemsMessage(), e); } } } } } }; }