Search in sources :

Example 6 with KNIMEJob

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);
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableColumn(org.eclipse.swt.widgets.TableColumn) KNIMEJob(org.knime.core.util.KNIMEJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ISelection(org.eclipse.jface.viewers.ISelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) GridData(org.eclipse.swt.layout.GridData) KNIMEJob(org.knime.core.util.KNIMEJob) UpdateJob(org.knime.workbench.workflowcoach.prefs.UpdateJob) Job(org.eclipse.core.runtime.jobs.Job) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Job (org.eclipse.core.runtime.jobs.Job)6 KNIMEJob (org.knime.core.util.KNIMEJob)6 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)3 Transfer (org.eclipse.swt.dnd.Transfer)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Cursor (org.eclipse.swt.graphics.Cursor)1 GridData (org.eclipse.swt.layout.GridData)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 Root (org.knime.workbench.repository.model.Root)1 RepositoryContentProvider (org.knime.workbench.repository.view.RepositoryContentProvider)1 RepositoryLabelProvider (org.knime.workbench.repository.view.RepositoryLabelProvider)1 NodeRecommendation (org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation)1