use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class DataSourcePropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
try {
// Get root datasource node (we don't want to
while (receiver instanceof DBNDatabaseNode && !(receiver instanceof DBNDataSource)) {
receiver = ((DBNDatabaseNode) receiver).getParentNode();
}
if (!(receiver instanceof DBPContextProvider)) {
return false;
}
DBPContextProvider contextProvider = (DBPContextProvider) receiver;
@Nullable DBCExecutionContext context = contextProvider.getExecutionContext();
switch(property) {
case PROP_CONNECTED:
boolean isConnected;
if (context != null) {
isConnected = context.getDataSource().getContainer().isConnected();
} else if (receiver instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) receiver).getDataSourceContainer();
isConnected = container != null && container.isConnected();
} else {
isConnected = false;
}
boolean checkConnected = Boolean.TRUE.equals(expectedValue);
return checkConnected ? isConnected : !isConnected;
case PROP_TRANSACTIONAL:
{
if (context == null) {
return false;
}
if (!context.isConnected()) {
return Boolean.FALSE.equals(expectedValue);
}
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
try {
return txnManager != null && Boolean.valueOf(!txnManager.isAutoCommit()).equals(expectedValue);
} catch (DBCException e) {
log.debug("Error checking auto-commit state", e);
return false;
}
}
case PROP_SUPPORTS_TRANSACTIONS:
{
if (context == null || !context.isConnected()) {
return false;
}
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
return txnManager != null && txnManager.isSupportsTransactions();
}
case PROP_TRANSACTION_ACTIVE:
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
return txnManager != null && !txnManager.isAutoCommit();
// boolean active = QMUtils.isTransactionActive(context);
// return Boolean.valueOf(active).equals(expectedValue);
}
return Boolean.FALSE.equals(expectedValue);
}
return false;
} catch (Exception e) {
log.debug("Error testing property " + property + ": " + e.getMessage());
return false;
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class AddBookmarkHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
final DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDataSource) {
DBWorkbench.getPlatformUI().showError(CoreMessages.actions_navigator_bookmark_error_title, "Connection itself cannot be bookmarked. Choose some element under a connection element.");
return null;
}
if (node instanceof DBNDatabaseNode) {
try {
AddBookmarkDialog dialog = new AddBookmarkDialog(activeShell, (DBNDatabaseNode) node);
final String title = dialog.chooseName();
if (title != null) {
BookmarksHandlerImpl.createBookmark((DBNDatabaseNode) node, title, dialog.getTargetFolder());
}
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError(CoreMessages.actions_navigator_bookmark_error_title, CoreMessages.actions_navigator_bookmark_error_message, e);
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class SQLScriptTaskPageSettings method saveSettings.
public void saveSettings() {
if (sqlWizard == null) {
return;
}
SQLScriptExecuteSettings settings = sqlWizard.getSettings();
List<String> scriptPaths = new ArrayList<>();
for (DBNResource resource : selectedScripts) {
IResource res = resource.getResource();
if (res instanceof IFile) {
scriptPaths.add(res.getFullPath().toString());
}
}
settings.setScriptFiles(scriptPaths);
List<DBPDataSourceContainer> dsList = new ArrayList<>();
for (DBNDataSource dsNode : selectedDataSources) {
dsList.add(dsNode.getDataSourceContainer());
}
settings.setDataSources(dsList);
settings.setIgnoreErrors(ignoreErrorsCheck.getSelection());
settings.setDumpQueryResultsToLog(dumpQueryCheck.getSelection());
settings.setAutoCommit(autoCommitCheck.getSelection());
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class SQLScriptTaskPageSettings method loadSettings.
public void loadSettings() {
SQLScriptExecuteSettings settings = sqlWizard.getSettings();
List<String> scriptFiles = settings.getScriptFiles();
for (String filePath : scriptFiles) {
IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
if (file == null) {
log.debug("Script file '" + filePath + "' not found");
continue;
}
DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
if (currentProject == null) {
log.debug("Project '" + file.getProject().getName() + "' not found");
continue;
}
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
if (projectNode != null) {
DBNResource resource = projectNode.findResource(file);
if (resource != null) {
selectedScripts.add(resource);
}
}
}
scriptsViewer.setInput(selectedScripts);
for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
if (dsNode != null) {
selectedDataSources.add(dsNode);
}
}
dataSourceViewer.setInput(selectedDataSources);
// if (!selectedDataSources.isEmpty()) {
// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
// }
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class DiagramCreateWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite placeholder = UIUtils.createPlaceholder(parent, 1);
Composite configGroup = UIUtils.createControlGroup(placeholder, ERDUIMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
// $NON-NLS-1$
final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
projectNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
diagram.setName(projectNameText.getText());
updateState();
}
});
Label contentLabel = UIUtils.createControlLabel(configGroup, ERDUIMessages.wizard_page_diagram_create_label_init_content);
GridData gd = new GridData(GridData.BEGINNING);
gd.horizontalSpan = 2;
contentLabel.setLayoutData(gd);
final DBNProject rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject());
if (rootNode == null) {
setControl(placeholder);
return;
}
contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
gd.heightHint = 400;
contentTree.setLayoutData(gd);
CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
viewer.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isChecked(Object element) {
return false;
}
@Override
public boolean isGrayed(Object element) {
if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSTable) {
return false;
}
}
return true;
}
});
if (entitySelection != null) {
viewer.setSelection(entitySelection, true);
viewer.setCheckedElements(entitySelection.toArray());
}
setControl(placeholder);
}
Aggregations