Search in sources :

Example 1 with AbstractWizardNodeView

use of org.knime.core.node.wizard.AbstractWizardNodeView in project knime-core by knime.

the class OpenInteractiveWebViewAction method run.

@Override
public void run() {
    LOGGER.debug("Open Interactive Web Node View " + m_nodeContainer.getName());
    NativeNodeContainer nativeNC = m_webViewForNode.getNativeNodeContainer();
    try {
        @SuppressWarnings("rawtypes") AbstractWizardNodeView view = null;
        NodeContext.pushContext(nativeNC);
        try {
            NodeModel nodeModel = nativeNC.getNodeModel();
            view = getConfiguredWizardNodeView(nodeModel);
        } finally {
            NodeContext.removeLastContext();
        }
        view.setWorkflowManagerAndNodeID(nativeNC.getParent(), nativeNC.getID());
        final String title = m_webViewForNode.getViewName();
        Node.invokeOpenView(view, title, OpenViewAction.getAppBoundsAsAWTRec());
    } catch (Throwable t) {
        final MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Interactive View cannot be opened");
        mb.setMessage("The interactive view cannot be opened for the following reason:\n" + t.getMessage());
        mb.open();
        LOGGER.error("The interactive view for node '" + nativeNC.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
    }
}
Also used : NodeModel(org.knime.core.node.NodeModel) AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with AbstractWizardNodeView

use of org.knime.core.node.wizard.AbstractWizardNodeView in project knime-core by knime.

the class OpenInteractiveWebViewAction method getConfiguredWizardNodeView.

@SuppressWarnings({ "rawtypes", "unchecked" })
static AbstractWizardNodeView getConfiguredWizardNodeView(final ViewableModel model) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor("org.knime.core.WizardNodeView");
    Class<?> viewClass = null;
    String classString = JSCorePlugin.getDefault().getPreferenceStore().getString(JSCorePlugin.P_VIEW_BROWSER);
    if (StringUtils.isNotEmpty(classString)) {
        // try loading selected view
        viewClass = getViewClassByReflection(classString, configurationElements);
        if (viewClass == null) {
            LOGGER.error("JS view set in preferences (" + classString + ") can't be loaded. Switching to default.");
        }
    }
    if (viewClass == null) {
        // try loading defaults
        viewClass = getViewClassByReflection(CHROMIUM_BROWSER, configurationElements);
        if (viewClass == null) {
            viewClass = getViewClassByReflection(CHROME_BROWSER, configurationElements);
            try {
                Method isChromePresentM = viewClass.getMethod("isChromePresent");
                boolean isChromePresent = (boolean) isChromePresentM.invoke(null);
                if (!isChromePresent) {
                    // no Chrome found on system, defaulting to SWT browser
                    viewClass = null;
                }
            } catch (Exception e) {
            /* do nothing */
            }
        }
    }
    if (viewClass != null) {
        try {
            Method isEnabledM = viewClass.getMethod("isEnabled");
            boolean isEnabled = (boolean) isEnabledM.invoke(null);
            if (!isEnabled) {
                LOGGER.error("JS view (" + classString + ") is not available. Falling back to internal SWT browser.");
                viewClass = null;
            }
        } catch (Exception e) {
        /*do nothing */
        }
    }
    if (viewClass != null) {
        try {
            Constructor<?> constructor = viewClass.getConstructor(ViewableModel.class);
            return (AbstractWizardNodeView) constructor.newInstance(model);
        } catch (Exception e) {
            LOGGER.error("JS view can not be initialized. Falling back to internal SWT browser.");
        }
    }
    return new WizardNodeView(model);
}
Also used : AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) Method(java.lang.reflect.Method) AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) WizardNodeView(org.knime.workbench.editor2.WizardNodeView) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 3 with AbstractWizardNodeView

use of org.knime.core.node.wizard.AbstractWizardNodeView in project knime-core by knime.

the class OpenSubnodeWebViewAction method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    LOGGER.debug("Open Interactive Web Node View " + getSubnodeViewName());
    try {
        @SuppressWarnings("rawtypes") AbstractWizardNodeView view = null;
        NodeContext.pushContext(m_nodeContainer);
        try {
            SubnodeViewableModel model = new SubnodeViewableModel(m_nodeContainer, getSubnodeViewName());
            view = OpenInteractiveWebViewAction.getConfiguredWizardNodeView(model);
            model.registerView(view);
        } finally {
            NodeContext.removeLastContext();
        }
        view.setWorkflowManagerAndNodeID(m_nodeContainer.getParent(), m_nodeContainer.getID());
        final String title = m_nodeContainer.getName();
        Node.invokeOpenView(view, title, OpenViewAction.getAppBoundsAsAWTRec());
    } catch (Throwable t) {
        final MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Interactive View cannot be opened");
        mb.setMessage("The interactive view cannot be opened for the following reason:\n" + t.getMessage());
        mb.open();
        LOGGER.error("The interactive view for node '" + m_nodeContainer.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
    }
}
Also used : SubnodeViewableModel(org.knime.core.wizard.SubnodeViewableModel) AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

AbstractWizardNodeView (org.knime.core.node.wizard.AbstractWizardNodeView)3 MessageBox (org.eclipse.swt.widgets.MessageBox)2 Method (java.lang.reflect.Method)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 NodeModel (org.knime.core.node.NodeModel)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 SubnodeViewableModel (org.knime.core.wizard.SubnodeViewableModel)1 WizardNodeView (org.knime.workbench.editor2.WizardNodeView)1