Search in sources :

Example 1 with MoveResourcesOperation

use of org.eclipse.ui.ide.undo.MoveResourcesOperation in project translationstudio8 by heartsome.

the class RenameResourceAndCloseEditorAction method createOperation.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.actions.WorkspaceAction#createOperation(org.eclipse.core.runtime.IStatus[])
	 * 
	 * Overridden to create and execute an undoable operation that performs the
	 * rename.
	 * @since 3.3
	 */
protected IRunnableWithProgress createOperation(final IStatus[] errorStatus) {
    return new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            IResource[] resources = (IResource[]) getActionResources().toArray(new IResource[getActionResources().size()]);
            // 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);
                        }
                    }
                }
            }
        }
    };
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) MoveResourcesOperation(org.eclipse.ui.ide.undo.MoveResourcesOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 MoveResourcesOperation (org.eclipse.ui.ide.undo.MoveResourcesOperation)1