use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.
the class AddOutFieldDialog method initKnimeNameComboBox.
/**
* Initialize the selection list for the knime name.
*/
private void initKnimeNameComboBox() {
m_replacedKnimeName.removeAllItems();
if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
for (DataColumnSpec colSpec : m_spec) {
m_replacedKnimeName.addItem(colSpec);
}
m_replacedKnimeName.setRenderer(new DataColumnSpecListCellRenderer());
} else {
for (FlowVariable flowVar : m_flowVars.values()) {
// created.
if (FieldsTableUtil.verifyNameOfFlowVariable(flowVar.getName())) {
m_replacedKnimeName.addItem(flowVar);
}
}
m_replacedKnimeName.setRenderer(new FlowVariableListCellRenderer());
}
if (m_replacedKnimeName.getItemCount() <= 0) {
m_replacedKnimeName.setEnabled(false);
m_knimeName.setEnabled(true);
m_replace.setEnabled(false);
m_replace.setSelected(false);
m_append.setSelected(true);
} else {
m_replacedKnimeName.setEnabled(true);
m_replace.setEnabled(true);
}
}
use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.
the class MissingValueHandling2Panel method createWestLayout.
/**
* @param setting
* @param tabPanel
* @param icon
* @param name
* @param spec
*/
private void createWestLayout(final MissingValueHandling2ColSetting setting, final JPanel tabPanel, final Icon icon, final String name, final DataColumnSpec... spec) {
String shortName = name;
if (setting.isMetaConfig()) {
if (name.length() > 15) {
shortName = name.substring(0, 14).concat("...");
}
JLabel jLabel = new JLabel(shortName, icon, SwingConstants.LEFT);
jLabel.setToolTipText(name);
JPanel typePanel = new JPanel(new BorderLayout());
typePanel.add(jLabel, BorderLayout.NORTH);
tabPanel.add(typePanel, BorderLayout.WEST);
} else {
final JList jList = new JList(spec);
jList.setCellRenderer(new DataColumnSpecListCellRenderer() {
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
// The super method will reset the icon if we call this method
// last. So we let super do its job first and then we take care
// that everything is properly set.
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = null;
if (value instanceof DataColumnSpec && MissingValueHandling2NodeDialogPane.isIncompatible((DataColumnSpec) value)) {
setBorder(BorderFactory.createLineBorder(Color.YELLOW));
text = "Column " + ((DataColumnSpec) value).getName() + " is incompatible to the current settings";
}
setToolTipText(text);
return this;
}
});
jList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
jList.setSelectedIndices(new int[0]);
}
});
// jList.setSE
JScrollPane columns = new JScrollPane(jList);
columns.setMaximumSize(new Dimension(150, 150));
columns.setPreferredSize(new Dimension(100, 150));
tabPanel.add(columns, BorderLayout.WEST);
}
}
use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.
the class RuleEngineNodeDialog method createTopPart.
/*
* top part (from left to right) = variable list, operator list, editor box
*/
private Box createTopPart() {
/*
* Variable list (column names)
*/
m_variableModel = new DefaultListModel();
m_variableList = new JList(m_variableModel);
m_variableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_variableList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_variableList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (arg0.getValueIsAdjusting()) {
return;
}
if (m_lastUsedTextfield != null) {
String existingText = m_lastUsedTextfield.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
if (!m_variableList.isSelectionEmpty()) {
String newText = ((DataColumnSpec) m_variableList.getSelectedValue()).getName();
m_lastUsedTextfield.setText((existingText + " $" + newText + "$").trim());
m_lastUsedTextfield.requestFocusInWindow();
if (m_lastUsedTextfield == m_ruleLabelEditor) {
m_outcomeIsColumn.setSelected(true);
}
}
}
m_variableList.clearSelection();
}
});
/*
* Operators (<, >, <=, >=, =, AND, OR, etc)
*/
m_operatorModel = new DefaultListModel();
m_operatorList = new JList(m_operatorModel);
m_operatorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_operatorList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (!arg0.getValueIsAdjusting() && !m_operatorList.isSelectionEmpty()) {
String existingText = m_ruleEditor.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
String newText = (String) m_operatorList.getSelectedValue();
m_ruleEditor.setText(existingText + " " + newText);
m_ruleEditor.requestFocusInWindow();
m_operatorList.clearSelection();
}
}
});
Box editorBox = createEditorPart();
Box listBox = Box.createHorizontalBox();
JScrollPane variableScroller = new JScrollPane(m_variableList);
variableScroller.setBorder(BorderFactory.createTitledBorder("Columns"));
JScrollPane operatorScroller = new JScrollPane(m_operatorList);
operatorScroller.setBorder(BorderFactory.createTitledBorder("Operators"));
listBox.add(variableScroller);
listBox.add(operatorScroller);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listBox, editorBox);
Dimension minimumSize = new Dimension(200, 50);
listBox.setMinimumSize(minimumSize);
editorBox.setMinimumSize(minimumSize);
Box topBox = Box.createHorizontalBox();
topBox.add(splitPane);
topBox.add(Box.createHorizontalGlue());
return topBox;
}
use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.
the class DataValidatorColPanel method createWestLayout.
/**
* @param tabPanel
* @param spec
* @param setting
* @param icon
* @param name
*/
private void createWestLayout(final JPanel tabPanel, final List<DataColumnSpec> spec) {
m_defaultListModel = new DefaultListModel<>();
for (DataColumnSpec s : spec) {
m_defaultListModel.addElement(s);
}
m_defaultListModel.addElement(DROP_COLUMN_PLACEHOLDER);
final JList<Object> jList = new JList<>(m_defaultListModel);
jList.setCellRenderer(new DataColumnSpecListCellRenderer() {
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != DROP_COLUMN_PLACEHOLDER) {
return this;
}
setIcon(DnDConfigurationPanel.ADD_ICON_16);
setText("<drop columns>");
setForeground(isSelected ? Color.white : Color.gray);
return this;
}
});
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selectedItem = jList.getSelectedValue();
if (selectedItem != null && selectedItem instanceof DataColumnSpec) {
DataColumnSpec selectedValue = (DataColumnSpec) selectedItem;
m_defaultListModel.removeElement(selectedValue);
String colName = selectedValue.getName();
List<String> asList = new ArrayList<>(Arrays.asList(m_setting.getNames()));
asList.remove(colName);
if (asList.isEmpty()) {
firePropertyChange(REMOVE_ACTION, null, null);
} else {
firePropertyChange(REMOVED_COLUMNS, null, new DataColumnSpec[] { selectedValue });
DataColumnSpec[] currSpecs = new DataColumnSpec[m_defaultListModel.size() - 1];
// let the last item go
for (int i = 0; i < m_defaultListModel.size() - 1; i++) {
currSpecs[i] = (DataColumnSpec) m_defaultListModel.get(i);
}
if (isInvalid(selectedValue)) {
DataValidatorColPanel.this.removeAll();
createContent(Arrays.asList(currSpecs));
} else {
updateUiElements(Arrays.asList(currSpecs));
DataValidatorColPanel.this.repaint();
}
}
m_setting.setNames(asList.toArray(new String[asList.size()]));
}
}
}
});
JScrollPane columns = new JScrollPane(jList);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(10, 10, 10, 10);
c.gridx = 0;
c.gridy = 1;
c.gridheight = 2;
c.weightx = 1;
tabPanel.add(columns, c);
}
use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.
the class ParameterizedDBQueryPanel method createColumnsAndVariablesPanel.
private JComponent createColumnsAndVariablesPanel() {
/* Create database column list */
final JPanel dbColumnsPanel = new JPanel(new BorderLayout());
dbColumnsPanel.setPreferredSize(new Dimension(200, 150));
final JLabel dbColumnsLabel = new JLabel("Database Column List");
dbColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
dbColumnsPanel.add(dbColumnsLabel, BorderLayout.NORTH);
dbColumnsPanel.add(new JScrollPane(m_dbColumnsList), BorderLayout.CENTER);
m_dbColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_dbColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_dbColumnsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInDatabaseList();
}
}
});
m_dbColumnsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInDatabaseList();
}
}
});
/* Create Knime column list */
final JPanel knimeColumnsPanel = new JPanel(new BorderLayout());
knimeColumnsPanel.setPreferredSize(new Dimension(200, 150));
final JLabel knimeColumnsLabel = new JLabel("Column List");
knimeColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
knimeColumnsPanel.add(knimeColumnsLabel, BorderLayout.NORTH);
knimeColumnsPanel.add(new JScrollPane(m_knimeColumnsList), BorderLayout.CENTER);
m_knimeColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_knimeColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_knimeColumnsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInColumnList();
}
}
});
m_knimeColumnsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInColumnList();
}
}
});
final JSplitPane columnsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
columnsSplitPane.setResizeWeight(0.5);
columnsSplitPane.setOneTouchExpandable(true);
columnsSplitPane.setDividerSize(8);
columnsSplitPane.setTopComponent(dbColumnsPanel);
columnsSplitPane.setBottomComponent(knimeColumnsPanel);
columnsSplitPane.setDividerLocation(150);
/* Create flow variables list*/
final JPanel variablesPanel = new JPanel(new BorderLayout());
variablesPanel.setPreferredSize(new Dimension(200, 150));
final JLabel variablesLabel = new JLabel("Flow Variable List");
variablesLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
variablesPanel.add(variablesLabel, BorderLayout.NORTH);
variablesPanel.add(new JScrollPane(m_flowVariablesList), BorderLayout.CENTER);
m_flowVariablesList.setCellRenderer(new FlowVariableListCellRenderer());
m_flowVariablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_flowVariablesList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInFlowVariableList();
}
}
});
m_flowVariablesList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInFlowVariableList();
}
}
});
final JSplitPane columnsVariableSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
columnsVariableSplitPane.setResizeWeight(0.5);
columnsVariableSplitPane.setOneTouchExpandable(true);
columnsVariableSplitPane.setDividerSize(8);
columnsVariableSplitPane.setTopComponent(columnsSplitPane);
columnsVariableSplitPane.setBottomComponent(variablesPanel);
columnsVariableSplitPane.setDividerLocation(300);
return columnsVariableSplitPane;
}
Aggregations