Search in sources :

Example 1 with SubnodeViewableModel

use of org.knime.core.wizard.SubnodeViewableModel in project knime-core by knime.

the class TestSubnodeView method testSubnodeViewableModel.

/**
 * Creates and tests the {@link SubnodeViewableModel}
 * @throws Exception
 */
@Test
public void testSubnodeViewableModel() throws Exception {
    initialExecute();
    SubNodeContainer snc = getManager().getNodeContainer(m_subnodeID, SubNodeContainer.class, true);
    SubnodeViewableModel svm = new SubnodeViewableModel(snc, "testView");
    JSONWebNodePage page = svm.getViewRepresentation();
    validateJSONPage(page);
    SubnodeViewValue viewValue = svm.getViewValue();
    assertNotNull("Combined view value should exist", viewValue);
    assertNotNull("Combined view value map should exist", viewValue.getViewValues());
    assertEquals("Combined view value should contain three entries", 3, viewValue.getViewValues().size());
    Map<String, String> changedValueMap = new HashMap<String, String>(3);
    changedValueMap.putAll(viewValue.getViewValues());
    changedValueMap = changeStringInputTo("foo", changedValueMap);
    SubnodeViewValue newViewValue = new SubnodeViewValue();
    newViewValue.setViewValues(changedValueMap);
    ValidationError validationError = svm.validateViewValue(newViewValue);
    assertTrue("Validation error should be instance of CollectionValidationError", validationError instanceof CollectionValidationError);
    Map<String, String> errorMap = ((CollectionValidationError) validationError).getErrorMap();
    assertNotNull("Error map should exist", errorMap);
    changedValueMap.putAll(viewValue.getViewValues());
    changeStringInputTo(CHANGED_URL, changedValueMap);
    selectRowInTable(changedValueMap);
    validationError = svm.validateViewValue(newViewValue);
    assertNull("There should not be any validation errors", validationError);
    svm.loadViewValue(newViewValue, false);
    waitWhileNodeInExecution(m_subnodeID);
    assertTrue("Subnode should be executed.", getManager().getNodeContainer(m_subnodeID).getNodeContainerState().isExecuted());
    validateReexecutionResult();
    svm.discard();
    assertNull("Page should be null after reset", svm.getViewRepresentation());
    assertNull("View value should be null after reset", svm.getViewValue());
}
Also used : HashMap(java.util.HashMap) SubnodeViewableModel(org.knime.core.wizard.SubnodeViewableModel) ValidationError(org.knime.core.node.web.ValidationError) CollectionValidationError(org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError) CollectionValidationError(org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError) JSONWebNodePage(org.knime.js.core.JSONWebNodePage) SubnodeViewValue(org.knime.core.wizard.SubnodeViewValue) Test(org.junit.Test)

Example 2 with SubnodeViewableModel

use of org.knime.core.wizard.SubnodeViewableModel 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

SubnodeViewableModel (org.knime.core.wizard.SubnodeViewableModel)2 HashMap (java.util.HashMap)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Test (org.junit.Test)1 ValidationError (org.knime.core.node.web.ValidationError)1 AbstractWizardNodeView (org.knime.core.node.wizard.AbstractWizardNodeView)1 SubnodeViewValue (org.knime.core.wizard.SubnodeViewValue)1 CollectionValidationError (org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError)1 JSONWebNodePage (org.knime.js.core.JSONWebNodePage)1