use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class NavigatorHandlerAssociateScript method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
List<IFile> scripts = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
final DBNNode node = RuntimeUtils.getObjectAdapter(iter.next(), DBNNode.class);
if (node instanceof DBNResource) {
IResource resource = ((DBNResource) node).getResource();
if (resource instanceof IFile) {
scripts.add((IFile) resource);
}
}
}
}
if (!scripts.isEmpty()) {
SelectDataSourceDialog dialog = new SelectDataSourceDialog(activeShell, scripts.get(0).getProject(), null);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return null;
}
DBPDataSourceContainer dataSource = dialog.getDataSource();
for (IFile script : scripts) {
EditorUtils.setFileDataSource(script, dataSource, true);
}
}
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
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();
}
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class DatabaseEditorInputFactory method createElement.
@Override
public IAdaptable createElement(IMemento memento) {
// Get the node path.
final String inputClass = memento.getString(TAG_CLASS);
final String nodePath = memento.getString(TAG_NODE);
final String nodeName = memento.getString(TAG_NODE_NAME);
final String dataSourceId = memento.getString(TAG_DATA_SOURCE);
if (nodePath == null || inputClass == null || dataSourceId == null) {
// $NON-NLS-2$
log.error("Corrupted memento");
return null;
}
final String activePageId = memento.getString(TAG_ACTIVE_PAGE);
final String activeFolderId = memento.getString(TAG_ACTIVE_FOLDER);
final DBPDataSourceContainer dataSourceContainer = DataSourceRegistry.findDataSource(dataSourceId);
if (dataSourceContainer == null) {
// $NON-NLS-2$
log.error("Can't find data source '" + dataSourceId + "'");
return null;
}
if (lookupEditor && !dataSourceContainer.isConnected()) {
// . for some object. Connection must be instantiated.
return null;
}
final IProject project = dataSourceContainer.getRegistry().getProject();
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
navigatorModel.ensureProjectLoaded(project);
return new DatabaseLazyEditorInput(dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId);
}
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) {
String containerId = stmtExec.getStatement().getSession().getContainerId();
dsContainer = DataSourceRegistry.findDataSource(containerId);
}
String queryString = stmtExec.getQueryString();
if (!CommonUtils.isEmptyTrimmed(queryString)) {
if (sql.length() > 0) {
sql.append("\n");
}
queryString = queryString.trim();
sql.append(queryString);
if (!queryString.endsWith(SQLConstants.DEFAULT_STATEMENT_DELIMITER)) {
sql.append(SQLConstants.DEFAULT_STATEMENT_DELIMITER).append("\n");
}
}
}
}
if (sql.length() > 0) {
OpenHandler.openSQLConsole(DBeaverUI.getActiveWorkbenchWindow(), dsContainer, "QueryManager", sql.toString());
}
}
Aggregations