List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.foglyn.ui.FoglynFilterQueryPage.java
License:Open Source License
private void initializePage(IWizardContainer wizard) { final FoglynRepositoryConnector connector = (FoglynRepositoryConnector) TasksUi.getRepositoryManager() .getRepositoryConnector(FoglynCorePlugin.CONNECTOR_KIND); final AtomicReference<List<FogBugzFilter>> filtersRef = new AtomicReference<List<FogBugzFilter>>(); try {// ww w .j ava 2s .co m IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Fetching filters", IProgressMonitor.UNKNOWN); FogBugzClient client = connector.getClientManager().getFogbugzClient(getTaskRepository(), monitor); List<FogBugzFilter> filters = client.listFilters(monitor); filtersRef.set(filters); monitor.done(); } catch (FogBugzException e) { throw new InvocationTargetException(e, e.getMessage()); } catch (CoreException e) { throw new InvocationTargetException(e, e.getMessage()); } } }; wizard.run(true, true, runnable); filtersList.setInput(filtersRef.get()); if (queryToEdit != null && filtersRef.get() != null) { IStructuredSelection sel = null; for (FogBugzFilter filter : filtersRef.get()) { if (filter.getFilterID().equals(queryToEdit.getFilterID())) { sel = new StructuredSelection(filter); break; } } if (sel != null) { filtersList.setSelection(sel, true); } } } catch (InvocationTargetException e) { FoglynUIPlugin.log("Cannot fetch list of filters from FogBugz", e.getCause()); setErrorMessage("Cannot fetch list of filters from FogBugz"); } catch (InterruptedException e) { FoglynUIPlugin.log("Cannot fetch list of filters from FogBugz", e); setErrorMessage("Cannot fetch list of filters from FogBugz"); } }
From source file:com.foglyn.ui.FoglynNewQueryWizardPage.java
License:Open Source License
private void initializePage(IWizardContainer wizard) { final FoglynRepositoryConnector connector = (FoglynRepositoryConnector) TasksUi.getRepositoryManager() .getRepositoryConnector(FoglynCorePlugin.CONNECTOR_KIND); final AtomicReference<List<FogBugzFilter>> filtersRef = new AtomicReference<List<FogBugzFilter>>(); final AtomicReference<Collection<FogBugzProject>> projectsRef = new AtomicReference<Collection<FogBugzProject>>(); final AtomicReference<Collection<FogBugzFixFor>> milestonesRef = new AtomicReference<Collection<FogBugzFixFor>>(); final AtomicReference<FogBugzClient> fbclient = new AtomicReference<FogBugzClient>(); try {/*from w w w . j av a 2 s .co m*/ IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Fetching data from FogBugz server", IProgressMonitor.UNKNOWN); FogBugzClient client = connector.getClientManager().getFogbugzClient(getTaskRepository(), monitor); filtersRef.set(client.listFilters(monitor)); projectsRef.set(client.getAllProjects()); milestonesRef.set(client.getAllFixFors()); fbclient.set(client); monitor.done(); } catch (FogBugzException e) { throw new InvocationTargetException(e, e.getMessage()); } catch (CoreException e) { throw new InvocationTargetException(e, e.getMessage()); } } }; wizard.run(true, true, runnable); client = fbclient.get(); filter.setInput(filtersRef.get()); project.setInput(projectsRef.get()); setupMilestones(fbclient.get(), milestonesRef.get()); QueryType qt = null; if (query != null) { if (query instanceof FilterQuery && filtersRef.get() != null) { qt = QueryType.FILTER_CASES; FilterID fid = ((FilterQuery) query).getFilterID(); for (FogBugzFilter f : filtersRef.get()) { if (f.getFilterID().equals(fid)) { filter.setSelection(new StructuredSelection(f), true); } } } if (query instanceof AdvancedSearchQuery) { AdvancedSearchQuery asq = (AdvancedSearchQuery) query; if (asq.getProject() != null && projectsRef.get() != null) { qt = QueryType.MY_PROJECT_CASES; for (FogBugzProject p : projectsRef.get()) { if (p.getID().equals(asq.getProject())) { project.setSelection(new StructuredSelection(p), true); } } } else if (asq.getFixFor() != null && milestonesRef.get() != null) { qt = QueryType.MY_MILESTONE_CASES; for (FogBugzFixFor m : milestonesRef.get()) { if (m.getID().equals(asq.getFixFor())) { milestone.setSelection(new StructuredSelection(m), true); } } } } if (qt != null) { for (Button b : radioButtons) { b.setSelection(qt.equals(b.getData(QUERY_TYPE_KEY))); } } updateViewers(); queryName.setText(query.getQueryTitle()); } } catch (InvocationTargetException e) { FoglynUIPlugin.log("Cannot fetch data from FogBugz", e.getCause()); setErrorMessage("Cannot fetch data from FogBugz"); } catch (InterruptedException e) { FoglynUIPlugin.log("Cannot fetch data from FogBugz", e); setErrorMessage("Cannot fetch data from FogBugz"); } }
From source file:com.foglyn.ui.OpenAttachmentWithDefaultProgramHandler.java
License:Open Source License
private void openAttachments(final Shell shell, final ITaskAttachment attachment) { String extension = getAttachmentExtension(attachment); final Program program = Program.findProgram(extension); if (program == null) { MessageDialog.openError(shell, "Unable to find default program", "Cannot find default program associated with " + attachment.getFileName()); return;//from w ww .j a v a 2 s .co m } IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { String filename = "unknown.bin"; if (attachment.getFileName() != null) { filename = attachment.getFileName(); } File file = null; try { file = File.createTempFile("attach-", "-" + filename); } catch (IOException e) { throw new InvocationTargetException(e); } file.deleteOnExit(); monitor.beginTask("Downloading attachment " + filename, IProgressMonitor.UNKNOWN); try { AttachmentUtils.download(attachment, monitor, file); } catch (IOException e) { AttachmentUtils.delete(file); throw new InvocationTargetException(e); } catch (CoreException e) { AttachmentUtils.delete(file); throw new InvocationTargetException(e); } Program program = Program.findProgram(getAttachmentExtension(attachment)); if (program == null) { throw new InvocationTargetException( new CoreException(new Status(IStatus.ERROR, FoglynUIPlugin.PLUGIN_ID, "Cannot find default program associated with " + attachment.getFileName()))); } // everything is OK... invoke if (!program.execute(file.getAbsolutePath())) { throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR, FoglynUIPlugin.PLUGIN_ID, "Unable to start " + program.getName()))); } } }; ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell); try { dlg.run(true, true, runnable); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { MessageDialog.openError(shell, "Unable to open attachment in default program", "Input/output problem occured: " + cause.getMessage()); } else { MessageDialog.openError(shell, "Unable to open attachment in default program", cause.getMessage()); } } catch (InterruptedException e) { // } }
From source file:com.freescale.deadlockpreventer.agent.InstrumentedProcess.java
License:Open Source License
public void downloadGlobalLockState() { FileDialog dialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);//from ww w . ja va2s . c o m dialog.setFileName(label + ".lockState"); final String filePath = dialog.open(); if (filePath == null) return; try { new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { XMLMemento root = XMLMemento.createWriteRoot("locks"); ITransaction transaction = null; try { IMemento locksRoot = root.createChild("root"); HashMap<String, QueryService.IBundleInfo> plugins = new HashMap<String, QueryService.IBundleInfo>(); transaction = queryService.createTransaction(); if (transaction == null) return; int count = transaction.getLockCount(); monitor.beginTask("Saving state...", count); int index = 0; int interval = 100; while (index < count) { ILock[] tmp = transaction.getLocks(index, Math.min(index + interval, count)); monitor.worked(tmp.length); for (int i = 0; i < tmp.length; i++) { XMLUtil.write(locksRoot, tmp[i]); String[] stackTrace = tmp[i].getStackTrace(); if (stackTrace.length > 0) { QueryService.IBundleInfo bundle = transaction.getBundleInfo(tmp[i]); if (!plugins.containsKey(bundle.getName())) plugins.put(bundle.getName(), bundle); } } index += interval; if (monitor.isCanceled()) break; } XMLUtil.write(root, plugins.values()); } finally { if (transaction != null) transaction.close(); } File file = new File(filePath); if (file.exists()) file.delete(); try { FileWriter writer = new FileWriter(file); root.save(writer); writer.close(); } catch (IOException e) { e.printStackTrace(); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { } }
From source file:com.freescale.deadlockpreventer.agent.InstrumentedProcess.java
License:Open Source License
private ArrayList<StatisticsDialog.Row> downloadLocks(final ITransaction[] transactions) { final ArrayList<StatisticsDialog.Row> locks = new ArrayList<StatisticsDialog.Row>(); if (!queryService.isConnected()) { try {// w w w . j a v a 2 s . co m new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { while (!queryService.isConnected()) { if (Display.getDefault().readAndDispatch()) Thread.sleep(100); if (monitor.isCanceled()) break; } } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } if (queryService.isConnected()) { if (!queryService.isClosed()) { try { new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()) .run(true, true, new DownloadRunnable(transactions, locks)); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } if (locks.size() == 0) MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Can't retrieve process information", "Process need to be running to get lock information."); else { StatisticsDialog dialog = new StatisticsDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), locks.toArray(new StatisticsDialog.Row[0]), transactions[0]); dialog.open(); } } return locks; }
From source file:com.freescale.deadlockpreventer.agent.StatisticsUtil.java
License:Open Source License
public static void export(final ITransaction transaction) { FileDialog dialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); String file = dialog.open();//from www . j a v a2s . c o m if (file != null) { File outputFile = new File(file); if (!outputFile.getParentFile().exists()) outputFile.getParentFile().mkdirs(); try { if (!outputFile.exists()) outputFile.createNewFile(); final FileWriter writer = new FileWriter(outputFile); new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int count = transaction.getLockCount(); monitor.beginTask("Downloading statistics...", count); int index = 0; int interval = 100; while (index < count) { ILock[] tmp = transaction.getLocks(index, Math.min(index + interval, count)); monitor.worked(tmp.length); Logger.dumpLockInformation(tmp, writer); index += interval; if (monitor.isCanceled()) break; } monitor.done(); } }); writer.close(); } catch (IOException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:com.ge.research.sadl.ui.imports.OwlFileResourceImportPage1.java
License:Open Source License
/** * Update the tree to only select those elements that match the selected types *//*from w ww. ja va 2 s . c o m*/ protected void setupSelectionsBasedOnSelectedTypes() { ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog(getContainer().getShell()); final Map selectionMap = new Hashtable(); final IElementFilter filter = new IElementFilter() { 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()); } } 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]); } } 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 = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InterruptedException { monitor.beginTask(SADLImportMessages.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(); // The updateSelections method accesses SWT widgets so cannot be executed // as part of the above progress dialog operation since the operation forks // a new process. if (selectionMap != null) { updateSelections(selectionMap); } }
From source file:com.generalrobotix.ui.item.GrxProjectItem.java
License:Open Source License
public void restoreProject() { String mode = manager_.getCurrentModeName(); System.out.println("Restore Project (Mode:" + mode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ IRunnableWithProgress runnableProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InterruptedException { String mode = manager_.getCurrentModeName(); monitor.beginTask("Restore Project (Mode:" + mode + ")", 10); //$NON-NLS-1$ //$NON-NLS-2$ restoreProject_work(mode, monitor); monitor.done();/*from w w w . j a va2 s . c o m*/ } }; ProgressMonitorDialog progressMonitorDlg = new ProgressMonitorDialog( GrxUIPerspectiveFactory.getCurrentShell()); try { progressMonitorDlg.run(false, false, runnableProgress); //????????E// Grx3DView view3d = (Grx3DView) manager_.getView(Grx3DView.class, true); if (view3d != null) { view3d.repaint(); } } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.generalrobotix.ui.item.GrxWorldStateItem.java
License:Open Source License
private void _loadLog(final File logFile) { try {/* w ww .j av a 2 s . c o m*/ IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int size = 0; try { ZipFile local = new ZipFile(logFile); size = local.size(); local.close(); } catch (IOException ex) { ex.printStackTrace(); return; } catch (Exception ex) { ex.printStackTrace(); return; } monitor.beginTask("Loading log as a file:" + logFile.getName(), //$NON-NLS-1$ size + LOAD_LOG_MODITOR_DIM + 2); _loadLog(logFile, monitor); monitor.done(); notifyObservers("LoadLog"); } }; new ProgressMonitorDialog(GrxUIPerspectiveFactory.getCurrentShell()).run(false, true, op); setLogMenus(true); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { clearLog(); } }
From source file:com.generalrobotix.ui.view.GrxServerManagerView.java
License:Open Source License
private void restartServers() { try {/*from ww w . java2s .co m*/ IRunnableWithProgress iProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(MessageBundle.get("GrxServerManagerView.dialog.title.progress"), 2 + (serverManager_.getServerInfo().size() + 1) * 2); //$NON-NLS-1$ restartServers(monitor); monitor.done(); } }; new ProgressMonitorDialog(GrxUIPerspectiveFactory.getCurrentShell()).run(false, false, iProgress); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { } }