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

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

Introduction

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

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:com.skratchdot.riff.wav.presentation.WavEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->// www. j a va 2s. com
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    IRunnableWithProgress operation = new IRunnableWithProgress() {
        // This is the method that gets invoked when the operation runs.
        //
        public void run(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        RIFFWaveEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.smartmonkey.recrep.actions.ScreenshotAction.java

License:Apache License

@Override
public void run() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell());
    try {/*from w ww .j  av a2 s  . co m*/
        dialog.run(true, false, new IRunnableWithProgress() {
            private void showError(final String msg, final Throwable t, IProgressMonitor monitor) {
                monitor.done();
                mViewer.getShell().getDisplay().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        Status s = new Status(IStatus.ERROR, "Screenshot", msg, t);
                        ErrorDialog.openError(mViewer.getShell(), "Error", "Cannot take screenshot", s);
                    }
                });
            }

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProcRunner procRunner = null;
                String serial = System.getenv("ANDROID_SERIAL");
                File tmpDir = null;
                File xmlDumpFile = null;
                File screenshotFile = null;
                int retCode = -1;
                try {
                    tmpDir = File.createTempFile("uiautomatorviewer_", "");
                    tmpDir.delete();
                    if (!tmpDir.mkdirs())
                        throw new IOException("Failed to mkdir");
                    xmlDumpFile = File.createTempFile("dump_", ".xml", tmpDir);
                    screenshotFile = File.createTempFile("screenshot_", ".png", tmpDir);
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Cannot get temp directory", e, monitor);
                    return;
                }

                // boiler plates to do a bunch of adb stuff to take XML
                // snapshot and screenshot
                monitor.beginTask("Getting UI status dump from device...", IProgressMonitor.UNKNOWN);
                monitor.subTask("Detecting device...");
                procRunner = ProcUtils.getAdbRunner(serial, "shell", "ls", "/system/bin/uiautomator");
                try {
                    retCode = procRunner.run(30000);
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to detect device", e, monitor);
                    return;
                }
                if (retCode != 0) {
                    showError("No device or multiple devices connected. "
                            + "Use ANDROID_SERIAL environment variable " + "if you have multiple devices", null,
                            monitor);
                    return;
                }
                if (procRunner.getOutputBlob().indexOf("No such file or directory") != -1) {
                    showError("/system/bin/uiautomator not found on device", null, monitor);
                    return;
                }
                monitor.subTask("Deleting old UI XML snapshot ...");
                procRunner = ProcUtils.getAdbRunner(serial, "shell", "rm", "/sdcard/uidump.xml");
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException("Non-zero return code from \"rm\" xml dump command:\n"
                                + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to execute \"rm\" xml dump command.", e, monitor);
                    return;
                }

                monitor.subTask("Taking UI XML snapshot...");
                procRunner = ProcUtils.getAdbRunner(serial, "shell", "/system/bin/uiautomator", "dump",
                        "/sdcard/uidump.xml");
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException(
                                "Non-zero return code from dump command:\n" + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to execute dump command.", e, monitor);
                    return;
                }
                procRunner = ProcUtils.getAdbRunner(serial, "pull", "/sdcard/uidump.xml",
                        xmlDumpFile.getAbsolutePath());
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException(
                                "Non-zero return code from pull command:\n" + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to pull dump file.", e, monitor);
                    return;
                }

                monitor.subTask("Deleting old device screenshot...");
                procRunner = ProcUtils.getAdbRunner(serial, "shell", "rm", "/sdcard/screenshot.png");
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException("Non-zero return code from \"rm\" screenshot command:\n"
                                + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to execute \"rm\" screenshot command.", e, monitor);
                    return;
                }

                monitor.subTask("Taking device screenshot...");
                procRunner = ProcUtils.getAdbRunner(serial, "shell", "screencap", "-p",
                        "/sdcard/screenshot.png");
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException(
                                "Non-zero return code from screenshot command:\n" + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to execute screenshot command.", e, monitor);
                    return;
                }
                procRunner = ProcUtils.getAdbRunner(serial, "pull", "/sdcard/screenshot.png",
                        screenshotFile.getAbsolutePath());
                try {
                    retCode = procRunner.run(30000);
                    if (retCode != 0) {
                        throw new IOException(
                                "Non-zero return code from pull command:\n" + procRunner.getOutputBlob());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    showError("Failed to pull dump file.", e, monitor);
                    return;
                }

                monitor.subTask("Getting Chimp...");
                IChimpDevice device = SMonkeyModel.getModel().getChimp();
                if (device == null) {
                    // get the Chimpchat device
                    try {
                        long TIMEOUT = 5000;
                        ChimpChat mChimpChat = ChimpChat.getInstance();
                        device = mChimpChat.waitForConnection(TIMEOUT, ".*");
                        if (device == null) {
                            throw new RuntimeException("Chimp Timeout");
                        }
                        device.wake();

                    } catch (Exception e) {
                        e.printStackTrace();
                        showError("Failed to get MonkeyDevice", e, monitor);
                    }

                } else {
                    monitor.subTask("Already have chimp");
                }

                final File png = screenshotFile, xml = xmlDumpFile;
                final IChimpDevice finaldevice = device;
                if (png.length() == 0) {
                    showError("Screenshot file size is 0", null, monitor);
                    return;
                } else {
                    mViewer.getShell().getDisplay().syncExec(new Runnable() {
                        @Override
                        public void run() {
                            SMonkeyModel.getModel().loadScreenshotAndXmlDump(png, xml);
                            SMonkeyModel.getModel().setChimp(finaldevice);
                        }
                    });
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.symbian.driver.presentation.DriverEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from w  w w.jav  a 2  s.  co m*/
 * <!-- end-user-doc -->
 * @generated
 */
//   @Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        //            @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        savedResources.add(resource);
                        resource.save(saveOptions);
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        DriverEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.symbian.ini.presentation.IniEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from w ww  .  j a v  a  2s  .  c o m*/
 * <!-- end-user-doc -->
 * @generated
 */
//   @Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        //            @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        savedResources.add(resource);
                        resource.save(saveOptions);
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        IniEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.symbian.smt.gui.smtwidgets.XmlFileSelectionDialog.java

License:Open Source License

@Override
protected void okPressed() {
    IRunnableWithProgress op = new IRunnableWithProgress() {
        String input = getValue();
        String result;/*www. j a  v a  2s  .c  o  m*/

        // Validation of the XML content does not happen here as an invalid XML
        // file
        // is deemed acceptable. It occurs as part of the update that takes
        // place
        // in the ManageResources class, which is also responsible for arranging
        // for error markers to be placed on any invalid resource file or sys
        // def file.
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Reading " + input, 2);

            try {
                input = getValue();

                if (validator.isUrl(input)) {
                    result = validator.isUrlResourceReadable(input);
                } else { // If file path is local
                    result = validator.isFileReadable(input);
                }
            } catch (InvalidPathException e) {
                result = e.getMessage();
            }

            monitor.worked(1);
            monitor.setTaskName("Checking validation");
            setValidationError(result);
            monitor.worked(1);
            monitor.done();
        }
    };

    try {
        new ProgressMonitorDialog(getShell()).run(true, false, op);
    } catch (InterruptedException e) {
        return;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return;
    } finally {
        if (validationError != null) {
            setErrorMessage(validationError);
            setValidationError(null);

            return;
        }
    }

    super.okPressed();
}

From source file:com.symbian.tef.script.presentation.ScriptEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//from  w  ww .  ja  v  a  2 s  .c o m
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        savedResources.add(resource);
                        resource.save(saveOptions);
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        TefEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.sympedia.density.gen.arch.presentation.ArchEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from w ww.j  a v a 2 s  .c  om*/
 * <!-- end-user-doc -->
 * @generated
 */
public void doSave(IProgressMonitor progressMonitor) {
    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        public void execute(IProgressMonitor monitor) {
            try {
                // Save the resource to the file system.
                //
                Resource savedResource = (Resource) editingDomain.getResourceSet().getResources().get(0);
                savedResources.add(savedResource);
                savedResource.save(Collections.EMPTY_MAP);
            } catch (Exception exception) {
                ArchEditorActivator.INSTANCE.log(exception);
            }
        }
    };

    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        ArchEditorActivator.INSTANCE.log(exception);
    }
}

From source file:com.sympedia.density.gen.deploy.presentation.DeployEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//from w  w  w . j  ava  2  s  .  c  om
 * <!-- end-user-doc -->
 * @generated
 */
public void doSave(IProgressMonitor progressMonitor) {
    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        public void execute(IProgressMonitor monitor) {
            try {
                // Save the resource to the file system.
                //
                Resource savedResource = (Resource) editingDomain.getResourceSet().getResources().get(0);
                savedResources.add(savedResource);
                savedResource.save(Collections.EMPTY_MAP);
            } catch (Exception exception) {
                DeployEditorPlugin.INSTANCE.log(exception);
            }
        }
    };

    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        DeployEditorPlugin.INSTANCE.log(exception);
    }
}

From source file:com.sympedia.density.gen.deploytest.presentation.DeploytestEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//from   w ww  . j  a  v  a 2  s .c om
 * <!-- end-user-doc -->
 * @generated
 */
public void doSave(IProgressMonitor progressMonitor) {
    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        public void execute(IProgressMonitor monitor) {
            try {
                // Save the resource to the file system.
                //
                Resource savedResource = (Resource) editingDomain.getResourceSet().getResources().get(0);
                savedResources.add(savedResource);
                savedResource.save(Collections.EMPTY_MAP);
            } catch (Exception exception) {
                DeploytestEditorPlugin.INSTANCE.log(exception);
            }
        }
    };

    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        DeploytestEditorPlugin.INSTANCE.log(exception);
    }
}

From source file:com.sympedia.genfw.presentation.GenfwEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//from w  ww.j  a v a 2  s.  co  m
 * <!-- end-user-doc -->
 * @generated
 */
public void doSave(IProgressMonitor progressMonitor) {
    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        public void execute(IProgressMonitor monitor) {
            try {
                // Save the resources to the file system.
                //
                boolean first = true;
                for (Iterator i = editingDomain.getResourceSet().getResources().iterator(); i.hasNext();) {
                    Resource resource = (Resource) i.next();
                    if ((first || !resource.getContents().isEmpty()) && !editingDomain.isReadOnly(resource)) {
                        savedResources.add(resource);
                        resource.save(Collections.EMPTY_MAP);
                    }
                    first = false;
                }
            } catch (Exception exception) {
                GenfwEditorPlugin.INSTANCE.log(exception);
            }
        }
    };

    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        GenfwEditorPlugin.INSTANCE.log(exception);
    }
}