Search in sources :

Example 16 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class OutputDirMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources != null && resources.length == 1) {
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        Project relatedProject = project.get();
        if (!isJavaProject(relatedProject)) {
            return promises.resolve("");
        }
        if (relatedProject.getAttributes().containsKey(OUTPUT_FOLDER)) {
            return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).append(relatedProject.getAttributes().get(OUTPUT_FOLDER).get(0)).toString());
        } else {
            return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).toString());
        }
    }
    return promises.resolve("");
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 17 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class CopyPresenter method showCopy.

/** Show copy dialog. */
public void showCopy() {
    final Project project = appContext.getRootProject();
    Preconditions.checkState(project != null && SvnUtil.isUnderSvn(project));
    final Resource[] resources = appContext.getResources();
    Preconditions.checkState(resources != null && resources.length == 1);
    sourceNode = resources[0];
    if (sourceNode.getResourceType() == Resource.FILE) {
        view.setDialogTitle(constants.copyViewTitleFile());
    } else {
        view.setDialogTitle(constants.copyViewTitleDirectory());
    }
    view.setNewName(sourceNode.getName());
    view.setComment(sourceNode.getName());
    view.setSourcePath(sourceNode.getLocation().toString(), false);
    validate();
    view.show();
    view.setProjectNode(project);
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 18 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class DiffPresenter method showDiff.

public void showDiff() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

        @Override
        public Promise<CLIOutputResponse> perform(Credentials credentials) {
            return service.showDiff(project.getLocation(), toRelative(project, resources), "HEAD", credentials);
        }
    }, null).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandDiff());
            ;
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Operation(org.eclipse.che.api.promises.client.Operation) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 19 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class ExportPresenter method onExportClicked.

/** {@inheritDoc} */
@Override
public void onExportClicked() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    checkState(resources.length == 1);
    final String givenRevision = view.isRevisionSpecified() ? view.getRevision() : null;
    final StatusNotification notification = new StatusNotification(constants.exportStarted(resources[0].getLocation().toString()), PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    view.onClose();
    if (!isNullOrEmpty(givenRevision)) {
        service.getRevisions(project.getLocation(), toRelative(project, resources[0]), "1:HEAD").then(new Operation<GetRevisionsResponse>() {

            @Override
            public void apply(GetRevisionsResponse response) throws OperationException {
                final List<String> pathRevisions = response.getRevisions();
                if (pathRevisions.size() > 0) {
                    final String pathFirstRevision = pathRevisions.get(0);
                    final String pathLastRevision = pathRevisions.get(pathRevisions.size() - 1);
                    final int givenRevisionNb = Integer.valueOf(givenRevision);
                    final int pathFirstRevisionNb = Integer.valueOf(pathFirstRevision.substring(1));
                    final int pathLastRevisionNb = Integer.valueOf(pathLastRevision.substring(1));
                    final List<String> errOutput = response.getErrOutput();
                    if (errOutput != null && !errOutput.isEmpty()) {
                        printErrors(errOutput, constants.commandInfo());
                        notification.setTitle(constants.exportCommandExecutionError());
                        notification.setStatus(FAIL);
                    } else if (givenRevisionNb < pathFirstRevisionNb || givenRevisionNb > pathLastRevisionNb) {
                        notification.setTitle(constants.exportRevisionDoNotExistForPath(givenRevision, toRelative(project, resources[0]).toString()));
                        notification.setStatus(FAIL);
                    } else {
                        openExportPopup(project.getLocation(), toRelative(project, resources[0]), givenRevision, notification);
                    }
                } else {
                    notification.setTitle(constants.exportNoRevisionForPath(toRelative(project, resources[0]).toString()));
                    notification.setStatus(FAIL);
                }
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notification.setTitle(constants.exportCommandExecutionError() + "\n" + error.getMessage());
                notification.setStatus(FAIL);
            }
        });
    } else {
        openExportPopup(project.getLocation(), toRelative(project, resources[0]), null, notification);
    }
}
Also used : GetRevisionsResponse(org.eclipse.che.plugin.svn.shared.GetRevisionsResponse) Resource(org.eclipse.che.ide.api.resources.Resource) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 20 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class CleanupPresenter method cleanup.

public void cleanup() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    service.cleanup(project.getLocation(), toRelative(project, resources)).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse result) throws OperationException {
            printResponse(result.getCommand(), result.getOutput(), result.getErrOutput(), constants.commandCleanup());
            notificationManager.notify(constants.cleanupSuccessful());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(constants.cleanupFailed() + ": " + error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Resource (org.eclipse.che.ide.api.resources.Resource)146 Project (org.eclipse.che.ide.api.resources.Project)73 OperationException (org.eclipse.che.api.promises.client.OperationException)48 Operation (org.eclipse.che.api.promises.client.Operation)46 PromiseError (org.eclipse.che.api.promises.client.PromiseError)40 Container (org.eclipse.che.ide.api.resources.Container)32 Path (org.eclipse.che.ide.resource.Path)30 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)22 Optional (com.google.common.base.Optional)15 File (org.eclipse.che.ide.api.resources.File)14 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)14 List (java.util.List)13 Promise (org.eclipse.che.api.promises.client.Promise)13 FunctionException (org.eclipse.che.api.promises.client.FunctionException)12 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 ArrayList (java.util.ArrayList)11 Function (org.eclipse.che.api.promises.client.Function)9 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8