Search in sources :

Example 1 with IndexFile

use of org.eclipse.che.api.git.shared.IndexFile 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 2 with IndexFile

use of org.eclipse.che.api.git.shared.IndexFile in project che by eclipse.

the class ResetFilesViewImpl method initColumns.

/** Initialize the columns of the grid. */
private void initColumns() {
    indexFiles = new CellTable<IndexFile>();
    // Create files column:
    Column<IndexFile, String> filesColumn = new Column<IndexFile, String>(new TextCell()) {

        @Override
        public String getValue(IndexFile file) {
            return file.getPath();
        }
    };
    // Create column with checkboxes:
    Column<IndexFile, Boolean> checkColumn = new Column<IndexFile, Boolean>(new CheckboxCell(false, true)) {

        @Override
        public Boolean getValue(IndexFile file) {
            return !file.isIndexed();
        }
    };
    // Create bean value updater:
    FieldUpdater<IndexFile, Boolean> checkFieldUpdater = new FieldUpdater<IndexFile, Boolean>() {

        @Override
        public void update(int index, IndexFile file, Boolean value) {
            file.setIndexed(!value);
        }
    };
    checkColumn.setFieldUpdater(checkFieldUpdater);
    filesColumn.setHorizontalAlignment(ALIGN_LEFT);
    indexFiles.addColumn(checkColumn, new SafeHtml() {

        @Override
        public String asString() {
            return "&nbsp;";
        }
    });
    indexFiles.setColumnWidth(checkColumn, 1, Style.Unit.PCT);
    indexFiles.addColumn(filesColumn, FILES);
    indexFiles.setColumnWidth(filesColumn, 35, Style.Unit.PCT);
    indexFiles.addStyleName(resources.gitCSS().cells());
}
Also used : FieldUpdater(com.google.gwt.cell.client.FieldUpdater) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) IndexFile(org.eclipse.che.api.git.shared.IndexFile) TextCell(com.google.gwt.cell.client.TextCell) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell)

Example 3 with IndexFile

use of org.eclipse.che.api.git.shared.IndexFile in project che by eclipse.

the class ResetFilesPresenterTest method testOnResetClickedWhenNothingToReset.

@Test
public void testOnResetClickedWhenNothingToReset() throws Exception {
    MessageDialog messageDialog = mock(MessageDialog.class);
    final Status status = mock(Status.class);
    IndexFile indexFile = mock(IndexFile.class);
    when(dtoFactory.createDto(IndexFile.class)).thenReturn(indexFile);
    when(constant.messagesWarningTitle()).thenReturn("Warning");
    when(constant.indexIsEmpty()).thenReturn("Index is Empty");
    when(dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null)).thenReturn(messageDialog);
    when(indexFile.isIndexed()).thenReturn(true);
    when(indexFile.withIndexed(anyBoolean())).thenReturn(indexFile);
    when(indexFile.withPath(anyString())).thenReturn(indexFile);
    List<String> changes = new ArrayList<String>();
    changes.add("Change");
    when(status.getAdded()).thenReturn(changes);
    when(status.getChanged()).thenReturn(changes);
    when(status.getRemoved()).thenReturn(changes);
    presenter.showDialog(project);
    verify(statusPromise).then(statusPromiseCaptor.capture());
    statusPromiseCaptor.getValue().apply(status);
    presenter.onResetClicked();
    verify(view).close();
    verify(console).print(anyString());
    verify(constant, times(2)).nothingToReset();
}
Also used : Status(org.eclipse.che.api.git.shared.Status) IndexFile(org.eclipse.che.api.git.shared.IndexFile) ArrayList(java.util.ArrayList) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) Matchers.anyString(org.mockito.Matchers.anyString) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

Example 4 with IndexFile

use of org.eclipse.che.api.git.shared.IndexFile in project che by eclipse.

the class ResetFilesPresenter method onResetClicked.

/** {@inheritDoc} */
@Override
public void onResetClicked() {
    Path[] paths = new Path[0];
    for (IndexFile file : indexedFiles) {
        if (!file.isIndexed()) {
            paths = add(paths, Path.valueOf(file.getPath()));
        }
    }
    final GitOutputConsole console = gitOutputConsoleFactory.create(RESET_COMMAND_NAME);
    if (paths.length == 0) {
        view.close();
        console.print(constant.nothingToReset());
        consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
        notificationManager.notify(constant.nothingToReset());
        return;
    }
    view.close();
    service.reset(appContext.getDevMachine(), project.getLocation(), "HEAD", ResetType.MIXED, paths).then(new Operation<Void>() {

        @Override
        public void apply(Void ignored) throws OperationException {
            console.print(constant.resetFilesSuccessfully());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.resetFilesSuccessfully());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            String errorMassage = error.getMessage() != null ? error.getMessage() : constant.resetFilesFailed();
            console.printError(errorMassage);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(errorMassage);
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) 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) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

IndexFile (org.eclipse.che.api.git.shared.IndexFile)4 Status (org.eclipse.che.api.git.shared.Status)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)2 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)1 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 TextCell (com.google.gwt.cell.client.TextCell)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Column (com.google.gwt.user.cellview.client.Column)1 ArrayList (java.util.ArrayList)1 MessageDialog (org.eclipse.che.ide.api.dialogs.MessageDialog)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 BaseTest (org.eclipse.che.ide.ext.git.client.BaseTest)1 Path (org.eclipse.che.ide.resource.Path)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1