use of org.eclipse.ui.progress.IProgressService in project xtext-eclipse by eclipse.
the class RefactoringWizardOpenOperation_NonForking method checkInitialConditions.
/**
* 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);
}
}
use of org.eclipse.ui.progress.IProgressService in project archi-modelrepository-plugin by archi-contribs.
the class CloneModelAction method run.
@Override
public void run() {
// Check primary key set
try {
if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
return;
}
} catch (GeneralSecurityException ex) {
displayCredentialsErrorDialog(ex);
return;
} catch (Exception ex) {
displayErrorDialog(Messages.CloneModelAction_0, ex);
return;
}
CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final boolean storeCredentials = dialog.doStoreCredentials();
final UsernamePassword npw = dialog.getUsernamePassword();
if (!StringUtils.isSet(repoURL)) {
return;
}
if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0, Messages.CloneModelAction_1);
return;
}
// Create a new local folder
File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
setRepository(new ArchiRepository(localRepoFolder));
try {
// Clone
Exception[] exception = new Exception[1];
IProgressService ps = PlatformUI.getWorkbench().getProgressService();
ps.busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor pm) {
try {
// Update Proxy
ProxyAuthenticator.update();
pm.beginTask(Messages.CloneModelAction_4, -1);
getRepository().cloneModel(repoURL, npw, new ProgressMonitorWrapper(pm));
} catch (Exception ex) {
exception[0] = ex;
} finally {
// Clear Proxy
ProxyAuthenticator.clear();
}
}
});
if (exception[0] != null) {
throw exception[0];
}
// Load it from the Grafico files if we can
IArchimateModel graficoModel = new GraficoModelLoader(getRepository()).loadModel();
// We couldn't load it from Grafico so create a new blank model
if (graficoModel == null) {
// New one. This will open in the tree
IArchimateModel model = IEditorModelManager.INSTANCE.createNewModel();
model.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(model);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
// And do a first commit
getRepository().commitChanges(Messages.CloneModelAction_3, false);
// Save the checksum
getRepository().saveChecksum();
}
// Store repo credentials if HTTP and option is set
if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
cs.store(npw);
}
// Notify listeners
notifyChangeListeners(IRepositoryListener.REPOSITORY_ADDED);
} catch (Exception ex) {
displayErrorDialog(Messages.CloneModelAction_0, ex);
}
}
use of org.eclipse.ui.progress.IProgressService in project archi-modelrepository-plugin by archi-contribs.
the class CreateRepoFromModelAction method run.
@Override
public void run() {
try {
if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
return;
}
} catch (GeneralSecurityException ex) {
displayCredentialsErrorDialog(ex);
return;
} catch (IOException ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
return;
}
NewModelRepoDialog dialog = new NewModelRepoDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final boolean storeCredentials = dialog.doStoreCredentials();
final UsernamePassword npw = dialog.getUsernamePassword();
if (!StringUtils.isSet(repoURL)) {
return;
}
if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CreateRepoFromModelAction_0, Messages.CreateRepoFromModelAction_3);
return;
}
// Create a new local folder
File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
setRepository(new ArchiRepository(localRepoFolder));
try {
// Create a new repo
try (Git git = getRepository().createNewLocalGitRepository(repoURL)) {
}
// TODO: If the model has not been saved yet this is fine but if the model already exists
// We should tell the user this is the case
// Set new file location
fModel.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(fModel);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
// Commit changes
getRepository().commitChanges(Messages.CreateRepoFromModelAction_5, false);
// Push
Exception[] exception = new Exception[1];
IProgressService ps = PlatformUI.getWorkbench().getProgressService();
ps.busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor pm) {
try {
// Update Proxy
ProxyAuthenticator.update();
pm.beginTask(Messages.CreateRepoFromModelAction_4, -1);
getRepository().pushToRemote(npw, new ProgressMonitorWrapper(pm));
} catch (Exception ex) {
exception[0] = ex;
} finally {
// Clear Proxy
ProxyAuthenticator.clear();
}
}
});
if (exception[0] != null) {
throw exception[0];
}
// Store repo credentials if HTTP and option is set
if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
cs.store(npw);
}
// Save the checksum
getRepository().saveChecksum();
} catch (Exception ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
}
}
use of org.eclipse.ui.progress.IProgressService in project egit by eclipse.
the class GitScopeUtil method findRelatedChanges.
private static IResource[] findRelatedChanges(final IWorkbenchPart part, final IResource[] selectedResources) throws InvocationTargetException, InterruptedException {
final List<IResource> relatedChanges = new ArrayList<>();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask(UIText.CommitActionHandler_lookingForChanges, 100);
List<IResource> collectedResources = collectRelatedChanges(selectedResources, part, monitor);
relatedChanges.addAll(collectedResources);
} finally {
monitor.done();
}
}
};
IProgressService progressService = CommonUtils.getService(part.getSite(), IProgressService.class);
progressService.run(true, true, runnable);
return relatedChanges.toArray(new IResource[relatedChanges.size()]);
}
use of org.eclipse.ui.progress.IProgressService in project gemoc-studio by eclipse.
the class GemocPackageDiscovery method openModelingDiscoveryWizard.
public static void openModelingDiscoveryWizard(IWorkbenchWindow window) {
final DiscoveryContentProvider provider = new GemocPackageDiscovery();
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
try {
ps.busyCursorWhile(new IRunnableWithProgress() {
public void run(IProgressMonitor pm) {
try {
provider.load(pm);
} catch (InterruptedException e) {
/*
* End user cancelled
*/
}
}
});
if (provider.getDiscovery() != null) {
DiscoveryWizard wizard = new DiscoveryWizard(provider);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.setMinimumPageSize(600, 400);
dialog.open();
}
} catch (InvocationTargetException e1) {
if (!(e1.getCause() instanceof OperationCanceledException)) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
}
} catch (InterruptedException e1) {
/*
* End user cancelled
*/
}
}
Aggregations