@Override public ValidationState getValidationState(Appendable errMsg) { try { // TODO: check duplicate columns here!!! if (ntmp.getSourceIndex() == -1) { if (ntmp.getTargetIndex() == -1) { errMsg.append( "The network cannot be created without selecting the source and target columns."); return ValidationState.INVALID; } else { errMsg.append( "No edges will be created in the network; the target column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } } else { if (ntmp.getTargetIndex() == -1) { errMsg.append( "No edges will be created in the network; the source column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } else { return ValidationState.OK; } } } catch (IOException ioe) { ioe.printStackTrace(); return ValidationState.INVALID; } }
@Override public void run(TaskMonitor tm) throws Exception { tm.setTitle("Loading network from table"); tm.setProgress(0.0); tm.setStatusMessage("Loading network..."); Workbook workbook = null; // Load Spreadsheet data for preview. if (fileType != null && (fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) && workbook == null) { try { workbook = WorkbookFactory.create(is); } catch (InvalidFormatException e) { throw new IllegalArgumentException( "Could not read Excel file. Maybe the file is broken?", e); } finally { if (is != null) is.close(); } } try { if (this.fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || this.fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) { String networkName = ntmp.getName(); if (networkName == null) networkName = workbook.getSheetName(0); final Sheet sheet = workbook.getSheet(networkName); reader = new ExcelNetworkSheetReader( networkName, sheet, ntmp, nMap, rootNetwork, serviceRegistrar); } else { reader = new NetworkTableReader(inputName, is, ntmp, nMap, rootNetwork, serviceRegistrar); } } catch (Exception ioe) { tm.showMessage(TaskMonitor.Level.ERROR, "Unable to read table: " + ioe.getMessage()); return; } loadNetwork(tm); tm.setProgress(1.0); }