use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeOutputView method workflowChanged.
/**
* {@inheritDoc}
*/
@Override
public void workflowChanged(final WorkflowEvent event) {
if (event.getType() == Type.NODE_REMOVED) {
// unregister from the node removed
Object oldValue = event.getOldValue();
if (oldValue instanceof NodeContainer) {
NodeContainer oldNode = (NodeContainer) oldValue;
if (oldNode.getID().equals(m_workflow.getID())) {
// our flow got removed (i.e. the editor or the workbench is closed)
disconnectFromWFM();
m_lastNode = null;
m_workflow = null;
m_parentWfm = null;
updateNCinfoInSWT(null);
return;
}
if (oldNode.getID().equals(m_lastNode)) {
oldNode.removeNodeStateChangeListener(this);
// pinned node is gone: unpin
m_pinButton.setChecked(false);
}
}
return;
}
if (!m_pinned || (m_pinned && !m_branchLocked)) {
return;
}
Type type = event.getType();
if (type == Type.CONNECTION_ADDED) {
ConnectionContainer cc = (ConnectionContainer) event.getNewValue();
if (cc.getSource().equals(m_lastNode)) {
if (m_workflow.getOutgoingConnectionsFor(m_lastNode).size() == 1) {
if (m_workflow.containsNodeContainer(cc.getDest())) {
// could be an outgoing metanode connection
// first connection: follow this new branch extension
updateNCinfoInSWT(cc.getDest());
}
}
}
} else if (type == Type.CONNECTION_REMOVED) {
ConnectionContainer cc = (ConnectionContainer) event.getOldValue();
if (cc.getDest().equals(m_lastNode)) {
if (m_workflow.containsNodeContainer(m_lastNode)) {
if (m_workflow.getOutgoingConnectionsFor(m_lastNode).size() == 0) {
updateNCinfoInSWT(cc.getSource());
}
} else {
updateNCinfoInSWT(cc.getSource());
}
}
} else {
return;
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeOutputView method updateNodeContainerInfo.
/* Update all visuals with information regarding new NodeContainer.
* Also de-register previous node and register with the new one if
* the underlying NC changed.
*/
private void updateNodeContainerInfo(final NodeID nc) {
if (m_portIndex.getCombo().isDisposed()) {
return;
}
if (nc == null) {
showErrorAndClear("");
return;
}
m_portIndex.getCombo().setEnabled(false);
assert Display.getCurrent().getThread() == Thread.currentThread();
if ((m_lastNode != null) && (m_lastNode != nc)) {
if (m_workflow.containsNodeContainer(m_lastNode)) {
NodeContainer last = m_workflow.getNodeContainer(m_lastNode);
last.removeNodeStateChangeListener(NodeOutputView.this);
}
}
NodeContainer node = m_workflow.getNodeContainer(nc);
if ((m_lastNode == null) || (m_lastNode != nc)) {
m_lastNode = nc;
node.addNodeStateChangeListener(NodeOutputView.this);
setPartName(node.getNameWithID());
}
m_title.setText(node.getName() + " (" + node.getID() + ")");
switch(m_choice) {
case VARS:
updateVariableTable(node);
break;
case SETTINGS:
case ALLSETTINGS:
updateSettingsTable(node, DISPLAYOPTIONS.ALLSETTINGS.equals(m_choice));
break;
case TABLE:
m_portIndex.getCombo().setEnabled(true);
int nrPorts = node.getNrOutPorts();
if (node instanceof SingleNodeContainer) {
// correct for (default - mostly invisible) Variable Port
nrPorts--;
}
String[] vals = new String[nrPorts];
for (int i = 0; i < nrPorts; i++) {
vals[i] = "Port " + i;
}
m_portIndex.getCombo().removeAll();
m_portIndex.getCombo().setItems(vals);
m_portIndex.getCombo().select(0);
updateDataTable(node, 0);
break;
case GRAPHANNOTATIONS:
updateGraphAnnotationTable(node);
break;
default:
throw new AssertionError("Unhandled switch case: " + m_choice);
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeOutputView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
// Toolbar
IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
// create button for stick with branch.
final RetargetAction lockAction = new RetargetAction("StayOnBranch", "Pin view to new node added to branch", IAction.AS_CHECK_BOX);
lockAction.setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "icons/lock.png"));
lockAction.setChecked(m_branchLocked);
lockAction.setEnabled(m_pinned);
lockAction.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (lockAction.isChecked()) {
m_branchLocked = true;
m_selectionWhenLocked = m_lastSelection;
} else {
m_branchLocked = false;
selectionChanged(null, m_lastSelectionWhilePinned);
}
}
});
toolbarMGR.add(lockAction);
// create button which allows to "pin" selection:
m_pinButton = new RetargetAction("PinView", "Pin view to selected node", IAction.AS_CHECK_BOX);
m_pinButton.setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "icons/pin.png"));
m_pinButton.setChecked(m_pinned);
m_pinButton.setEnabled(true);
m_pinButton.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (m_pinButton.isChecked()) {
m_pinned = true;
m_lastSelectionWhilePinned = m_lastSelection;
lockAction.setEnabled(true);
} else {
m_pinned = false;
selectionChanged(null, m_lastSelectionWhilePinned);
lockAction.setEnabled(false);
}
}
});
toolbarMGR.add(m_pinButton);
toolbarMGR.add(new Separator());
// configure drop down menu
IMenuManager dropDownMenu = getViewSite().getActionBars().getMenuManager();
// drop down menu entry for outport table:
final RetargetAction menuentrytable = new RetargetAction("OutputTable", "Show Output Table", IAction.AS_RADIO_BUTTON);
menuentrytable.setChecked(DISPLAYOPTIONS.TABLE.equals(m_choice));
menuentrytable.setEnabled(true);
menuentrytable.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrytable.isChecked()) {
m_choice = DISPLAYOPTIONS.TABLE;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrytable);
// drop down menu entry for node variables:
final RetargetAction dropdownmenuvars = new RetargetAction("NodeVariables", "Show Variables", IAction.AS_RADIO_BUTTON);
dropdownmenuvars.setChecked(DISPLAYOPTIONS.VARS.equals(m_choice));
dropdownmenuvars.setEnabled(true);
dropdownmenuvars.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (dropdownmenuvars.isChecked()) {
m_choice = DISPLAYOPTIONS.VARS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(dropdownmenuvars);
// drop down menu entry for configuration/settings:
final RetargetAction menuentrysettings = new RetargetAction("NodeConf", "Show Configuration", IAction.AS_RADIO_BUTTON);
menuentrysettings.setChecked(DISPLAYOPTIONS.SETTINGS.equals(m_choice));
menuentrysettings.setEnabled(true);
menuentrysettings.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrysettings.isChecked()) {
m_choice = DISPLAYOPTIONS.SETTINGS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrysettings);
// drop down menu entry for configuration/settings:
final RetargetAction menuentryallsettings = new RetargetAction("NodeConfAll", "Show Entire Configuration", IAction.AS_RADIO_BUTTON);
menuentryallsettings.setChecked(DISPLAYOPTIONS.ALLSETTINGS.equals(m_choice));
menuentryallsettings.setEnabled(true);
menuentryallsettings.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentryallsettings.isChecked()) {
m_choice = DISPLAYOPTIONS.ALLSETTINGS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentryallsettings);
// drop down menu entry for node graph annotations
final RetargetAction menuentrygraphannotations = new RetargetAction("NodeGraphAnno", "Show Graph Annotations", IAction.AS_RADIO_BUTTON);
menuentrygraphannotations.setChecked(DISPLAYOPTIONS.GRAPHANNOTATIONS.equals(m_choice));
menuentrygraphannotations.setEnabled(true);
menuentrygraphannotations.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrygraphannotations.isChecked()) {
m_choice = DISPLAYOPTIONS.GRAPHANNOTATIONS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrygraphannotations);
// Content
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
// Node Title:
Label titlelabel = new Label(parent, SWT.NONE);
titlelabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
titlelabel.setText("Node: ");
m_title = new Text(parent, SWT.BORDER);
m_title.setEditable(false);
m_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
m_title.setText("n/a.");
// Panel for currently displayed information (some information
// providers will add more elements to this):
Composite infoPanel = new Composite(parent, SWT.NONE);
GridData infoGrid = new GridData(SWT.FILL, SWT.TOP, true, false);
infoGrid.horizontalSpan = 2;
infoPanel.setLayoutData(infoGrid);
GridLayoutFactory.swtDefaults().numColumns(3).applyTo(infoPanel);
m_info = new Label(infoPanel, SWT.NONE);
m_info.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
m_info.setText("n/a. ");
m_portIndex = new ComboViewer(infoPanel);
m_portIndex.add(new String[] { "port 0", "port 1", "port 2" });
m_portIndex.getCombo().setEnabled(false);
m_portIndex.getCombo().setSelection(new Point(m_portIndexInit, m_portIndexInit));
m_portIndex.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ISelection sel = event.getSelection();
try {
int newIndex = Integer.parseInt(sel.toString().substring(5).replace(']', ' ').trim());
NodeContainer node;
if (m_workflow.containsNodeContainer(m_lastNode)) {
node = m_workflow.getNodeContainer(m_lastNode);
updateDataTable(node, newIndex);
}
} catch (NumberFormatException nfe) {
// ignore.
}
}
});
// Table:
// stack panel switches between KNIME data table view and SWT table for other info
m_stackPanel = new Composite(parent, SWT.NONE);
m_stackPanel.setLayout(new StackLayout());
GridData tableGrid = new GridData(SWT.FILL, SWT.FILL, true, true);
m_stackPanel.setLayoutData(tableGrid);
// DataTable view wrapped in AWT-SWT bridge
m_tableView = new TableView();
m_tableViewPanel = new Panel2CompositeWrapper(m_stackPanel, m_tableView, SWT.NONE);
m_errorLabel = new Label(m_stackPanel, SWT.NONE);
// SWT Table for the other info
m_table = new Table(m_stackPanel, SWT.MULTI | SWT.BORDER);
m_table.setLinesVisible(true);
m_table.setHeaderVisible(true);
tableGrid.horizontalSpan = 2;
m_table.setLayoutData(tableGrid);
String[] titles = { "Name", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
for (int i = 0; i < titles.length; i++) {
m_table.getColumn(i).pack();
}
m_lastNode = null;
getViewSite().getPage().addSelectionListener(this);
if (m_choice.equals(DISPLAYOPTIONS.TABLE)) {
((StackLayout) m_stackPanel.getLayout()).topControl = m_tableViewPanel;
m_stackPanel.layout();
} else {
((StackLayout) m_stackPanel.getLayout()).topControl = m_table;
m_stackPanel.layout();
}
m_stackPanel.layout();
selectionChanged(null, m_lastSelection);
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeOutputView method selectionChanged.
/**
* The method updating the content of the monitor.
*
* {@inheritDoc}
*/
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (!(selection instanceof IStructuredSelection)) {
// showErrorAndClear("");
return;
}
IStructuredSelection structSel = (IStructuredSelection) selection;
if (m_pinned) {
m_lastSelectionWhilePinned = structSel;
if (m_branchLocked && m_selectionWhenLocked == null) {
m_selectionWhenLocked = structSel;
}
return;
}
if (structSel.equals(m_lastSelection)) {
// selection hasn't changed - return.
return;
}
m_lastSelection = structSel;
if (structSel.size() < 1) {
// Nothing selected
showErrorAndClear("No node selected");
return;
}
if (structSel.size() > 1) {
// too many selected items
showErrorAndClear("Multiple elements selected");
return;
}
// retrieve first (and only!) selection:
Iterator<?> selIt = structSel.iterator();
Object sel = selIt.next();
//
if (sel instanceof NodeContainerEditPart) {
// a NodeContainer was selected, display it's name and status
NodeContainer nc = Wrapper.unwrapNC(((NodeContainerEditPart) sel).getNodeContainer());
WorkflowManager wfm = nc.getParent();
checkWorkflowManagerListener(wfm);
updateNodeContainerInfo(nc.getID());
} else if (sel instanceof WorkflowInPortBarEditPart) {
WorkflowManager wfm = Wrapper.unwrapWFM(((WorkflowInPortBarEditPart) sel).getNodeContainer());
checkWorkflowManagerListener(wfm);
} else {
// unsupported selection
showErrorAndClear("No info available for this selection");
return;
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ReconfigureMetaNodeCommand method canExecute.
/**
* {@inheritDoc}
*/
@Override
public boolean canExecute() {
if (!super.canExecute()) {
return false;
}
if (m_metanodeID == null) {
return false;
}
NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
boolean isWriteProtected;
if (nc instanceof WorkflowManager) {
isWriteProtected = ((WorkflowManager) nc).isWriteProtected();
} else if (nc instanceof SubNodeContainer) {
isWriteProtected = ((SubNodeContainer) nc).isWriteProtected();
} else {
return false;
}
if (!(nc instanceof WorkflowManager) && !(nc instanceof SubNodeContainer)) {
return false;
}
if (isWriteProtected) {
return false;
}
// at least one thing to change should be set
return (m_inPorts != null || m_outPorts != null || m_name != null);
}
Aggregations