use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.
the class ConnectionWizard method testConnection.
public void testConnection() {
DataSourceDescriptor dataSource = getPageSettings().getActiveDataSource();
DataSourceDescriptor testDataSource = new DataSourceDescriptor(dataSource);
saveSettings(testDataSource);
// Generate new ID to avoid session conflicts in QM
testDataSource.setId(DataSourceDescriptor.generateNewId(dataSource.getDriver()));
testDataSource.getPreferenceStore().setValue(ModelPreferences.META_SEPARATE_CONNECTION, false);
try {
final ConnectionTester op = new ConnectionTester(testDataSource);
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Wait for job to finish
op.ownerMonitor = RuntimeUtils.makeMonitor(monitor);
op.schedule();
while (op.getState() == Job.WAITING || op.getState() == Job.RUNNING) {
if (monitor.isCanceled()) {
op.cancel();
throw new InterruptedException();
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
}
if (op.getConnectError() != null) {
throw new InvocationTargetException(op.getConnectError());
}
if (op.getConnectStatus() == Status.CANCEL_STATUS) {
throw new InterruptedException();
}
}
});
String message = "";
if (!CommonUtils.isEmpty(op.productName)) {
message += "Server: " + op.productName + " " + op.productVersion + "\n";
}
if (!CommonUtils.isEmpty(op.driverName)) {
message += "Driver: " + op.driverName + " " + op.driverVersion + "\n";
}
if (!CommonUtils.isEmpty(message)) {
message += "\n";
}
message += NLS.bind(CoreMessages.dialog_connection_wizard_start_connection_monitor_connected, op.connectTime);
MessageDialog.openInformation(getShell(), CoreMessages.dialog_connection_wizard_start_connection_monitor_success, message);
} catch (InterruptedException ex) {
DBUserInterface.getInstance().showError(CoreMessages.dialog_connection_wizard_start_dialog_interrupted_title, CoreMessages.dialog_connection_wizard_start_dialog_interrupted_message);
} catch (InvocationTargetException ex) {
DBUserInterface.getInstance().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
}
} finally {
testDataSource.dispose();
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.
the class ContentEditor method doSaveAs.
@Override
public void doSaveAs() {
Shell shell = getSite().getShell();
final File saveFile = DialogUtils.selectFileForSave(shell, getPartName());
if (saveFile == null) {
return;
}
try {
getSite().getWorkbenchWindow().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
getEditorInput().saveToExternalFile(saveFile, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Can't save content", "Can't save content to file '" + saveFile.getAbsolutePath() + "'", e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project yamcs-studio by yamcs.
the class SchemaService method reLoad.
/**
* Reload schema opi.
*/
public void reLoad() {
schemaWidgetsMap.clear();
final IPath schemaOPI = PreferencesHelper.getSchemaOPIPath();
if (schemaOPI == null || schemaOPI.isEmpty()) {
return;
}
if (Display.getCurrent() != null) {
// in UI thread, show progress dialog
IRunnableWithProgress job = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Connecting to " + schemaOPI, IProgressMonitor.UNKNOWN);
loadSchema(schemaOPI);
monitor.done();
}
};
try {
new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(true, false, job);
} catch (Exception e) {
ErrorHandlerUtil.handleError("Failed to load schema", e);
}
} else
loadSchema(schemaOPI);
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.
the class DatabaseConsumerSettings method loadNode.
public void loadNode(IRunnableContext runnableContext) {
if (containerNode == null && !CommonUtils.isEmpty(containerNodePath)) {
if (!CommonUtils.isEmpty(containerNodePath)) {
try {
runnableContext.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByPath(new DefaultProgressMonitor(monitor), containerNodePath);
if (node instanceof DBNDatabaseNode) {
containerNode = (DBNDatabaseNode) node;
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
checkContainerConnection(runnableContext);
} catch (InvocationTargetException e) {
log.error("Error getting container node", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project erlide_eclipse by erlang.
the class ProjectCreator method createProject.
public IProject createProject() throws CoreException {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject newProjectHandle = workspace.getRoot().getProject(name);
if (newProjectHandle.exists()) {
throw new CoreException(Status.OK_STATUS);
}
final IProjectDescription description = workspace.newProjectDescription(name);
description.setLocationURI(location);
// // update the referenced project if provided
if (referencedProjects != null) {
description.setReferencedProjects(referencedProjects);
}
// create the new project operation
final IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
final CreateProjectOperation op1 = new CreateProjectOperation(description, WizardMessages.NewProject_windowTitle);
try {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
// Making this undoable would be a bad idea
op1.execute(monitor, notifier);
newProjectHandle.open(monitor);
description.setNatureIds(new String[] { ErlangCore.NATURE_ID });
newProjectHandle.setDescription(description, null);
final BuilderTool builder = info.getBuilder();
ErlangNature.setErlangProjectBuilder(newProjectHandle, builder);
createBuilderConfig(builder);
createFolders(newProjectHandle, Lists.newArrayList(info.getOutputDir()), monitor);
createFolders(newProjectHandle, info.getSourceDirs(), monitor);
createFolders(newProjectHandle, info.getIncludeDirs(), monitor);
createConfig(newProjectHandle, info.getConfigType(), monitor);
final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(newProjectHandle);
erlProject.setConfigType(info.getConfigType());
final BuilderProperties builderProperties = new BuilderProperties();
builderProperties.setBuilderTool(builder);
builderProperties.setCompileTarget(info.getBuilderData().get("compile"));
builderProperties.setCleanTarget(info.getBuilderData().get("clean"));
erlProject.setBuilderProperties(builderProperties);
erlProject.setProperties(info);
} catch (final Exception e) {
throw new InvocationTargetException(e);
}
}
};
// run the new project creation operation
try {
context.run(false, true, op);
} catch (final InterruptedException e) {
return null;
} catch (final InvocationTargetException e) {
final Throwable t = e.getTargetException();
if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
final CoreException cause = (CoreException) t.getCause();
StatusAdapter status;
if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS.bind(WizardMessages.NewProject_caseVariantExistsError, newProjectHandle.getName()), cause));
} else {
status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), WizardMessages.NewProject_errorMessage, cause));
}
status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
StatusManager.getManager().handle(status, StatusManager.BLOCK);
} else {
final StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ErlideUIPlugin.PLUGIN_ID, 0, NLS.bind(WizardMessages.NewProject_internalError, t.getMessage()), t));
status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
}
return null;
}
return newProjectHandle;
}
Aggregations