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:es.bsc.servicess.ide.wizards.coretypes.ServiceWarSpecificTreatment.java
License:Apache License
private void loadWSDLFile(final String selectedDirectory) { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try {//w w w . j a va 2s. co m final File fpath = new File(selectedDirectory); if (fpath.exists()) { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { loadWSDL(fpath); } catch (Exception e) { throw (new InvocationTargetException(e)); } } }); wsdlLocation.setText(selectedDirectory); resetServiceInfo(); } else { throw (new InvocationTargetException(new Exception("The selected file doesn't exists"))); } } catch (InvocationTargetException e) { ErrorDialog.openError(dialog.getShell(), "Error loading new WSDL file", e.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); e.printStackTrace(); } catch (InterruptedException e) { ErrorDialog.openError(dialog.getShell(), "WSDL load interrumped", e.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); e.printStackTrace(); } }
From source file:es.bsc.servicess.ide.wizards.ServiceSsImportOrchestrationClassPage.java
License:Apache License
private boolean loadWarFile(final String selectedDirectory, final IFolder importFolder) { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(this.getShell()); try {//from w w w . j av a 2s . c o m log.debug("Selected dir: " + selectedDirectory); final File warFile = new File(selectedDirectory); if (warFile.exists()) { dialog.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { if (!importFolder.exists()) importFolder.create(true, true, monitor); String name = PackagingUtils.getPackageName(warFile); log.debug("Package name is " + name); IFolder extractFolder = importFolder.getFolder(name); if (!extractFolder.exists()) { extractWar(warFile, extractFolder, monitor); updateDeps(warPath, selectedDirectory, ProjectMetadata.WAR_DEP_TYPE, monitor); } else log.info("Package already exists. Not extracting"); } catch (Exception e) { throw (new InvocationTargetException(e)); } } }); return true; } else throw (new InvocationTargetException(new Exception("The selected file doesn't exists"))); } catch (InvocationTargetException e) { log.error("Error loading package"); ErrorDialog.openError(dialog.getShell(), "Error loading new package file", "Exception when loading package", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); return false; } catch (InterruptedException e) { log.error("Error loading package"); ErrorDialog.openError(dialog.getShell(), "Package load interrumped", "Exception when loading package", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); return false; } }
From source file:eu.celar.ui.UIAuthTokenProvider.java
License:Open Source License
/** * Validates the specified token. This method does the validation in a * separate thread and provides a progress monitor for the validation process. * //from w ww. j a v a2s . c o m * @param token The token to be validated. * @throws InvocationTargetException Thrown if an exception occurs in the * validation thread. * @throws InterruptedException Thrown if the validation thread is * interrupted. */ protected void validateToken(final IAuthenticationToken token) throws InvocationTargetException, InterruptedException { final Exception[] exc = new Exception[1]; Runnable runnable = new Runnable() { public void run() { ProgressMonitorDialog progMon = new ProgressMonitorDialog(UIAuthTokenProvider.this.shell); try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { token.validate(monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException exception) { exc[0] = exception; } catch (InterruptedException exception) { exc[0] = exception; } } }; runInUIThread(runnable); if (exc[0] instanceof InvocationTargetException) { throw (InvocationTargetException) exc[0]; } else if (exc[0] instanceof InterruptedException) { throw (InterruptedException) exc[0]; } }
From source file:eu.celar.ui.UIAuthTokenProvider.java
License:Open Source License
/** * Activate the specified token. This method does the activation in a separate * thread and provides a progress monitor for the activation process. * /*from w ww.ja v a 2s. c o m*/ * @param token The token to be activated. * @throws InvocationTargetException Thrown if an exception occurs in the * activation thread. * @throws InterruptedException Thrown if the activation thread is * interrupted. */ protected void activateToken(final IAuthenticationToken token) throws InvocationTargetException, InterruptedException { final Exception[] exc = new Exception[1]; Runnable uiRunnable = new Runnable() { public void run() { ProgressMonitorDialog progMon = new ProgressMonitorDialog(UIAuthTokenProvider.this.shell); try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException { try { token.setActive(true, monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException exception) { exc[0] = exception; } catch (InterruptedException exception) { exc[0] = exception; } } }; runInUIThread(uiRunnable); if (exc[0] instanceof InvocationTargetException) { throw (InvocationTargetException) exc[0]; } else if (exc[0] instanceof InterruptedException) { throw (InterruptedException) exc[0]; } }
From source file:eu.celar.ui.views.AuthTokenView.java
License:Open Source License
/** * Activates or deactivates the currently selected token. * //from w w w . jav a 2 s . c o m * @param active If true the token will be activated, otherwise it will be deactivated. * @see #getSelectedToken() */ protected void setSelectedTokenActive(final boolean active) { final IAuthenticationToken token = getSelectedToken(); if (active == token.isActive()) return; ProgressMonitorDialog progMon = new ProgressMonitorDialog(getSite().getShell()); Throwable exc = null; try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { token.setActive(active, monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException itExc) { exc = itExc.getCause(); } catch (InterruptedException intExc) { exc = intExc; } if (exc != null) { String errMsg = active ? Messages.getString("AuthTokenView.token_activation_error") //$NON-NLS-1$ : Messages.getString("AuthTokenView.token_deactivation_error"); //$NON-NLS-1$ ProblemDialog.openProblem(getSite().getShell(), Messages.getString("AuthTokenView.token_activation_error_title"), //$NON-NLS-1$ errMsg, exc); } }
From source file:eu.esdihumboldt.hale.ui.codelist.inspire.internal.CodeListSelectionDialog.java
License:Open Source License
/** * @see AbstractViewerSelectionDialog#setupViewer(StructuredViewer, Object) */// w w w.j a va 2 s. c o m @Override protected void setupViewer(final TreeViewer viewer, final CodeListRef initialSelection) { viewer.setLabelProvider(new CodeListLabelProvider()); viewer.setContentProvider(new CodeListContentProvider()); ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell()); final Display display = Display.getCurrent(); try { dlg.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Loading available code lists from INSPIRE registry", IProgressMonitor.UNKNOWN); final Collection<CodeListRef> codeLists = RegistryCodeLists.loadCodeLists().values(); display.asyncExec(new Runnable() { @Override public void run() { viewer.setInput(codeLists); if (initialSelection != null) { viewer.setSelection(new StructuredSelection(initialSelection)); } } }); monitor.done(); } }); } catch (InvocationTargetException | InterruptedException e) { throw new IllegalStateException("Failed to load code lists", e); } }
From source file:eu.esdihumboldt.hale.ui.templates.handler.OpenWebTemplate.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final Display display = HandlerUtil.getActiveShell(event).getDisplay(); ProgressMonitorDialog taskDlg = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); try {// w w w. ja va 2 s .co m taskDlg.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Downloading template list", IProgressMonitor.UNKNOWN); // load templates final List<WebTemplate> templates; try { templates = WebTemplateLoader.load(); } catch (Exception e) { log.userError("Failed to download template list", e); return; } finally { monitor.done(); } if (templates != null) { // launch dialog asynchronously in display thread display.asyncExec(new Runnable() { @Override public void run() { WebTemplatesDialog dlg = new WebTemplatesDialog(display.getActiveShell(), templates); if (dlg.open() == WebTemplatesDialog.OK) { WebTemplate template = dlg.getObject(); if (template != null) { ProjectService ps = (ProjectService) PlatformUI.getWorkbench() .getService(ProjectService.class); ps.load(template.getProject()); } } } }); } } }); } catch (InvocationTargetException | InterruptedException e) { log.userError("Failed to download template list", e); } return null; }
From source file:eu.esdihumboldt.hale.ui.util.graph.ExportGraphAction.java
License:Open Source License
/** * @see Action#run()/*from w ww .j a v a2 s .c o m*/ */ @Override public void run() { FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); // XXX if called from TTreeExporter during transformation, the active // shell may be null! dialog.setOverwrite(true); dialog.setText("Export graph to file"); String[] imageExtensions = ImageIO.getWriterFileSuffixes(); StringBuffer extensions = new StringBuffer("*.svg;*.gv;*.dot"); for (String imageExt : imageExtensions) { extensions.append(";*."); extensions.append(imageExt); } dialog.setFilterExtensions(new String[] { extensions.toString() }); dialog.setFilterNames(new String[] { "Image, SVG or dot file (" + extensions + ")" }); String fileName = dialog.open(); if (fileName != null) { final File file = new File(fileName); // //XXX use an off-screen graph (testing) // OffscreenGraph graph = new OffscreenGraph(1000, 1000) { // // @Override // protected void configureViewer(GraphViewer viewer) { // viewer.setContentProvider(RenderAction.this.viewer.getContentProvider()); // viewer.setLabelProvider(RenderAction.this.viewer.getLabelProvider()); // viewer.setInput(RenderAction.this.viewer.getInput()); // viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT), false); // } // }; // get the graph final Graph graph = viewer.getGraphControl(); final String ext = FilenameUtils.getExtension(file.getAbsolutePath()); final IFigure root = graph.getRootLayer(); ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { progress.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); if (ext.equalsIgnoreCase("gv") || ext.equalsIgnoreCase("dot")) { OffscreenGraph.saveDot(graph, out); } // else if (ext.equalsIgnoreCase("svg")) { // OffscreenGraph.saveSVG(root, out); // } else { OffscreenGraph.saveImage(root, out, ext); } } catch (Throwable e) { log.userError("Error saving graph to file", e); } } }); } catch (Throwable e) { log.error("Error launching graph export", e); } } }
From source file:eu.numberfour.n4js.ui.compare.ProjectCompareTree.java
License:Open Source License
/** * Creates a new default comparison of all API / implementation projects in the default workspace (i.e. the one * accessed via {@link IN4JSCore}) and shows this comparison in the widget. */// w ww. j a v a2 s. c o m public void setComparison() { final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getTree().getShell()); try { dlg.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { setComparison(monitor); } }); } catch (InvocationTargetException | InterruptedException e) { // ignore } }
From source file:eu.udig.tools.internal.ui.util.DialogUtil.java
License:LGPL
/** * Runs a blocking task in a ProgressDialog. It is ran in such a way that * even if the task blocks it can be cancelled. This is unlike the normal * ProgressDialog.run(...) method which requires that the * {@link IProgressMonitor} be checked and the task to "nicely" cancel. * //w w w .j a va 2 s.c o m * @param dialogTitle * The title of the Progress dialog * @param showRunInBackground * if true a button added to the dialog that will make the job be * ran in the background. * @param process * the task to execute. * @param runASync * @param confirmCancelRequests * wether to ask the user to confirm the cancelation when the * cancel button is pressed */ public static void runInProgressDialog(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress process, boolean runASync, final boolean confirmCancelRequests) { Runnable object = new Runnable() { @Override public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = DialogUtil.openProgressMonitorDialog(shell, dialogTitle, showRunInBackground, confirmCancelRequests); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { PlatformGISMediator.runBlockingOperation(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { process.run(monitor); } }, monitor); } catch (InvocationTargetException e) { throw e; } catch (InterruptedException e) { throw e; } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }; if (runASync) Display.getDefault().asyncExec(object); // TODO should be tested with this method // PlatformGISMediator.asyncInDisplayThread(object, false); else PlatformGISMediator.syncInDisplayThread(object); }