use of org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor in project che by eclipse.
the class MoveResourcesRefactoringContribution method retrieveArgumentMap.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.RefactoringContribution#retrieveArgumentMap(org.eclipse.ltk.core.refactoring.RefactoringDescriptor)
*/
public Map retrieveArgumentMap(final RefactoringDescriptor descriptor) {
HashMap map = new HashMap();
if (descriptor instanceof MoveResourcesDescriptor) {
MoveResourcesDescriptor moveDescriptor = (MoveResourcesDescriptor) descriptor;
IPath[] paths = moveDescriptor.getResourcePathsToMove();
String project = moveDescriptor.getProject();
IPath destinationPath = moveDescriptor.getDestinationPath();
map.put(ATTRIBUTE_NUMBER_OF_RESOURCES, String.valueOf(paths.length));
for (int i = 0; i < paths.length; i++) {
map.put(ATTRIBUTE_ELEMENT + (i + 1), ResourceProcessors.resourcePathToHandle(project, paths[i]));
}
map.put(ATTRIBUTE_DESTINATION, ResourceProcessors.resourcePathToHandle(project, destinationPath));
//$NON-NLS-1$//$NON-NLS-2$
map.put(ATTRIBUTE_UPDATE_REFERENCES, moveDescriptor.isUpdateReferences() ? "true" : "false");
return map;
}
return null;
}
use of org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor in project che by eclipse.
the class MoveResourcesProcessor method createDescriptor.
protected MoveResourcesDescriptor createDescriptor() {
MoveResourcesDescriptor descriptor = new MoveResourcesDescriptor();
descriptor.setProject(fDestination.getProject().getName());
descriptor.setDescription(getMoveDescription());
if (fResourcesToMove.length <= 1) {
descriptor.setComment(descriptor.getDescription());
} else {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < fResourcesToMove.length; i++) {
if (i > 0)
//$NON-NLS-1$
buf.append(", ");
buf.append(fResourcesToMove[i].getName());
}
descriptor.setComment(Messages.format(RefactoringCoreMessages.MoveResourceProcessor_comment, new String[] { buf.toString(), BasicElementLabels.getResourceName(fDestination) }));
}
descriptor.setFlags(RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.BREAKING_CHANGE);
descriptor.setDestination(fDestination);
descriptor.setUpdateReferences(isUpdateReferences());
descriptor.setResourcesToMove(fResourcesToMove);
return descriptor;
}
use of org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor in project xtext-eclipse by eclipse.
the class ResourceMoveTest method performMove.
protected void performMove(IContainer theDestination, IResource... theResources) throws Exception {
MoveResourcesDescriptor moveResourcesDescriptor = new MoveResourcesDescriptor();
moveResourcesDescriptor.setResourcePathsToMove(Lists.transform(Arrays.asList(theResources), IResource::getFullPath).toArray(new IPath[0]));
moveResourcesDescriptor.setDestinationPath(theDestination.getFullPath());
performRefactoring(moveResourcesDescriptor);
}
use of org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor in project che by eclipse.
the class MoveResourcesRefactoringContribution method createDescriptor.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.RefactoringContribution#createDescriptor(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map, int)
*/
public RefactoringDescriptor createDescriptor(String id, String project, String description, String comment, Map arguments, int flags) {
try {
int numResources = Integer.parseInt((String) arguments.get(ATTRIBUTE_NUMBER_OF_RESOURCES));
if (numResources < 0 || numResources > 100000) {
//$NON-NLS-1$
throw new IllegalArgumentException("Can not restore MoveResourceDescriptor from map, number of moved elements invalid");
}
IPath[] resourcePaths = new IPath[numResources];
for (int i = 0; i < numResources; i++) {
String resource = (String) arguments.get(ATTRIBUTE_ELEMENT + String.valueOf(i + 1));
if (resource == null) {
//$NON-NLS-1$
throw new IllegalArgumentException("Can not restore MoveResourceDescriptor from map, resource missing");
}
resourcePaths[i] = ResourceProcessors.handleToResourcePath(project, resource);
}
String destination = (String) arguments.get(ATTRIBUTE_DESTINATION);
if (destination == null) {
//$NON-NLS-1$
throw new IllegalArgumentException("Can not restore MoveResourceDescriptor from map, destination missing");
}
IPath destPath = ResourceProcessors.handleToResourcePath(project, destination);
//$NON-NLS-1$
boolean updateReferences = "true".equals(arguments.get(ATTRIBUTE_UPDATE_REFERENCES));
MoveResourcesDescriptor descriptor = new MoveResourcesDescriptor();
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setResourcePathsToMove(resourcePaths);
descriptor.setDestinationPath(destPath);
descriptor.setUpdateReferences(updateReferences);
return descriptor;
} catch (NumberFormatException e) {
//$NON-NLS-1$
throw new IllegalArgumentException("Can not restore MoveResourceDescriptor from map");
}
}
use of org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor in project translationstudio8 by heartsome.
the class ResourceDropAdapterAssistant method performResourceMove.
/**
* Performs a resource move
*/
private IStatus performResourceMove(CommonDropAdapter dropAdapter, IResource[] sources) {
MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation()));
IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());
boolean shouldLinkAutomatically = false;
if (target.isVirtual()) {
shouldLinkAutomatically = true;
for (int i = 0; i < sources.length; i++) {
if (sources[i].isVirtual() || sources[i].isLinked()) {
shouldLinkAutomatically = false;
break;
}
}
}
if (shouldLinkAutomatically) {
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell());
operation.setCreateLinks(true);
operation.copyResources(sources, target);
} else {
ReadOnlyStateChecker checker = new ReadOnlyStateChecker(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_checkMoveMessage);
sources = checker.checkReadOnlyResources(sources);
try {
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID);
MoveResourcesDescriptor descriptor = (MoveResourcesDescriptor) contribution.createDescriptor();
descriptor.setResourcesToMove(sources);
descriptor.setDestination(target);
refactoringStatus = new RefactoringStatus();
final Refactoring refactoring = descriptor.createRefactoring(refactoringStatus);
returnStatus = null;
IRunnableWithProgress checkOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
refactoringStatus = refactoring.checkAllConditions(monitor);
} catch (CoreException ex) {
returnStatus = WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
}
}
};
if (returnStatus != null)
return returnStatus;
try {
PlatformUI.getWorkbench().getProgressService().run(false, false, checkOp);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
} catch (InvocationTargetException e) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, e.getLocalizedMessage(), e);
}
if (refactoringStatus.hasEntries()) {
RefactoringStatusEntry[] entries = refactoringStatus.getEntries();
StringBuffer message = new StringBuffer();
int severity = 0;
for (RefactoringStatusEntry refactoringStatusEntry : entries) {
if (refactoringStatusEntry.getSeverity() > severity) {
severity = refactoringStatusEntry.getSeverity();
message.replace(0, message.length(), refactoringStatusEntry.getMessage());
} else if (refactoringStatusEntry.getSeverity() == severity) {
message.append("\n\n").append(refactoringStatusEntry.getMessage());
}
}
if (severity == RefactoringStatus.INFO) {
MessageDialog.openInformation(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
} else if (severity == RefactoringStatus.WARNING) {
boolean result = MessageDialog.openConfirm(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
if (!result) {
return Status.CANCEL_STATUS;
}
} else if (severity == RefactoringStatus.ERROR || severity == RefactoringStatus.FATAL) {
MessageDialog.openError(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
return Status.CANCEL_STATUS;
} else {
}
/**
* Weachy:
* RefactoringUI 类需引入 org.eclipse.ltk.ui.refactoring 插件,
* 而 org.eclipse.ltk.ui.refactoring 插件会引入
* org.eclipse.compare、org.eclipse.team.core、org.eclipse.team.ui
* 三个插件。会导致在导航视图、首选项等出现无用的功能项。因此注释以下4行代码。
*/
// Dialog dialog= RefactoringUI.createLightWeightStatusDialog(refactoringStatus, getShell(), WorkbenchNavigatorMessages.MoveResourceAction_title);
// int result = dialog.open();
// if (result != IStatus.OK)
// return Status.CANCEL_STATUS;
}
final PerformRefactoringOperation op = new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
final IWorkspaceRunnable r = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
op.run(monitor);
}
};
returnStatus = null;
IRunnableWithProgress refactorOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
ResourcesPlugin.getWorkspace().run(r, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException ex) {
returnStatus = WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
}
}
};
if (returnStatus != null)
return returnStatus;
try {
PlatformUI.getWorkbench().getProgressService().run(false, false, refactorOp);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
} catch (InvocationTargetException e) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, e.getLocalizedMessage(), e);
}
} catch (CoreException ex) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
} catch (OperationCanceledException e) {
}
}
return problems;
}
Aggregations