use of org.knime.core.util.KNIMEJob in project knime-core by knime.
the class WorkflowCoachView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
m_viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.FULL_SELECTION) {
@Override
public ISelection getSelection() {
ISelection sel = super.getSelection();
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) sel;
if (ss.getFirstElement() instanceof NodeRecommendation[]) {
// turn node recommendation selection into a node template selection
NodeRecommendation[] nps = (NodeRecommendation[]) ss.getFirstElement();
return new StructuredSelection(new Object[] { getNonNullEntry(nps).getNodeTemplate() });
}
}
return sel;
}
};
getSite().setSelectionProvider(m_viewer);
m_viewer.setComparator(new TableColumnSorter(m_viewer));
Table table = m_viewer.getTable();
// drag & drop
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new WorkflowCoachDragSource(this));
// column configuration
TableColumn column = new TableColumn(table, SWT.LEFT, 0);
column.setText("Recommended Nodes");
column.setToolTipText("Nodes recommended to use next (e.g. based on the currently selected node).");
column.setWidth(200);
table.setHeaderVisible(true);
table.setLinesVisible(false);
m_viewer.setContentProvider(new WorkflowCoachContentProvider());
m_viewer.setLabelProvider(new WorkflowCoachLabelProvider());
m_viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
getViewSite().getPage().addSelectionListener(this);
hookDoubleClickAction();
// actions
IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
toolbarMGR.add(new ConfigureAction(m_viewer));
updateInput("Waiting for node repository to be loaded ...");
m_loadState.set(LoadState.LoadingNodes);
Job nodesLoader = new KNIMEJob("Workflow Coach loader", FrameworkUtil.getBundle(getClass())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
// wait until the repository is fully loaded
RepositoryManager.INSTANCE.getRoot();
if (m_loadState.get() == LoadState.Disposed) {
return Status.CANCEL_STATUS;
} else if (monitor.isCanceled()) {
m_loadState.set(LoadState.Initizalized);
return Status.CANCEL_STATUS;
} else {
// check for update if necessary
updateInput("Loading recommendations...");
checkForStatisticUpdates();
}
m_loadState.set(LoadState.Initizalized);
NodeRecommendationManager.getInstance().addUpdateListener(WorkflowCoachView.this);
updateFrequencyColumnHeadersAndToolTips();
updateInput(StructuredSelection.EMPTY);
return Status.OK_STATUS;
}
};
nodesLoader.setSystem(true);
nodesLoader.schedule();
// if the 'send anonymous statistics'-property has been changed, try updating the workflow coach
KNIMECorePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(e -> {
if (e.getProperty().equals(HeadlessPreferencesConstants.P_SEND_ANONYMOUS_STATISTICS)) {
if (e.getNewValue().equals(Boolean.TRUE)) {
// enable the community recommendations
PREFS.setValue(WorkflowCoachPreferenceInitializer.P_COMMUNITY_NODE_TRIPLE_PROVIDER, true);
try {
PREFS.save();
} catch (Exception e1) {
throw new RuntimeException(e1);
}
updateInput(StructuredSelection.EMPTY);
}
}
});
}
Aggregations