use of org.eclipse.core.resources.IResourceVisitor in project che by eclipse.
the class DeleteResourcesProcessor method checkDirtyResources.
private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
for (int i = 0; i < fResources.length; i++) {
IResource resource = fResources[i];
if (resource instanceof IProject && !((IProject) resource).isOpen())
continue;
resource.accept(new IResourceVisitor() {
public boolean visit(IResource visitedResource) throws CoreException {
if (visitedResource instanceof IFile) {
checkDirtyFile(result, (IFile) visitedResource);
}
return true;
}
}, IResource.DEPTH_INFINITE, false);
}
}
use of org.eclipse.core.resources.IResourceVisitor in project flux by eclipse.
the class Repository method getProject.
public void getProject(JSONObject request) {
try {
final int callbackID = request.getInt("callback_id");
final String sender = request.getString("requestSenderID");
final String projectName = request.getString("project");
final String username = request.getString("username");
final ConnectedProject connectedProject = this.syncedProjects.get(projectName);
if (this.username.equals(username) && connectedProject != null) {
final JSONArray files = new JSONArray();
IProject project = connectedProject.getProject();
try {
project.accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
JSONObject projectResource = new JSONObject();
String path = resource.getProjectRelativePath().toString();
try {
projectResource.put("path", path);
projectResource.put("timestamp", connectedProject.getTimestamp(path));
projectResource.put("hash", connectedProject.getHash(path));
if (resource instanceof IFile) {
projectResource.put("type", "file");
} else if (resource instanceof IFolder) {
projectResource.put("type", "folder");
}
files.put(projectResource);
} catch (JSONException e) {
e.printStackTrace();
}
return true;
}
}, IResource.DEPTH_INFINITE, IContainer.EXCLUDE_DERIVED);
} catch (Exception e) {
e.printStackTrace();
}
JSONObject message = new JSONObject();
message.put("callback_id", callbackID);
message.put("requestSenderID", sender);
message.put("username", this.username);
message.put("project", projectName);
message.put("username", this.username);
message.put("files", files);
messagingConnector.send("getProjectResponse", message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.core.resources.IResourceVisitor in project sling by apache.
the class ExportWizard method performFinish.
@Override
public boolean performFinish() {
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
final Repository[] selectedServer = new Repository[1];
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
selectedServer[0] = ServerUtil.getConnectedRepository(exportPage.getServer(), monitor);
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
});
try {
syncStartPoint.accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
if (command == null) {
return true;
}
Result<?> result = command.execute();
if (!result.isSuccess()) {
throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed exporting: " + result.toString()));
}
return true;
}
});
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (Throwable t) {
t.printStackTrace();
throw new InvocationTargetException(t);
}
}
});
return true;
} catch (RuntimeException | InterruptedException e) {
exportPage.setErrorMessage(e.getMessage());
return false;
} catch (InvocationTargetException e) {
exportPage.setErrorMessage(e.getCause().getMessage());
return false;
}
}
use of org.eclipse.core.resources.IResourceVisitor in project che by eclipse.
the class ResourceChangeDescriptionFactory method moveOrCopyDeep.
/**
* Helper method that generate a move or copy delta for a sub-tree
* of resources being moved or copied.
*/
private void moveOrCopyDeep(IResource resource, IPath destination, final boolean move) {
final IPath sourcePrefix = resource.getFullPath();
final IPath destinationPrefix = destination;
try {
//build delta for the entire sub-tree if available
if (resource.isAccessible()) {
resource.accept(new IResourceVisitor() {
public boolean visit(IResource child) {
return moveOrCopy(child, sourcePrefix, destinationPrefix, move);
}
});
} else {
//just build a delta for the single resource
moveOrCopy(resource, sourcePrefix, destination, move);
}
} catch (CoreException e) {
fail(e);
}
}
use of org.eclipse.core.resources.IResourceVisitor in project che by eclipse.
the class DeleteResourceChange method perform.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 10);
pm.setTaskName(RefactoringCoreMessages.DeleteResourceChange_deleting);
try {
IResource resource = getResource();
if (resource == null || !resource.exists()) {
if (fDeleteContent)
// see https://bugs.eclipse.org/343584
return null;
String message = Messages.format(RefactoringCoreMessages.DeleteResourceChange_error_resource_not_exists, BasicElementLabels.getPathLabel(fResourcePath.makeRelative(), false));
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), message));
}
// make sure all files inside the resource are saved so restoring works
if (resource.isAccessible()) {
resource.accept(new IResourceVisitor() {
public boolean visit(IResource curr) throws CoreException {
try {
if (curr instanceof IFile) {
// progress is covered outside.
saveFileIfNeeded((IFile) curr, new NullProgressMonitor());
}
} catch (CoreException e) {
// ignore
}
return true;
}
}, IResource.DEPTH_INFINITE, false);
}
ResourceUndoState desc = ResourceUndoState.fromResource(resource);
if (resource instanceof IProject) {
((IProject) resource).delete(fDeleteContent, fForceOutOfSync, new SubProgressMonitor(pm, 10));
} else {
int updateFlags;
if (fForceOutOfSync) {
updateFlags = IResource.KEEP_HISTORY | IResource.FORCE;
} else {
updateFlags = IResource.KEEP_HISTORY;
}
resource.delete(updateFlags, new SubProgressMonitor(pm, 5));
desc.recordStateFromHistory(resource, new SubProgressMonitor(pm, 5));
}
return new UndoDeleteResourceChange(desc);
} finally {
pm.done();
}
}
Aggregations