Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run.

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:ch.novcom.elexis.mednet.plugin.ui.commands.GetResult.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ProgressMonitorDialog progress = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event));

    try {/*from  w  w  w.j a  v  a2 s  . c  om*/
        progress.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                DocumentImporterPage dip = new DocumentImporterPage();
                try {
                    dip.doImport(monitor);
                } catch (Exception e) {
                    LOGGER.error("execute() - " + "Exception calling doImport", e);//$NON-NLS-1$
                }

            }
        });

    } catch (InvocationTargetException | InterruptedException e) {
        MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler",
                "Fehler beim PDF erzeugen.\n" + e.getMessage());
    }

    return null;
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.wizards.DockerFoundryServiceWizardPage.java

License:Open Source License

/** Returns the list of available services, or null if the user cancelled the monitor. */
private List<AvailableService> updateConfiguration() {
    final List<AvailableService> result = new ArrayList<AvailableService>();

    try {/* w  ww .j  a  va2  s. com*/

        final GetServiceOfferingsRunnable runnable = new GetServiceOfferingsRunnable();

        // Begin retrieving the service offerings
        ProgressMonitorDialog monitorDlg = new ProgressMonitorDialog(getShell());
        monitorDlg.run(true, true, runnable);

        // If the user cancelled service acquisition, then just return null.
        if (runnable.isUserCancelled()) {
            return null;
        }

        if (runnable.getServiceOfferingResult() != null) {
            int index = 0;
            for (DockerContainerElement o : runnable.getServiceOfferingResult()) {
                String name = o.getName();
                String image = "Image: " + o.getImage();
                result.add(new AvailableService(name, image, index, o));
                index++;
            }
        }
    } catch (InvocationTargetException e) {
        IStatus status = cloudServer.error(NLS.bind(
                Messages.DockerFoundryServiceWizardPage_ERROR_CONFIG_RETRIVE, e.getCause().getMessage()), e);
        StatusManager.getManager().handle(status, StatusManager.LOG);
        setMessage(status.getMessage(), IMessageProvider.ERROR);
    } catch (InterruptedException e) {
        if (Logger.WARNING) {
            Logger.println(Logger.WARNING_LEVEL, this, "updateConfiguration", //$NON-NLS-1$
                    "Failed to load the list of available services."); //$NON-NLS-1$
        }
    }

    return result;
}

From source file:com.aljoschability.defectr.ui.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();/*from  w  w w .  ja va  2  s.c o m*/
    dialog.run(true, true, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                Object clientObject = contribution.getObject();
                System.out.println(clientObject);
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                // pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:com.android.ddmuilib.heap.NativeHeapPanel.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  w  ww.j a  va 2  s  .com*/
public void clientChanged(final Client client, int changeMask) {
    if (client != getCurrentClient()) {
        return;
    }

    if ((changeMask & Client.CHANGE_NATIVE_HEAP_DATA) != Client.CHANGE_NATIVE_HEAP_DATA) {
        return;
    }

    List<NativeAllocationInfo> allocations = client.getClientData().getNativeAllocationList();
    if (allocations.size() == 0) {
        return;
    }

    // We need to clone this list since getClientData().getNativeAllocationList() clobbers
    // the list on future updates
    final List<NativeAllocationInfo> nativeAllocations = shallowCloneList(allocations);

    addNativeHeapSnapshot(new NativeHeapSnapshot(nativeAllocations));
    updateDisplay();

    // Attempt to resolve symbols in a separate thread.
    // The UI should be refreshed once the symbols have been resolved.
    if (USE_OLD_RESOLVER) {
        Thread t = new Thread(
                new SymbolResolverTask(nativeAllocations, client.getClientData().getMappedNativeLibraries()));
        t.setName("Address to Symbol Resolver");
        t.start();
    } else {
        Display.getDefault().asyncExec(new Runnable() {
            @Override
            public void run() {
                resolveSymbols();
                mDetailsTreeViewer.refresh();
                mStackTraceTreeViewer.refresh();
            }

            public void resolveSymbols() {
                Shell shell = Display.getDefault().getActiveShell();
                ProgressMonitorDialog d = new ProgressMonitorDialog(shell);

                NativeSymbolResolverTask resolver = new NativeSymbolResolverTask(nativeAllocations,
                        client.getClientData().getMappedNativeLibraries(), mSymbolSearchPathText.getText(),
                        client.getClientData().getAbi());

                try {
                    d.run(true, true, resolver);
                } catch (InvocationTargetException e) {
                    MessageDialog.openError(shell, "Error Resolving Symbols", e.getCause().getMessage());
                    return;
                } catch (InterruptedException e) {
                    return;
                }

                MessageDialog.openInformation(shell, "Symbol Resolution Status",
                        getResolutionStatusMessage(resolver));
            }
        });
    }
}

From source file:com.android.ddmuilib.heap.NativeHeapPanel.java

License:Apache License

private void loadHeapDataFromFile() {
    // pop up a file dialog and get the file to load
    final String path = getHeapDumpToImport();
    if (path == null) {
        return;/*from www  .j a v  a2 s .c  o m*/
    }

    Reader reader = null;
    try {
        reader = new FileReader(path);
    } catch (FileNotFoundException e) {
        // cannot occur since user input was via a FileDialog
    }

    Shell shell = Display.getDefault().getActiveShell();
    ProgressMonitorDialog d = new ProgressMonitorDialog(shell);

    NativeHeapDataImporter importer = new NativeHeapDataImporter(reader);
    try {
        d.run(true, true, importer);
    } catch (InvocationTargetException e) {
        // exception while parsing, display error to user and then return
        MessageDialog.openError(shell, "Error Importing Heap Data", e.getCause().getMessage());
        return;
    } catch (InterruptedException e) {
        // operation cancelled by user, simply return
        return;
    }

    NativeHeapSnapshot snapshot = importer.getImportedSnapshot();

    addToImportedSnapshots(snapshot); // save imported snapshot for future use
    addNativeHeapSnapshot(snapshot); // add to currently displayed snapshots as well

    updateDisplay();
}

From source file:com.android.glesv2debugger.CodeGen.java

License:Apache License

void codeGenFrames(final DebugContext dbgCtx, int count, final Shell shell) {
    this.dbgCtx = dbgCtx;
    this.count = count;
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    this.progress = dialog.getProgressMonitor();
    try {//from  w w w.  j a  va 2s . com
        dialog.run(false, true, this);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        assert false;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    this.dbgCtx = null;
    this.count = 0;
    progress = null;
}

From source file:com.android.ide.eclipse.ddms.views.DeviceView.java

License:Apache License

private void takeUiAutomatorSnapshot(final IDevice device, final Shell shell) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {//w w w .ja v a  2 s.  co  m
        dialog.run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                UiAutomatorResult result = null;
                try {
                    result = UiAutomatorHelper.takeSnapshot(device, monitor);
                } catch (UiAutomatorException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }

                UiAutomatorViewer.openEditor(result);
            }
        });
    } catch (Exception e) {
        Throwable t = e;
        if (e instanceof InvocationTargetException) {
            t = ((InvocationTargetException) e).getTargetException();
        }
        Status s = new Status(IStatus.ERROR, DdmsPlugin.PLUGIN_ID, "Error obtaining UI hierarchy", t);
        ErrorDialog.openError(shell, "UI Automator", "Unexpected error while obtaining UI hierarchy", s);
    }
}

From source file:com.android.ide.eclipse.ddms.views.DeviceView.java

License:Apache License

private void launchSystrace(final IDevice device, final Shell parentShell) {
    final File systraceAssets = new File(DdmsPlugin.getPlatformToolsFolder(), "systrace"); //$NON-NLS-1$
    if (!systraceAssets.isDirectory()) {
        MessageDialog.openError(parentShell, "Systrace",
                "Updated version of platform-tools (18.0.1 or greater) is required.\n"
                        + "Please update your platform-tools using SDK Manager.");
        return;/*  w w  w  .j av  a2s .  c  om*/
    }

    SystraceVersionDetector detector = new SystraceVersionDetector(device);
    try {
        new ProgressMonitorDialog(parentShell).run(true, false, detector);
    } catch (InvocationTargetException e) {
        MessageDialog.openError(parentShell, "Systrace",
                "Unexpected error while detecting atrace version: " + e);
        return;
    } catch (InterruptedException e) {
        return;
    }

    final ISystraceOptionsDialog dlg;
    if (detector.getVersion() == SystraceVersionDetector.SYSTRACE_V1) {
        dlg = new SystraceOptionsDialogV1(parentShell);
    } else {
        Client[] clients = device.getClients();
        List<String> apps = new ArrayList<String>(clients.length);
        for (int i = 0; i < clients.length; i++) {
            String name = clients[i].getClientData().getClientDescription();
            if (name != null && !name.isEmpty()) {
                apps.add(name);
            }
        }
        dlg = new SystraceOptionsDialogV2(parentShell, detector.getTags(), apps);
    }

    if (dlg.open() != SystraceOptionsDialogV1.OK) {
        return;
    }

    final ISystraceOptions options = dlg.getSystraceOptions();

    // set trace tag if necessary:
    //      adb shell setprop debug.atrace.tags.enableflags <tag>
    String tag = options.getTags();
    if (tag != null) {
        CountDownLatch setTagLatch = new CountDownLatch(1);
        CollectingOutputReceiver receiver = new CollectingOutputReceiver(setTagLatch);
        try {
            String cmd = "setprop debug.atrace.tags.enableflags " + tag;
            device.executeShellCommand(cmd, receiver);
            setTagLatch.await(5, TimeUnit.SECONDS);
        } catch (Exception e) {
            MessageDialog.openError(parentShell, "Systrace", "Unexpected error while setting trace tags: " + e);
            return;
        }

        String shellOutput = receiver.getOutput();
        if (shellOutput.contains("Error type")) { //$NON-NLS-1$
            throw new RuntimeException(receiver.getOutput());
        }
    }

    // obtain the output of "adb shell atrace <trace-options>" and generate the html file
    ProgressMonitorDialog d = new ProgressMonitorDialog(parentShell);
    try {
        d.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                boolean COMPRESS_DATA = true;

                monitor.setTaskName("Collecting Trace Information");
                final String atraceOptions = options.getOptions() + (COMPRESS_DATA ? " -z" : "");
                SystraceTask task = new SystraceTask(device, atraceOptions);
                Thread t = new Thread(task, "Systrace Output Receiver");
                t.start();

                // check if the user has cancelled tracing every so often
                while (true) {
                    t.join(1000);

                    if (t.isAlive()) {
                        if (monitor.isCanceled()) {
                            task.cancel();
                            return;
                        }
                    } else {
                        break;
                    }
                }

                if (task.getError() != null) {
                    throw new RuntimeException(task.getError());
                }

                monitor.setTaskName("Saving trace information");
                SystraceOutputParser parser = new SystraceOutputParser(COMPRESS_DATA,
                        SystraceOutputParser.getJs(systraceAssets), SystraceOutputParser.getCss(systraceAssets),
                        SystraceOutputParser.getHtmlPrefix(systraceAssets),
                        SystraceOutputParser.getHtmlSuffix(systraceAssets));

                parser.parse(task.getAtraceOutput());

                String html = parser.getSystraceHtml();
                try {
                    Files.write(html.getBytes(), new File(dlg.getTraceFilePath()));
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(parentShell, "Systrace", "Unable to collect system trace.",
                new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID,
                        "Unexpected error while collecting system trace.", e.getCause()));
    } catch (InterruptedException ignore) {
    }
}

From source file:com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer.java

License:Apache License

public void setInput(Shell shell, String tracePath) {
    ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
    TraceFileParserTask parser = new TraceFileParserTask(mFilePath);
    try {/* w w  w  . j  a  va  2s. c om*/
        dlg.run(true, true, parser);
    } catch (InvocationTargetException e) {
        // exception while parsing, display error to user
        MessageDialog.openError(shell, "Error parsing OpenGL Trace File", e.getCause().getMessage());
        return;
    } catch (InterruptedException e) {
        // operation canceled by user, just return
        return;
    }

    mTrace = parser.getTrace();
    mShowContextSwitcher = (mTrace == null) ? false : mTrace.getContexts().size() > 1;
    if (mStateViewPage != null) {
        mStateViewPage.setInput(mTrace);
    }
    if (mFrameSummaryViewPage != null) {
        mFrameSummaryViewPage.setInput(mTrace);
    }
    if (mDetailsPage != null) {
        mDetailsPage.setInput(mTrace);
    }
    if (mDurationMinimap != null) {
        mDurationMinimap.setInput(mTrace);
    }

    Display.getDefault().asyncExec(new Runnable() {
        @Override
        public void run() {
            refreshUI();
        }
    });
}

From source file:com.android.uiautomator.actions.ScreenshotAction.java

License:Apache License

@Override
public void run() {
    if (!DebugBridge.isInitialized()) {
        MessageDialog.openError(mViewer.getShell(), "Error obtaining Device Screenshot",
                "Unable to connect to adb. Check if adb is installed correctly.");
        return;// w w w .j  av a 2  s . c o  m
    }

    final IDevice device = pickDevice();
    if (device == null) {
        return;
    }

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell());
    try {
        dialog.run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                UiAutomatorResult result = null;
                try {
                    result = UiAutomatorHelper.takeSnapshot(device, monitor, mCompressed);
                } catch (UiAutomatorException e) {
                    monitor.done();
                    showError(e.getMessage(), e);
                    return;
                }

                mViewer.setModel(result.model, result.uiHierarchy, result.screenshot);
                monitor.done();
            }
        });
    } catch (Exception e) {
        showError("Unexpected error while obtaining UI hierarchy", e);
    }
}