/* * Override the parent method to validate whether column names have been set such that it is * possible to determine whether the header row is completely empty in the worksheet. */ @Override public SpreadsheetColumn addColumn(SpreadsheetColumnMetadata cObj) throws EolModelLoadingException { SpreadsheetColumn c = super.addColumn(cObj); if (c.getName() != null && !c.getName().isEmpty()) { this.headerEmpty = false; } return c; }
@Override protected void createInSpreadsheet() throws RuntimeException { try { // Create the worksheet URL worksheetFeedUrl = ((GSModel) this.model).spreadsheetEntry.getWorksheetFeedUrl(); this.worksheetEntry = ((GSModel) this.model).spreadsheetService.insert(worksheetFeedUrl, this.worksheetEntry); this.existsInSpreadsheet = true; if (this.headerEmpty) { // Worksheet is completely empty - insert a value in the header row, otherwise list feed // uses the header row CellFeed cf = this.fetchCellFeed(1, true); CellEntry cellEntry = new CellEntry(1, 1, "TEMP"); cf.insert(cellEntry); } else { // Write any known column names CellFeed cf = this.fetchCellFeed(1, true); for (SpreadsheetColumn c : this.getHeader()) { if (c.getName() != null && !c.getName().isEmpty()) { CellEntry cellEntry = new CellEntry(1, c.getIndex(), c.getName()); cf.insert(cellEntry); } } } // Update the worksheet entry to reflect the new state this.worksheetEntry = this.worksheetEntry.getSelf(); // Set up the worksheet this.initialiseListFeed(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }