Search in sources :

Example 86 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.

the class StapNewWizard method performFinish.

/**
 * This method is called when 'Finish' button is pressed in
 * the wizard. We will create an operation and run it
 * using wizard as execution context.
 */
@Override
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = monitor -> {
        try {
            doFinish(containerName, fileName, monitor);
        } catch (CoreException e) {
            throw new InvocationTargetException(e);
        } finally {
            monitor.done();
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        MessageDialog.openError(getShell(), "Error", e.getLocalizedMessage());
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        // $NON-NLS-1$
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}
Also used : WorkbenchException(org.eclipse.ui.WorkbenchException) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) PlatformUI(org.eclipse.ui.PlatformUI) CoreException(org.eclipse.core.runtime.CoreException) Wizard(org.eclipse.jface.wizard.Wizard) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IDEPerspective(org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPerspective) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceBundle(java.util.ResourceBundle) Path(org.eclipse.core.runtime.Path) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) INewWizard(org.eclipse.ui.INewWizard) IFile(org.eclipse.core.resources.IFile) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbench(org.eclipse.ui.IWorkbench) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 87 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.

the class SpecfileNewWizard method performFinish.

/**
 * This method is called when 'Finish' button is pressed in the wizard. We
 * will create an operation and run it using wizard as execution context.
 */
@Override
public boolean performFinish() {
    final String containerName = page.getProjectName();
    final String fileName = page.getFileName();
    final InputStream contentInputStream = openContentStream();
    IRunnableWithProgress op = monitor -> {
        try {
            doFinish(containerName, fileName, contentInputStream, monitor);
        } catch (CoreException e) {
            throw new InvocationTargetException(e);
        } finally {
            monitor.done();
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        SpecfileLog.logError(e);
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), Messages.SpecfileNewWizard_0, realException.getMessage());
        return false;
    }
    return true;
}
Also used : ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) SpecfileNewWizardPage(org.eclipse.linuxtools.rpm.ui.editor.wizards.SpecfileNewWizardPage) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) SpecfileLog(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog) IStatus(org.eclipse.core.runtime.IStatus) Activator(org.eclipse.linuxtools.internal.rpm.ui.editor.Activator) ByteArrayInputStream(java.io.ByteArrayInputStream) PartInitException(org.eclipse.ui.PartInitException) IFile(org.eclipse.core.resources.IFile) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Files(java.nio.file.Files) PlatformUI(org.eclipse.ui.PlatformUI) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) Wizard(org.eclipse.jface.wizard.Wizard) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Paths(java.nio.file.Paths) Messages(org.eclipse.linuxtools.rpm.ui.editor.wizards.Messages) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) INewWizard(org.eclipse.ui.INewWizard) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbench(org.eclipse.ui.IWorkbench) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InputStream(java.io.InputStream) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 88 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.

the class PrepareChangeLogAction method doRun.

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 */
protected void doRun() {
    IRunnableWithProgress code = monitor -> {
        // $NON-NLS-1$
        monitor.beginTask(Messages.getString("ChangeLog.PrepareChangeLog"), 1000);
        prepareChangeLog(monitor);
        monitor.done();
    };
    ProgressMonitorDialog pd = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    try {
        pd.run(false, /* fork */
        false, /* cancelable */
        code);
    } catch (InvocationTargetException e) {
        ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return;
    } catch (InterruptedException e) {
        ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }
}
Also used : IParserChangeLogContrib(org.eclipse.linuxtools.changelog.core.IParserChangeLogContrib) ChangeLogEditor(org.eclipse.linuxtools.internal.changelog.core.editors.ChangeLogEditor) CoreException(org.eclipse.core.runtime.CoreException) IFormatterChangeLogContrib(org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib) ChangelogPlugin(org.eclipse.linuxtools.internal.changelog.core.ChangelogPlugin) IStatus(org.eclipse.core.runtime.IStatus) Vector(java.util.Vector) IPath(org.eclipse.core.runtime.IPath) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) PartInitException(org.eclipse.ui.PartInitException) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) IStorage(org.eclipse.core.resources.IStorage) ChangeLogWriter(org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter) Subscriber(org.eclipse.team.core.subscribers.Subscriber) IResourceDiff(org.eclipse.team.core.mapping.IResourceDiff) IEditorPart(org.eclipse.ui.IEditorPart) IAdaptable(org.eclipse.core.runtime.IAdaptable) FileDocumentProvider(org.eclipse.ui.editors.text.FileDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Status(org.eclipse.core.runtime.Status) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Path(org.eclipse.core.runtime.Path) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TeamException(org.eclipse.team.core.TeamException) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Messages(org.eclipse.linuxtools.internal.changelog.core.Messages) IFileRevision(org.eclipse.team.core.history.IFileRevision) IDiff(org.eclipse.team.core.diff.IDiff) IDiffElement(org.eclipse.compare.structuremergeviewer.IDiffElement) HashMap(java.util.HashMap) LineComparator(org.eclipse.linuxtools.internal.changelog.core.LineComparator) RangeDifference(org.eclipse.compare.rangedifferencer.RangeDifference) ArrayList(java.util.ArrayList) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IDocument(org.eclipse.jface.text.IDocument) Differencer(org.eclipse.compare.structuremergeviewer.Differencer) IProject(org.eclipse.core.resources.IProject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IFile(org.eclipse.core.resources.IFile) BadLocationException(org.eclipse.jface.text.BadLocationException) RangeDifferencer(org.eclipse.compare.rangedifferencer.RangeDifferencer) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IThreeWayDiff(org.eclipse.team.core.diff.IThreeWayDiff) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) StorageDocumentProvider(org.eclipse.ui.editors.text.StorageDocumentProvider) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) Collections(java.util.Collections) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 89 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.

the class ContainerCopyToPage method setupSelectionsBasedOnSelectedTypes.

/**
 * Update the tree to only select those elements that match the selected
 * types
 */
@SuppressWarnings("rawtypes")
@Override
protected void setupSelectionsBasedOnSelectedTypes() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getContainer().getShell());
    final Map selectionMap = new Hashtable();
    final IElementFilter filter = new IElementFilter() {

        @Override
        public void filterElements(Collection files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            Iterator filesList = files.iterator();
            while (filesList.hasNext()) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(filesList.next());
            }
        }

        @Override
        public void filterElements(Object[] files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            for (int i = 0; i < files.length; i++) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(files[i]);
            }
        }

        @SuppressWarnings("unchecked")
        private void checkFile(Object fileElement) {
            MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement;
            if (isExportableExtension(file.getFileNameExtension())) {
                List elements = new ArrayList();
                FileSystemElement parent = file.getParent();
                if (selectionMap.containsKey(parent)) {
                    elements = (List) selectionMap.get(parent);
                }
                elements.add(file);
                selectionMap.put(parent, elements);
            }
        }
    };
    IRunnableWithProgress runnable = monitor -> {
        monitor.beginTask(CopyToContainerMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN);
        getSelectedResources(filter, monitor);
    };
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException exception) {
        // Couldn't start. Do nothing.
        return;
    } catch (InterruptedException exception) {
        // Got interrupted. Do nothing.
        return;
    }
    // make sure that all paint operations caused by closing the progress
    // dialog get flushed, otherwise extra pixels will remain on the screen
    // until
    // updateSelections is completed
    getShell().update();
    // a new process.
    if (selectionMap != null) {
        updateSelections(selectionMap);
    }
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ContainerFileProxy(org.eclipse.linuxtools.internal.docker.core.ContainerFileProxy) BusyIndicator(org.eclipse.swt.custom.BusyIndicator) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ContainerDirectorySelectionDialog(org.eclipse.linuxtools.internal.docker.ui.ContainerDirectorySelectionDialog) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ContainerFileSystemProvider(org.eclipse.linuxtools.internal.docker.ui.ContainerFileSystemProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) BidiUtils(org.eclipse.jface.util.BidiUtils) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) GridData(org.eclipse.swt.layout.GridData) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Hashtable(java.util.Hashtable) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) Text(org.eclipse.swt.widgets.Text) WizardResourceImportPage(org.eclipse.ui.dialogs.WizardResourceImportPage) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator) IDEFileSystemStructureProvider(org.eclipse.linuxtools.internal.docker.ui.IDEFileSystemStructureProvider) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Collection(java.util.Collection) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) Path(org.eclipse.core.runtime.Path) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) KeyListener(org.eclipse.swt.events.KeyListener) Label(org.eclipse.swt.widgets.Label) IElementFilter(org.eclipse.ui.ide.dialogs.IElementFilter) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Hashtable(java.util.Hashtable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IElementFilter(org.eclipse.ui.ide.dialogs.IElementFilter) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) Iterator(java.util.Iterator) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 90 with IRunnableWithProgress

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

the class NodeDescriptionConverter method buildDocumentationWithProgress.

/**
 * @param plugins the plugin names
 */
public void buildDocumentationWithProgress(final String[] plugins) {
    Display display = Display.getDefault();
    Shell shell = new Shell(display);
    m_dialog = new ProgressMonitorDialog(shell);
    m_dialog.setCancelable(true);
    m_monitor = m_dialog.getProgressMonitor();
    m_monitor.setTaskName("Retrieving information from repository...");
    m_nrPlugins = plugins.length;
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                m_first = true;
                monitor.beginTask("Building documentation", m_nrPlugins);
                for (String s : plugins) {
                    if (m_monitor.isCanceled()) {
                        m_canceled = true;
                        return;
                    }
                    buildDocumentationFor(s);
                    m_currentPlugin++;
                    monitor.worked(m_currentPlugin);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    try {
        m_dialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        m_monitor.done();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DynamicNodeDescriptionCreator.htmlString(org.knime.workbench.repository.util.DynamicNodeDescriptionCreator.htmlString) InvocationTargetException(java.lang.reflect.InvocationTargetException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) 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