use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class WorkflowVariablesDialog method editWorkflowVariable.
private void editWorkflowVariable(final FlowVariable selectedVar, final int selectionIdx) {
if (selectedVar.isGlobalConstant()) {
MessageDialog.openError(getParentShell(), "Global Constant", selectedVar.getName() + " is a global constant " + "and cannot be modified!");
return;
}
WorkflowVariablesEditDialog dialog = new WorkflowVariablesEditDialog();
dialog.create();
dialog.loadFrom(selectedVar);
if (dialog.open() == Window.CANCEL) {
// if the user has canceled the dialog there is nothing left to do
return;
}
// else replace it...
FlowVariable var = dialog.getScopeVariable();
if (var != null) {
m_table.replace(selectionIdx, var);
m_table.getViewer().refresh();
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class WorkflowVariablesDialog method replaceWorkflowVariables.
private void replaceWorkflowVariables(final boolean skipReset) {
List<FlowVariable> toBeRemoved = new ArrayList<FlowVariable>();
toBeRemoved.addAll(m_workflow.getWorkflowVariables());
toBeRemoved.removeAll(m_table.getVariables());
for (FlowVariable v : toBeRemoved) {
m_workflow.removeWorkflowVariable(v.getName());
}
// replace
FlowVariable[] vars = new FlowVariable[m_table.getVariables().size()];
m_workflow.addWorkflowVariables(skipReset, m_table.getVariables().toArray(vars));
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class WorkflowVariablesEditDialog method okPressed.
/**
* {@inheritDoc}
*/
@Override
protected void okPressed() {
String varName = m_varNameCtrl.getText().trim();
if (varName.isEmpty()) {
String msg = "Variable name must not be empty!";
showError(msg);
throw new OperationCanceledException(msg);
}
String value = m_varDefaultValueCtrl.getText().trim();
if (value.isEmpty()) {
String msg = "A default value must be entered!";
showError(msg);
throw new OperationCanceledException(msg);
}
int selectionIdx = m_typeSelectionCtrl.getSelectionIndex();
if (selectionIdx < 0) {
String msg = "No type selected for variable " + varName;
showError(msg);
throw new IllegalArgumentException(msg);
}
String typeString = m_typeSelectionCtrl.getItem(selectionIdx);
m_type = FlowVariable.Type.valueOf(typeString);
if (FlowVariable.Type.DOUBLE.equals(m_type)) {
try {
m_variable = new FlowVariable(varName, Double.parseDouble(value));
} catch (NumberFormatException nfe) {
m_variable = null;
String msg = "Invalid default value " + value + " for variable " + varName + "!";
showError(msg);
throw new OperationCanceledException(msg);
}
} else if (FlowVariable.Type.STRING.equals(m_type)) {
m_variable = new FlowVariable(varName, value);
} else if (FlowVariable.Type.INTEGER.equals(m_type)) {
try {
m_variable = new FlowVariable(varName, Integer.parseInt(value));
} catch (NumberFormatException nfe) {
m_variable = null;
String msg = "Invalid default value " + value + " for variable " + varName + "!";
showError(msg);
throw new OperationCanceledException(msg);
}
}
super.okPressed();
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class AppendToTableNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
Map<String, FlowVariable> scopeVars = getAvailableFlowVariables();
AppendVariableToTableSettings sets = new AppendVariableToTableSettings();
sets.loadSettingsFrom(settings, scopeVars);
DefaultListModel model = (DefaultListModel) m_list.getModel();
model.removeAllElements();
int[] selIndices = new int[sets.getVariablesOfInterest().size()];
int current = 0;
int pointer = 0;
for (FlowVariable v : scopeVars.values()) {
model.addElement(v);
if (sets.getVariablesOfInterest().contains(new Pair<String, FlowVariable.Type>(v.getName(), v.getType()))) {
selIndices[pointer++] = current;
}
current += 1;
}
selIndices = Arrays.copyOf(selIndices, pointer);
m_list.setSelectedIndices(selIndices);
m_all.setSelected(sets.getIncludeAll());
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class VariableFileReaderNodeSettings method createSettingsFrom.
/**
* Creates a clone from this object replacing the dataURL location by the
* value from stack.
*
* @param stack the map containing all currently available variables and
* their values
* @return a copy of this settings object with the file location replaced by
* the value of the variable
* @throws InvalidSettingsException if the variable is not on the stack
* @throws MalformedURLException if the value of the variable is not a valid
* URL
*/
VariableFileReaderNodeSettings createSettingsFrom(final Map<String, FlowVariable> stack) throws MalformedURLException, InvalidSettingsException {
VariableFileReaderNodeSettings result = new VariableFileReaderNodeSettings(this);
FlowVariable var = stack.get(m_variableName);
if (var == null) {
throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not on the stack.");
}
if (!var.getType().equals(FlowVariable.Type.STRING)) {
throw new InvalidSettingsException("Selected file location variable (" + m_variableName + ") is not of type string.");
}
if (var.getStringValue() == null || var.getStringValue().isEmpty()) {
throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not set. Execute predecessor.");
}
URL loc = FileReaderNodeDialog.textToURL(var.getStringValue());
result.setDataFileLocationAndUpdateTableName(loc);
return result;
}
Aggregations