Search in sources :

Example 1 with AbstractContentProvider

use of org.knime.workbench.explorer.view.AbstractContentProvider in project knime-core by knime.

the class ChangeMetaNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainerUI nc = nodes[0].getNodeContainer();
    if (!(nc instanceof WorkflowManagerUI)) {
        return false;
    }
    WorkflowManagerUI metaNode = (WorkflowManagerUI) nc;
    if (!Role.Link.equals(unwrapWFM(metaNode).getTemplateInformation().getRole()) || metaNode.getParent().isWriteProtected()) {
        // metanode must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = unwrapWFM(metaNode).getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = metaNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with AbstractContentProvider

use of org.knime.workbench.explorer.view.AbstractContentProvider in project knime-core by knime.

the class ChangeSubNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainer nc = Wrapper.unwrapNC(nodes[0].getNodeContainer());
    if (!(nc instanceof SubNodeContainer)) {
        return false;
    }
    SubNodeContainer subNode = (SubNodeContainer) nc;
    if (!Role.Link.equals(subNode.getTemplateInformation().getRole()) || subNode.getParent().isWriteProtected()) {
        // sub node must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = subNode.getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = subNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IOException(java.io.IOException) URI(java.net.URI)

Example 3 with AbstractContentProvider

use of org.knime.workbench.explorer.view.AbstractContentProvider in project knime-core by knime.

the class WorkflowEditor method getNewLocation.

/**
 * For SaveAs...
 * @param currentLocation
 * @param allowRemoteLocation local and remote mount points are added to the selection dialog
 * @return new (different!) URI or null if user canceled. Caller should create a snapshot if told so.
 */
private OverwriteAndMergeInfo getNewLocation(final URI currentLocation, final boolean allowRemoteLocation) {
    final AbstractExplorerFileStore currentStore = getFileStore(currentLocation);
    AbstractExplorerFileStore currentParent = null;
    if (currentStore != null) {
        currentParent = currentStore.getParent();
    }
    String currentName = new Path(currentLocation.getPath()).lastSegment();
    List<String> selIDs = new LinkedList<String>();
    for (String id : ExplorerMountTable.getAllVisibleMountIDs()) {
        AbstractContentProvider provider = ExplorerMountTable.getMountPoint(id).getProvider();
        if (!provider.isRemote() || (allowRemoteLocation && provider.isWritable())) {
            selIDs.add(id);
        }
    }
    ContentObject preSel = ContentObject.forFile(currentParent);
    if (isTempRemoteWorkflowEditor()) {
        AbstractExplorerFileStore remoteStore = null;
        try {
            remoteStore = ExplorerFileSystem.INSTANCE.getStore(m_origRemoteLocation);
        } catch (IllegalArgumentException e) {
        /* don't preselect on unknown original location */
        }
        if (remoteStore != null) {
            preSel = ContentObject.forFile(remoteStore);
        } else {
            preSel = null;
        }
    }
    OverwriteAndMergeInfo result = null;
    while (result == null) {
        // keep the selection dialog open until we get a useful result
        final SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(getSite().getShell(), selIDs.toArray(new String[selIDs.size()]), preSel);
        SaveAsValidator validator = new SaveAsValidator(dialog, currentStore);
        String defName = currentName + " - Copy";
        if (!isTempRemoteWorkflowEditor()) {
            if (currentParent != null) {
                try {
                    Set<String> childs = new HashSet<String>(Arrays.asList(currentParent.childNames(EFS.NONE, null)));
                    defName = guessNewWorkflowNameOnSaveAs(childs, currentName);
                } catch (CoreException e1) {
                // keep the simple default
                }
            }
        } else {
            defName = currentName;
            if (defName.endsWith("." + KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION)) {
                defName = defName.substring(0, defName.length() - KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION.length() - 1);
            }
        }
        dialog.setTitle("Save to new Location");
        dialog.setDescription("Select the new destination workflow group for the workflow.");
        dialog.setValidator(validator);
        // Setup the name field of the dialog
        dialog.setNameFieldEnabled(true);
        dialog.setNameFieldDefaultValue(defName);
        final AtomicBoolean proceed = new AtomicBoolean(false);
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                proceed.set(dialog.open() == Window.OK);
            }
        });
        if (!proceed.get()) {
            return null;
        }
        AbstractExplorerFileStore newLocation = dialog.getSelection();
        if (newLocation.fetchInfo().isWorkflowGroup()) {
            newLocation = newLocation.getChild(dialog.getNameFieldValue());
        } else {
            // in case they have selected a flow but changed the name in the name field afterwards
            newLocation = newLocation.getParent().getChild(dialog.getNameFieldValue());
        }
        assert !newLocation.fetchInfo().exists() || newLocation.fetchInfo().isWorkflow();
        if (newLocation.fetchInfo().exists()) {
            // confirm overwrite (with snapshot?)
            final AtomicBoolean snapshotSupported = new AtomicBoolean(false);
            final AtomicReference<SnapshotPanel> snapshotPanel = new AtomicReference<SnapshotPanel>(null);
            if (newLocation.getContentProvider().supportsSnapshots() && (newLocation instanceof RemoteExplorerFileStore)) {
                snapshotSupported.set(true);
            }
            MessageDialog dlg = new MessageDialog(getSite().getShell(), "Confirm SaveAs Overwrite", null, "The selected destination\n\n\t" + newLocation.getMountIDWithFullPath() + "\n\nalready exists. Do you want to overwrite?\n", MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 1) {

                /**
                 * {@inheritDoc}
                 */
                @Override
                protected Control createCustomArea(final Composite parent) {
                    if (snapshotSupported.get()) {
                        snapshotPanel.set(new SnapshotPanel(parent, SWT.NONE));
                        snapshotPanel.get().setEnabled(true);
                        return snapshotPanel.get();
                    } else {
                        return null;
                    }
                }
            };
            int dlgResult = dlg.open();
            if (dlgResult == 2) /* CANCEL */
            {
                return null;
            }
            if (dlgResult == 0) {
                /* YES (= please overwrite) */
                if (snapshotPanel.get() != null) {
                    SnapshotPanel snapPanel = snapshotPanel.get();
                    result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, snapPanel.createSnapshot(), snapPanel.getComment());
                } else {
                    result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, false, "");
                }
            } else {
                /* NO, don't overwrite: continue while loop asking for a different location */
                preSel = ContentObject.forFile(newLocation);
                currentName = newLocation.getName();
            }
        } else {
            result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, false, false, "");
        }
    }
    /* end of while (result != null) keep the target selection dialog open */
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) SaveAsValidator(org.knime.workbench.explorer.dialogs.SaveAsValidator) Composite(org.eclipse.swt.widgets.Composite) AtomicReference(java.util.concurrent.atomic.AtomicReference) SnapshotPanel(org.knime.workbench.explorer.view.dialogs.SnapshotPanel) LinkedList(java.util.LinkedList) ContentObject(org.knime.workbench.explorer.view.ContentObject) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OverwriteAndMergeInfo(org.knime.workbench.explorer.view.dialogs.OverwriteAndMergeInfo) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) CoreException(org.eclipse.core.runtime.CoreException) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) RemoteExplorerFileStore(org.knime.workbench.explorer.filesystem.RemoteExplorerFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) HashSet(java.util.HashSet)

Example 4 with AbstractContentProvider

use of org.knime.workbench.explorer.view.AbstractContentProvider 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 5 with AbstractContentProvider

use of org.knime.workbench.explorer.view.AbstractContentProvider 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

AbstractContentProvider (org.knime.workbench.explorer.view.AbstractContentProvider)9 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)6 ContentObject (org.knime.workbench.explorer.view.ContentObject)5 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 ArrayList (java.util.ArrayList)3 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)3 SpaceResourceSelectionDialog (org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 Shell (org.eclipse.swt.widgets.Shell)2 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)2 Validator (org.knime.workbench.explorer.dialogs.Validator)2 AbstractExplorerFileInfo (org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo)2 LocalExplorerFileStore (org.knime.workbench.explorer.filesystem.LocalExplorerFileStore)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1