public void connectToTableNamePropertyWidget(final SingleTableNamePropertyWidget tableNamePropertyWidget) { addComboListener(item -> { // update the table name when schema is selected tableNamePropertyWidget.setSchema(_datastoreRef.get(), item); }); }
public void setTable(final Table table) { if (table != _tableRef.get()) { _tableRef.set(table); updateMappedColumns(); } }
private List<String> buildJarFiles(final MutableRef<String> primaryJarRef) throws IOException { final List<String> list = new ArrayList<>(); final Path directoryPath = new Path(_jarDirectoryPath); final RemoteIterator<LocatedFileStatus> files = _fileSystem.listFiles(directoryPath, false); while (files.hasNext()) { final LocatedFileStatus file = files.next(); final Path path = file.getPath(); final String filename = path.getName(); boolean primaryJar = false; for (final String prefix : PRIMARY_JAR_FILENAME_PREFIXES) { if (filename.startsWith(prefix)) { primaryJarRef.set(path.toString()); primaryJar = true; break; } } if (!primaryJar) { list.add(path.toString()); } } if (primaryJarRef.get() == null) { throw new IllegalArgumentException( "Failed to find primary jar (starting with '" + PRIMARY_JAR_FILENAME_PREFIXES[0] + "') in JAR file directory: " + _jarDirectoryPath); } return list; }
/** * Sets the table to use as a source for the available columns in the * combobox. * * @param table */ public void setTable(final Table table) { if (table != _tableRef.get()) { _tableRef.set(table); if (table == null) { _comboBox.setEmptyModel(); } else { _comboBox.setModel(table); } } }
sparkLauncher.addAppArgs(primaryJar.get());
private void updateMappedColumns() { final Table table = _tableRef.get(); final Set<Entry<InputColumn<?>, SourceColumnComboBox>> entrySet = _mappedColumnComboBoxes.entrySet(); batchUpdateWidget(() -> { for (final Entry<InputColumn<?>, SourceColumnComboBox> entry : entrySet) { final InputColumn<?> inputColumn = entry.getKey(); final SourceColumnComboBox comboBox = entry.getValue(); if (table == null) { comboBox.setEmptyModel(); } else { comboBox.setModel(table); if (comboBox.getSelectedItem() == null) { final Column column = getDefaultMappedColumn(inputColumn, table); if (column != null) { comboBox.setEditable(true); comboBox.setSelectedItem(column); comboBox.setEditable(false); } } } } }); }
private SourceColumnComboBox createComboBox(final InputColumn<?> inputColumn, Column mappedColumn) { final SourceColumnComboBox sourceColumnComboBox = new SourceColumnComboBox(); _mappedColumnComboBoxes.put(inputColumn, sourceColumnComboBox); final Table table = _tableRef.get(); if (mappedColumn == null && table != null) { mappedColumn = getDefaultMappedColumn(inputColumn, table); } if (mappedColumn == null) { logger.info("No default mapping found for column: {}", inputColumn); } else { sourceColumnComboBox.setEditable(true); sourceColumnComboBox.setSelectedItem(mappedColumn); sourceColumnComboBox.setEditable(false); } sourceColumnComboBox.addColumnSelectedListener(item -> { if (isBatchUpdating()) { return; } _mappedColumnNamesPropertyWidget.fireValueChanged(); fireValueChanged(); }); return sourceColumnComboBox; }
@Override protected JComponent decorateCheckBox(final DCCheckBox<InputColumn<?>> checkBox) { final SourceColumnComboBox sourceColumnComboBox; final InputColumn<?> inputColumn = checkBox.getValue(); if (_mappedColumnComboBoxes.containsKey(inputColumn)) { sourceColumnComboBox = _mappedColumnComboBoxes.get(inputColumn); } else { sourceColumnComboBox = createComboBox(inputColumn, null); } final JComponent decoratedSourceColumnComboBox = decorateSourceColumnComboBox(inputColumn, sourceColumnComboBox); _comboBoxDecorations.put(sourceColumnComboBox, decoratedSourceColumnComboBox); checkBox.addListenerToHead(this::setMappedColumnVisible); checkBox.addListener((item, selected) -> { if (isBatchUpdating()) { return; } _mappedColumnNamesPropertyWidget.fireValueChanged(); }); final Table table = _tableRef.get(); if (table != null) { sourceColumnComboBox.setModel(table); } setMappedColumnVisible(sourceColumnComboBox, checkBox.isSelected()); final DCPanel panel = new DCPanel(); panel.setLayout(new BorderLayout()); panel.add(checkBox, BorderLayout.CENTER); panel.add(decoratedSourceColumnComboBox, BorderLayout.EAST); return panel; }
@Override protected void setValue(final String value) { if (getValue() == value) { return; } final Schema schema = _schemaRef.get(); final Table table; if (value == null) { table = null; } else if (schema == null) { table = new MutableTable(value); } else { table = schema.getTableByName(value); } _comboBox.setEditable(true); _comboBox.setSelectedItem(table); _comboBox.setEditable(false); fireValueChanged(); }
private static Table getTable(final UpdateableDataContext dataContext, final String sheetName, final String[] columnNames) { final Schema schema = dataContext.getDefaultSchema(); Table table = schema.getTableByName(sheetName); if (table == null) { final MutableRef<Table> tableRef = new MutableRef<>(); dataContext.executeUpdate(callback -> { final TableCreationBuilder tableBuilder = callback.createTable(schema, sheetName); for (final String columnName : columnNames) { tableBuilder.withColumn(columnName); } tableRef.set(tableBuilder.execute()); }); table = tableRef.get(); } return table; }
protected void addComboBox(final String value, final boolean updateUI) { final SourceColumnComboBox comboBox = new SourceColumnComboBox(); final Column column; final Table table = _tableRef.get(); if (value == null) { column = null; } else if (table == null) { column = new MutableColumn(value); } else { column = table.getColumnByName(value); } comboBox.setModel(table); comboBox.setEditable(true); comboBox.setSelectedItem(column); comboBox.setEditable(false); comboBox.addColumnSelectedListener(item -> fireValueChanged()); _comboBoxes.add(comboBox); _comboBoxPanel.add(comboBox); if (updateUI) { _comboBoxPanel.updateUI(); } }
createTableButton.setToolTipText("Create table"); createTableButton.addActionListener(e -> { final Schema schema = _schemaRef.get(); final Datastore datastore = _datastoreRef.get(); if (datastore instanceof UpdateableDatastore) { final UpdateableDatastore updateableDatastore = (UpdateableDatastore) datastore;
@Override protected void setValue(String value) { final Datastore datastore = _datastoreRef.get(); if (value == null && datastore != null) { try (DatastoreConnection con = datastore.openConnection()) { value = con.getSchemaNavigator().getDefaultSchema().getName(); } } if (getValue() == value) { return; } final Schema schema; if (value == null) { schema = null; } else if (datastore == null) { schema = new MutableSchema(value); } else { try (DatastoreConnection con = datastore.openConnection()) { schema = con.getSchemaNavigator().getSchemaByName(value); } } _comboBox.setEditable(true); _comboBox.setSelectedItem(schema); _comboBox.setEditable(false); }