Search in sources :

Example 16 with File

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

the class OpenRecentFilesPresenter method setRecentFiles.

/**
     * Set recent file list.
     *
     * @param recentFiles
     *         recent file list
     */
public void setRecentFiles(List<File> recentFiles) {
    final List<FileNode> nodes = newArrayListWithCapacity(recentFiles.size());
    for (File recentFile : recentFiles) {
        nodes.add(nodeFactory.newFileNode(recentFile, settingsProvider.getSettings()));
    }
    view.setRecentFiles(nodes);
}
Also used : File(org.eclipse.che.ide.api.resources.File) FileNode(org.eclipse.che.ide.resources.tree.FileNode)

Example 17 with File

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

the class ProjectTreeStateNotificationOperation method apply.

@Override
public void apply(String endpointId, ProjectTreeStateUpdateDto params) throws JsonRpcException {
    final String path = params.getPath();
    final FileWatcherEventType type = params.getType();
    final int status;
    switch(type) {
        case CREATED:
            {
                status = ADDED;
                break;
            }
        case DELETED:
            {
                status = REMOVED;
                break;
            }
        case MODIFIED:
            {
                status = UPDATED;
                break;
            }
        default:
            {
                status = UPDATED;
                break;
            }
    }
    Log.debug(getClass(), "Received request\npath: " + path + "\ntype:" + type + "\nstatus:" + status);
    if (path == null || path.isEmpty()) {
        appContext.getWorkspaceRoot().synchronize();
    } else {
        appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), status));
    }
    if (status == ADDED) {
        appContext.getWorkspaceRoot().getFile(Path.valueOf(path)).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> arg) throws OperationException {
                if (arg.isPresent()) {
                    appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), UPDATED));
                }
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Optional(com.google.common.base.Optional) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 18 with File

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

the class CompareWithLatestAction 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(project.getLocation().isPrefixOf(resource.getLocation()), "Given selected item is not descendant of given project");
    final String selectedItemPath = resource.getLocation().removeFirstSegments(project.getLocation().segmentCount()).removeTrailingSeparator().toString();
    service.diff(appContext.getDevMachine(), project.getLocation(), selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath), NAME_STATUS, false, 0, REVISION, false).then(new Operation<String>() {

        @Override
        public void apply(String diff) throws OperationException {
            if (diff.isEmpty()) {
                dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(), locale.compareMessageIdenticalContentText(), null).show();
            } else {
                final String[] changedFiles = diff.split("\n");
                if (changedFiles.length == 1) {
                    project.getFile(changedFiles[0].substring(2)).then(new Operation<Optional<File>>() {

                        @Override
                        public void apply(Optional<File> file) throws OperationException {
                            if (file.isPresent()) {
                                comparePresenter.showCompareWithLatest(file.get(), defineStatus(changedFiles[0].substring(0, 1)), REVISION);
                            }
                        }
                    });
                } else {
                    Map<String, Status> items = new HashMap<>();
                    for (String item : changedFiles) {
                        items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
                    }
                    changedListPresenter.show(items, REVISION, null, project);
                }
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
        }
    });
}
Also used : Status(org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status) FileStatus.defineStatus(org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 19 with File

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

the class AddToIndexPresenterTest method shouldSetMultiSelectionMessageToViewAndShowDialog.

@Test
public void shouldSetMultiSelectionMessageToViewAndShowDialog() throws Exception {
    File file1 = mock(File.class);
    File file2 = mock(File.class);
    when(file1.getName()).thenReturn(FILE_NAME + "1");
    when(file2.getName()).thenReturn(FILE_NAME + "2");
    when(appContext.getResource()).thenReturn(file2);
    when(appContext.getResources()).thenReturn(new Resource[] { file1, file2 });
    when(constant.addToIndexMultiSelect()).thenReturn(MESSAGE);
    presenter.showDialog();
    verify(constant).addToIndexMultiSelect();
    verify(view).setMessage(eq(MESSAGE));
    verify(view).setUpdated(eq(false));
    verify(view).showDialog();
}
Also used : File(org.eclipse.che.ide.api.resources.File) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

Example 20 with File

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

the class AddToIndexPresenterTest method shouldSetFileMessageToViewAndShowDialog.

@Test
public void shouldSetFileMessageToViewAndShowDialog() throws Exception {
    File file = mock(File.class);
    when(file.getName()).thenReturn(FILE_NAME);
    when(appContext.getResource()).thenReturn(file);
    when(appContext.getResources()).thenReturn(new Resource[] { file });
    when(constant.addToIndexFile(FILE_NAME)).thenReturn(MESSAGE);
    presenter.showDialog();
    verify(constant).addToIndexFile(eq(FILE_NAME));
    verify(view).setMessage(eq(MESSAGE));
    verify(view).setUpdated(eq(false));
    verify(view).showDialog();
}
Also used : File(org.eclipse.che.ide.api.resources.File) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

Aggregations

File (org.eclipse.che.ide.api.resources.File)25 Resource (org.eclipse.che.ide.api.resources.Resource)14 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)13 Optional (com.google.common.base.Optional)11 Operation (org.eclipse.che.api.promises.client.Operation)10 OperationException (org.eclipse.che.api.promises.client.OperationException)10 Project (org.eclipse.che.ide.api.resources.Project)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)7 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 Container (org.eclipse.che.ide.api.resources.Container)5 Scheduler (com.google.gwt.core.client.Scheduler)4 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)4 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 SyntheticFile (org.eclipse.che.ide.api.resources.SyntheticFile)3 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Document (org.eclipse.che.ide.api.editor.document.Document)2 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)2