List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork
. From source file:org.eclipse.ajdt.internal.ui.preferences.AJCompilerPreferencePage.java
License:Open Source License
protected void doFullBuild() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try {/*from www . j a v a2 s . c om*/ dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask("", 2); //$NON-NLS-1$ try { monitor.setTaskName(UIMessages.OptionsConfigurationBlock_buildall_taskname); ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new SubProgressMonitor(monitor, 2)); } catch (CoreException e) { AJDTErrorHandler.handleAJDTError(UIMessages.OptionsConfigurationBlock_builderror_message, e); } finally { monitor.done(); } } }); } catch (InterruptedException e) { // cancelled by user } catch (InvocationTargetException e) { } }
From source file:org.eclipse.andmore.android.devices.services.console.ADBShellHandler.java
License:Apache License
@Override public IStatus runService(IInstance theInstance, Map<Object, Object> arguments, IProgressMonitor monitor) { IStatus status = Status.OK_STATUS;//from ww w . j av a 2 s.co m List<String> command = new LinkedList<String>(); final IInstance instance = theInstance; File sdkPath = new File(SdkUtils.getSdkPath()); String adbPath = SdkUtils.getAdbPath(); File adb = new File(adbPath); if ((sdkPath != null) && sdkPath.exists() && sdkPath.isDirectory()) { if (adb.exists() && adb.isFile()) { if (instance instanceof ISerialNumbered) { final String[] serialNumber = new String[1]; serialNumber[0] = ((ISerialNumbered) instance).getSerialNumber(); if (serialNumber[0] == null) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { ProgressMonitorDialog dialog = new ProgressMonitorDialog( new Shell(PlatformUI.getWorkbench().getDisplay())); try { dialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int limit = 20; SubMonitor theMonitor = SubMonitor.convert(monitor); theMonitor.beginTask(ServicesNLS.ADBShellHandler_WaitingDeviceToLoad, limit); int times = 0; while ((serialNumber[0] == null) && (times < limit)) { theMonitor.worked(1); Thread.sleep(500); serialNumber[0] = ((ISerialNumbered) instance).getSerialNumber(); times++; } theMonitor.setWorkRemaining(0); } }); } catch (Exception e) { // do nothing } } }); } // Fix a condition that Studio holds the UI thread forever if (serialNumber[0] == null) { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_ADBShellHandler_CouldNotExecuteTheAdbShell); return status; } if (adbPath.contains(" ")) //$NON-NLS-1$ { if (DeviceServicesPlugin.IS_WIN32) { adbPath = "\"" + adbPath + "\""; //$NON-NLS-1$ //$NON-NLS-2$ } else { adbPath = adbPath.replace(" ", "\\ "); //$NON-NLS-1$ //$NON-NLS-2$ } } command.add(adbPath); command.add(SERIAL_PARAMETER); command.add(serialNumber[0]); command.add(SHELL_COMMAND); try { Integer i = consolesCache.get(serialNumber[0]); i = (i == null ? 1 : ++i); consolesCache.put(serialNumber[0], i); String[] cmdArray = command.toArray(new String[4]); StringBuffer sb = new StringBuffer(); for (String cmd : cmdArray) { sb.append(cmd); sb.append(" "); //$NON-NLS-1$ } Process p = Runtime.getRuntime().exec(cmdArray); String consoleName = CONSOLE_NAME + " - " + serialNumber[0]; //$NON-NLS-1$ if (i != null) { consoleName += " (" + i + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } consolesProcesses.put(consoleName, p); DeviceServicesPlugin.redirectProcessStreamsToConsole(p, consoleName); DeviceServicesPlugin.addConsoleKilledListener(listener); } catch (IOException e) { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_ADBShellHandler_CouldNotExecuteTheAdbShell, e); } } } else { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_ADBShellHandler_MissingAdbShell); } } else { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_ADBShellHandler_AndroidSdkIsNotConfigured); } return status; }
From source file:org.eclipse.andmore.android.devices.services.console.EmulatorConsoleHandler.java
License:Apache License
@Override public IStatus runService(final IInstance instance, Map<Object, Object> arguments, IProgressMonitor monitor) { IStatus status = Status.OK_STATUS;//from w ww .jav a 2 s . co m if (instance instanceof ISerialNumbered) { // Retrieve the emulator port from its serial number Pattern pattern = Pattern.compile("emulator-([0-9]+)"); final String[] serialNumber = new String[1]; serialNumber[0] = ((ISerialNumbered) instance).getSerialNumber(); if (serialNumber[0] == null) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { ProgressMonitorDialog dialog = new ProgressMonitorDialog( new Shell(PlatformUI.getWorkbench().getDisplay())); try { dialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int limit = 20; SubMonitor theMonitor = SubMonitor.convert(monitor); theMonitor.beginTask(ServicesNLS.ADBShellHandler_WaitingDeviceToLoad, limit); int times = 0; while ((serialNumber[0] == null) && (times < limit)) { theMonitor.worked(1); Thread.sleep(500); serialNumber[0] = ((ISerialNumbered) instance).getSerialNumber(); times++; } theMonitor.setWorkRemaining(0); } }); } catch (Exception e) { // do nothing } } }); } // Fix a condition that Studio holds the UI thread forever if (serialNumber[0] == null) { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_EmulatorConsoleHandler_CouldNotOpenTheConsoleShell); return status; } Matcher matcher = pattern.matcher(serialNumber[0]); if (matcher.matches()) { String port = matcher.group(1); final TelnetFrameworkAndroid telnet = new TelnetFrameworkAndroid(); try { Integer i = consolesCache.get(serialNumber[0]); i = (i == null ? 1 : ++i); consolesCache.put(serialNumber[0], i); telnet.connect(LOCALHOST, Integer.parseInt(port)); InputStream in = telnet.getInputStream(); OutputStream out = telnet.getOutputStream(); String consoleName = CONSOLE_NAME + " - " + serialNumber[0]; if (i != null) { consoleName += " (" + i + ")"; } telnetsCache.put(consoleName, telnet); DeviceServicesPlugin.addConsoleKilledListener(listener); DeviceServicesPlugin.redirectStreamsToConsole(in, out, consoleName); } catch (IOException e) { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_EmulatorConsoleHandler_CouldNotOpenTheConsoleShell, e); } } } else { status = new Status(IStatus.ERROR, DeviceServicesPlugin.PLUGIN_ID, ServicesNLS.ERR_EmulatorConsoleHandler_CouldNotRetrieveTheEmulatorPort); } return status; }
From source file:org.eclipse.andmore.android.emulator.ui.view.AbstractAndroidView.java
License:Apache License
/** * Stops all emulator instances with the Progress Monitor opened. *///from www.ja v a 2s .c o m private void stopEmulatorInstances() { // defines the runnable object for stopping emulator instances. final IRunnableWithProgress stopRunnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { Collection<IAndroidEmulatorInstance> startedInstances = DeviceFrameworkManager.getInstance() .getAllStartedInstances(); boolean errorsHappened = false; for (IAndroidEmulatorInstance instance : startedInstances) { try { instance.stop(true); } catch (InstanceStopException e) { errorsHappened = true; } } // if closing on shutdown, use a progress bar and stall UI if (closingOnShutdown) { // start a progress monitor monitor.beginTask("", IProgressMonitor.UNKNOWN); // make sure the stop instance job finished Job[] jobs = Job.getJobManager().find(null); // get all jobs for (Job job : jobs) { if (job.getName().equals(EmulatorNLS.UI_AbstractAndroidView_StopInstanceJob)) { // when job result is not null, it has finished while (job.getResult() == null) { try { // sleep a little so the waiting is not too // busy Thread.sleep(1000); } catch (InterruptedException e) { // do nothing } } } } } if (errorsHappened) { EclipseUtils.showErrorDialog(EmulatorNLS.GEN_Error, EmulatorNLS.EXC_AncroidView_CannotRunMultipleStopServices); } } }; // executes the runnable defined above. PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { Shell currentShell = getViewSite().getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(currentShell); try { dialog.run(true, false, stopRunnable); } catch (Exception e) { // Should not have exceptions. // The runnable is not interrupted and it handles exceptions // internally // Log runtime exceptions error("Runtime exception was thrown: " + e.getClass().getSimpleName()); } } }); }
From source file:org.eclipse.andmore.android.generatemenucode.ui.GenerateMenuCodeHandler.java
License:Apache License
/** * Open {@link GenerateMenuCodeDialog} and use * {@link JavaModifierBasedOnMenu} to insert code into Android source code * (Activity/Fragment)./*from w w w . ja v a 2s. c o m*/ */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { SelectionBean selectionBean = resolveSelection(event); if (selectionBean.isProject() || selectionBean.isAllowedClassInstance()) { final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); GenerateMenuCodeDialog menuDialog = new GenerateMenuCodeDialog(window.getShell(), CodeUtilsNLS.GenerateMenuCodeDialog_DefaultMessage, CodeUtilsNLS.GenerateMenuCodeDialog_Title, CodeUtilsNLS.GenerateMenuCodeDialog_ShellTitle, CodeUtilsActivator.getImageDescriptor(WIZARD_IMAGE_PATH).createImage()); final JavaModifierBasedOnMenu modifier = new JavaModifierBasedOnMenu(); menuDialog.init(modifier, selectionBean.getJavaProject(), selectionBean.getJavaFile()); int status = menuDialog.open(); if (status == Window.OK) { ICompilationUnit compilationUnit = menuDialog.getJavaFile(); IEditorPart editor = null; try { editor = JavaUI.openInEditor(compilationUnit); } catch (Exception e) { AndmoreLogger.warn(GenerateMenuCodeHandler.class, "Unable to open editor or bring it to front for Java file while trying to generate menu code based on xml file", //$NON-NLS-1$ e); } final ProgressMonitorDialog dialog = new ProgressMonitorDialog(menuDialog.getShell()); final IEditorPart editorPart = editor; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { try { dialog.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { // collect usage data - UDC AndmoreLogger.collectUsageData(UsageDataConstants.WHAT_VIEW_BY_MENU_EXEC, UsageDataConstants.KIND_VIEW_BY_MENU_EXEC, "View by menu feature executed.", //$NON-NLS-1$ CodeUtilsActivator.PLUGIN_ID, CodeUtilsActivator.getDefault() .getBundle().getVersion().toString()); modifier.insertCode(monitor, editorPart); } catch (final JavaModelException e) { final MultiStatus errorStatus = new MultiStatus( CodeUtilsActivator.PLUGIN_ID, IStatus.ERROR, "Error inserting code on activity/fragment based on menu", //$NON-NLS-1$ null); errorStatus.merge(e.getStatus()); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { IStatus mostSevere = EclipseUtils.findMostSevereError(errorStatus); ErrorDialog.openError( PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error inserting code on activity/fragment based on menu", //$NON-NLS-1$ e.getMessage(), mostSevere); } }); AndmoreLogger.error(this.getClass(), "Error inserting code on activity/fragment based on menu" //$NON-NLS-1$ + ": " + e.getMessage()); //$NON-NLS-1$ } } }); } catch (Exception e) { AndmoreLogger.error(this.getClass(), "Error inserting code on activity/fragment based on menu" //$NON-NLS-1$ + ": " + e.getMessage()); //$NON-NLS-1$ } } }); } } else { EclipseUtils.showErrorDialog(CodeUtilsNLS.GenerateMenuCodeDialog_Title, CodeUtilsNLS.GenerateMenuCodeHandler_SelectedClassNeitherActivityFragment);// GenerateMenuCodeHandler_SelectedClassNeitherActivityFragment } return null; }
From source file:org.eclipse.andmore.android.generateviewbylayout.ui.AbstractCodeGeneratorHandler.java
License:Apache License
protected static void executeCodeGenerationWizard(ExecutionEvent event, IFile javaFile, final IProject javaProject, final AbstractLayoutItemsDialog layoutDialog) { final JavaModifierBasedOnLayout modifier = new JavaModifierBasedOnLayout(); layoutDialog.init(modifier, javaProject, javaFile); int status = layoutDialog.open(); if (status == Window.OK) { ICompilationUnit compilationUnit = layoutDialog.getJavaFile(); IEditorPart editor = null;//from ww w .ja v a 2 s. co m try { editor = JavaUI.openInEditor(compilationUnit); } catch (Exception e) { AndmoreLogger.warn(AbstractCodeGeneratorHandler.class, "Unable to open editor or bring it to front for Java file while trying to generate code from layout xml file", //$NON-NLS-1$ e); } final ProgressMonitorDialog dialog = new ProgressMonitorDialog(layoutDialog.getShell()); final IEditorPart editorPart = editor; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { try { dialog.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { // collect usage data - UDC AndmoreLogger.collectUsageData(UsageDataConstants.WHAT_VIEW_BY_LAYOUT_EXEC, UsageDataConstants.KIND_VIEW_BY_LAYOUT_EXEC, "View by layout feature executed.", //$NON-NLS-1$ CodeUtilsActivator.PLUGIN_ID, CodeUtilsActivator.getDefault().getBundle().getVersion().toString()); modifier.insertCode(monitor, editorPart); } catch (final JavaModelException e) { final MultiStatus errorStatus = new MultiStatus(CodeUtilsActivator.PLUGIN_ID, IStatus.ERROR, "Error inserting code on activity/fragment based on layout", null); errorStatus.merge(e.getStatus()); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { IStatus mostSevere = EclipseUtils.findMostSevereError(errorStatus); ErrorDialog.openError( PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error inserting code on activity/fragment based on layout", e.getMessage(), mostSevere); } }); AndmoreLogger.error(this.getClass(), "Error inserting code on activity/fragment based on layout" + ": " //$NON-NLS-2$ + e.getMessage()); } } }); } catch (Exception e) { AndmoreLogger.error(this.getClass(), "Error inserting code on activity/fragment based on layout" + ": " //$NON-NLS-2$ + e.getMessage()); } } }); } }
From source file:org.eclipse.andmore.android.packaging.ui.export.PackageExportWizardArea.java
License:Apache License
/** * do the finish: Create the package for each selected descriptor */// ww w . j ava 2 s.c o m public boolean performFinish() { final boolean[] finished = { false }; boolean destOK = false; final MultiStatus status = new MultiStatus(PackagingUIPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$ ProgressMonitorDialog monitorDialog = null; String DESCRIPTION_TO_LOG = UsageDataConstants.DESCRIPTION_DEFAULT; try { destOK = checkDestination(); } catch (CoreException e) { status.add(e.getStatus()); } if (destOK) { monitorDialog = new ProgressMonitorDialog(parentComposite.getShell()); try { monitorDialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor aMonitor) throws InvocationTargetException, InterruptedException { int finishSize = getSelectedItems().size() * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER; SubMonitor monitor = SubMonitor.convert(aMonitor); monitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_FINISH_ACTION_LABEL, finishSize); IPath exportDestinationFolder = new Path(destinationText.getText()); IPath exportDestinationFile = null; for (TreeItem item : getSelectedItems()) { // get the eclipse project as a java project to get // the project // destination IProject eclipseProject = (IProject) item.getData(); try { monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); JavaProject javaProject = new JavaProject(); javaProject.setProject(eclipseProject); // find all packages built by Android builder Map<String, String> apkConfigurations = SdkUtils .getAPKConfigurationsForProject(eclipseProject); Set<String> apkConfNames = new HashSet<String>(); if (apkConfigurations != null) { apkConfNames.addAll(apkConfigurations.keySet()); } apkConfNames.add(""); // the default package //$NON-NLS-1$ SubMonitor submonitor = monitor .newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); submonitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_EXPORTING_ACTION_LABEL, 3 * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER * apkConfNames.size()); for (String apkConfName : apkConfNames) { String apkName = eclipseProject.getName() + (apkConfName.isEmpty() ? apkConfName : "-" //$NON-NLS-1$ + apkConfName); if (defaultDestination.getSelection()) { exportDestinationFolder = eclipseProject.getLocation() .append(CertificateManagerActivator.PACKAGE_PROJECT_DESTINATION); } exportDestinationFile = exportDestinationFolder.append(apkName) .addFileExtension(CertificateManagerActivator.PACKAGE_EXTENSION); File file = exportDestinationFile.toFile(); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); // always export unsigned package AdtUtils.exportUnsignedReleaseApk(javaProject.getProject(), file, submonitor); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); if (signCheckBox.getSelection()) { // sign the package if required IStatus signStatus = signPackage(eclipseProject, file); status.add(signStatus); } // zipalign the file and we are done // exporting the package PackageFile.zipAlign(file); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); } submonitor.done(); } catch (CoreException e) { AndmoreLogger.error(PackageExportWizardArea.class, "Error while building project or getting project output folder" //$NON-NLS-1$ + eclipseProject.getName(), e); status.add(new Status(IStatus.ERROR, PackagingUIPlugin.PLUGIN_ID, Messages.PACKAGE_EXPORT_WIZARD_AREA_ERROR_PROJECT_BUILD + " " //$NON-NLS-1$ + eclipseProject.getName())); } finally { try { eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4)); } catch (CoreException e) { // do nothing } } monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); } finished[0] = true; } }); } catch (Exception e) { AndmoreLogger.warn("Error finishing package export."); } } if (!status.isOK()) { status.getMessage(); DESCRIPTION_TO_LOG = Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE; ErrorDialog.openError(parentComposite.getShell(), Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE, Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_MESSAGE, status); } // Saving usage data try { AndmoreLogger.collectUsageData(UsageDataConstants.WHAT_APP_MANAGEMENT_PACKAGE, UsageDataConstants.KIND_APP_MANAGEMENT, DESCRIPTION_TO_LOG, PackagingUIPlugin.PLUGIN_ID, PackagingUIPlugin.getDefault().getBundle().getVersion().toString()); } catch (Throwable e) { // Do nothing, but error on the log should never prevent app from // working } return finished[0]; }
From source file:org.eclipse.andmore.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.jav a 2s .c o m } 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() != Window.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(IStatus.ERROR, DdmsPlugin.PLUGIN_ID, "Unexpected error while collecting system trace.", e.getCause())); } catch (InterruptedException ignore) { } }
From source file:org.eclipse.cdt.cpp.ui.internal.actions.CloseProjectAction.java
License:Open Source License
public void run() { for (int i = 0; i < _projects.size(); i++) { IProject project = (IProject) _projects.get(i); CloseOperation op = new CloseOperation(project, _api); ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(_api.getDummyShell()); try {/* w ww . j a v a 2 s. co m*/ progressDlg.run(true, true, op); } catch (InterruptedException e) { } catch (InvocationTargetException e) { } } }
From source file:org.eclipse.cdt.cpp.ui.internal.actions.CopyAction.java
License:Open Source License
public void run() { ModelInterface api = ModelInterface.getInstance(); ChooseProjectDialog dlg = new ChooseProjectDialog("Choose a Directory to Copy to", api.findWorkspaceElement()); dlg.useFilter(true);// w ww .j a v a 2 s .c o m dlg.open(); if (dlg.getReturnCode() == dlg.OK) { List projects = dlg.getSelected(); for (int i = 0; i < _subjects.size(); i++) { DataElement subject = (DataElement) _subjects.get(i); CopyOperation op = new CopyOperation(subject, projects, api); ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(api.getDummyShell()); try { progressDlg.run(false, true, op); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }