use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class SelectActiveSchemaHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (SelectActiveDataSourceHandler.getDataSourceContainerProvider(HandlerUtil.getActiveEditor(event)) == null) {
return null;
}
DBPDataSourceContainer dataSourceContainer = DataSourceToolbarUtils.getCurrentDataSource(HandlerUtil.getActiveWorkbenchWindow(event));
if (dataSourceContainer == null) {
log.debug("No active connection. Action is in disabled state.");
return null;
}
DBCExecutionContext executionContext = getExecutionContextFromPart(HandlerUtil.getActiveEditor(event));
ContextDefaultObjectsReader contextDefaultObjectsReader = new ContextDefaultObjectsReader(dataSourceContainer.getDataSource(), executionContext);
try {
UIUtils.runInProgressService(contextDefaultObjectsReader);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Schema list", "Error reading schema list", e.getTargetException());
return null;
} catch (InterruptedException e) {
return null;
}
DBSObject selectedDB = null;
DBSObject defaultObject = contextDefaultObjectsReader.getDefaultObject();
if (defaultObject != null) {
for (DBSObject object : contextDefaultObjectsReader.getObjectList()) {
if (object == defaultObject || object == defaultObject.getParentObject()) {
selectedDB = object;
}
}
}
DBNDatabaseNode selectedNode = selectedDB == null ? null : DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(selectedDB);
SelectDatabaseDialog dialog = new SelectDatabaseDialog(HandlerUtil.getActiveShell(event), dataSourceContainer, contextDefaultObjectsReader.getDefaultCatalogName(), contextDefaultObjectsReader.getNodeList(), selectedNode == null ? null : Collections.singletonList(selectedNode));
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return null;
}
DBNDatabaseNode node = dialog.getSelectedObject();
if (node != null && node.getObject() != defaultObject) {
// Change current schema
changeDataBaseSelection(dataSourceContainer, executionContext, contextDefaultObjectsReader.getDefaultCatalogName(), dialog.getCurrentInstanceName(), node.getNodeName());
}
return null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class DatabaseEditorUtils method setPartBackground.
public static void setPartBackground(IEditorPart editor, Composite composite) {
if (composite == null || composite.isDisposed()) {
return;
}
CTabFolder tabFolder = null;
Composite rootComposite = composite;
for (Composite c = composite; c != null; c = c.getParent()) {
if (!c.isDisposed() && c.getParent() instanceof CTabFolder) {
tabFolder = (CTabFolder) c.getParent();
// rootComposite = c;
break;
}
}
if (tabFolder != null) {
tabFolder.setBorderVisible(false);
}
DBPDataSourceContainer dsContainer = null;
if (editor instanceof IDataSourceContainerProvider) {
dsContainer = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
} else if (editor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
if (context != null) {
dsContainer = context.getDataSource().getContainer();
}
}
if (dsContainer == null) {
rootComposite.setBackground(null);
} else {
Color bgColor = UIUtils.getConnectionColor(dsContainer.getConnectionConfiguration());
rootComposite.setData(DBStyles.DATABASE_EDITOR_COMPOSITE_DATASOURCE, dsContainer);
rootComposite.setBackground(bgColor);
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class ObjectEditorPageControl method isObjectEditable.
public boolean isObjectEditable() {
IEditorInput editorInput = getEditorPart().getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
DBCExecutionContext context = ((IDatabaseEditorInput) editorInput).getExecutionContext();
if (context == null) {
return false;
}
if (context.getDataSource().getInfo().isReadOnlyMetaData()) {
return false;
}
DBSObject databaseObject = ((IDatabaseEditorInput) editorInput).getDatabaseObject();
return databaseObject != null && DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(databaseObject.getClass(), DBEObjectManager.class) != null;
}
return false;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class ResultSetFilterPanel method setCustomDataFilter.
private void setCustomDataFilter() {
DBCExecutionContext context = viewer.getExecutionContext();
if (context == null) {
return;
}
String condition = filtersText.getText();
StringBuilder currentCondition = new StringBuilder();
SQLUtils.appendConditionString(viewer.getModel().getDataFilter(), context.getDataSource(), null, currentCondition, true);
if (currentCondition.toString().trim().equals(condition.trim())) {
// The same
return;
}
DBDDataFilter newFilter = new DBDDataFilter(viewer.getModel().getDataFilter());
for (DBDAttributeConstraint ac : newFilter.getConstraints()) {
ac.setCriteria(null);
}
newFilter.setWhere(condition);
viewer.setDataFilter(newFilter, true);
// viewer.getControl().setFocus();
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class PrefPageSQLFormat method createPreferenceContent.
@Override
protected Control createPreferenceContent(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 3, 5);
formatterSelector = UIUtils.createLabelCombo(composite, SQLEditorMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
formatters.sort(Comparator.comparing(SQLFormatterDescriptor::getLabel));
for (SQLFormatterDescriptor formatterDesc : formatters) {
formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel()));
}
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showFormatterSettings();
performApply();
}
});
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatCurrentQueryCheck = UIUtils.createCheckbox(composite, "Format active query only", "Formats only active query or selected text. Otherwise formats entire SQL script", true, 1);
Composite formatterGroup = UIUtils.createPlaceholder(composite, 1, 5);
formatterGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
((GridData) formatterGroup.getLayoutData()).horizontalSpan = 3;
/*
{
Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 4, 5);
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
keywordCaseCombo = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Database");
for (DBPIdentifierCase c :DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
*/
// External formatter
{
formatterConfigPlaceholder = UIUtils.createPlaceholder(formatterGroup, 2, 5);
formatterConfigPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
formatterConfigPlaceholder.setLayout(new FillLayout());
}
{
// SQL preview
Composite previewGroup = new Composite(composite, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
previewGroup.setLayoutData(gd);
previewGroup.setLayout(new FillLayout());
sqlViewer = new SQLEditorBase() {
@Override
public DBCExecutionContext getExecutionContext() {
final DBPDataSourceContainer container = getDataSourceContainer();
if (container != null) {
final DBPDataSource dataSource = container.getDataSource();
if (dataSource != null) {
return DBUtils.getDefaultContext(dataSource.getDefaultInstance(), false);
}
}
return null;
}
};
try {
try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
final String sqlText = ContentUtils.readToString(sqlStream, StandardCharsets.UTF_8);
IEditorSite subSite = new SubEditorSite(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
}
} catch (Exception e) {
log.error(e);
}
sqlViewer.createPartControl(previewGroup);
Object text = sqlViewer.getAdapter(Control.class);
if (text instanceof StyledText) {
((StyledText) text).setWordWrap(true);
}
sqlViewer.reloadSyntaxRules();
previewGroup.addDisposeListener(e -> sqlViewer.dispose());
{
// Styles
// Composite afGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_style, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
// ((GridData)afGroup.getLayoutData()).horizontalSpan = 2;
styleBoldKeywords = UIUtils.createCheckbox(composite, SQLEditorMessages.pref_page_sql_format_label_bold_keywords, SQLEditorMessages.pref_page_sql_format_label_bold_keywords_tip, false, 2);
styleBoldKeywords.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
}
return composite;
}
Aggregations