use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class WorkflowCoachDragSource method dragStart.
/**
* {@inheritDoc}
*/
@Override
public void dragStart(final DragSourceEvent event) {
IStructuredSelection sel = (IStructuredSelection) m_view.getSelection();
event.detail = DND.DROP_COPY;
// selected
if (!(sel.getFirstElement() instanceof NodeTemplate) || (sel.size() != 1)) {
event.doit = false;
} else {
event.doit = true;
LocalSelectionTransfer.getTransfer().setSelection(sel);
}
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class AbstractRepositoryView method hookDoubleClickAction.
private void hookDoubleClickAction() {
m_viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(final DoubleClickEvent event) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof NodeTemplate) {
NodeTemplate tmplt = (NodeTemplate) o;
NodeFactory<? extends NodeModel> nodeFact;
try {
nodeFact = tmplt.createFactoryInstance();
} catch (Exception e) {
LOGGER.error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
return;
}
boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
if (added) {
NodeUsageRegistry.addNode(tmplt);
}
} else if (o instanceof MetaNodeTemplate) {
MetaNodeTemplate mnt = (MetaNodeTemplate) o;
NodeID metaNode = mnt.getManager().getID();
NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
} else if (o instanceof Category) {
m_viewer.setExpandedState(o, !m_viewer.getExpandedState(o));
}
}
});
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class AbstractRepositoryView method enrichWithAdditionalInfo.
/**
* This methods recursively retrieves and enriches the repository objects with additional information,
* e.g. number of ports, whether the node is streamable and/or distributable, etc.
* Should be called only after the repository content was already loaded with {@link #readRepository(Composite, IProgressMonitor)}.
*/
protected void enrichWithAdditionalInfo(final IRepositoryObject parent, final IProgressMonitor monitor, final boolean updateTreeStructure) {
if (monitor.isCanceled()) {
return;
}
if (!m_additionalInfoAvailable) {
if (parent instanceof IContainerObject) {
IRepositoryObject[] children = ((IContainerObject) parent).getChildren();
for (IRepositoryObject child : children) {
enrichWithAdditionalInfo(child, monitor, updateTreeStructure);
}
} else if (parent instanceof NodeTemplate) {
NodeTemplate nodeTemplate = (NodeTemplate) parent;
try {
NodeFactory<? extends NodeModel> nf = nodeTemplate.createFactoryInstance();
NodeModel nm = nf.createNodeModel();
// check whether the current node model overrides the #createStreamableOperator-method
Method m = nm.getClass().getMethod("createStreamableOperator", PartitionInfo.class, PortObjectSpec[].class);
if (m.getDeclaringClass() != NodeModel.class) {
// method has been overriden -> node is probably streamable or distributable
nodeTemplate.addAdditionalInfo(KEY_INFO_STREAMABLE, "streamable");
}
// possible TODO: parse xml description and get some more additional information (e.g. short description, ...)
// nodeTemplate.addAdditionalInfo(KEY_INFO_SHORT_DESCRIPTION,
// "this could be the short description, number of ports etc.");
} catch (Throwable t) {
LOGGER.error("Unable to instantiate the node " + nodeTemplate.getFactory().getName(), t);
return;
}
if (!updateTreeStructure) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!m_viewer.getControl().isDisposed()) {
m_viewer.update(parent, null);
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!m_viewer.getControl().isDisposed()) {
m_viewer.update(parent, null);
TreeViewerUpdater.update(m_viewer, true, false);
}
}
});
}
}
}
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class FavoriteNodesDragSource method dragStart.
/**
* {@inheritDoc}
*/
public void dragStart(final DragSourceEvent event) {
IStructuredSelection sel = (IStructuredSelection) m_view.getSelection();
LocalSelectionTransfer.getTransfer().setSelection(sel);
event.detail = DND.DROP_COPY;
// selected
if (!(sel.getFirstElement() instanceof NodeTemplate) || (sel.size() != 1)) {
event.doit = false;
} else {
event.doit = true;
}
}
use of org.knime.workbench.repository.model.NodeTemplate in project knime-core by knime.
the class FavoriteNodesManager method loadFavoriteNodes.
private void loadFavoriteNodes(final XMLMemento favoriteNodes) {
IMemento favNodes = favoriteNodes.getChild(TAG_PERSONAL_FAVS);
for (IMemento favNode : favNodes.getChildren(TAG_FAVORITE)) {
String id = favNode.getString(TAG_NODE_ID);
NodeTemplate node = RepositoryManager.INSTANCE.getNodeTemplate(id);
if (node != null) {
addFavoriteNode(node);
}
}
IMemento freqNodes = favoriteNodes.getChild(TAG_MOST_FREQUENT);
NodeUsageRegistry.loadFrequentNodes(freqNodes);
IMemento lastNodes = favoriteNodes.getChild(TAG_LAST_USED);
NodeUsageRegistry.loadLastUsedNodes(lastNodes);
updateNodes();
}
Aggregations