Search in sources :

Example 21 with IProgressService

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

the class RowGenProcessMain method run.

/**
     * yzhang Comment method "run".
     * 
     * @param refresh
     * @param number
     * @return
     */
public List<List<String>> run(final Button refresh, String number) {
    this.number = number;
    results.clear();
    IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    try {
        progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) {
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("RowGenPreivewCodeMain.Process.Generate"), IProgressMonitor.UNKNOWN);
                try {
                    try {
                        process = runPreviewCode();
                        if (process == null) {
                            return;
                        }
                        StringBuffer out = new StringBuffer();
                        StringBuffer err = new StringBuffer();
                        createResultThread(process.getErrorStream(), err).start();
                        createResultThread(process.getInputStream(), out).start();
                        process.waitFor();
                        if (out.length() > 0) {
                            convert(out.toString());
                        }
                        if (err.length() > 0) {
                            //$NON-NLS-1$
                            String mainMsg = Messages.getString("RowGenPreivewCodeMain.PerlRun.Error");
                            new ErrorDialogWidthDetailArea(Display.getCurrent().getActiveShell(), PluginUtils.PLUGIN_ID, mainMsg, //$NON-NLS-1$
                            Messages.getString("RowGenProcessMain.checkParameter", err.toString()));
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        kill();
                    }
                } finally {
                    monitor.done();
                    //$NON-NLS-1$
                    refresh.setText(Messages.getString("RowGenPreivewCodeMain.PreviewBtn.Text"));
                }
            }
        }, null);
    } catch (Exception ex) {
        ExceptionHandler.process(ex);
    } finally {
        proc.reconnection();
    }
    return results;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressService(org.eclipse.ui.progress.IProgressService) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 22 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project linuxtools by eclipse.

the class ValgrindExportWizard method performFinish.

@Override
public boolean performFinish() {
    final File[] logs = exportPage.getSelectedFiles();
    final IPath outputPath = exportPage.getOutputPath();
    IProgressService ps = PlatformUI.getWorkbench().getProgressService();
    try {
        ps.busyCursorWhile(monitor -> {
            if (logs.length > 0) {
                File outputDir = outputPath.toFile();
                monitor.beginTask(// $NON-NLS-1$
                NLS.bind(Messages.getString("ValgrindExportWizard.Export_task"), outputPath.toOSString()), logs.length);
                for (File log : logs) {
                    monitor.subTask(// $NON-NLS-1$
                    NLS.bind(Messages.getString("ValgrindExportWizard.Export_subtask"), log.getName()));
                    File outLog = new File(outputDir, log.getName());
                    try (FileInputStream fis = new FileInputStream(log);
                        FileChannel inChan = fis.getChannel();
                        FileOutputStream fos = new FileOutputStream(outLog);
                        FileChannel outChan = fos.getChannel()) {
                        outChan.transferFrom(inChan, 0, inChan.size());
                    } catch (IOException e) {
                        throw new InvocationTargetException(e);
                    }
                    monitor.worked(1);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        IStatus status = new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, Messages.getString("ValgrindExportWizard.Export_fail"), e);
        ErrorDialog.openError(getShell(), ExportWizardConstants.WIZARD_TITLE, null, status);
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
    // ignore
    }
    return true;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IProgressService(org.eclipse.ui.progress.IProgressService) FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with IProgressService

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

the class WorkflowEditor method saveTo.

/**
 * Save workflow to resource.
 *
 * @param fileResource .. the resource, usually m_fileResource or m_autoSaveFileResource or soon-to-be
 *            m_fileResource (for save-as)
 * @param monitor ...
 * @param saveWithData ... save data also
 * @param newContext a new workflow context for the saved workflow; if this is non-<code>null</code>, a "save as" is
 *            performed
 */
private void saveTo(final URI fileResource, final IProgressMonitor monitor, final boolean saveWithData, final WorkflowContext newContext) {
    LOGGER.debug("Saving workflow " + getWorkflowManager().get().getNameWithID());
    // Exception messages from the inner thread
    final StringBuilder exceptionMessage = new StringBuilder();
    if (fileResource == null && m_parentEditor != null) {
        m_parentEditor.doSave(monitor);
        m_isDirty = false;
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                firePropertyChange(IEditorPart.PROP_DIRTY);
            }
        });
        return;
    }
    // attach editor properties with the workflow manager - for all sub editors too
    saveEditorSettingsToWorkflowManager();
    /* TODO: EditorSettings should be saved on all child editors too. But this triggers them dirty. And they stay
         * dirty even after save (and setting them clean!). The dirty flag is a mess. Needs to be cleaned up!
         * And after that, we may not inherit the zoom level (in metanodes) from the parent anymore
         * (see #applyEditorSettingsFromWorkflowManager).
         * for (IEditorPart subEditor : getSubEditors()) {
         *   ((WorkflowEditor)subEditor).saveEditorSettingsToWorkflowManager();
         * }
         */
    // to be sure to mark dirty and inform the user about running nodes
    // we ask for the state BEFORE saving
    // this flag is evaluated at the end of this method
    boolean wasInProgress = false;
    try {
        final File workflowDir = new File(fileResource);
        AbstractSaveRunnable saveRunnable;
        if (newContext != null) {
            saveRunnable = new SaveAsRunnable(this, exceptionMessage, monitor, newContext);
        } else {
            WorkflowSaveHelper saveHelper = new WorkflowSaveHelper(saveWithData, false);
            saveRunnable = new InplaceSaveRunnable(this, exceptionMessage, saveHelper, monitor, workflowDir);
        }
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();
        NodeContainerState state = m_manager.getNodeContainerState();
        wasInProgress = state.isExecutionInProgress() && !state.isExecutingRemotely();
        ps.run(true, false, saveRunnable);
        // this code is usually (always?) run in the UI thread but in case it's not we schedule in UI thread
        // (SVG export always in UI thread)
        final File svgFile = new File(workflowDir, WorkflowPersistor.SVG_WORKFLOW_FILE);
        svgFile.delete();
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                if (m_manager.isProject()) {
                    saveSVGImage(svgFile);
                }
            }
        });
        // mark command stack (no undo beyond this point)
        getCommandStack().markSaveLocation();
    } catch (Exception e) {
        LOGGER.error("Could not save workflow: " + exceptionMessage, e);
        // inform the user
        if (exceptionMessage.length() > 0) {
            showInfoMessage("Workflow could not be saved ...", exceptionMessage.toString());
        }
        throw new OperationCanceledException("Workflow was not saved: " + exceptionMessage.toString());
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            if (!Display.getDefault().isDisposed() && (m_manager != null)) {
                // mark all sub editors as saved
                for (IEditorPart subEditor : getSubEditors()) {
                    final WorkflowEditor editor = (WorkflowEditor) subEditor;
                    ((WorkflowEditor) subEditor).setIsDirty(false);
                    editor.firePropertyChange(IEditorPart.PROP_DIRTY);
                }
            }
        }
    });
    monitor.done();
    // or simply saves (Ctrl+S)
    if (wasInProgress) {
        markDirty();
        final Pointer<Boolean> abortPointer = new Pointer<Boolean>();
        abortPointer.set(Boolean.FALSE);
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                boolean abort = false;
                Shell sh = Display.getDefault().getActiveShell();
                String title = "Workflow in execution";
                String message = "Executing nodes are not saved!";
                if (m_isClosing) {
                    abort = !MessageDialog.openQuestion(sh, title, message + " Exit anyway?");
                    // user canceled close
                    m_isClosing = !abort;
                } else {
                    IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
                    String toogleMessage = "Don't warn me again";
                    if (prefStore.getBoolean(PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED)) {
                        MessageDialogWithToggle.openInformation(sh, title, message, toogleMessage, false, prefStore, PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED);
                    }
                }
                abortPointer.set(Boolean.valueOf(abort));
            }
        });
        if (abortPointer.get()) {
            throw new OperationCanceledException("Closing workflow canceled on user request.");
        }
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Pointer(org.knime.core.util.Pointer) IEditorPart(org.eclipse.ui.IEditorPart) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) Shell(org.eclipse.swt.widgets.Shell) WorkflowSaveHelper(org.knime.core.node.workflow.WorkflowSaveHelper) IProgressService(org.eclipse.ui.progress.IProgressService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 24 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project netxms by netxms.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
	 * )
	 */
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    // Register icon for our jobs
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    // $NON-NLS-1$
    service.registerIconForFamily(getImageDescriptor("icons/graph.png"), Activator.PLUGIN_ID);
}
Also used : IProgressService(org.eclipse.ui.progress.IProgressService)

Example 25 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project netxms by netxms.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
	 * )
	 */
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    // Register icon for our jobs
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    // $NON-NLS-1$
    service.registerIconForFamily(getImageDescriptor("icons/server_config.png"), ServerConfigurationEditor.JOB_FAMILY);
}
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