Search in sources :

Example 1 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project knime-core by knime.

the class CheckUpdateMetaNodeLinkAction method runInSWT.

/**
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    List<NodeID> candidateList = getMetaNodesToCheck();
    final Shell shell = Display.getCurrent().getActiveShell();
    IWorkbench wb = PlatformUI.getWorkbench();
    IProgressService ps = wb.getProgressService();
    LOGGER.debug("Checking for updates for " + candidateList.size() + " node link(s)...");
    CheckUpdateRunnableWithProgress runner = new CheckUpdateRunnableWithProgress(getManager(), candidateList);
    try {
        ps.busyCursorWhile(runner);
    } catch (InvocationTargetException e) {
        LOGGER.warn("Failed to check for updates: " + e.getMessage(), e);
        return;
    } catch (InterruptedException e) {
        return;
    }
    List<NodeID> updateList = runner.getUpdateList();
    Status status = runner.getStatus();
    if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) {
        ErrorDialog.openError(Display.getDefault().getActiveShell(), null, "Errors while checking for " + "updates on node links", status);
        if (candidateList.size() == 1) {
            /* As only one node is selected and its update failed,
                 * there is nothing else to do. */
            return;
        }
    }
    // find nodes that will be reset as part of the update
    int nodesToResetCount = 0;
    for (NodeID id : updateList) {
        NodeContainerTemplate templateNode = (NodeContainerTemplate) getManager().findNodeContainer(id);
        // TODO problematic with through-connections
        if (templateNode.containsExecutedNode()) {
            nodesToResetCount += 1;
        }
    }
    if (updateList.isEmpty()) {
        if (m_showInfoMsgIfNoUpdateAvail) {
            MessageDialog.openInformation(shell, "Node Update", "No updates available");
        } else {
            LOGGER.info("No updates available (" + candidateList.size() + " node link(s))");
        }
    } else {
        boolean isSingle = updateList.size() == 1;
        String title = "Update Node" + (isSingle ? "" : "s");
        StringBuilder messageBuilder = new StringBuilder();
        messageBuilder.append("Update available for ");
        if (isSingle && candidateList.size() == 1) {
            messageBuilder.append("node \"");
            messageBuilder.append(getManager().findNodeContainer(candidateList.get(0)).getNameWithID());
            messageBuilder.append("\".");
        } else if (isSingle) {
            messageBuilder.append("one node.");
        } else {
            messageBuilder.append(updateList.size());
            messageBuilder.append(" nodes.");
        }
        messageBuilder.append("\n\n");
        if (nodesToResetCount > 0) {
            messageBuilder.append("Reset nodes and update now?");
        } else {
            messageBuilder.append("Update now?");
        }
        String message = messageBuilder.toString();
        if (MessageDialog.openQuestion(shell, title, message)) {
            LOGGER.debug("Running update for " + updateList.size() + " node(s): " + updateList);
            execute(new UpdateMetaNodeLinkCommand(getManager(), updateList.toArray(new NodeID[updateList.size()])));
        }
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) UpdateMetaNodeLinkCommand(org.knime.workbench.editor2.commands.UpdateMetaNodeLinkCommand) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) IProgressService(org.eclipse.ui.progress.IProgressService) NodeID(org.knime.core.node.workflow.NodeID)

Example 2 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project knime-core by knime.

the class WorkflowEditor method setInput.

/**
 * Sets the editor input, that is, the file that contains the serialized
 * workflow manager.
 *
 * {@inheritDoc}
 */
@Override
protected void setInput(final IEditorInput input) {
    LOGGER.debug("Setting input into editor...");
    super.setInput(input);
    m_origRemoteLocation = null;
    if (input instanceof WorkflowManagerInput) {
        // metanode and subnode
        setWorkflowManagerInput((WorkflowManagerInput) input);
    } else if (input instanceof IURIEditorInput) {
        File wfFile;
        AbstractExplorerFileStore wfFileFileStore = null;
        File mountPointRoot = null;
        URI uri = ((IURIEditorInput) input).getURI();
        if (input instanceof RemoteWorkflowInput) {
            m_origRemoteLocation = ((RemoteWorkflowInput) input).getRemoteOriginalLocation();
        }
        if ("file".equals(uri.getScheme())) {
            wfFile = new File(uri);
            try {
                LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfFile);
                if ((fs == null) || (fs.getContentProvider() == null)) {
                    LOGGER.info("Could not determine mount point root for " + wfFile.getParent() + ", looks like it is a linked resource");
                } else {
                    wfFileFileStore = fs;
                    mountPointRoot = fs.getContentProvider().getFileStore("/").toLocalFile();
                }
            } catch (CoreException ex) {
                LOGGER.warn("Could not determine mount point root for " + wfFile.getParent() + ": " + ex.getMessage(), ex);
            }
        } else if (ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
            AbstractExplorerFileStore filestore = ExplorerFileSystem.INSTANCE.getStore(uri);
            if (filestore == null) {
                LOGGER.error("Could not find filestore for URI " + uri);
                openErrorDialogAndCloseEditor("Could not find filestore for URI " + uri);
                return;
            }
            wfFileFileStore = filestore;
            try {
                wfFile = filestore.toLocalFile();
            } catch (CoreException ex) {
                LOGGER.error(ex.getMessage(), ex);
                openErrorDialogAndCloseEditor(ex.getMessage());
                return;
            }
            if (wfFile == null) {
                LOGGER.error("URI " + uri + " is not a local workflow");
                openErrorDialogAndCloseEditor("URI " + uri + " is not a local workflow");
                return;
            }
            try {
                mountPointRoot = filestore.getContentProvider().getFileStore("/").toLocalFile();
            } catch (CoreException ex) {
                LOGGER.warn("Could not determine mount point root for " + wfFile.getParent() + ": " + ex.getMessage(), ex);
            }
        } else {
            LOGGER.error("Unsupported scheme for workflow URI: " + uri);
            openErrorDialogAndCloseEditor("Unsupported scheme for workflow URI: " + uri);
            return;
        }
        URI oldFileResource = m_fileResource;
        WorkflowManagerUI oldManager = m_manager;
        final File wfDir = wfFile.getParentFile();
        m_fileResource = wfDir.toURI();
        LOGGER.debug("Resource File's project: " + m_fileResource);
        boolean isEnableAutoSave = true;
        try {
            if (oldManager != null) {
                // doSaveAs called
                assert oldFileResource != null;
                WorkflowManagerUI managerForOldResource = (WorkflowManagerUI) ProjectWorkflowMap.getWorkflowUI(oldFileResource);
                if (m_manager != managerForOldResource) {
                    throw new IllegalStateException(String.format("Cannot set new input for workflow editor " + "as there was already a workflow manager set (old resource: \"%s\", " + "new resource: \"%s\", old manager: \"%s\", manager to old resource: \"%s\"", oldFileResource, m_fileResource, oldManager, managerForOldResource));
                }
                ProjectWorkflowMap.replace(m_fileResource, oldManager, oldFileResource);
                isEnableAutoSave = m_isAutoSaveAllowed;
            } else {
                m_manager = (WorkflowManagerUI) ProjectWorkflowMap.getWorkflowUI(m_fileResource);
            }
            if (m_manager != null) {
                // in case the workflow manager was edited somewhere else
                if (m_manager.isDirty()) {
                    markDirty();
                }
            } else {
                File autoSaveDirectory = WorkflowSaveHelper.getAutoSaveDirectory(new ReferencedFile(wfDir));
                if (autoSaveDirectory.exists()) {
                    if (!autoSaveDirectory.isDirectory() || !autoSaveDirectory.canRead()) {
                        LOGGER.warnWithFormat("Found existing auto-save location to workflow \"%s\" (\"%s\") but %s" + " - disabling auto-save", wfDir.getName(), autoSaveDirectory.getAbsolutePath(), (!autoSaveDirectory.isDirectory() ? "it is not a directory" : "cannot read it"));
                        isEnableAutoSave = false;
                    } else {
                        File parentDir = autoSaveDirectory.getParentFile();
                        String date = DateFormatUtils.format(autoSaveDirectory.lastModified(), "yyyy-MM-dd HH-mm");
                        String newName = wfDir.getName() + " (Auto-Save Copy - " + date + ")";
                        int unique = 1;
                        File restoredAutoSaveDirectory;
                        while ((restoredAutoSaveDirectory = new File(parentDir, newName)).exists()) {
                            newName = wfDir.getName() + " (Auto-Save Copy - " + date + " #" + (unique++) + ")";
                        }
                        // this is the file store object to autoSaveDirectory - if we can resolve it
                        // we use it below in user messages and to do the rename in order to trigger a refresh
                        // in the explorer tree - if we can't resolve it (dunno why) we use java.io.File operation
                        AbstractExplorerFileStore autoSaveDirFileStore = null;
                        AbstractExplorerFileStore restoredAutoSaveDirFileStore = null;
                        if (wfFileFileStore != null) {
                            try {
                                // first parent is workflow dir, parent of that is the workflow group
                                AbstractExplorerFileStore parFS = wfFileFileStore.getParent().getParent();
                                AbstractExplorerFileStore temp = parFS.getChild(autoSaveDirectory.getName());
                                if (autoSaveDirectory.equals(temp.toLocalFile())) {
                                    autoSaveDirFileStore = temp;
                                }
                                restoredAutoSaveDirFileStore = parFS.getChild(newName);
                            } catch (CoreException e) {
                                LOGGER.warn("Unable to resolve parent file store for \"" + wfFileFileStore + "\"", e);
                            }
                        }
                        int action = openQuestionDialogWhenLoadingWorkflowWithAutoSaveCopy(wfDir.getName(), restoredAutoSaveDirectory.getName());
                        final boolean openCopy;
                        switch(action) {
                            case // Open Copy
                            0:
                                openCopy = true;
                                break;
                            case // Open Original
                            1:
                                openCopy = false;
                                break;
                            default:
                                // Cancel
                                String error = "Canceling due to auto-save copy conflict";
                                openErrorDialogAndCloseEditor(error);
                                throw new OperationCanceledException(error);
                        }
                        boolean couldRename = false;
                        if (autoSaveDirFileStore != null) {
                            // preferred way to rename, updates explorer tree
                            try {
                                autoSaveDirFileStore.move(restoredAutoSaveDirFileStore, EFS.NONE, null);
                                couldRename = true;
                            } catch (CoreException e) {
                                String message = "Could not rename auto-save copy\n" + "from\n  " + autoSaveDirFileStore.getMountIDWithFullPath() + "\nto\n  " + newName;
                                LOGGER.error(message, e);
                            }
                        } else {
                            LOGGER.warnWithFormat("Could not resolve explorer file store to \"%s\" - " + "renaming on file system directly", autoSaveDirectory.getAbsolutePath());
                            // just rename on file system and ignore explorer tree
                            couldRename = autoSaveDirectory.renameTo(restoredAutoSaveDirectory);
                        }
                        if (!couldRename) {
                            isEnableAutoSave = false;
                            String message = "Could not rename auto-save copy\n" + "from\n  " + autoSaveDirectory.getAbsolutePath() + "\nto\n  " + restoredAutoSaveDirectory.getAbsolutePath() + "";
                            if (openCopy) {
                                openErrorDialogAndCloseEditor(message);
                                throw new OperationCanceledException(message);
                            } else {
                                MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Auto-Save Rename Problem", message + "\nAuto-Save will be disabled.");
                            }
                        }
                        if (openCopy) {
                            m_fileResource = restoredAutoSaveDirectory.toURI();
                            wfFile = new File(restoredAutoSaveDirectory, wfFile.getName());
                        }
                    }
                }
                IWorkbench wb = PlatformUI.getWorkbench();
                IProgressService ps = wb.getProgressService();
                // this one sets the workflow manager in the editor
                LoadWorkflowRunnable loadWorkflowRunnable = new LoadWorkflowRunnable(this, m_origRemoteLocation != null ? m_origRemoteLocation : uri, wfFile, mountPointRoot);
                ps.busyCursorWhile(loadWorkflowRunnable);
                // non-null if set by workflow runnable above
                if (m_manager == null) {
                    if (loadWorkflowRunnable.hasLoadingBeenCanceled()) {
                        String cancelError = loadWorkflowRunnable.getLoadingCanceledMessage();
                        openErrorDialogAndCloseEditor(cancelError);
                        throw new OperationCanceledException(cancelError);
                    } else if (loadWorkflowRunnable.getThrowable() != null) {
                        throw new RuntimeException(loadWorkflowRunnable.getThrowable());
                    }
                }
                ProjectWorkflowMap.putWorkflowUI(m_fileResource, m_manager);
            }
            if (oldManager == null) {
                // not null if via doSaveAs
                // in any case register as client (also if the workflow was already loaded by another client
                ProjectWorkflowMap.registerClientTo(m_fileResource, this);
            }
        } catch (InterruptedException ie) {
            LOGGER.fatal("Workflow loading thread interrupted", ie);
        } catch (InvocationTargetException e) {
            LOGGER.fatal("Workflow could not be loaded.", e);
        }
        m_isAutoSaveAllowed = m_parentEditor == null && isEnableAutoSave;
        setupAutoSaveSchedule();
        m_manuallySetToolTip = null;
        updatePartName();
        if (getGraphicalViewer() != null) {
            loadProperties();
            updateTempRemoteWorkflowMessage();
        }
        // update Actions, as now there's everything available
        updateActions();
    } else {
        throw new IllegalArgumentException("Unsupported editor input: " + input.getClass());
    }
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) URI(java.net.URI) ReferencedFile(org.knime.core.internal.ReferencedFile) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) CoreException(org.eclipse.core.runtime.CoreException) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IProgressService(org.eclipse.ui.progress.IProgressService) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) RemoteWorkflowInput(org.knime.workbench.explorer.RemoteWorkflowInput)

Example 3 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project knime-core by knime.

the class UpdateMetaNodeLinkCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    UpdateMetaNodeTemplateRunnable updateRunner = null;
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();
        WorkflowManager hostWFM = getHostWFM();
        updateRunner = new UpdateMetaNodeTemplateRunnable(hostWFM, m_ids);
        ps.busyCursorWhile(updateRunner);
        m_newIDs = updateRunner.getNewIDs();
        m_undoPersistors = updateRunner.getUndoPersistors();
        assert m_newIDs.size() == m_undoPersistors.size();
    } catch (Exception ex) {
        // if fails notify the user
        LOGGER.debug("Node cannot be created.", ex);
        MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Node cannot be created.", "The selected node could not be created " + "due to the following reason:\n" + ex.getMessage());
        return;
    } finally {
        if (updateRunner != null) {
            updateRunner.discard();
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) UpdateMetaNodeTemplateRunnable(org.knime.workbench.editor2.UpdateMetaNodeTemplateRunnable) IProgressService(org.eclipse.ui.progress.IProgressService) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 4 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project knime-core by knime.

the class CreateMetaNodeTemplateCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // Add node to workflow and get the container
    LoadMetaNodeTemplateRunnable loadRunnable = null;
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();
        // this one sets the workflow manager in the editor
        loadRunnable = new LoadMetaNodeTemplateRunnable(getHostWFM(), m_templateKNIMEFolder);
        ps.run(false, true, loadRunnable);
        MetaNodeLinkUpdateResult result = loadRunnable.getLoadResult();
        m_container = (NodeContainer) result.getLoadedInstance();
        if (m_container == null) {
            throw new RuntimeException("No template returned by load routine, see log for details");
        }
        // create extra info and set it
        NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
        m_container.setUIInformation(info);
    } catch (Throwable t) {
        Throwable cause = t;
        while ((cause.getCause() != null) && (cause.getCause() != cause)) {
            cause = cause.getCause();
        }
        String error = "The selected node could not be created";
        if (cause instanceof FileNotFoundException) {
            error += " because a file could not be found: " + cause.getMessage();
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
        } else if (cause instanceof IOException) {
            error += " because of an I/O error: " + cause.getMessage();
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
        } else if (cause instanceof InvalidSettingsException) {
            error += " because the metanode contains invalid settings: " + cause.getMessage();
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
        } else if (cause instanceof UnsupportedWorkflowVersionException) {
            error += " because the metanode version is incompatible: " + cause.getMessage();
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
        } else if ((cause instanceof CanceledExecutionException) || (cause instanceof InterruptedException)) {
            LOGGER.info("Metanode loading was canceled by the user", cause);
        } else {
            LOGGER.error(String.format("Metanode loading failed with %s: %s", cause.getClass().getSimpleName(), cause.getMessage()), cause);
            error += ": " + cause.getMessage();
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
        }
    }
}
Also used : UnsupportedWorkflowVersionException(org.knime.core.node.workflow.UnsupportedWorkflowVersionException) LoadMetaNodeTemplateRunnable(org.knime.workbench.editor2.LoadMetaNodeTemplateRunnable) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IWorkbench(org.eclipse.ui.IWorkbench) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IProgressService(org.eclipse.ui.progress.IProgressService) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) MetaNodeLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult)

Example 5 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project tmdm-studio-se by Talend.

the class ImportDataContentProcess method processDatas.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.mdm.repository.core.datacontent.IDataContentProcess#processDatas(org.talend.mdm.repository.core.
     * datacontent.DataProcessRule, org.eclipse.core.runtime.IProgressMonitor)
     */
public void processDatas(DataProcessRule rule) throws InterruptedException, InvocationTargetException {
    IProgressService progressService = getProcessService();
    ImportProcess process = new ImportProcess(rule);
    progressService.run(true, true, process);
}
Also used : IProgressService(org.eclipse.ui.progress.IProgressService)

Aggregations

IProgressService (org.eclipse.ui.progress.IProgressService)38 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)17 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)15 IStatus (org.eclipse.core.runtime.IStatus)11 IOException (java.io.IOException)7 Status (org.eclipse.core.runtime.Status)6 IWorkbench (org.eclipse.ui.IWorkbench)6 File (java.io.File)5 CoreException (org.eclipse.core.runtime.CoreException)5 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IContext (org.talend.core.model.process.IContext)4 ProcessorException (org.talend.designer.runprocess.ProcessorException)4 MessageFormat (java.text.MessageFormat)3 Date (java.util.Date)3 IProject (org.eclipse.core.resources.IProject)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)3 IProcessor (org.talend.designer.runprocess.IProcessor)3 ClearPerformanceAction (org.talend.designer.runprocess.ui.actions.ClearPerformanceAction)3