Search in sources :

Example 91 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.

the class NodeContainerEditPart method openNodeDialog.

/**
 * Opens the node's dialog (also metanode dialogs).
 *
 * @since 2.6
 */
public void openNodeDialog() {
    final NodeContainerUI container = (NodeContainerUI) getModel();
    // if this node does not have a dialog
    if (!container.hasDialog()) {
        LOGGER.debug("No dialog for " + container.getNameWithID());
        return;
    }
    final Shell shell = Display.getCurrent().getActiveShell();
    shell.setEnabled(false);
    try {
        if (container.hasDataAwareDialogPane() && !container.isAllInputDataAvailable() && container.canExecuteUpToHere()) {
            IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
            String prefPrompt = store.getString(PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS);
            boolean isExecuteUpstreamNodes;
            if (MessageDialogWithToggle.PROMPT.equals(prefPrompt)) {
                int returnCode = MessageDialogWithToggle.openYesNoCancelQuestion(shell, "Execute upstream nodes", "The " + container.getName() + " node can be configured using the full input data.\n\n" + "Execute upstream nodes?", "Remember my decision", false, store, PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS).getReturnCode();
                if (returnCode == Window.CANCEL) {
                    return;
                } else if (returnCode == IDialogConstants.YES_ID) {
                    isExecuteUpstreamNodes = true;
                } else {
                    isExecuteUpstreamNodes = false;
                }
            } else if (MessageDialogWithToggle.ALWAYS.equals(prefPrompt)) {
                isExecuteUpstreamNodes = true;
            } else {
                isExecuteUpstreamNodes = false;
            }
            if (isExecuteUpstreamNodes) {
                try {
                    PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {

                        @Override
                        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            Future<Void> submit = DATA_AWARE_DIALOG_EXECUTOR.submit(new Callable<Void>() {

                                @Override
                                public Void call() throws Exception {
                                    container.getParent().executePredecessorsAndWait(container.getID());
                                    return null;
                                }
                            });
                            while (!submit.isDone()) {
                                if (monitor.isCanceled()) {
                                    submit.cancel(true);
                                    throw new InterruptedException();
                                }
                                try {
                                    submit.get(300, TimeUnit.MILLISECONDS);
                                } catch (ExecutionException e) {
                                    LOGGER.error("Error while waiting for execution to finish", e);
                                } catch (InterruptedException e) {
                                    submit.cancel(true);
                                    throw e;
                                } catch (TimeoutException e) {
                                // do another round
                                }
                            }
                        }
                    });
                } catch (InvocationTargetException e) {
                    String error = "Exception while waiting for completion of execution";
                    LOGGER.warn(error, e);
                    ErrorDialog.openError(shell, "Failed opening dialog", error, new Status(IStatus.ERROR, KNIMEEditorPlugin.PLUGIN_ID, error, e));
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
        // 
        try {
            if (Wrapper.wraps(container, NodeContainer.class)) {
                WrappedNodeDialog dlg = new WrappedNodeDialog(shell, Wrapper.unwrapNC(container));
                dlg.open();
            }
        } catch (NotConfigurableException ex) {
            MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
            mb.setText("Dialog cannot be opened");
            mb.setMessage("The dialog cannot be opened for the following" + " reason:\n" + ex.getMessage());
            mb.open();
        } catch (Throwable t) {
            LOGGER.error("The dialog pane for node '" + container.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
        }
    } finally {
        shell.setEnabled(true);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NotConfigurableException(org.knime.core.node.NotConfigurableException) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callable(java.util.concurrent.Callable) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Future(java.util.concurrent.Future) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) WrappedNodeDialog(org.knime.workbench.ui.wrapper.WrappedNodeDialog)

Example 92 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.

the class KnimeResourceUtil method importWorkflowIntoWorkspace.

/**
 * Stores the flow in the archive in the local workspace.
 *
 * @param destination the name of the new workflow. Must denote a flow (if
 *            it exists it is overwritten).
 * @param zippedWorkflow
 * @throws IOException
 * @throws ZipException
 * @throws InterruptedException
 * @throws InvocationTargetException
 */
private static void importWorkflowIntoWorkspace(final IPath destination, final File zippedWorkflow) throws ZipException, IOException, InvocationTargetException, InterruptedException {
    ZipFile zFile = new ZipFile(zippedWorkflow);
    ZipLeveledStructProvider importStructureProvider = new ZipLeveledStructProvider(zFile);
    importStructureProvider.setStrip(1);
    ZipEntry root = (ZipEntry) importStructureProvider.getRoot();
    List<ZipEntry> rootChild = importStructureProvider.getChildren(root);
    if (rootChild.size() == 1) {
        // the zipped workflow normally contains only one dir
        root = rootChild.get(0);
    }
    LOGGER.debug("Importing workflow. Destination:" + destination.toString());
    try {
        final ImportOperation iOper = new ImportOperation(destination, root, importStructureProvider, new IOverwriteQuery() {

            @Override
            public String queryOverwrite(final String pathString) {
                return IOverwriteQuery.YES;
            }
        });
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                iOper.run(monitor);
            }
        });
    } finally {
        importStructureProvider.closeArchive();
    }
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 93 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.

the class WorkflowImportSelectionPage method collectWorkflowsFromDir.

/**
 * @param selectedDir the directory to collect the contained workflows from
 */
public void collectWorkflowsFromDir(final String selectedDir) {
    clear();
    initialDirLocation = selectedDir;
    m_fromDirTextUI.setText(selectedDir);
    File dir = new File(selectedDir);
    IWorkflowImportElement root = null;
    // the name only is considered when the resource is created
    if (WorkflowImportElementFromFile.isWorkflow(dir)) {
        // if the user selected a workflow we set the parent and the
        // child to this workflow - otherwise it would not be displayed
        root = new WorkflowImportElementFromFile(dir, true);
        root.addChild(new WorkflowImportElementFromFile(dir));
    } else {
        root = new WorkflowImportElementFromFile(dir);
    }
    m_importRoot = root;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Looking for workflows in ", IProgressMonitor.UNKNOWN);
                collectWorkflowsFromDir((WorkflowImportElementFromFile) m_importRoot, monitor);
                monitor.done();
            }
        });
    } catch (Exception e) {
        String message = "Error while trying to import workflows from " + selectedDir;
        IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, message, e);
        setErrorMessage(message);
        LOGGER.error(message, e);
        ErrorDialog.openError(getShell(), "Import Error", null, status);
    }
    validateWorkflows();
    m_workflowListUI.setInput(m_importRoot);
    m_workflowListUI.expandAll();
    m_workflowListUI.setAllChecked(true);
    m_workflowListUI.refresh(true);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 94 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.

the class WorkflowImportSelectionPage method collectWorkflowsFromZipFile.

private void collectWorkflowsFromZipFile(final String path) {
    ILeveledImportStructureProvider provider = null;
    if (ArchiveFileManipulations.isTarFile(path)) {
        try {
            TarFile sourceTarFile = new TarFile(path);
            provider = new TarLeveledStructureProvider(sourceTarFile);
        } catch (Exception io) {
            // no file -> list stays empty
            setErrorMessage("Invalid .tar file: " + path + ". Contains no workflow.");
        }
    } else if (ArchiveFileManipulations.isZipFile(path)) {
        try {
            ZipFile sourceFile = new ZipFile(path);
            provider = new ZipLeveledStructureProvider(sourceFile);
        } catch (Exception e) {
            // no file -> list stays empty
            setErrorMessage("Invalid .zip file: " + path + ". Contains no workflows");
        }
    }
    // TODO: store only the workflows (dirs are created automatically)
    final ILeveledImportStructureProvider finalProvider = provider;
    if (provider != null) {
        // reset error
        setErrorMessage(null);
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    Object child = finalProvider.getRoot();
                    m_importRoot = new WorkflowImportElementFromArchive(finalProvider, child, 0);
                    monitor.beginTask("Scanning for workflows in ", IProgressMonitor.UNKNOWN);
                    collectWorkflowsFromProvider((WorkflowImportElementFromArchive) m_importRoot, monitor);
                }
            });
        } catch (Exception e) {
            String message = "Error while trying to import workflows from " + path;
            IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, message, e);
            setErrorMessage(message);
            LOGGER.error(message, e);
            ErrorDialog.openError(getShell(), "Import Error", null, status);
        }
        validateWorkflows();
        m_workflowListUI.setInput(m_importRoot);
        m_workflowListUI.expandAll();
        m_workflowListUI.setAllChecked(true);
        m_workflowListUI.refresh(true);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)

Example 95 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.

the class NewProjectWizard method performFinish.

/**
 * Perform finish - queries the page and creates the project / file.
 *
 * {@inheritDoc}
 */
@Override
public boolean performFinish() {
    final IPath workflowPath = m_page.getWorkflowPath();
    // Create new runnable
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException {
            try {
                // call the worker method
                doFinish(workflowPath, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
        IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(workflowPath);
        KnimeResourceUtil.revealInNavigator(r);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        // get the exception that issued this async exception
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)417 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)397 InvocationTargetException (java.lang.reflect.InvocationTargetException)386 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)194 CoreException (org.eclipse.core.runtime.CoreException)123 ArrayList (java.util.ArrayList)86 IStatus (org.eclipse.core.runtime.IStatus)67 IOException (java.io.IOException)65 List (java.util.List)54 Status (org.eclipse.core.runtime.Status)53 IFile (org.eclipse.core.resources.IFile)51 File (java.io.File)47 Shell (org.eclipse.swt.widgets.Shell)44 IProject (org.eclipse.core.resources.IProject)40 PartInitException (org.eclipse.ui.PartInitException)32 IPath (org.eclipse.core.runtime.IPath)26 Display (org.eclipse.swt.widgets.Display)26 IResource (org.eclipse.core.resources.IResource)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 Path (org.eclipse.core.runtime.Path)23