Search in sources :

Example 1 with UpdatableNodeTripleProvider

use of org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider in project knime-core by knime.

the class UpdateJob method run.

/**
 * {@inheritDoc}
 */
@Override
protected IStatus run(final IProgressMonitor monitor) {
    Exception exception = null;
    for (UpdatableNodeTripleProvider ntp : m_providers) {
        try {
            ntp.update();
        } catch (Exception e) {
            if (exception == null) {
                exception = e;
            }
        }
    }
    monitor.done();
    if (exception == null) {
        m_listener.updateFinished(Optional.empty());
        return Status.OK_STATUS;
    } else {
        m_listener.updateFinished(Optional.of(exception));
        // don't return IStatus.ERROR -> otherwise an annoying error message will be opened
        return new Status(IStatus.OK, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error while updating the statistics for the node recommendations (Workflow Coach).", exception);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)

Example 2 with UpdatableNodeTripleProvider

use of org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider in project knime-core by knime.

the class WorkflowCoachPreferencePage method onUpate.

/**
 * Called when the update button has been pressed.
 */
private void onUpate() {
    Display.getDefault().syncExec(() -> {
        m_updateButton.setEnabled(false);
        m_lastUpdate.setText("Updating ...");
        m_lastUpdate.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
        setValid(false);
    });
    // update the currently enabled providers
    List<UpdatableNodeTripleProvider> toUpdate = new ArrayList<>();
    for (NodeTripleProvider ntp : NodeRecommendationManager.getInstance().getNodeTripleProviders()) {
        if (m_checkCommunityProvider.getSelection() && (ntp instanceof CommunityTripleProvider)) {
            toUpdate.add((CommunityTripleProvider) ntp);
        }
    }
    UpdateJob.schedule(e -> {
        if (e.isPresent()) {
            Display.getDefault().syncExec(() -> {
                m_updateButton.setEnabled(true);
                m_lastUpdate.setText("Update failed.");
                setErrorMessage("Error loading the community node recommendations:" + e.get().getMessage() + ". Please check your internet connection.");
                if (!m_checkCommunityProvider.getSelection()) {
                    setValid(true);
                }
            });
        } else {
            Display.getDefault().syncExec(() -> {
                m_updateButton.setEnabled(true);
                m_lastUpdate.setText("Update finished!");
                setValid(true);
                setErrorMessage(null);
            });
        }
    }, toUpdate, false);
}
Also used : CommunityTripleProvider(org.knime.workbench.workflowcoach.data.CommunityTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) ArrayList(java.util.ArrayList) NodeTripleProvider(org.knime.workbench.workflowcoach.data.NodeTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)

Example 3 with UpdatableNodeTripleProvider

use of org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider in project knime-core by knime.

the class WorkflowCoachView method updateTripleProviders.

/**
 * Updates all updatable and enabled triple providers.
 *
 * @param requiredOnly if only the enabled triple providers should be updated that require an update in order to
 *            work
 * @param updateListener to get feedback of the updating process
 * @param block if <code>true</code> the method will block till the update is finished, otherwise it will return
 *            immediately after triggering the update job
 */
private void updateTripleProviders(final UpdateListener updateListener, final boolean requiredOnly, final boolean block) {
    List<UpdatableNodeTripleProvider> toUpdate = NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().filter(ntp -> {
        if (!(ntp instanceof UpdatableNodeTripleProvider)) {
            return false;
        } else {
            UpdatableNodeTripleProvider untp = (UpdatableNodeTripleProvider) ntp;
            return ntp.isEnabled() && (!requiredOnly || untp.updateRequired());
        }
    }).map(ntp -> (UpdatableNodeTripleProvider) ntp).collect(Collectors.toList());
    UpdateJob.schedule(updateListener, toUpdate, block);
}
Also used : Arrays(java.util.Arrays) IUpdateListener(org.knime.workbench.workflowcoach.NodeRecommendationManager.IUpdateListener) TableViewer(org.eclipse.jface.viewers.TableViewer) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) DND(org.eclipse.swt.dnd.DND) TableColumn(org.eclipse.swt.widgets.TableColumn) IToolBarManager(org.eclipse.jface.action.IToolBarManager) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IStatus(org.eclipse.core.runtime.IStatus) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Cursor(org.eclipse.swt.graphics.Cursor) IEditorPart(org.eclipse.ui.IEditorPart) NodeProvider(org.knime.workbench.core.nodeprovider.NodeProvider) KNIMEJob(org.knime.core.util.KNIMEJob) CommunityTripleProvider(org.knime.workbench.workflowcoach.data.CommunityTripleProvider) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) NodeModel(org.knime.core.node.NodeModel) Collectors(java.util.stream.Collectors) WorkflowCoachPreferenceInitializer(org.knime.workbench.workflowcoach.prefs.WorkflowCoachPreferenceInitializer) RepositoryManager(org.knime.workbench.repository.RepositoryManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Transfer(org.eclipse.swt.dnd.Transfer) IElementComparer(org.eclipse.jface.viewers.IElementComparer) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) MouseListener(org.eclipse.swt.events.MouseListener) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Wrapper(org.knime.core.ui.wrapper.Wrapper) SWT(org.eclipse.swt.SWT) Optional(java.util.Optional) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MouseAdapter(org.eclipse.swt.events.MouseAdapter) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) ViewPart(org.eclipse.ui.part.ViewPart) WorkflowEditor(org.knime.workbench.editor2.WorkflowEditor) LocalDateTime(java.time.LocalDateTime) Table(org.eclipse.swt.widgets.Table) AtomicReference(java.util.concurrent.atomic.AtomicReference) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Pair(org.knime.core.util.Pair) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UpdateJob(org.knime.workbench.workflowcoach.prefs.UpdateJob) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) NodeLogger(org.knime.core.node.NodeLogger) GridData(org.eclipse.swt.layout.GridData) NodeRecommendationManager(org.knime.workbench.workflowcoach.NodeRecommendationManager) HeadlessPreferencesConstants(org.knime.workbench.core.preferences.HeadlessPreferencesConstants) NodeFactory(org.knime.core.node.NodeFactory) CombinatoricsUtils(org.apache.commons.math3.util.CombinatoricsUtils) Iterator(java.util.Iterator) Job(org.eclipse.core.runtime.jobs.Job) KNIMECorePlugin(org.knime.workbench.core.KNIMECorePlugin) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) ChronoUnit(java.time.temporal.ChronoUnit) UpdateListener(org.knime.workbench.workflowcoach.prefs.UpdateJob.UpdateListener) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) Comparator(java.util.Comparator) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)

Aggregations

UpdatableNodeTripleProvider (org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)3 ArrayList (java.util.ArrayList)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 CommunityTripleProvider (org.knime.workbench.workflowcoach.data.CommunityTripleProvider)2 LocalDateTime (java.time.LocalDateTime)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 CombinatoricsUtils (org.apache.commons.math3.util.CombinatoricsUtils)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1