use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by serge-rider.
the class NodeDropTargetListener method createTargetRequest.
@Override
protected Request createTargetRequest() {
CreateRequest request = new CreateRequest();
request.setFactory(new CreationFactory() {
@Override
public Object getNewObject() {
Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (objects == null) {
return null;
}
DBRRunnableWithResult<List<ERDEntity>> collector = new DBRRunnableWithResult<List<ERDEntity>>() {
@Override
public void run(DBRProgressMonitor monitor) {
result = DiagramObjectCollector.generateEntityList(monitor, ((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
}
};
try {
UIUtils.runInProgressService(collector);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
} catch (InterruptedException e) {
// ignore
}
return collector.getResult();
}
@Override
public Object getObjectType() {
return RequestConstants.REQ_CREATE;
}
});
request.setLocation(getDropLocation());
return request;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by dbeaver.
the class DBUtils method createNewAttributeValue.
public static <T> T createNewAttributeValue(DBCExecutionContext context, DBDValueHandler valueHandler, DBSTypedObject valueType, Class<T> targetType) throws DBCException {
DBRRunnableWithResult<Object> runnable = new DBRRunnableWithResult<Object>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Create new object")) {
result = valueHandler.createNewValueObject(session, valueType);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
};
try {
DBWorkbench.getPlatformUI().executeWithProgress(runnable);
// UIUtils.runInProgressService(runnable);
} catch (InvocationTargetException e) {
throw new DBCException(e.getTargetException(), context);
} catch (InterruptedException e) {
throw new DBCException(e, context);
}
Object result = runnable.getResult();
if (result == null) {
throw new DBCException("Internal error - null object created");
}
if (!targetType.isInstance(result)) {
throw new DBCException("Internal error - wrong object type '" + result.getClass().getName() + "' while '" + targetType.getName() + "' was expected");
}
return targetType.cast(result);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by dbeaver.
the class ObjectListDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
createUpperControls(group);
objectList = createObjectSelector(group, singleSelection, listId, selectedObjects, new DBRRunnableWithResult<List<T>>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
result = getObjects(monitor);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
objectList.createProgressPanel();
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.minimumWidth = 300;
objectList.setLayoutData(gd);
objectList.getSelectionProvider().addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedObjects.clear();
selectedObjects.addAll(selection.toList());
if (!isModeless()) {
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
}
});
objectList.setDoubleClickHandler(event -> {
if (isModeless() || getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
});
objectList.loadData();
closeOnFocusLost(objectList.getItemsViewer().getControl(), objectList.getSearchTextControl());
return group;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by dbeaver.
the class SelectDatabaseDialog method createInstanceSelector.
private void createInstanceSelector(Composite group, DBSObjectContainer instanceContainer) {
((GridLayout) group.getLayout()).numColumns++;
instanceList = createObjectSelector(group, true, "DatabaseInstanceSelector", selectedInstances, new DBRRunnableWithResult<List<DBNDatabaseNode>>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
if (!CommonUtils.isEmpty(currentInstanceName) && selectedInstances.isEmpty()) {
DBSObject activeInstance = instanceContainer.getChild(monitor, currentInstanceName);
if (activeInstance != null) {
DBNDatabaseNode activeInstanceNode = DBNUtils.getNodeByObject(monitor, activeInstance, false);
if (activeInstanceNode != null) {
selectedInstances.add(activeInstanceNode);
}
}
}
Collection<? extends DBSObject> instances = instanceContainer.getChildren(new VoidProgressMonitor());
List<DBNDatabaseNode> instanceNodes = new ArrayList<>();
if (!CommonUtils.isEmpty(instances)) {
for (DBSObject instance : instances) {
DBNDatabaseNode instanceNode = DBNUtils.getNodeByObject(monitor, instance, false);
if (instanceNode != null) {
instanceNodes.add(instanceNode);
}
}
}
result = instanceNodes;
objectList.loadData();
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
instanceList.createProgressPanel();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.minimumWidth = 300;
instanceList.setLayoutData(gd);
instanceList.getSelectionProvider().addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedInstances.clear();
selectedInstances.addAll(selection.toList());
DBNDatabaseNode instance = selectedInstances.isEmpty() ? null : selectedInstances.get(0);
if (instance != null && !CommonUtils.equalObjects(instance.getNodeName(), currentInstanceName)) {
currentInstanceName = instance.getNodeName();
objectList.loadData();
}
});
instanceList.loadData();
closeOnFocusLost(instanceList);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by dbeaver.
the class DatabaseNavigatorTree method expandNodeOnLoad.
private void expandNodeOnLoad(final DBNNode node) {
if (node instanceof DBNDataSource && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_EXPAND_ON_CONNECT)) {
try {
DBRRunnableWithResult<DBNNode> runnable = new DBRRunnableWithResult<DBNNode>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
result = findActiveNode(monitor, node);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
UIUtils.runInProgressService(runnable);
if (runnable.getResult() != null && !treeViewer.getTree().isDisposed()) {
showNode(runnable.getResult());
treeViewer.expandToLevel(runnable.getResult(), 1);
/*
// TODO: it is a bug in Eclipse Photon.
try {
treeViewer.expandToLevel(runnable.getResult(), 1, true);
} catch (Throwable e) {
treeViewer.expandToLevel(runnable.getResult(), 1);
}
*/
}
} catch (InvocationTargetException e) {
log.error("Can't expand node", e.getTargetException());
} catch (InterruptedException e) {
// skip it
}
}
}
Aggregations