Search in sources :

Example 11 with Container

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

the class AbstractNewResourceAction method createFile.

final void createFile(String nameWithoutExtension) {
    final String name = getExtension().isEmpty() ? nameWithoutExtension : nameWithoutExtension + '.' + getExtension();
    Resource resource = appContext.getResource();
    if (!(resource instanceof Container)) {
        final Container parent = resource.getParent();
        checkState(parent != null, "Parent should be a container");
        resource = parent;
    }
    ((Container) resource).newFile(name, getDefaultContent()).then(new Operation<File>() {

        @Override
        public void apply(File newFile) throws OperationException {
            eventBus.fireEvent(FileEvent.createOpenFileEvent(newFile));
            eventBus.fireEvent(new RevealResourceEvent(newFile));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify("Failed to create resource", error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 12 with Container

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

the class ComparePresenter method onClose.

@Override
public void onClose(final String newContent) {
    if (!compareWithLatest || this.localContent == null || newContent.equals(localContent)) {
        view.hide();
        return;
    }
    ConfirmCallback confirmCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            comparedFile.updateContent(newContent).then(new Operation<Void>() {

                @Override
                public void apply(Void ignored) throws OperationException {
                    final Container parent = comparedFile.getParent();
                    if (parent != null) {
                        parent.synchronize();
                    }
                    eventBus.fireEvent(new FileContentUpdateEvent(comparedFile.getLocation().toString()));
                    view.hide();
                }
            });
        }
    };
    CancelCallback cancelCallback = new CancelCallback() {

        @Override
        public void cancelled() {
            view.hide();
        }
    };
    dialogFactory.createConfirmDialog(locale.compareSaveTitle(), locale.compareSaveQuestion(), locale.buttonYes(), locale.buttonNo(), confirmCallback, cancelCallback).show();
}
Also used : FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) Container(org.eclipse.che.ide.api.resources.Container) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 13 with Container

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

the class AddToIndexPresenter method showDialog.

public void showDialog() {
    Resource[] resources = appContext.getResources();
    checkState(resources != null && resources.length > 0);
    if (resources.length == 1) {
        Resource resource = appContext.getResource();
        if (resource instanceof Container) {
            view.setMessage(constant.addToIndexFolder(resource.getName()));
        } else {
            view.setMessage(constant.addToIndexFile(resource.getName()));
        }
    } else {
        view.setMessage(constant.addToIndexMultiSelect());
    }
    view.setUpdated(false);
    view.showDialog();
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 14 with Container

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

the class RemoveFromIndexPresenter method showDialog.

public void showDialog(Project project) {
    Resource[] resources = appContext.getResources();
    checkState(resources != null && resources.length > 0);
    this.project = project;
    if (resources.length == 1) {
        Resource resource = appContext.getResource();
        String selectedItemName = resource.getName();
        if (resource instanceof Container) {
            view.setMessage(constant.removeFromIndexFolder(selectedItemName));
        } else {
            view.setMessage(constant.removeFromIndexFile(selectedItemName));
        }
    } else {
        view.setMessage(constant.removeFromIndexAll());
    }
    view.setRemoved(false);
    view.showDialog();
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 15 with Container

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

the class CutJavaSourceAction method update.

@Override
public void update(ActionEvent event) {
    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];
    final Optional<Project> project = resource.getRelatedProject();
    final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
    if (resource.getResourceType() == FILE) {
        event.getPresentation().setEnabled(!isEditorPartActive && isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
    } else if (resource instanceof Container) {
        event.getPresentation().setEnabled(!isEditorPartActive && isJavaProject(project.get()) && srcFolder.isPresent());
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Container (org.eclipse.che.ide.api.resources.Container)38 Resource (org.eclipse.che.ide.api.resources.Resource)32 Project (org.eclipse.che.ide.api.resources.Project)13 Operation (org.eclipse.che.api.promises.client.Operation)7 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Optional (com.google.common.base.Optional)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 File (org.eclipse.che.ide.api.resources.File)5 Path (org.eclipse.che.ide.resource.Path)5 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)4 List (java.util.List)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Folder (org.eclipse.che.ide.api.resources.Folder)3 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Node (org.eclipse.che.ide.api.data.tree.Node)2