use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class CopyResourceChange method deleteIfAlreadyExists.
/**
* returns false if source and destination are the same (in workspace or on disk)
* in such case, no action should be performed
* @param pm the progress monitor
* @param newName the new name
* @return returns <code>true</code> if the resource already exists
* @throws CoreException thrown when teh resource cannpt be accessed
*/
private boolean deleteIfAlreadyExists(IProgressMonitor pm, String newName) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
IResource current = getDestination().findMember(newName);
if (current == null)
return true;
if (!current.exists())
return true;
IResource resource = getResource();
Assert.isNotNull(resource);
if (ReorgUtils.areEqualInWorkspaceOrOnDisk(resource, current))
return false;
if (current instanceof IFile)
((IFile) current).delete(false, true, new SubProgressMonitor(pm, 1));
else if (current instanceof IFolder)
((IFolder) current).delete(false, true, new SubProgressMonitor(pm, 1));
else
Assert.isTrue(false);
return true;
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class CoreUtility method createFolder.
/**
* Creates a folder and all parent folders if not existing.
* Project must exist.
* <code> org.eclipse.ui.dialogs.ContainerGenerator</code> is too heavy
* (creates a runnable)
* @param folder the folder to create
* @param force a flag controlling how to deal with resources that
* are not in sync with the local file system
* @param local a flag controlling whether or not the folder will be local
* after the creation
* @param monitor the progress monitor
* @throws CoreException thrown if the creation failed
*/
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent, force, local, null);
}
folder.create(force, local, monitor);
}
}
use of org.eclipse.core.resources.IFolder in project flux by eclipse.
the class DownloadProject method getProjectResponse.
public void getProjectResponse(JSONObject response) {
try {
final String responseProject = response.getString("project");
final String responseUser = response.getString("username");
final JSONArray files = response.getJSONArray("files");
if (this.username.equals(responseUser)) {
Set<String> newFiles = new HashSet<String>();
for (int i = 0; i < files.length(); i++) {
JSONObject resource = files.getJSONObject(i);
String resourcePath = resource.getString("path");
long timestamp = resource.getLong("timestamp");
String type = resource.optString("type");
if (type.equals("folder")) {
if (!resourcePath.isEmpty()) {
IFolder folder = project.getFolder(new Path(resourcePath));
createFolder(folder);
folder.setLocalTimeStamp(timestamp);
}
} else if (type.equals("file")) {
boolean added = this.projectFiles.add(resourcePath);
if (added) {
newFiles.add(resourcePath);
}
}
}
for (Iterator<String> newFilesIterator = newFiles.iterator(); newFilesIterator.hasNext(); ) {
String resourcePath = (String) newFilesIterator.next();
this.requestedProjectFiles.add(resourcePath);
JSONObject message = new JSONObject();
message.put("callback_id", callbackID);
message.put("username", this.username);
message.put("project", responseProject);
message.put("resource", resourcePath);
messagingConnector.send("getResourceRequest", message);
}
}
} catch (Exception e) {
e.printStackTrace();
this.messagingConnector.removeMessageHandler(projectResponseHandler);
this.messagingConnector.removeMessageHandler(resourceResponseHandler);
this.completionCallback.downloadFailed();
}
}
use of org.eclipse.core.resources.IFolder in project flux by eclipse.
the class DownloadProject method createFolder.
private void createFolder(IFolder folder) throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent);
}
folder.create(true, true, null);
}
}
use of org.eclipse.core.resources.IFolder in project flux by eclipse.
the class Repository method getProjectResponse.
public void getProjectResponse(JSONObject response) {
try {
final String username = response.getString("username");
final String projectName = response.getString("project");
final JSONArray files = response.getJSONArray("files");
final JSONArray deleted = response.optJSONArray("deleted");
ConnectedProject connectedProject = this.syncedProjects.get(projectName);
if (this.username.equals(username) && connectedProject != null) {
for (int i = 0; i < files.length(); i++) {
JSONObject resource = files.getJSONObject(i);
String resourcePath = resource.getString("path");
long timestamp = resource.getLong("timestamp");
String type = resource.optString("type");
String hash = resource.optString("hash");
boolean newFile = type != null && type.equals("file") && !connectedProject.containsResource(resourcePath);
boolean updatedFileTimestamp = type != null && type.equals("file") && connectedProject.containsResource(resourcePath) && connectedProject.getHash(resourcePath).equals(hash) && connectedProject.getTimestamp(resourcePath) < timestamp;
boolean updatedFile = type != null && type.equals("file") && connectedProject.containsResource(resourcePath) && !connectedProject.getHash(resourcePath).equals(hash) && connectedProject.getTimestamp(resourcePath) < timestamp;
if (newFile || updatedFile) {
JSONObject message = new JSONObject();
message.put("callback_id", GET_RESOURCE_CALLBACK);
message.put("project", projectName);
message.put("username", this.username);
message.put("resource", resourcePath);
message.put("timestamp", timestamp);
message.put("hash", hash);
messagingConnector.send("getResourceRequest", message);
}
if (updatedFileTimestamp) {
connectedProject.setTimestamp(resourcePath, timestamp);
IResource file = connectedProject.getProject().findMember(resourcePath);
file.setLocalTimeStamp(timestamp);
}
boolean newFolder = type != null && type.equals("folder") && !connectedProject.containsResource(resourcePath);
boolean updatedFolder = type != null && type.equals("folder") && connectedProject.containsResource(resourcePath) && !(connectedProject.getHash(resourcePath) == null || connectedProject.getHash(resourcePath).equals(hash)) && connectedProject.getTimestamp(resourcePath) < timestamp;
if (newFolder) {
IProject project = connectedProject.getProject();
IFolder folder = project.getFolder(resourcePath);
connectedProject.setHash(resourcePath, hash);
connectedProject.setTimestamp(resourcePath, timestamp);
folder.create(true, true, null);
folder.setLocalTimeStamp(timestamp);
} else if (updatedFolder) {
}
}
if (deleted != null) {
for (int i = 0; i < deleted.length(); i++) {
JSONObject deletedResource = deleted.getJSONObject(i);
String resourcePath = deletedResource.getString("path");
long deletedTimestamp = deletedResource.getLong("timestamp");
IProject project = connectedProject.getProject();
IResource resource = project.findMember(resourcePath);
if (resource != null && resource.exists() && (resource instanceof IFile || resource instanceof IFolder)) {
long localTimestamp = connectedProject.getTimestamp(resourcePath);
if (localTimestamp < deletedTimestamp) {
resource.delete(true, null);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations