use of javax.swing.DefaultComboBoxModel in project knime-core by knime.
the class StringManipulationNodeDialog method createStringManipulationPanel.
/**
* @return the controls for the string manipulation node
* @since 3.3
*/
public Component createStringManipulationPanel() {
m_snippetPanel = new JSnippetPanel(StringManipulatorProvider.getDefault(), createCompletionProvider(), !m_isOnlyVariables);
m_newNameField = new JTextField(10);
String radioButtonName;
String radioButtonToolTip;
radioButtonName = "Append " + WordUtils.capitalize(m_columnOrVariable) + ": ";
radioButtonToolTip = "Appends a new " + m_columnOrVariable + " to the input with a given name.";
m_appendRadio = new JRadioButton(radioButtonName);
m_appendRadio.setToolTipText(radioButtonToolTip);
radioButtonName = "Replace " + WordUtils.capitalize(m_columnOrVariable) + ": ";
if (m_isOnlyVariables) {
radioButtonToolTip = "Replaces the " + m_columnOrVariable + " if the type stays the same.";
} else {
radioButtonToolTip = "Replaces the " + m_columnOrVariable + " and changes the " + m_columnOrVariable + " type accordingly.";
}
m_replaceRadio = new JRadioButton(radioButtonName);
m_replaceRadio.setToolTipText(radioButtonToolTip);
if (m_isOnlyVariables) {
// show all variables
m_replaceVariableCombo = new JComboBox<FlowVariable>(new DefaultComboBoxModel<FlowVariable>());
m_replaceVariableCombo.setRenderer(new FlowVariableListCellRenderer());
} else {
// show all columns
m_replaceColumnCombo = new ColumnSelectionPanel((Border) null, DataValue.class);
m_replaceColumnCombo.setRequired(false);
}
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(m_appendRadio);
buttonGroup.add(m_replaceRadio);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (m_isOnlyVariables) {
m_replaceVariableCombo.setEnabled(m_replaceRadio.isSelected());
} else {
m_replaceColumnCombo.setEnabled(m_replaceRadio.isSelected());
}
m_newNameField.setEnabled(m_appendRadio.isSelected());
}
};
m_appendRadio.addActionListener(actionListener);
m_replaceRadio.addActionListener(actionListener);
m_compileOnCloseChecker = new JCheckBox("Syntax check on close");
m_compileOnCloseChecker.setToolTipText("Checks the syntax of the expression on close.");
m_insertMissingAsNullChecker = new JCheckBox("Insert Missing As Null");
m_insertMissingAsNullChecker.setToolTipText("If unselected, missing values in the input will produce a missing cell result");
return createPanel();
}
use of javax.swing.DefaultComboBoxModel in project knime-core by knime.
the class StringManipulationNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
DataTableSpec spec;
if (m_isOnlyVariables) {
spec = new DataTableSpec();
} else {
spec = (DataTableSpec) specs[0];
}
StringManipulationSettings s = new StringManipulationSettings();
s.loadSettingsInDialog(settings, spec);
String exp = s.getExpression();
String defaultNewName = "new " + m_columnOrVariable;
String newName = s.getColName();
boolean isReplace = s.isReplace();
boolean isTestCompilation = s.isTestCompilationOnDialogClose();
boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
m_newNameField.setText("");
final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
if (m_isOnlyVariables) {
DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
cmbModel.removeAllElements();
for (FlowVariable v : availableFlowVariables.values()) {
switch(v.getScope()) {
case Flow:
cmbModel.addElement(v);
break;
default:
}
}
if (availableFlowVariables.containsValue(newName)) {
m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
}
} else {
// will select newColName only if it is in the spec list
try {
m_replaceColumnCombo.update(spec, newName);
} catch (NotConfigurableException e1) {
NodeLogger.getLogger(getClass()).coding("Combo box throws exception although content is not required", e1);
}
}
m_currentSpec = spec;
// whether there are variables or columns available
// -- which of two depends on the customizer
boolean fieldsAvailable;
if (m_isOnlyVariables) {
fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
} else {
fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
}
m_replaceRadio.setEnabled(fieldsAvailable);
if (isReplace && fieldsAvailable) {
m_replaceRadio.doClick();
} else {
m_appendRadio.doClick();
String newNameString = (newName != null ? newName : defaultNewName);
m_newNameField.setText(newNameString);
}
m_snippetPanel.update(exp, spec, availableFlowVariables);
m_compileOnCloseChecker.setSelected(isTestCompilation);
m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
use of javax.swing.DefaultComboBoxModel in project knime-core by knime.
the class ConfigEditTreeNodePanel method setTreeNode.
/**
* Set a new tree node to display.
* @param treeNode the new node to represent (may be null).
*/
public void setTreeNode(final ConfigEditTreeNode treeNode) {
m_treeNode = treeNode;
boolean isEditable = m_treeNode != null && m_treeNode.isLeaf();
Type selType;
String usedVariable;
m_valueField.setEnabled(isEditable);
if (m_treeNode != null) {
AbstractConfigEntry entry = treeNode.getConfigEntry();
switch(entry.getType()) {
case xbyte:
case xlong:
case xshort:
case xint:
selType = Type.INTEGER;
break;
case xdouble:
case xfloat:
selType = Type.DOUBLE;
break;
default:
selType = Type.STRING;
}
Icon icon;
switch(entry.getType()) {
case xstring:
icon = ICON_STRING;
break;
case xdouble:
icon = ICON_DOUBLE;
break;
case xint:
icon = ICON_INT;
break;
default:
icon = ICON_UNKNOWN;
}
m_keyIcon = icon;
m_keyLabel.setText(entry.getKey());
m_keyLabel.setToolTipText(entry.getKey());
usedVariable = m_treeNode.getUseVariableName();
String exposeVariable = m_treeNode.getExposeVariableName();
m_exposeAsVariableField.setText(exposeVariable);
} else {
selType = Type.STRING;
m_keyLabel.setText("");
m_keyLabel.setToolTipText(null);
m_keyIcon = ICON_UNKNOWN;
m_exposeAsVariableField.setText("");
usedVariable = null;
}
m_keyLabel.setMinimumSize(LABEL_DIMENSION);
m_keyLabel.setMaximumSize(LABEL_DIMENSION);
m_keyLabel.setPreferredSize(LABEL_DIMENSION);
m_keyLabel.setSize(LABEL_DIMENSION);
DefaultComboBoxModel model = (DefaultComboBoxModel) m_valueField.getModel();
model.removeAllElements();
model.addElement(" ");
@SuppressWarnings("unchecked") Collection<FlowVariable> allVars = getFlowObjectStack() != null ? getFlowObjectStack().getAvailableFlowVariables().values() : (Collection<FlowVariable>) Collections.EMPTY_LIST;
ComboBoxElement match = null;
for (FlowVariable v : allVars) {
boolean isOk = ConfigEditTreeModel.doesTypeAccept(selType, v.getType());
if (isOk) {
ComboBoxElement cbe = new ComboBoxElement(v);
model.addElement(cbe);
if (v.getName().equals(usedVariable)) {
match = cbe;
}
} else if (v.getName().equals(usedVariable)) {
String error = "Variable \"" + usedVariable + "\" has wrong type (" + v.getType() + "), expected " + selType;
ComboBoxElement cbe = new ComboBoxElement(v, error);
model.addElement(cbe);
match = cbe;
}
}
if (match != null) {
m_valueField.setSelectedItem(match);
} else if (usedVariable != null) {
// show name in variable in arrows; makes also sure to
// not violate the namespace of the variable (could be
// node-local variable, which can't be created outside
// the workflow package)
String errorName = "<" + usedVariable + ">";
String error = "Invalid variable \"" + usedVariable + "\"";
FlowVariable virtualVar;
switch(selType) {
case DOUBLE:
virtualVar = new FlowVariable(errorName, 0.0);
break;
case INTEGER:
virtualVar = new FlowVariable(errorName, 0);
break;
default:
virtualVar = new FlowVariable(errorName, "");
break;
}
ComboBoxElement cbe = new ComboBoxElement(virtualVar, error);
model.addElement(cbe);
m_valueField.setSelectedItem(cbe);
}
m_valueField.setEnabled(model.getSize() > 1);
}
use of javax.swing.DefaultComboBoxModel in project knime-core by knime.
the class ColumnPairsSelectionPanel method addUIControls.
private void addUIControls(final int index, final String leftSelected, final String rightSelected) {
m_leftComboBoxes.add(index, new JComboBox());
m_leftComboBoxes.get(index).setModel(new DefaultComboBoxModel());
ColumnComboBoxRenderer renderer = new ColumnComboBoxRenderer();
renderer.attachTo(m_leftComboBoxes.get(index));
initComboBox(m_specs[0], m_leftComboBoxes.get(index), leftSelected);
m_rightComboBoxes.add(index, new JComboBox());
m_rightComboBoxes.get(index).setModel(new DefaultComboBoxModel());
renderer = new ColumnComboBoxRenderer();
renderer.attachTo(m_rightComboBoxes.get(index));
initComboBox(m_specs[1], m_rightComboBoxes.get(index), rightSelected);
JButton addButton = new JButton("+");
addButton.setToolTipText("Add row preceding this.");
addButton.addActionListener(m_addButtonListener);
m_addButtons.add(index, addButton);
JButton removeButton = new JButton("-");
removeButton.addActionListener(m_removeButtonListener);
removeButton.setToolTipText("Remove this row.");
m_removeButtons.add(index, removeButton);
// if the first row was added
if (m_leftComboBoxes.size() == 1) {
m_persistentAddButton.setText("+");
}
}
use of javax.swing.DefaultComboBoxModel in project knime-core by knime.
the class StringHistoryPanel method updateHistory.
/**
* Updates the elements in the combo box, reads the file history.
*/
public void updateHistory() {
StringHistory history = StringHistory.getInstance(m_historyID);
String[] allVals = history.getHistory();
DefaultComboBoxModel comboModel = (DefaultComboBoxModel) m_textBox.getModel();
comboModel.removeAllElements();
for (String s : allVals) {
comboModel.addElement(s);
}
// changing the model will also change the minimum size to be
// quite big. We have tooltips, we don't need that
Dimension newMin = new Dimension(0, getPreferredSize().height);
setMinimumSize(newMin);
}
Aggregations