use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class OpenHandler method openEditor.
private static void openEditor(ExecutionEvent event) throws ExecutionException, CoreException {
List<DBPDataSourceContainer> containers = getDataSourceContainers(event);
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
IProject project = !containers.isEmpty() ? containers.get(0).getRegistry().getProject() : DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
checkProjectIsOpen(project);
final DBPDataSourceContainer[] containerList = containers.toArray(new DBPDataSourceContainer[containers.size()]);
final IFolder rootFolder = ResourceUtils.getScriptsFolder(project, true);
final List<ResourceUtils.ResourceInfo> scriptTree = ResourceUtils.findScriptTree(rootFolder, containerList.length == 0 ? null : containerList);
if (scriptTree.isEmpty() && containerList.length == 1) {
// Create new script
final IFile newScript = ResourceUtils.createNewScript(project, rootFolder, containers.isEmpty() ? null : containers.get(0));
NavigatorHandlerObjectOpen.openResource(newScript, workbenchWindow);
} else {
// Show script chooser
ScriptSelectorPanel selector = new ScriptSelectorPanel(workbenchWindow, containerList, rootFolder);
selector.showTree(scriptTree);
}
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class OpenObjectConsoleHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
DBPDataSourceContainer ds = null;
List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
List<DBSEntity> entities = new ArrayList<>();
for (DBSObject object : selectedObjects) {
if (object instanceof DBSEntity) {
entities.add((DBSEntity) object);
ds = object.getDataSource().getContainer();
}
}
DBRRunnableWithResult<String> generator = GenerateSQLContributor.SELECT_GENERATOR(entities, true);
DBeaverUI.runInUI(workbenchWindow, generator);
String sql = generator.getResult();
SQLEditor editor = OpenHandler.openSQLConsole(workbenchWindow, ds, "Query", sql);
if (editor != null) {
editor.processSQL(false, false);
}
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
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 serge-rider.
the class ResourceUtils method findChildScripts.
private static boolean findChildScripts(ResourceInfo folder, @Nullable DBPDataSourceContainer[] containers) throws CoreException {
boolean hasScripts = false;
for (IResource resource : ((IFolder) folder.resource).members()) {
if (resource instanceof IFile && SCRIPT_FILE_EXTENSION.equals(resource.getFileExtension())) {
final DBPDataSourceContainer scriptDataSource = EditorUtils.getFileDataSource((IFile) resource);
if (containers == null || ArrayUtils.containsRef(containers, scriptDataSource)) {
folder.children.add(new ResourceInfo((IFile) resource, scriptDataSource));
hasScripts = true;
}
} else if (resource instanceof IFolder) {
final ResourceInfo folderInfo = new ResourceInfo((IFolder) resource);
if (findChildScripts(folderInfo, containers)) {
folder.children.add(folderInfo);
hasScripts = true;
}
}
}
return hasScripts;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class WMIConnectionPage method loadSettings.
@Override
public void loadSettings() {
// Load values from new connection info
DBPDataSourceContainer activeDataSource = site.getActiveDataSource();
DBPConnectionConfiguration connectionInfo = activeDataSource.getConnectionConfiguration();
if (connectionInfo.getHostName() == null) {
connectionInfo.setHostName(DEFAULT_HOST);
}
if (connectionInfo.getDatabaseName() == null) {
connectionInfo.setDatabaseName(DEFAULT_NAMESPACE);
}
if (hostText != null) {
hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
}
if (domainText != null) {
domainText.setText(CommonUtils.notEmpty(connectionInfo.getServerName()));
}
if (usernameText != null) {
usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
}
if (passwordText != null) {
passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
}
if (namespaceCombo != null) {
namespaceCombo.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
}
}
Aggregations