Search in sources :

Example 71 with Resource

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

the class CompareWithRevisionAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Project project = appContext.getRootProject();
    final Resource resource = appContext.getResource();
    checkState(project != null, "Null project occurred");
    checkState(resource instanceof File, "Invalid file occurred");
    presenter.showRevisions(project, (File) resource);
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) File(org.eclipse.che.ide.api.resources.File)

Example 72 with Resource

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

the class OrionEditorPresenter method onResourceCreated.

private void onResourceCreated(ResourceDelta delta) {
    if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
        return;
    }
    final Resource resource = delta.getResource();
    final Path movedFrom = delta.getFromPath();
    //file moved directly
    if (document.getFile().getLocation().equals(movedFrom)) {
        deletedFilesController.add(movedFrom.toString());
        document.setFile((File) resource);
        input.setFile((File) resource);
        updateContent();
    } else if (movedFrom.isPrefixOf(document.getFile().getLocation())) {
        //directory where file moved
        final Path relPath = document.getFile().getLocation().removeFirstSegments(movedFrom.segmentCount());
        final Path newPath = delta.getToPath().append(relPath);
        appContext.getWorkspaceRoot().getFile(newPath).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    final Path location = document.getFile().getLocation();
                    deletedFilesController.add(location.toString());
                    generalEventBus.fireEvent(newFileTrackingStartEvent(file.get().getLocation().toString()));
                    document.setFile(file.get());
                    input.setFile(file.get());
                    updateTabReference(file.get(), location);
                    updateContent();
                }
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Optional(com.google.common.base.Optional) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) File(org.eclipse.che.ide.api.resources.File)

Example 73 with Resource

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

the class PlainJavaPagePresenterTest method selectedNodeShouldBeWithRelativePath.

@Test
public void selectedNodeShouldBeWithRelativePath() throws Exception {
    when(view.getLibraryFolder()).thenReturn("lib1,   lib2");
    when(view.getSourceFolder()).thenReturn("src1,   src2");
    List<Node> selectedNodes = new ArrayList<>();
    ResourceNode selectedNode1 = mock(ResourceNode.class);
    ResourceNode selectedNode2 = mock(ResourceNode.class);
    Resource resource1 = mock(Resource.class);
    Resource resource2 = mock(Resource.class);
    selectedNodes.add(selectedNode1);
    selectedNodes.add(selectedNode2);
    when(selectedNode1.getData()).thenReturn(resource1);
    when(resource1.getLocation()).thenReturn(Path.valueOf("projectName/folder1/folder2"));
    when(selectedNode2.getData()).thenReturn(resource2);
    when(resource2.getLocation()).thenReturn(Path.valueOf("projectName/folder"));
    when(dataObject.getName()).thenReturn("projectName");
    page.setUpdateDelegate(updateDelegate);
    page.init(dataObject);
    page.onNodeSelected(selectedNodes);
    verify(view).setLibraryFolder(eq("folder1/folder2,   folder"));
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) Test(org.junit.Test)

Example 74 with Resource

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

the class NewFolderAction method createFolder.

final void createFolder(String name) {
    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).newFolder(name).then(new Operation<Folder>() {

        @Override
        public void apply(Folder folder) throws OperationException {
            eventBus.fireEvent(new RevealResourceEvent(folder));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            dialogFactory.createMessageDialog("Error", error.getMessage(), null).show();
        }
    });
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Folder(org.eclipse.che.ide.api.resources.Folder) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 75 with Resource

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

the class EmptyEditorsPanel method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    final Resource resource = delta.getResource();
    if (!(resource.getResourceType() == PROJECT && resource.getLocation().segmentCount() == 1)) {
        return;
    }
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            updateOnProjectsChange();
        }
    });
}
Also used : ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) CssResource(com.google.gwt.resources.client.CssResource)

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