use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.
the class SQLCompletionProposal method apply.
@Override
public void apply(IDocument document) {
try {
if (dataSource != null) {
if (dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.INSERT_SPACE_AFTER_PROPOSALS)) {
boolean insertTrailingSpace = true;
if (object instanceof DBSObjectContainer) {
// Do not append trailing space after schemas/catalogs/etc.
} else {
int docLen = document.getLength();
if (docLen <= replacementOffset + replacementLength + 2) {
insertTrailingSpace = false;
} else {
insertTrailingSpace = document.getChar(replacementOffset + replacementLength) != ' ';
}
if (insertTrailingSpace) {
replacementString += " ";
}
cursorPosition++;
}
}
}
document.replace(replacementOffset, replacementLength, replacementString);
} catch (BadLocationException e) {
// ignore
log.debug(e);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class NavigatorHandlerObjectOpen method openEntityEditor.
public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow) {
if (selectedNode instanceof DBNDataSource) {
final DataSourceDescriptor dataSourceContainer = (DataSourceDescriptor) ((DBNDataSource) selectedNode).getDataSourceContainer();
openConnectionEditor(workbenchWindow, dataSourceContainer);
return null;
}
try {
String defaultFolderId = null;
if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
defaultFolderId = selectedNode.getNodeType();
selectedNode = selectedNode.getParentNode();
}
IEditorPart editor = findEntityEditor(workbenchWindow, selectedNode);
if (editor != null) {
if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
// Activate default folder
((ITabbedFolderContainer) editor).switchFolder(defaultFolderId);
}
workbenchWindow.getActivePage().activate(editor);
return editor;
}
if (selectedNode instanceof DBNDatabaseObject) {
DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
} else if (selectedNode instanceof DBNDatabaseNode) {
DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
if (dnNode.getObject() != null) {
EntityEditorInput editorInput = new EntityEditorInput(dnNode);
if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
if (dnNode.getObject() instanceof DBSObjectContainer) {
// do not auto-refresh object containers (too expensive)
} else {
refreshDatabaseNode(dnNode);
}
}
setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
} else {
DBUserInterface.getInstance().showError("No object", "Node do not has associated database object");
return null;
}
} else {
NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
}
} catch (Exception ex) {
DBUserInterface.getInstance().showError(CoreMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
return null;
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class CompareObjectsExecutor method compareChildren.
private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
// Compare children
int nodeCount = nodes.size();
List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
DBNDatabaseNode node = nodes.get(i);
// Cache structure if possible
if (node.getObject() instanceof DBSObjectContainer) {
((DBSObjectContainer) node.getObject()).cacheStructure(monitor, DBSObjectContainer.STRUCT_ALL);
}
try {
DBNDatabaseNode[] children = node.getChildren(monitor);
allChildren.add(children);
} catch (Exception e) {
log.warn("Error reading child nodes for compare", e);
allChildren.add(null);
}
}
Set<String> allChildNames = new LinkedHashSet<>();
for (DBNDatabaseNode[] childList : allChildren) {
if (childList == null)
continue;
for (DBNDatabaseNode child : childList) {
DBXTreeNode meta = child.getMeta();
if (meta.isVirtual()) {
// Skip virtual nodes
continue;
}
if (settings.isSkipSystemObjects() && child.getObject() instanceof DBPSystemObject && ((DBPSystemObject) child.getObject()).isSystem()) {
// Skip system objects
continue;
}
allChildNames.add(child.getNodeName());
}
}
for (String childName : allChildNames) {
int[] childIndexes = new int[nodeCount];
for (int i = 0; i < nodeCount; i++) {
childIndexes[i] = -1;
DBNDatabaseNode[] childList = allChildren.get(i);
if (childList == null)
continue;
for (int k = 0; k < childList.length; k++) {
DBNDatabaseNode child = childList[k];
if (child.getNodeName().equals(childName)) {
childIndexes[i] = k;
break;
}
}
}
List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
if (childIndexes[i] == -1) {
// Missing
} else {
for (int k = 0; k < nodeCount; k++) {
if (k != i && childIndexes[k] != childIndexes[i]) {
// Wrong index - add to report
break;
}
}
final DBNDatabaseNode[] childList = allChildren.get(i);
if (childList != null) {
nodesToCompare.add(childList[childIndexes[i]]);
}
}
}
// Compare children recursively
compareNodes(monitor, nodesToCompare);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class EditForeignKeyPage method createSchemaSelector.
private void createSchemaSelector(Composite tableGroup) throws DBException {
// Here is a trick - we need to find schema/catalog container node and list its children
DBNDatabaseNode schemaContainerNode = null;
for (DBNNode node = ownerTableNode.getParentNode(); node != null; node = node.getParentNode()) {
if (node instanceof DBNDatabaseNode) {
DBSObject nodeObject = ((DBNDatabaseNode) node).getObject();
if (nodeObject instanceof DBSSchema || nodeObject instanceof DBSCatalog) {
if (node.getParentNode() instanceof DBNDatabaseNode) {
schemaContainerNode = (DBNDatabaseNode) node.getParentNode();
break;
}
}
}
}
if (schemaContainerNode != null) {
ILabelProvider labelProvider = new LabelProvider() {
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNDatabaseNode) element).getNodeIcon());
}
@Override
public String getText(Object element) {
return ((DBNDatabaseNode) element).getNodeName();
}
};
boolean isSchema = (ownTable.getParentObject() instanceof DBSSchema);
DBPDataSourceInfo dsInfo = ownTable.getDataSource().getInfo();
UIUtils.createControlLabel(tableGroup, isSchema ? dsInfo.getSchemaTerm() : dsInfo.getCatalogTerm());
final CSmartCombo<DBNDatabaseNode> schemaCombo = new CSmartCombo<>(tableGroup, SWT.BORDER, labelProvider);
schemaCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
DBNDatabaseNode selectedNode = null;
for (DBNNode node : schemaContainerNode.getChildren(new VoidProgressMonitor())) {
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSObjectContainer) {
schemaCombo.addItem((DBNDatabaseNode) node);
if (((DBNDatabaseNode) node).getObject() == ownTable.getParentObject()) {
selectedNode = (DBNDatabaseNode) node;
}
}
}
if (selectedNode != null) {
schemaCombo.select(selectedNode);
}
schemaCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Here is another trick
// We need to find table container node
// This node is a child of schema node and has the same meta as our original table parent node
DBNDatabaseNode newContainerNode = null;
DBXTreeNode tableContainerMeta = ((DBNDatabaseNode) ownerTableNode.getParentNode()).getMeta();
DBNDatabaseNode schemaNode = schemaCombo.getSelectedItem();
if (schemaNode.getMeta() == tableContainerMeta) {
newContainerNode = schemaNode;
} else {
try {
for (DBNNode child : schemaNode.getChildren(new VoidProgressMonitor())) {
if (child instanceof DBNDatabaseNode && ((DBNDatabaseNode) child).getMeta() == tableContainerMeta) {
newContainerNode = (DBNDatabaseNode) child;
break;
}
}
} catch (DBException e1) {
log.debug(e1);
// Shouldn't be here
}
}
if (newContainerNode != null) {
tableList.setRootNode(newContainerNode);
tableList.loadData();
}
}
});
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class SQLCompletionProcessor method filterProposals.
private void filterProposals(SQLCompletionAnalyzer.CompletionRequest request, DBPDataSource dataSource) {
// Remove duplications
final Set<String> proposalMap = new HashSet<>(request.proposals.size());
for (int i = 0; i < request.proposals.size(); ) {
SQLCompletionProposal proposal = request.proposals.get(i);
if (proposalMap.contains(proposal.getDisplayString())) {
request.proposals.remove(i);
continue;
}
proposalMap.add(proposal.getDisplayString());
i++;
}
DBSObject selectedObject = dataSource == null ? null : DBUtils.getActiveInstanceObject(dataSource);
boolean hideDups = editor.getActivePreferenceStore().getBoolean(SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS) && selectedObject != null;
if (hideDups) {
for (int i = 0; i < request.proposals.size(); i++) {
SQLCompletionProposal proposal = request.proposals.get(i);
for (int j = 0; j < request.proposals.size(); ) {
SQLCompletionProposal proposal2 = request.proposals.get(j);
if (i != j && proposal.hasStructObject() && proposal2.hasStructObject() && CommonUtils.equalObjects(proposal.getObject().getName(), proposal2.getObject().getName()) && proposal.getObjectContainer() == selectedObject) {
request.proposals.remove(j);
} else {
j++;
}
}
}
}
if (hideDups) {
if (selectedObject instanceof DBSObjectContainer) {
}
}
}
Aggregations