Search in sources :

Example 26 with IFolder

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IFolder(org.eclipse.core.resources.IFolder)

Example 27 with IFolder

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);
    }
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 28 with IFolder

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();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) HashSet(java.util.HashSet) IFolder(org.eclipse.core.resources.IFolder)

Example 29 with IFolder

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);
    }
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 30 with IFolder

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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)237 IFile (org.eclipse.core.resources.IFile)95 IPath (org.eclipse.core.runtime.IPath)70 CoreException (org.eclipse.core.runtime.CoreException)65 IProject (org.eclipse.core.resources.IProject)64 IResource (org.eclipse.core.resources.IResource)56 File (java.io.File)35 IContainer (org.eclipse.core.resources.IContainer)33 ArrayList (java.util.ArrayList)31 Path (org.eclipse.core.runtime.Path)31 IOException (java.io.IOException)26 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 Test (org.junit.Test)18 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 InputStream (java.io.InputStream)15 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)13 URL (java.net.URL)12