下面列出了怎么用org.eclipse.ui.progress.IProgressService的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* CHANGED to protected
* CHANGED do not fork as we are keeping the resource lock.
*/
protected RefactoringStatus checkInitialConditions(Refactoring refactoring, Shell parent, String title,
IRunnableContext context) throws InterruptedException {
try {
CheckConditionsOperation cco = new CheckConditionsOperation(refactoring,
CheckConditionsOperation.INITIAL_CONDITONS);
WorkbenchRunnableAdapter workbenchRunnableAdapter = new WorkbenchRunnableAdapter(cco, ResourcesPlugin
.getWorkspace().getRoot());
/* CHANGE: don't fork (or use busyCursorWhile) as this will cause a deadlock */
if (context == null) {
PlatformUI.getWorkbench().getProgressService().run(false, true, workbenchRunnableAdapter);
} else if (context instanceof IProgressService) {
((IProgressService) context).run(false, true, workbenchRunnableAdapter);
} else {
context.run(false, true, workbenchRunnableAdapter);
}
return cco.getStatus();
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, parent, title, RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
return RefactoringStatus
.createFatalErrorStatus(RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
}
}
@Override
public void createControl(Composite parent) {
if (progressBar) {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.runInUI(progressService, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
createPage(parent, monitor);
}
}, ResourcesPlugin.getWorkspace().getRoot());
} catch (InvocationTargetException | InterruptedException e) {
Logger.sys.error(e.getMessage());
}
} else {
createPage(parent, null);
}
}
protected void browseForAccessorClass() {
IProgressService service= PlatformUI.getWorkbench().getProgressService();
IPackageFragmentRoot root= fAccessorPackage.getSelectedFragmentRoot();
IJavaSearchScope scope= root != null ? SearchEngine.createJavaSearchScope(new IJavaElement[] { root }) : SearchEngine.createWorkspaceScope();
FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog (getShell(), false,
service, scope, IJavaSearchConstants.CLASS);
dialog.setTitle(NLSUIMessages.NLSAccessorConfigurationDialog_Accessor_Selection);
dialog.setMessage(NLSUIMessages.NLSAccessorConfigurationDialog_Choose_the_accessor_file);
dialog.setInitialPattern("*Messages"); //$NON-NLS-1$
if (dialog.open() == Window.OK) {
IType selectedType= (IType) dialog.getFirstResult();
if (selectedType != null) {
fAccessorClassName.setText(selectedType.getElementName());
fAccessorPackage.setSelected(selectedType.getPackageFragment());
}
}
}
private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException {
JavaSearchQuery query= new JavaSearchQuery(createQuery(element));
if (query.canRunInBackground()) {
/*
* This indirection with Object as parameter is needed to prevent the loading
* of the Search plug-in: the VM verifies the method call and hence loads the
* types used in the method signature, eventually triggering the loading of
* a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
*/
SearchUtil.runQueryInBackground(query);
} else {
IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
/*
* This indirection with Object as parameter is needed to prevent the loading
* of the Search plug-in: the VM verifies the method call and hence loads the
* types used in the method signature, eventually triggering the loading of
* a plug-in (in this case it would be ISearchQuery).
*/
IStatus status= SearchUtil.runQueryInForeground(progressService, query);
if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status);
}
}
}
public int deployApplicationNodeContainer(Shell shell, ApplicationNodeContainer applicationNodeContainer,
String[] onFinishButtons) {
if (applicationNodeContainer.getApplications().isEmpty()) {
MessageDialog.openInformation(shell, Messages.deployDoneTitle, Messages.nothingToDeploy);
return Dialog.CANCEL;
}
final GetApiSessionOperation apiSessionOperation = new GetApiSessionOperation();
try {
final APISession apiSession = apiSessionOperation.execute();
final ApplicationAPI applicationAPI = BOSEngineManager.getInstance().getApplicationAPI(apiSession);
final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
final DeployApplicationDescriptorOperation deployOperation = getDeployOperation(apiSession, applicationAPI,
applicationNodeContainer);
progressService.run(true, false, deployOperation);
return openStatusDialog(shell, deployOperation, onFinishButtons);
} catch (InvocationTargetException | InterruptedException | BonitaHomeNotSetException | ServerAPIException
| UnknownAPITypeException e) {
new ExceptionDialogHandler().openErrorDialog(shell, Messages.deployFailedTitle, e);
return Dialog.CANCEL;
} finally {
apiSessionOperation.logout();
}
}
protected void checkImplementationDependencies(final ConnectorImplementation implementation) {
if(!implementation.getJarDependencies().getJarDependency().isEmpty()){
try {
final IProgressService service = PlatformUI.getWorkbench().getProgressService() ;
service.run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.addingImplementationDependencies, IProgressMonitor.UNKNOWN) ;
final DependencyRepositoryStore depStore = RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class) ;
for(final String jarName : implementation.getJarDependencies().getJarDependency()){
if( depStore.getChild(jarName, true) == null){
final InputStream is = getResourceProvider().getDependencyInputStream(jarName) ;
if(is != null){
depStore.importInputStream(jarName, is) ;
}
}
}
}
}) ;
} catch (final Exception e){
BonitaStudioLog.error(e) ;
}
}
}
public void setProcess(final AbstractProcess process) {
this.process = process;
final Configuration configuration = getConfigurationFromProcess(process, configurationName);
if (configuration != null) {
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
new ConfigurationSynchronizer(process, configuration).synchronize(monitor);
}
});
} catch (final InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
}
configurationWorkingCopy = emfModelUpdater.from(configuration).getWorkingCopy();
}
}
@Execute
public void deploy(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
RepositoryAccessor repositoryAccessor, IProgressService progressService)
throws InvocationTargetException, InterruptedException {
progressService.busyCursorWhile(monitor -> {
repositoryModel = new RepositoryModelBuilder().create(repositoryAccessor);
});
SelectArtifactToDeployPage page = new SelectArtifactToDeployPage(repositoryModel,
new EnvironmentProviderFactory().getEnvironmentProvider());
if (defaultSelection != null) {
page.setDefaultSelectedElements(defaultSelection.stream()
.map(fStore -> asArtifact(fStore))
.filter(Objects::nonNull)
.collect(Collectors.toSet()));
}
Optional<IStatus> result = createWizard(newWizard(), page,
repositoryAccessor,
Messages.selectArtifactToDeployTitle,
Messages.selectArtifactToDeploy)
.open(activeShell, Messages.deploy);
if (result.isPresent()) {
openStatusDialog(activeShell, result.get(), repositoryAccessor);
}
}
@Inject
public ContractPropertySection(final ISharedImages sharedImages,
final IEclipseContext eclipseContext,
final ContractContainerAdaptableSelectionProvider selectionProvider,
final PoolAdaptableSelectionProvider poolSelectionProvider,
final RepositoryAccessor repositoryAccessor,
final FieldToContractInputMappingOperationBuilder fieldToContractInputMappingOperationBuilder,
final FieldToContractInputMappingExpressionBuilder fieldToContractInputMappingExpressionBuilder,
final ContractConstraintBuilder contractConstraintBuilder,
final IProgressService progressService) {
this.eclipseContext = eclipseContext;
this.repositoryAccessor = repositoryAccessor;
this.selectionProvider = selectionProvider;
this.poolSelectionProvider = poolSelectionProvider;
this.progressService = progressService;
this.sharedImages = sharedImages;
this.fieldToContractInputMappingOperationBuilder = fieldToContractInputMappingOperationBuilder;
this.fieldToContractInputMappingExpressionBuilder = fieldToContractInputMappingExpressionBuilder;
this.contractConstraintBuilder = contractConstraintBuilder;
}
@Test
public void should_open_an_error_dialog_if_remove_operation_failed() throws Exception {
final IProgressService mockProgressService = mock(IProgressService.class);
contractInputController = spy(new ContractInputController(mockProgressService));
doReturn(new TransactionalEditingDomainImpl(new ProcessItemProviderAdapterFactory())).when(contractInputController).editingDomain(any(Contract.class));
final Contract contract = aContract().havingInput(aContractInput()).in(aTask()).build();
observableValue.setValue(contract);
when(viewer.getSelection()).thenReturn(new StructuredSelection(contract.getInputs()));
final InvocationTargetException error = new InvocationTargetException(new Throwable());
doThrow(error).when(mockProgressService).run(anyBoolean(), anyBoolean(), any(IRunnableWithProgress.class));
contractInputController.remove(viewer);
verify(contractInputController).openErrorDialog(error);
}
@Test
public void create_a_new_page_should_trigger_a_refresh_on_a_page_filestore() throws Exception {
waitForServer();
RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
final CreateFormOperation createFormOperation = new CreateFormOperation(new PageDesignerURLFactory(
InstanceScope.INSTANCE.getNode(BonitaStudioPreferencesPlugin.PLUGIN_ID)), repositoryAccessor);
createFormOperation.setArtifactName("MyNewForm");
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
service.run(true, false, createFormOperation);
final WebPageRepositoryStore repositoryStore = RepositoryManager.getInstance()
.getRepositoryStore(WebPageRepositoryStore.class);
newPageResource = repositoryStore.getChild(createFormOperation.getNewArtifactId(), true).getResource()
.getFile(createFormOperation.getNewArtifactId() + ".json");
assertThat(newPageResource.exists()).overridingErrorMessage(
"Workspace should be in sync with new page file").isTrue();
}
private void refactorDocument(final Pool pool) throws InvocationTargetException, InterruptedException {
final Document documentToRefactor = pool.getDocuments().get(0);
final RefactorDocumentOperation refactorOperation = new RefactorDocumentOperation(RefactoringOperationType.UPDATE);
refactorOperation.setEditingDomain(TransactionUtil.getEditingDomain(pool));
final Document newDocument = EcoreUtil.copy(documentToRefactor);
newDocument.setName(newDocumentName);
refactorOperation.addItemToRefactor(newDocument, documentToRefactor);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
service.busyCursorWhile(refactorOperation);
final Document documentRefactored = pool.getDocuments().get(0);
assertEquals(newDocument.getName(), documentRefactored.getName());
testDocumentInExpressionsRefactored(documentRefactored, 2, pool);
final Document currentDoc = refactorDocumentTypeAndMultiplicity(pool, documentRefactored);
testRemoveDocumentRefactoring(currentDoc, pool);
}
private Document refactorDocumentTypeAndMultiplicity(final Pool pool, final Document document)
throws InvocationTargetException, InterruptedException {
final Document newDocument = EcoreUtil.copy(document);
newDocument.setMultiple(true);
newDocument.setDocumentType(DocumentType.EXTERNAL);
final RefactorDocumentOperation refactorOperation = new RefactorDocumentOperation(RefactoringOperationType.UPDATE);
refactorOperation.setEditingDomain(TransactionUtil.getEditingDomain(pool));
refactorOperation.addItemToRefactor(newDocument, document);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
service.busyCursorWhile(refactorOperation);
final Document documentRefactored = pool.getDocuments().get(0);
assertEquals(newDocument.getName(), documentRefactored.getName());
assertEquals(newDocument.getDocumentType(), documentRefactored.getDocumentType());
return documentRefactored;
}
protected void performNewSearch(String label, Iterable<? extends IJavaElement> elements) throws JavaModelException, InterruptedException {
CompositeSearchQuery compositeSearchQuery = createCompositeQuery(label, elements);
if (compositeSearchQuery.canRunInBackground()) {
SearchUtil.runQueryInBackground(compositeSearchQuery);
} else {
IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
IStatus status= SearchUtil.runQueryInForeground(progressService, compositeSearchQuery);
if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status);
}
}
}
private void findReferences(IResource resource, int offset, int length) {
TypeScriptSearchQuery query = new TypeScriptSearchQuery(resource, offset);
if (query.canRunInBackground()) {
/*
* This indirection with Object as parameter is needed to prevent
* the loading of the Search plug-in: the VM verifies the method
* call and hence loads the types used in the method signature,
* eventually triggering the loading of a plug-in (in this case
* ISearchQuery results in Search plug-in being loaded).
*/
SearchUtil.runQueryInBackground(query);
} else {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
/*
* This indirection with Object as parameter is needed to prevent
* the loading of the Search plug-in: the VM verifies the method
* call and hence loads the types used in the method signature,
* eventually triggering the loading of a plug-in (in this case it
* would be ISearchQuery).
*/
IStatus status = SearchUtil.runQueryInForeground(progressService, query);
if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title,
SearchMessages.Search_Error_search_message, status);
}
}
}
private void terminateLaunches() {
if( preferences.isTerminateBeforeRelaunch() ) {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.busyCursorWhile( this::terminateLaunches );
} catch( InvocationTargetException ite ) {
handleException( ite.getCause() );
} catch( InterruptedException ignore ) {
Thread.interrupted();
}
}
}
private SelectionDialog createAllPackagesDialog(Shell shell) {
IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
int flag= PackageSelectionDialog.F_HIDE_EMPTY_INNER;
PackageSelectionDialog dialog= new PackageSelectionDialog(shell, progressService, flag, scope);
dialog.setFilter(""); //$NON-NLS-1$
dialog.setIgnoreCase(false);
dialog.setMultipleSelection(false);
return dialog;
}
private IProgressService getProgressService() {
IEditorPart editor= getTextEditor();
if (editor != null) {
IWorkbenchPartSite site= editor.getSite();
if (site != null)
return (IWorkbenchSiteProgressService) editor.getSite().getAdapter(IWorkbenchSiteProgressService.class);
}
return PlatformUI.getWorkbench().getProgressService();
}
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final FileDialog fd = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN | SWT.MULTI);
fd.setFilterExtensions(new String[] { "*.jar;*.zip" });
if (filenames != null) {
fd.setFilterNames(filenames);
}
if (fd.open() != null) {
final DependencyRepositoryStore libStore = RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class);
final String[] jars = fd.getFileNames();
final IProgressService progressManager = PlatformUI.getWorkbench().getProgressService();
final IRunnableWithProgress runnable = new ImportLibsOperation(libStore, jars, fd.getFilterPath());
try {
progressManager.run(true, false, runnable);
progressManager.run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
RepositoryManager.getInstance().getCurrentRepository().build(monitor);
}
});
} catch (final InvocationTargetException e1) {
BonitaStudioLog.error(e1);
if (e1.getCause() != null && e1.getCause().getMessage() != null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), org.bonitasoft.studio.dependencies.i18n.Messages.importJar, e1.getCause()
.getMessage());
}
} catch (final InterruptedException e2) {
BonitaStudioLog.error(e2);
}
}
return fd.getFileNames();
}
private boolean executeRemoveOperation(final CompoundCommand cc) {
boolean isExecuted = false;
if (removeOperation != null) {
removeOperation.setCompoundCommand(cc);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.busyCursorWhile(removeOperation);
isExecuted = true;
} catch (final InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
}
}
return isExecuted;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
final FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
fileDialog.setFilterExtensions(new String[] { "*.zip" });
fileDialog.setText(getDialogTitle());
final String fileName = fileDialog.open();
if (fileName != null) {
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
final ImportConnectorArchiveOperation importOp = newImportOperation();
importOp.setFile(new File(fileName));
service.run(true, false, importOp);
final IStatus status = importOp.getStatus();
switch (status.getSeverity()) {
case IStatus.OK:
MessageDialog.openInformation(Display.getDefault().getActiveShell(), getImportSuccessTitle(), getImportSuccessMessage());
break;
case IStatus.WARNING:
MessageDialog.openWarning(Display.getDefault().getActiveShell(), getImportSuccessTitle(), status.getMessage());
break;
case IStatus.ERROR:
MessageDialog.openError(Display.getDefault().getActiveShell(), getFailedImportTitle(),
Messages.bind(getFailedImportMessage(), status.getMessage()));
break;
default:
break;
}
}
return null;
} catch (final Exception ex) {
throw new ExecutionException(ex.getMessage(), ex);
}
}
public void duplicate(MainProcess diagram) {
String newProcessLabel = diagram.getName();
String newProcessVersion = diagram.getVersion();
DiagramRepositoryStore diagramRepositoryStore = repositoryAccessor.getRepositoryStore(DiagramRepositoryStore.class);
final OpenNameAndVersionForDiagramDialog dialog = new OpenNameAndVersionForDiagramDialog(
Display.getDefault().getActiveShell(),
diagram, diagramRepositoryStore);
dialog.forceNameUpdate();
if (dialog.open() == Dialog.OK) {
final Identifier identifier = dialog.getIdentifier();
newProcessLabel = identifier.getName();
newProcessVersion = dialog.getIdentifier().getVersion();
List<ProcessesNameVersion> pools = dialog.getPools();
final DuplicateDiagramOperation op = new DuplicateDiagramOperation();
op.setDiagramToDuplicate(diagram);
op.setNewDiagramName(newProcessLabel);
op.setNewDiagramVersion(newProcessVersion);
op.setPoolsRenamed(pools);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, op);
} catch (InvocationTargetException | InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
DiagramFileStore store = diagramRepositoryStore.getDiagram(newProcessLabel, newProcessVersion);
store.open();
}
}
@Inject
public PoolGeneralPropertySection(
final PoolAdaptableSelectionProvider selectionProvider,
final RepositoryAccessor repositoryAccessor,
final ExceptionDialogHandler exceptionDialogHandler,
final IProgressService progressService) {
this.selectionProvider = selectionProvider;
this.exceptionDialogHandler = exceptionDialogHandler;
this.progressService = progressService;
}
@Inject
public InputParametersMappingSection(RepositoryAccessor repositoryAccessor,
FetchContractOperation fetchContractOperation,
IProgressService progressService,
ISharedImages sharedImages,
CallActivitySelectionProvider selectionProvider) {
this.fetchContractOperation = fetchContractOperation;
this.progressService = progressService;
this.sharedImages = sharedImages;
this.selectionProvider = selectionProvider;
this.callActivityHelper = new CallActivityHelper(repositoryAccessor, selectionProvider);
}
@Inject
public CreateOrEditFormProposalListener(final PageDesignerURLFactory pageDesignerURLFactory,
final IProgressService progressService,
final RepositoryAccessor repositoryAccessor,
NewFormOperationFactoryDelegate operationFactory) {
super(pageDesignerURLFactory, progressService, repositoryAccessor, operationFactory);
this.progressService = progressService;
}
@Execute
public void createLayout(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, PageDesignerURLFactory urlFactory,
RepositoryAccessor repositoryAccessor) {
CreateLayoutOperation operation = new CreateLayoutOperation(urlFactory, repositoryAccessor);
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.run(true, false, operation);
} catch (InvocationTargetException | InterruptedException e) {
new ExceptionDialogHandler().openErrorDialog(shell, Messages.createLayoutFailed, e);
}
}
@Execute
public void createPage(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, PageDesignerURLFactory urlFactory,
RepositoryAccessor repositoryAccessor) {
CreatePageOperation operation = new CreatePageOperation(urlFactory, repositoryAccessor);
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.run(true, false, operation);
} catch (InvocationTargetException | InterruptedException e) {
new ExceptionDialogHandler().openErrorDialog(shell, Messages.createPageFailed, e);
}
}
@Inject
public CreateNewFormProposalListener(final PageDesignerURLFactory pageDesignerURLFactory,
final IProgressService progressService,
final RepositoryAccessor repositoryAccessor,
NewFormOperationFactoryDelegate operationFactory) {
this.progressService = progressService;
this.pageDesignerURLFactory = pageDesignerURLFactory;
this.repositoryAccessor = repositoryAccessor;
this.operationFactory = operationFactory;
}
public static ObservableValueWithRefactor observeValueWithRefactor(
final EditingDomain editingDomain,
final EObject target,
final EStructuralFeature eStructuralFeature,
final IRefactorOperationFactory refactorOperationFactory,
final IProgressService progressService) {
return new ObservableValueWithRefactor(editingDomain, target, eStructuralFeature, refactorOperationFactory, progressService);
}
public static IObservableFactory valueWithRefactorFactory(final Realm realm, final EStructuralFeature eStructuralFeature, IRefactorOperationFactory refactorOperationFactory,
IProgressService progressService) {
return new IObservableFactory()
{
@Override
public IObservable createObservable(final Object target)
{
final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(target);
return new ObservableValueWithRefactor(editingDomain, (EObject) target, eStructuralFeature, refactorOperationFactory, progressService);
}
};
}