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);
}
});
}
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 " ";
}
});
indexFiles.setColumnWidth(checkColumn, 1, Style.Unit.PCT);
indexFiles.addColumn(filesColumn, FILES);
indexFiles.setColumnWidth(filesColumn, 35, Style.Unit.PCT);
indexFiles.addStyleName(resources.gitCSS().cells());
}
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();
}
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);
}
});
}
Aggregations