Search in sources :

Example 1 with Validator

use of org.knime.workbench.explorer.dialogs.Validator in project knime-core by knime.

the class SaveAsMetaNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length < 1) {
        return;
    }
    WorkflowManager wm = Wrapper.unwrapWFM(nodes[0].getNodeContainer());
    List<String> validMountPointList = new ArrayList<String>();
    // Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().findView(ID)
    for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
        AbstractContentProvider contentProvider = entry.getValue();
        if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
            validMountPointList.add(entry.getKey());
        }
    }
    if (validMountPointList.isEmpty()) {
        throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
    }
    String[] validMountPoints = validMountPointList.toArray(new String[0]);
    final Shell shell = Display.getCurrent().getActiveShell();
    ContentObject defSel = getDefaultSaveLocation(wm);
    SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
    dialog.setTitle("Save As Metanode Template");
    dialog.setHeader("Select destination workflow group for metanode template");
    dialog.setValidator(new Validator() {

        @Override
        public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
            final AbstractExplorerFileInfo info = selection.fetchInfo();
            if (info.isWorkflowGroup()) {
                return null;
            }
            return "Only workflow groups can be selected as target.";
        }
    });
    if (dialog.open() != Window.OK) {
        return;
    }
    AbstractExplorerFileStore target = dialog.getSelection();
    AbstractContentProvider contentProvider = target.getContentProvider();
    contentProvider.saveMetaNodeTemplate(wm, target);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) Shell(org.eclipse.swt.widgets.Shell) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) Map(java.util.Map) Validator(org.knime.workbench.explorer.dialogs.Validator)

Example 2 with Validator

use of org.knime.workbench.explorer.dialogs.Validator in project knime-core by knime.

the class SaveAsSubNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length < 1) {
        return;
    }
    SubNodeContainer snc = unwrap(nodes[0].getNodeContainer(), SubNodeContainer.class);
    WorkflowManager wm = snc.getWorkflowManager();
    List<String> validMountPointList = new ArrayList<String>();
    for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
        AbstractContentProvider contentProvider = entry.getValue();
        if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
            validMountPointList.add(entry.getKey());
        }
    }
    if (validMountPointList.isEmpty()) {
        throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
    }
    String[] validMountPoints = validMountPointList.toArray(new String[0]);
    final Shell shell = Display.getCurrent().getActiveShell();
    ContentObject defSel = getDefaultSaveLocation(wm);
    SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
    dialog.setTitle("Save As Wrapped Metanode Template");
    dialog.setHeader("Select destination workflow group for Wrapped Metanode template");
    dialog.setValidator(new Validator() {

        @Override
        public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
            final AbstractExplorerFileInfo info = selection.fetchInfo();
            if (info.isWorkflowGroup()) {
                return null;
            }
            return "Only workflow groups can be selected as target.";
        }
    });
    if (dialog.open() != Window.OK) {
        return;
    }
    AbstractExplorerFileStore target = dialog.getSelection();
    AbstractContentProvider contentProvider = target.getContentProvider();
    contentProvider.saveSubNodeTemplate(snc, target);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Shell(org.eclipse.swt.widgets.Shell) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) Map(java.util.Map) Validator(org.knime.workbench.explorer.dialogs.Validator)

Aggregations

ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Shell (org.eclipse.swt.widgets.Shell)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2 SpaceResourceSelectionDialog (org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog)2 Validator (org.knime.workbench.explorer.dialogs.Validator)2 AbstractExplorerFileInfo (org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo)2 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)2 AbstractContentProvider (org.knime.workbench.explorer.view.AbstractContentProvider)2 ContentObject (org.knime.workbench.explorer.view.ContentObject)2 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1