Search in sources :

Example 1 with PageChangedEvent

use of org.activityinfo.ui.client.component.importDialog.PageChangedEvent in project activityinfo by bedatadriven.

the class ColumnMappingGrid method refreshWithNewlyParsedRows.

private void refreshWithNewlyParsedRows() {
    eventBus.fireEvent(new PageChangedEvent(false, I18N.CONSTANTS.parsingRows()));
    Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {

        @Override
        public boolean execute() {
            SourceTable sourceTable = model.getSource();
            if (!sourceTable.parsedAllRows()) {
                sourceTable.parseNextRows(50);
                ColumnMappingGrid.this.setRowData(model.getSource().getRows());
                ColumnMappingGrid.this.getRowElement(ColumnMappingGrid.this.getRowCount() - 1).scrollIntoView();
            } else {
                ColumnMappingGrid.this.scrollColumnIntoView(0);
                eventBus.fireEvent(new PageChangedEvent(true, ""));
                return false;
            }
            return true;
        }
    }, 1);
}
Also used : Scheduler(com.google.gwt.core.client.Scheduler) SourceTable(org.activityinfo.ui.client.component.importDialog.model.source.SourceTable) PageChangedEvent(org.activityinfo.ui.client.component.importDialog.PageChangedEvent)

Example 2 with PageChangedEvent

use of org.activityinfo.ui.client.component.importDialog.PageChangedEvent in project activityinfo by bedatadriven.

the class ChooseSourcePage method fireStateChanged.

@Override
public void fireStateChanged() {
    // validate
    boolean valid = false;
    PastedTable pastedTable = null;
    try {
        pastedTable = new PastedTable(textArea.getValue());
        valid = !pastedTable.getRows().isEmpty();
        if (valid) {
            boolean isFirstColumnHeaderBlank = Strings.isNullOrEmpty(pastedTable.getColumnHeader(0));
            if (isFirstColumnHeaderBlank) {
                // first row may be occupied by attribute group name, so we just cut it
                valid = false;
                String source = textArea.getValue().substring(textArea.getValue().indexOf("\n") + 1);
                pastedTable = new PastedTable(source);
                valid = !pastedTable.getRows().isEmpty();
            }
        }
    } catch (Exception e) {
    // ignore : text is not valid
    }
    if (valid) {
        pastedTable.guessColumnsType(JsConverterFactory.get());
        model.setSource(pastedTable);
        eventBus.fireEvent(new PageChangedEvent(true, ""));
    } else {
        eventBus.fireEvent(new PageChangedEvent(false, errorMessage(pastedTable)));
    }
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) PageChangedEvent(org.activityinfo.ui.client.component.importDialog.PageChangedEvent)

Aggregations

PageChangedEvent (org.activityinfo.ui.client.component.importDialog.PageChangedEvent)2 Scheduler (com.google.gwt.core.client.Scheduler)1 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)1 SourceTable (org.activityinfo.ui.client.component.importDialog.model.source.SourceTable)1