Search in sources :

Example 61 with Resource

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

the class AbstractNewResourceAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
    e.getPresentation().setVisible(true);
    final Resource[] resources = appContext.getResources();
    if (resources != null && resources.length == 1) {
        final Resource resource = resources[0];
        if (resource instanceof Container) {
            e.getPresentation().setEnabled(true);
        } else {
            e.getPresentation().setEnabled(resource.getParent() != null);
        }
    } else {
        e.getPresentation().setEnabled(false);
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 62 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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 63 with Resource

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

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFolderLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFolderLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FOLDER_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/samples/");
    Path oldFilePath = new Path(FILE_PATH);
    Path newFilePath = new Path("testProject/src/main/java/org/eclipse/che/samples/" + FILE_NAME);
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
    when(delta.getFlags()).thenReturn(5632);
    when(delta.getFromPath()).thenReturn(fromPath);
    when(delta.getToPath()).thenReturn(toPath);
    when(delta.getResource()).thenReturn(resource);
    when(resource.isFile()).thenReturn(false);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(oldFilePath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(newFilePath);
    assertNull(oldGroup);
    assertNotNull(newGroup);
}
Also used : Path(org.eclipse.che.ide.resource.Path) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 64 with Resource

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

the class ResetFilesPresenter method showDialog.

/** Show dialog. */
public void showDialog(Project project) {
    this.project = project;
    service.getStatus(appContext.getDevMachine(), project.getLocation()).then(new Operation<Status>() {

        @Override
        public void apply(Status status) throws OperationException {
            if (status.isClean()) {
                dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
                return;
            }
            indexedFiles = new IndexFile[0];
            for (String path : status.getAdded()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            for (String path : status.getChanged()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            for (String path : status.getRemoved()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            if (indexedFiles.length == 0) {
                dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
                return;
            }
            //Mark selected items to reset from index
            Resource[] resources = appContext.getResources();
            if (resources != null) {
                for (Resource selectedItem : resources) {
                    String selectedItemPath = selectedItem.getLocation().removeFirstSegments(1).toString();
                    for (IndexFile file : indexedFiles) if (file.getPath().startsWith(selectedItemPath)) {
                        file.setIndexed(false);
                    }
                }
            }
            view.setIndexedFiles(indexedFiles);
            view.showDialog();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            String errorMassage = error.getMessage() != null ? error.getMessage() : constant.statusFailed();
            GitOutputConsole console = gitOutputConsoleFactory.create(STATUS_COMMAND_NAME);
            console.printError(errorMassage);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(errorMassage);
        }
    });
}
Also used : Status(org.eclipse.che.api.git.shared.Status) PromiseError(org.eclipse.che.api.promises.client.PromiseError) IndexFile(org.eclipse.che.api.git.shared.IndexFile) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 65 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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)

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