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; }
sparkLauncher.setAppName("DataCleaner"); final MutableRef<String> primaryJar = new MutableRef<>(); final List<String> jars = buildJarFiles(primaryJar); logger.info("Using JAR files: {}", jars); sparkLauncher.addAppArgs(primaryJar.get());
public void connectToTableNamePropertyWidget(final SingleTableNamePropertyWidget tableNamePropertyWidget) { addComboListener(item -> { // update the table name when schema is selected tableNamePropertyWidget.setSchema(_datastoreRef.get(), item); }); }
/** * Creates a DCModule based on a parent module. This constructor is * convenient when you want to create a module with overridden getter * methods. * * @param parent * @param analysisJobBuilder * the AnalysisJobBuilder to use within this module, or null if a * new AnalysisJobBuilder should be created. */ public DCModuleImpl(final DCModule parent, final AnalysisJobBuilder analysisJobBuilder) { final DCModuleImpl p = (DCModuleImpl) parent; _undecoratedConfigurationRef = p._undecoratedConfigurationRef; _userPreferencesRef = p._userPreferencesRef; _configuration = p._configuration; _windowContext = p._windowContext; if (analysisJobBuilder == null) { _analysisJobBuilderRef = new MutableRef<>(); } else { _analysisJobBuilderRef = ImmutableRef.of(analysisJobBuilder); } }
@Provides public AnalysisJobBuilder getAnalysisJobBuilder(final DataCleanerConfiguration configuration) { AnalysisJobBuilder ajb = _analysisJobBuilderRef.get(); if (ajb == null && _analysisJobBuilderRef instanceof MutableRef) { ajb = new AnalysisJobBuilder(configuration); final MutableRef<AnalysisJobBuilder> ref = (MutableRef<AnalysisJobBuilder>) _analysisJobBuilderRef; ref.set(ajb); } return ajb; }
super(componentBuilder, propertyDescriptor); _schemaRef = new MutableRef<>(); _datastoreRef = new MutableRef<>(); 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;
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); } } } } }); }
/** * Constructs a new DCModule based only on a DataCleaner home directory. New * window contexts and analysis job builder will be created. Thus this * constructor should only be used to create a completely new environment * (at bootstrap time). * * @param dataCleanerHome * @param configurationFile * a configuration file override, or null if not requested */ public DCModuleImpl(final FileObject dataCleanerHome, final FileObject configurationFile) { _userPreferencesRef = createUserPreferencesRef(dataCleanerHome); _undecoratedConfigurationRef = new DataCleanerConfigurationReader(dataCleanerHome, configurationFile, _userPreferencesRef); _analysisJobBuilderRef = new MutableRef<>(); _configuration = null; _windowContext = null; }
public void setTable(final Table table) { _tableRef.set(table); for (final SourceColumnComboBox comboBox : _comboBoxes) { comboBox.setModel(table); } }
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; }
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; }
@Inject public SingleColumnNamePropertyWidget(final ConfiguredPropertyDescriptor propertyDescriptor, final ComponentBuilder componentBuilder) { super(componentBuilder, propertyDescriptor); _tableRef = new MutableRef<>(); Enum<?>[] enumConstants = (Enum<?>[]) propertyDescriptor.getType().getEnumConstants(); if (!propertyDescriptor.isRequired()) { enumConstants = CollectionUtils.array(new Enum<?>[] { null }, enumConstants); } _comboBox = new SourceColumnComboBox(); final String currentValue = getCurrentValue(); setValue(currentValue); addComboListener(item -> fireValueChanged()); add(_comboBox); }
public void setSchema(final Datastore datastore, final Schema schema) { _panelAroundButton.setVisible(CreateTableDialog.isCreateTableAppropriate(datastore, schema)); final String previousValue = getValue(); _schemaRef.set(schema); _datastoreRef.set(datastore); if (schema == null) { _comboBox.setModel(new DefaultComboBoxModel<>(new Table[1])); } else { final List<Table> tables = new ArrayList<>(schema.getTables()); tables.add(0, null); _comboBox.setModel(new DefaultComboBoxModel<>(tables.toArray(new Table[0]))); if (previousValue == null) { if (schema.getTableCount() == 1) { // if there is only 1 table, select that final Table table = schema.getTable(0); _comboBox.setSelectedItem(table); } } else { // select table by name final Table table = schema.getTableByName(previousValue); _comboBox.setSelectedItem(table); } } }
@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; }
_mappedColumnsProperty = mappedColumnsProperty; _tableRef = new MutableRef<>(); _mappedColumnNamesPropertyWidget = new MappedColumnNamesPropertyWidget(componentBuilder, mappedColumnsProperty);
public void setDatastore(final Datastore datastore) { final String previousValue = getValue(); _datastoreRef.set(datastore); if (datastore == null) { _comboBox.setModel(new DefaultComboBoxModel<>(new Schema[1])); } else { try (DatastoreConnection con = datastore.openConnection()) { Schema[] schemas = con.getSchemaNavigator().getSchemas(); schemas = CollectionUtils.array(new Schema[1], schemas); _comboBox.setModel(new DefaultComboBoxModel<>(schemas)); Schema newValue = null; if (previousValue != null) { newValue = con.getSchemaNavigator().getSchemaByName(previousValue); } if (newValue == null) { newValue = con.getSchemaNavigator().getDefaultSchema(); } _comboBox.setSelectedItem(newValue); } } }
@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(); }
public SchemaNamePropertyWidget(final ComponentBuilder componentBuilder, final ConfiguredPropertyDescriptor propertyDescriptor) { super(componentBuilder, propertyDescriptor); _comboBox = new DCComboBox<>(); _comboBox.setRenderer(new SchemaStructureComboBoxListRenderer(false)); _comboBox.setEditable(false); addComboListener(item -> fireValueChanged()); add(_comboBox); _datastoreRef = new MutableRef<>(); setValue(getCurrentValue()); }