Search in sources :

Example 86 with Resource

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

the class PropertyEditorPresenter method obtainExistingPropertiesForPath.

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

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            List<String> properties = new ArrayList<String>();
            for (String property : response.getOutput()) {
                properties.add(property.trim());
            }
            view.setExistingPropertiesForPath(properties);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(notificationManager.notify(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) ArrayList(java.util.ArrayList) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 87 with Resource

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

the class ProjectConfigurationAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    final Resource[] resources = appContext.getResources();
    if (resources != null && resources.length == 1) {
        final Resource resource = resources[0];
        if (resource.getResourceType() == PROJECT) {
            event.getPresentation().setEnabledAndVisible(true);
            event.getPresentation().setText("Update Project Configuration...");
        } else {
            event.getPresentation().setEnabledAndVisible(false);
        }
    }
}
Also used : Resource(org.eclipse.che.ide.api.resources.Resource)

Example 88 with Resource

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

the class RefreshPathAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    event.getPresentation().setText("Refresh");
    event.getPresentation().setVisible(true);
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        event.getPresentation().setEnabled(false);
        return;
    }
    final Resource resource = resources[0];
    if (resource instanceof Container) {
        event.getPresentation().setText("Refresh '" + resource.getName() + "'");
    } else {
        final Container parent = resource.getParent();
        if (parent != null) {
            event.getPresentation().setText("Refresh '" + parent.getName() + "'");
        } else {
            event.getPresentation().setEnabled(false);
            return;
        }
    }
    event.getPresentation().setEnabled(true);
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 89 with Resource

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

the class RenameItemAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    checkState(resource != null, "Null resource occurred");
    final String resourceName = resource.getName();
    final int selectionLength = resourceName.indexOf('.') >= 0 ? resourceName.lastIndexOf('.') : resourceName.length();
    final InputValidator validator;
    final String dialogTitle;
    if (resource.getResourceType() == FILE) {
        validator = new FileNameValidator(resourceName);
        dialogTitle = localization.renameFileDialogTitle(resourceName);
    } else if (resource.getResourceType() == FOLDER) {
        validator = new FolderNameValidator(resourceName);
        dialogTitle = localization.renameFolderDialogTitle(resourceName);
    } else if (resource.getResourceType() == PROJECT) {
        validator = new ProjectNameValidator(resourceName);
        dialogTitle = localization.renameProjectDialogTitle(resourceName);
    } else {
        throw new IllegalStateException("Not a resource");
    }
    final InputCallback inputCallback = new InputCallback() {

        @Override
        public void accepted(final String value) {
            //we shouldn't perform renaming file with the same name
            if (!value.trim().equals(resourceName)) {
                closeRelatedEditors(resource);
                final Path destination = resource.getLocation().parent().append(value);
                resource.move(destination).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError arg) throws OperationException {
                        notificationManager.notify("", arg.getMessage(), FAIL, EMERGE_MODE);
                    }
                });
            }
        }
    };
    InputDialog inputDialog = dialogFactory.createInputDialog(dialogTitle, localization.renameDialogNewNameLabel(), resource.getName(), 0, selectionLength, inputCallback, null);
    inputDialog.withValidator(validator);
    inputDialog.show();
}
Also used : Path(org.eclipse.che.ide.resource.Path) InputDialog(org.eclipse.che.ide.api.dialogs.InputDialog) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Resource(org.eclipse.che.ide.api.resources.Resource) InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 90 with Resource

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

the class DownloadResourceAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    checkState(resource != null, "Null resource occurred");
    downloadContainer.setUrl(urlModifier.modify(resource.getURL()));
}
Also used : Resource(org.eclipse.che.ide.api.resources.Resource)

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