use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateCopy method pasteResource.
private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
final IResource resource = resourceNode.getResource();
final IResource targetResource = toFolder.getResource();
assert resource != null;
assert targetResource != null;
final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
copyResource(monitor, resource, targetFolder);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class NavigatorActionSetActiveObject method run.
@Override
public void run(IAction action) {
if (selection instanceof IStructuredSelection) {
DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
if (selectedNode instanceof DBNDatabaseNode) {
final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
if (activeContainer != null) {
TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
activeContainer.setDefaultObject(monitor, databaseNode.getObject());
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class SelectObjectDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
ObjectListControl<T> objectList = new ObjectListControl<T>(group, SWT.BORDER | (singleSelection ? SWT.SINGLE : SWT.MULTI), new ListContentProvider()) {
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return "ObjectsSelector";
}
@Override
protected LoadingJob<Collection<T>> createLoadService() {
return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {
@Override
public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
return objects;
}
@Override
public Object getFamily() {
return SelectObjectDialog.this;
}
}, new ObjectsLoadVisualizer());
}
};
objectList.createProgressPanel();
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.minimumWidth = 300;
objectList.setLayoutData(gd);
objectList.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedObjects.clear();
selectedObjects.addAll(selection.toList());
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
}
});
objectList.setDoubleClickHandler(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
}
});
objectList.loadData();
return group;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DialogUtils method loadFromFile.
public static boolean loadFromFile(final IValueController controller) {
if (!(controller.getValue() instanceof DBDContent)) {
log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
return false;
}
Shell shell = UIUtils.getShell(controller.getValueSite());
final File openFile = openFile(shell);
if (openFile == null) {
return false;
}
final DBDContent value = (DBDContent) controller.getValue();
DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBDContentStorage storage;
if (ContentUtils.isTextContent(value)) {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
} else {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
}
value.updateContents(monitor, storage);
controller.updateValue(value, true);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
return true;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class GotoObjectDialog method fillContentProvider.
@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, context.getDataSource());
if (structureAssistant == null) {
return;
}
String nameMask = ((ObjectFilter) itemsFilter).getNameMask();
DBRProgressMonitor monitor = RuntimeUtils.makeMonitor(progressMonitor);
try {
monitor.beginTask("Search for '" + nameMask + "'", 100);
List<DBSObjectType> typesToSearch = new ArrayList<>();
for (DBSObjectType type : structureAssistant.getSupportedObjectTypes()) {
Class<? extends DBSObject> typeClass = type.getTypeClass();
if (DBSEntityElement.class.isAssignableFrom(typeClass)) {
// Skipp attributes (columns), methods, etc
continue;
}
typesToSearch.add(type);
}
Collection<DBSObjectReference> result = structureAssistant.findObjectsByMask(monitor, container, typesToSearch.toArray(new DBSObjectType[typesToSearch.size()]), nameMask, false, true, 1000);
DBPDataSourceContainer dsContainer = context.getDataSource().getContainer();
for (DBSObjectReference ref : result) {
DBSObjectFilter filter = dsContainer.getObjectFilter(ref.getObjectClass(), ref.getContainer(), true);
if (filter == null || !filter.isEnabled() || filter.matches(ref.getName())) {
contentProvider.add(ref, itemsFilter);
}
}
} catch (DBException e) {
throw new CoreException(GeneralUtils.makeExceptionStatus(e));
} finally {
monitor.done();
}
}
Aggregations