use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class ConnectionPageWithAuth method loadSettings.
@Override
public void loadSettings() {
super.loadSettings();
DBPDataSourceContainer activeDataSource = getSite().getActiveDataSource();
DBPAuthModelDescriptor selectedAuthModel = null;
DBPConnectionConfiguration configuration = activeDataSource.getConnectionConfiguration();
if (site.isNew() && CommonUtils.isEmpty(configuration.getUserName())) {
configuration.setUserName(activeDataSource.getDriver().getDefaultUser());
}
String dsModelId = configuration.getAuthModelId();
if (dsModelId != null) {
selectedAuthModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(dsModelId);
}
authModelSelector.loadSettings(getSite().getActiveDataSource(), selectedAuthModel, getDefaultAuthModelId(activeDataSource));
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class ScriptSelectorPanel method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
/*Rectangle bounds = new Rectangle(100, 100, 500, 200);
final String boundsStr = getBoundsSettings().get(CONFIG_BOUNDS_PARAM);
if (boundsStr != null && !boundsStr.isEmpty()) {
final String[] bc = boundsStr.split(",");
try {
bounds = new Rectangle(
Integer.parseInt(bc[0]),
Integer.parseInt(bc[1]),
Integer.parseInt(bc[2]),
Integer.parseInt(bc[3]));
} catch (NumberFormatException e) {
log.warn(e);
}
}*/
patternText = new Text(composite, SWT.BORDER);
patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.addEmptyTextHint(patternText, text -> "Enter a part of script name here");
// patternText.setForeground(fg);
// patternText.setBackground(bg);
patternText.addModifyListener(e -> {
if (filterJob != null) {
return;
}
filterJob = new FilterJob();
filterJob.schedule(250);
});
// parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
final Color fg = patternText.getForeground();
// parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
final Color bg = patternText.getBackground();
composite.setForeground(fg);
composite.setBackground(bg);
Button newButton = new Button(composite, SWT.PUSH | SWT.FLAT);
newButton.setText("&New Script");
newButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IFile scriptFile;
try {
scriptFile = SQLEditorUtils.createNewScript(DBWorkbench.getPlatform().getWorkspace().getProject(rootFolder.getProject()), rootFolder, navigatorContext);
SQLEditorHandlerOpenEditor.openResource(scriptFile, navigatorContext);
} catch (CoreException ex) {
log.error(ex);
}
cancelPressed();
}
});
((GridData) UIUtils.createHorizontalLine(composite).getLayoutData()).horizontalSpan = 2;
Tree scriptTree = new Tree(composite, SWT.SINGLE | SWT.FULL_SELECTION);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
gd.widthHint = 500;
gd.heightHint = 200;
scriptTree.setLayoutData(gd);
scriptTree.setForeground(fg);
scriptTree.setBackground(bg);
scriptTree.setLinesVisible(true);
// scriptViewer.setHeaderVisible(true);
this.scriptViewer = new TreeViewer(scriptTree);
ColumnViewerToolTipSupport.enableFor(this.scriptViewer);
// scriptTree.setS
this.scriptViewer.setContentProvider(new TreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof ResourceInfo) {
final List<ResourceInfo> children = ((ResourceInfo) parentElement).getChildren();
return CommonUtils.isEmpty(children) ? null : children.toArray();
}
return null;
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof ResourceInfo) {
final List<ResourceInfo> children = ((ResourceInfo) element).getChildren();
return !CommonUtils.isEmpty(children);
}
return false;
}
});
ViewerColumnController columnController = new ViewerColumnController("scriptSelectorViewer", scriptViewer);
columnController.addColumn("Script", "Resource name", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
final ResourceInfo ri = (ResourceInfo) element;
if (!ri.isDirectory()) {
if (ri.getDataSource() == null) {
return DBeaverIcons.getImage(UIIcon.SQL_SCRIPT);
} else {
return DBeaverIcons.getImage(ri.getDataSource().getDriver().getIcon());
}
} else {
return DBeaverIcons.getImage(DBIcon.TREE_FOLDER);
}
}
@Override
public String getText(Object element) {
return ((ResourceInfo) element).getName();
}
@Override
public String getToolTipText(Object element) {
final DBPDataSourceContainer dataSource = ((ResourceInfo) element).getDataSource();
return dataSource == null ? null : dataSource.getName();
}
@Override
public Image getToolTipImage(Object element) {
final DBPDataSourceContainer dataSource = ((ResourceInfo) element).getDataSource();
return dataSource == null ? null : DBeaverIcons.getImage(dataSource.getDriver().getIcon());
}
});
columnController.addColumn("Time", "Modification time", SWT.LEFT, true, true, new ColumnLabelProvider() {
private SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);
@Override
public String getText(Object element) {
final File localFile = ((ResourceInfo) element).getLocalFile();
if (localFile.isDirectory()) {
return null;
} else {
return sdf.format(new Date(localFile.lastModified()));
}
}
});
columnController.addColumn("Info", "Script preview", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
// ((ResourceInfo)element).getDescription();
return "";
}
@Override
public Color getForeground(Object element) {
return getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
}
@Override
public String getToolTipText(Object element) {
final ResourceInfo ri = (ResourceInfo) element;
String description = ri.getDescription();
return description == null ? null : description.trim();
}
});
columnController.createColumns();
columnController.sortByColumn(1, SWT.UP);
scriptTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
List<ResourceInfo> files = new ArrayList<>();
for (Object item : ((IStructuredSelection) scriptViewer.getSelection()).toArray()) {
if (!((ResourceInfo) item).isDirectory()) {
files.add((ResourceInfo) item);
}
}
if (files.isEmpty()) {
return;
}
cancelPressed();
for (ResourceInfo ri : files) {
SQLEditorHandlerOpenEditor.openResourceEditor(ScriptSelectorPanel.this.workbenchWindow, ri, navigatorContext);
}
}
});
scriptTree.addListener(SWT.PaintItem, event -> {
final TreeItem item = (TreeItem) event.item;
final ResourceInfo ri = (ResourceInfo) item.getData();
if (ri != null && !ri.isDirectory() && CommonUtils.isEmpty(item.getText(2))) {
UIUtils.asyncExec(() -> {
if (!item.isDisposed()) {
item.setText(2, CommonUtils.getSingleLineString(CommonUtils.notEmpty(ri.getDescription())));
}
});
}
});
this.patternText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
final Tree tree = scriptViewer.getTree();
if (e.keyCode == SWT.ARROW_DOWN) {
// scriptViewer.get
scriptViewer.setSelection(new StructuredSelection(tree.getItem(0).getData()));
tree.setFocus();
} else if (e.keyCode == SWT.ARROW_UP) {
scriptViewer.setSelection(new StructuredSelection(tree.getItem(tree.getItemCount() - 1).getData()));
tree.setFocus();
}
}
});
closeOnFocusLost(patternText, scriptViewer.getTree(), newButton);
scriptViewer.setInput(scriptFiles);
UIUtils.expandAll(scriptViewer);
final Tree tree = scriptViewer.getTree();
final TreeColumn[] columns = tree.getColumns();
columns[0].pack();
columns[0].setWidth(columns[0].getWidth() + 10);
columns[1].pack();
columns[2].setWidth(200 * 8);
UIUtils.asyncExec(scriptTree::setFocus);
return composite;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class QueryLogViewer method openSelectionInEditor.
private void openSelectionInEditor() {
DBPDataSourceContainer dsContainer = null;
StringBuilder sql = new StringBuilder();
TableItem[] items = logTable.getSelection();
for (TableItem item : items) {
QMMetaEvent event = (QMMetaEvent) item.getData();
QMMObject object = event.getObject();
if (object instanceof QMMStatementExecuteInfo) {
QMMStatementExecuteInfo stmtExec = (QMMStatementExecuteInfo) object;
if (dsContainer == null) {
QMMSessionInfo session = stmtExec.getStatement().getSession();
DBPProject project = session.getProject();
String containerId = session.getContainerId();
if (project != null) {
dsContainer = project.getDataSourceRegistry().getDataSource(containerId);
} else {
dsContainer = DBUtils.findDataSource(containerId);
}
}
String queryString = stmtExec.getQueryString();
if (!CommonUtils.isEmptyTrimmed(queryString)) {
if (sql.length() > 0) {
// $NON-NLS-1$
sql.append("\n");
}
queryString = queryString.trim();
sql.append(queryString);
if (!queryString.endsWith(SQLConstants.DEFAULT_STATEMENT_DELIMITER)) {
// $NON-NLS-1$
sql.append(SQLConstants.DEFAULT_STATEMENT_DELIMITER).append("\n");
}
}
}
}
if (sql.length() > 0) {
SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(dsContainer), // $NON-NLS-1$
"QueryManager", sql.toString());
}
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class SQLEditorUtils method createNewScript.
public static IFile createNewScript(DBPProject project, @Nullable IFolder folder, @NotNull SQLNavigatorContext navigatorContext) throws CoreException {
final IProgressMonitor progressMonitor = new NullProgressMonitor();
// Get folder
final IFolder scriptsRootFolder = getScriptsFolder(project, true);
IFolder scriptsFolder = folder;
if (scriptsFolder == null) {
scriptsFolder = scriptsRootFolder;
}
if (!scriptsFolder.exists()) {
scriptsFolder.create(true, true, new NullProgressMonitor());
}
if (CommonUtils.equalObjects(scriptsRootFolder, scriptsFolder)) {
// We are in the root folder
DBPDataSourceContainer dataSourceContainer = navigatorContext.getDataSourceContainer();
if (dataSourceContainer != null) {
if (dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.SCRIPT_CREATE_CONNECTION_FOLDERS)) {
// Create script folders according to connection folders
DBPDataSourceFolder conFolder = dataSourceContainer.getFolder();
if (conFolder != null) {
List<DBPDataSourceFolder> conFolders = new ArrayList<>();
for (DBPDataSourceFolder f = conFolder; f != null; f = f.getParent()) {
conFolders.add(0, f);
}
for (DBPDataSourceFolder f : conFolders) {
IFolder dbFolder = scriptsFolder.getFolder(CommonUtils.escapeFileName(f.getName()));
if (dbFolder != null) {
if (!dbFolder.exists()) {
dbFolder.create(true, true, progressMonitor);
}
scriptsFolder = dbFolder;
}
}
}
}
if (dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.SCRIPT_AUTO_FOLDERS)) {
// Create special folder for connection
IFolder dbFolder = scriptsFolder.getFolder(CommonUtils.escapeFileName(dataSourceContainer.getName()));
if (dbFolder != null) {
if (!dbFolder.exists()) {
dbFolder.create(true, true, progressMonitor);
}
scriptsFolder = dbFolder;
}
}
}
}
// Make new script file
IFile tempFile = ContentUtils.getUniqueFile(scriptsFolder, "Script", SCRIPT_FILE_EXTENSION);
tempFile.create(new ByteArrayInputStream(new byte[] {}), true, progressMonitor);
// Save ds container reference
if (navigatorContext.getDataSourceContainer() != null) {
EditorUtils.setFileDataSource(tempFile, navigatorContext);
}
return tempFile;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class OracleDataSourceProvider method getObjectInformation.
@Nullable
@Override
public String getObjectInformation(@NotNull DBPObject object, @NotNull String infoType) {
if (object instanceof DBPDataSourceContainer && infoType.equals(INFO_TARGET_ADDRESS)) {
DBPConnectionConfiguration connectionInfo = ((DBPDataSourceContainer) object).getConnectionConfiguration();
OracleConstants.ConnectionType connectionType = getConnectionType(connectionInfo);
if (connectionType == OracleConstants.ConnectionType.CUSTOM) {
return JDBCURL.generateUrlByTemplate(connectionInfo.getUrl(), connectionInfo);
}
String databaseName = CommonUtils.notEmpty(connectionInfo.getDatabaseName());
if (connectionType == OracleConstants.ConnectionType.TNS) {
return databaseName;
} else {
String hostName = DataSourceUtils.getTargetTunnelHostName(connectionInfo);
String hostPort = connectionInfo.getHostPort();
if (CommonUtils.isEmpty(hostName)) {
return null;
} else if (CommonUtils.isEmpty(hostPort)) {
return hostName;
} else {
return hostName + ":" + hostPort;
}
}
}
return null;
}
Aggregations