List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
From source file:org.bonitasoft.studio.engine.command.RunProcessCommand.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final String configurationId = retrieveConfigurationId(event); String currentTheme = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() .getString(BonitaPreferenceConstants.DEFAULT_USERXP_THEME); String installedTheme = BonitaUserXpPreferencePage.getInstalledThemeId(); if (installedTheme != null && !installedTheme.equals(currentTheme)) { BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() .setValue(BonitaPreferenceConstants.DEFAULT_USERXP_THEME, currentTheme); BonitaUserXpPreferencePage.updateBonitaHome(); }/*from w w w . j a va 2 s . com*/ final Set<AbstractProcess> executableProcesses = getProcessesToDeploy(event); if (BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() .getBoolean(BonitaPreferenceConstants.VALIDATION_BEFORE_RUN)) { //Validate before run final ICommandService cmdService = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); Command cmd = cmdService.getCommand("org.bonitasoft.studio.validation.batchValidation"); if (cmd.isEnabled()) { final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench() .getService(IHandlerService.class); Set<String> procFiles = new HashSet<String>(); for (AbstractProcess p : executableProcesses) { Resource eResource = p.eResource(); if (eResource != null) { procFiles.add(URI.decode(eResource.getURI().lastSegment())); } } try { Parameterization showReportParam = new Parameterization(cmd.getParameter("showReport"), Boolean.FALSE.toString()); Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString()); final IStatus status = (IStatus) handlerService.executeCommand( new ParameterizedCommand(cmd, new Parameterization[] { showReportParam, filesParam }), null); if (statusContainsError(status)) { if (!FileActionDialog.getDisablePopup()) { String errorMessage = Messages.errorValidationMessage + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor().getTitle() + Messages.errorValidationContinueAnywayMessage; int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage, ValidationDialog.YES_NO_SEEDETAILS).open(); if (result == ValidationDialog.NO) { return null; } else if (result == ValidationDialog.SEE_DETAILS) { final IWorkbenchPage activePage = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IEditorPart part = activePage.getActiveEditor(); if (part != null && part instanceof DiagramEditor) { MainProcess proc = ModelHelper.getMainProcess( ((DiagramEditor) part).getDiagramEditPart().resolveSemanticElement()); String partName = proc.getName() + " (" + proc.getVersion() + ")"; for (IEditorReference ref : activePage.getEditorReferences()) { if (partName.equals(ref.getPartName())) { activePage.activate(ref.getPart(true)); break; } } } Display.getDefault().asyncExec(new Runnable() { @Override public void run() { try { activePage.showView("org.bonitasoft.studio.validation.view"); } catch (PartInitException e) { BonitaStudioLog.error(e); } } }); return null; } } } } catch (Exception e) { BonitaStudioLog.error(e); } } } IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.running, IProgressMonitor.UNKNOWN); final DeployProcessOperation operation = new DeployProcessOperation(); operation.setConfigurationId(configurationId); operation.setObjectToExclude(excludedObject); for (AbstractProcess process : executableProcesses) { operation.addProcessToDeploy(process); } status = operation.run(monitor); if (status == null) { return; } if (status.getSeverity() == IStatus.CANCEL) { return; } if (!status.isOK()) { if (!runSynchronously) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.deploymentFailedMessage, Messages.deploymentFailedMessage, status, IStatus.ERROR | IStatus.WARNING).open(); } }); } return; } final AbstractProcess p = getProcessToRun(event); hasInitiator = hasInitiator(p); if (p != null) { try { url = operation.getUrlFor(p, monitor); if (!runSynchronously) { BOSWebServerManager.getInstance().startServer(monitor); if (hasInitiator) { new OpenBrowserCommand(url, BonitaPreferenceConstants.APPLICATION_BROWSER_ID, "Bonita Application").execute(null); } else { Display.getDefault().syncExec(new Runnable() { @Override public void run() { IPreferenceStore preferenceStore = EnginePlugin.getDefault() .getPreferenceStore(); String pref = preferenceStore .getString(EnginePreferenceConstants.TOGGLE_STATE_FOR_NO_INITIATOR); if (MessageDialogWithToggle.NEVER.equals(pref)) { MessageDialogWithToggle.openWarning( Display.getDefault().getActiveShell(), Messages.noInitiatorDefinedTitle, Messages.bind(Messages.noInitiatorDefinedMessage, p.getName()), Messages.dontaskagain, false, preferenceStore, EnginePreferenceConstants.TOGGLE_STATE_FOR_NO_INITIATOR); } } }); status = openConsole(); } } } catch (Exception e) { status = new Status(IStatus.ERROR, EnginePlugin.PLUGIN_ID, e.getMessage(), e); BonitaStudioLog.error(e); } } else { if (!runSynchronously) { status = openConsole(); } } } private Status openConsole() { Status status = null; ICommandService service = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); Command cmd = service.getCommand("org.bonitasoft.studio.application.openConsole"); try { cmd.executeWithChecks(new ExecutionEvent()); } catch (Exception ex) { status = new Status(IStatus.ERROR, EnginePlugin.PLUGIN_ID, ex.getMessage(), ex); BonitaStudioLog.error(ex); } return status; } }; IProgressService service = PlatformUI.getWorkbench().getProgressService(); try { if (runSynchronously) { runnable.run(Repository.NULL_PROGRESS_MONITOR); } else { service.run(true, false, runnable); } } catch (final Exception e) { BonitaStudioLog.error(e); status = new Status(IStatus.ERROR, EnginePlugin.PLUGIN_ID, e.getMessage(), e); if (!runSynchronously) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.deploymentFailedMessage, Messages.deploymentFailedMessage, e).open(); } }); } } return status; }
From source file:org.bonitasoft.studio.fakes.FakeProgressService.java
License:Open Source License
@Override public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(new NullProgressMonitor()); }
From source file:org.caleydo.core.startup.CacheInitializers.java
License:Open Source License
public static void runInitializers(SubMonitor monitor) { Collection<IRunnableWithProgress> inits = ExtensionUtils.findImplementation(EXTENSION_POINT, "class", IRunnableWithProgress.class); monitor.beginTask("Running Initializers", inits.size()); for (IRunnableWithProgress init : inits) { try {//from www. j a va 2 s . c o m init.run(monitor.newChild(1, SubMonitor.SUPPRESS_SUBTASK)); } catch (InvocationTargetException | InterruptedException e) { log.error("can't initialize: " + init, e); } } monitor.done(); }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.AbstractAsynchCloudTest.java
License:Open Source License
protected void asynchExecuteOperation(final IRunnableWithProgress runnable) { Job job = new Job("Running Cloud Operation") { @Override/*from www .j ava 2 s. c o m*/ protected IStatus run(IProgressMonitor monitor) { try { runnable.run(monitor); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return Status.OK_STATUS; } }; job.setPriority(Job.INTERACTIVE); job.schedule(); }
From source file:org.dslforge.texteditor.BasicTextEditor.java
License:Open Source License
@SuppressWarnings("serial") protected void addListeners() { BasicText textWidget = viewer.getTextWidget(); if (textWidget != null && !textWidget.isDisposed()) { textWidget.addTextChangeListener(iTextChangeListener); KeyListener iKeyListener = new KeyListener() { @Override//from ww w .j a va2 s .com public void keyReleased(KeyEvent e) { //customize in subclasses } @Override public void keyPressed(KeyEvent e) { if ((e.stateMask & SWT.CTRL) == SWT.CTRL) { createCompletionProposals(); } } }; textWidget.addKeyListener(iKeyListener); textWidget.addTextModifyListener(new ITextModifyListener() { @Override public void handleTextModified(ModifyEvent event) { JsonObject object = (JsonObject) event.data; String text = object.get("value") != null ? object.get("value").asString() : null; if (text != null) { setText(text); } } }); textWidget.addTextSaveListener(new ITextSaveListener() { @Override public void handleTextSaved(TextSavedEvent event) { IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { Saveable[] saveables = getSaveables(); if (saveables.length == 0) return; monitor.beginTask(null, 100 * saveables.length); for (int i = 0; i < saveables.length; i++) { Saveable saveable = saveables[i]; try { saveable.doSave(SubMonitor.convert(monitor, 100)); } catch (CoreException e) { ErrorDialog.openError(getSite().getShell(), null, e.getMessage(), e.getStatus()); } if (monitor.isCanceled()) { break; } } monitor.done(); } }; try { runnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { // handle exception } catch (InterruptedException e) { // handle cancelation } } }); textWidget.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent event) { //customize in subclasses } @Override public void focusGained(FocusEvent event) { //customize in subclasses } }); textWidget.addMenuDetectListener(menuDetectListener); textWidget.addContentAssistListener(iContentAssistListener); textWidget.addMouseListener(new MouseListener() { @Override public void mouseUp(MouseEvent e) { //customize in subclasses } @Override public void mouseDown(MouseEvent e) { //customize in subclasses } @Override public void mouseDoubleClick(MouseEvent e) { //customize in subclasses } }); } }
From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.properties.registry.TurmericErrorRegistry.java
License:Open Source License
private static void init() throws Exception { long startTime = System.currentTimeMillis(); try {//from w w w .j av a 2 s .c o m synchronized (TurmericErrorRegistry.class) { if (errorLibs == null) { final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Initializing Turmeric Error Library Registry...", IProgressMonitor.UNKNOWN); monitor.internalWorked(10); try { monitor.internalWorked(20); final Map<String, ISOAErrLibrary> result = new Hashtable<String, ISOAErrLibrary>(); errorDomains = new Hashtable<String, ISOAErrDomain>(); errors = new Hashtable<String, ISOAError>(); for (AssetInfo lib : GlobalRepositorySystem.instanceOf().getActiveRepositorySystem() .getErorRegistryBridge().getErrorLibs()) { try { final ISOAErrLibrary errLib = TurmericErrorLibraryUtils .loadErrorLibrary(lib); ProgressUtil.progressOneStep(monitor); if (errLib != null) { result.put(errLib.getName(), errLib); for (ISOAErrDomain domain : errLib.getDomains()) { errorDomains.put(domain.getName().toLowerCase(Locale.US), domain); for (ISOAError error : domain.getErrors()) { // add domain name as part of the key to ensure uniqueness of error type under particular domain errors.put(getErrorTypeKey(domain.getName(), error.getName()), error); } } } } catch (Exception e) { logger.warning("Error occured while loading error library [" + lib + "], ignoring this library.", e); } } errorLibs = result; } catch (Exception e) { throw new SOAInvocationException(e); } finally { monitor.done(); } } }; if (Display.getCurrent() == null) { // non-UI thread runnable.run(ProgressUtil.getDefaultMonitor(null)); } else { final IProgressService service = PlatformUI.getWorkbench().getProgressService(); service.run(false, false, runnable); } while (errorLibs == null) { logger.warning("Turmeirc error library registry not initialized yet, sleeping..."); Thread.sleep(1000); } } } } finally { if (SOALogger.DEBUG) { long duration = System.currentTimeMillis() - startTime; logger.info("Time taken for initializing Turmeric error library registry is ", duration, " ms."); } } }
From source file:org.ebayopensource.turmeric.eclipse.ui.monitor.typelib.SOAGlobalRegistryAdapter.java
License:Open Source License
public SOATypeRegistry getGlobalRegistry() throws Exception { if (soaTypeRegistry == null) { long startTime = System.currentTimeMillis(); synchronized (SOAGlobalRegistryAdapter.class) { if (soaTypeRegistry == null) { // we should use a separate thread if this is not being // called from a UI thread. final IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Initializing SOA Type Registry...", 100); monitor.internalWorked(10); final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { init();/*from w ww . ja va 2 s . c om*/ monitor.internalWorked(20); Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); thread.setContextClassLoader(SOAGlobalRegistryFactory.class.getClassLoader()); SOATypeRegistry typeReg = GlobalRepositorySystem.instanceOf() .getActiveRepositorySystem().getTypeRegistryBridge().getSOATypeRegistry(); thread.setContextClassLoader(loader); monitor.internalWorked(40); typeLibclassLoader.setPluginBundles((GlobalRepositorySystem.instanceOf() .getActiveRepositorySystem().getTypeRegistryBridge().getPluginBundles())); monitor.internalWorked(10); Thread.currentThread().setContextClassLoader(typeLibclassLoader); monitor.internalWorked(10); List<RegistryUpdateDetails> libraries = typeReg .populateRegistryWithTypeLibrariesDetailed( ListUtil.arrayList(typeLibNamesForSOATools)); if (libraries != null) { for (RegistryUpdateDetails details : libraries) { if (details.isUpdateSucess() == false) { logger.warning("Invalid type library->", details.getLibraryName(), ". Detailed Error: ", details.getMessage()); } } } monitor.internalWorked(10); soaTypeRegistry = typeReg; } catch (Exception e) { throw new SOAInvocationException(e); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); monitor.done(); } } }; try { if (Display.getCurrent() == null) { // non-UI thread runnable.run(ProgressUtil.getDefaultMonitor(null)); } else { final IProgressService service = PlatformUI.getWorkbench().getProgressService(); service.run(false, false, runnable); } while (soaTypeRegistry == null) { logger.warning("SOA types registry not initialized yet, sleeping..."); Thread.sleep(1000); } } finally { if (SOALogger.DEBUG) { long duration = System.currentTimeMillis() - startTime; logger.info("Time taken for initializing SOA global type registry is ", duration, " ms."); } } } } } return soaTypeRegistry; }
From source file:org.eclipse.cdt.internal.ui.wizards.indexwizards.TeamProjectIndexExportWizardPage.java
License:Open Source License
private boolean executeExportOperation(final ICProject[] projects) { final String dest = getDestinationValue(); final MultiStatus status = new MultiStatus(CUIPlugin.PLUGIN_ID, 0, Messages.TeamProjectIndexExportWizardPage_errorExporting, null); final boolean exportResourceSnapshot = fResourceSnapshotButton.getSelection(); IRunnableWithProgress op = new IRunnableWithProgress() { @Override//w ww .j a v a2 s . c o m public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("", projects.length); //$NON-NLS-1$ for (ICProject project : projects) { TeamPDOMExportOperation op = new TeamPDOMExportOperation(project); op.setTargetLocation(dest); if (exportResourceSnapshot) { op.setOptions(TeamPDOMExportOperation.EXPORT_OPTION_RESOURCE_SNAPSHOT); } try { op.run(new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { status.merge(e.getStatus()); } } } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { CUIPlugin.log(Messages.TeamProjectIndexExportWizardPage_errorExporting, e.getTargetException()); displayErrorDialog(e.getTargetException()); return false; } if (!status.isOK()) { CUIPlugin.log(status); ErrorDialog.openError(getContainer().getShell(), getErrorDialogTitle(), null, // no special message status); return false; } return true; }
From source file:org.eclipse.cdt.oprofile.core.OpInfo.java
License:Open Source License
/** * Return all of Oprofile's generic information. * @return a class containing the information *///from w w w . ja v a 2 s . c o m public static OpInfo getInfo() { // Run opmxl and get the static information OpInfo info = new OpInfo(); if (Oprofile.isKernelModuleLoaded()) { try { IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().info(info); opxml.run(null); info._init(); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } catch (OpxmlException e) { String title = OprofileProperties.getString("opxmlProvider.error.dialog.title"); //$NON-NLS-1$ String msg = OprofileProperties.getString("opxmlProvider.error.dialog.message"); //$NON-NLS-1$ ErrorDialog.openError(null /* parent shell */, title, msg, e.getStatus()); } } return info; }
From source file:org.eclipse.cdt.oprofile.core.Oprofile.java
License:Open Source License
/** * Checks the requested counter, event, and unit mask for vailidity. * @param ctr the counter//w w w . ja va 2 s . c o m * @param event the event number * @param um the unit mask * @return whether the requested event is valid */ public static boolean checkEvent(int ctr, int event, int um) { int[] validResult = new int[1]; try { IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().checkEvents(ctr, event, um, validResult); opxml.run(null); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } catch (OpxmlException e) { _showErrorDialog("opxmlProvider", e); } return (validResult[0] == CheckEventsProcessor.EVENT_OK); }