use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DatabaseEditorInputFactory method saveState.
public static void saveState(IMemento memento, DatabaseEditorInput input) {
if (!DBWorkbench.getPlatform().getPreferenceStore().getBoolean(DatabaseEditorPreferences.PROP_SAVE_EDITORS_STATE)) {
return;
}
final DBCExecutionContext context = input.getExecutionContext();
if (context == null) {
// Detached - nothing to save
return;
}
if (input.getDatabaseObject() != null && !input.getDatabaseObject().isPersisted()) {
return;
}
final DBNDatabaseNode node = input.getNavigatorNode();
memento.putString(TAG_CLASS, input.getClass().getName());
memento.putString(TAG_PROJECT, context.getDataSource().getContainer().getProject().getName());
memento.putString(TAG_DATA_SOURCE, context.getDataSource().getContainer().getId());
memento.putString(TAG_NODE, node.getNodeItemPath());
memento.putString(TAG_NODE_NAME, node.getNodeName());
if (!CommonUtils.isEmpty(input.getDefaultPageId())) {
memento.putString(TAG_ACTIVE_PAGE, input.getDefaultPageId());
}
if (!CommonUtils.isEmpty(input.getDefaultFolderId())) {
memento.putString(TAG_ACTIVE_FOLDER, input.getDefaultFolderId());
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class EditForeignKeyPage method createPageContents.
@Override
protected Composite createPageContents(Composite parent) {
final Composite panel = UIUtils.createComposite(parent, 1);
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
{
final Composite tableGroup = UIUtils.createComposite(panel, 2);
tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createLabelText(tableGroup, EditorsMessages.dialog_struct_edit_fk_label_table, DBUtils.getObjectFullName(foreignKey.getParentObject(), DBPEvaluationContext.UI), SWT.READ_ONLY | SWT.BORDER);
if (allowedKeyTypes.length > 1) {
UIUtils.createControlLabel(tableGroup, "Key type");
Composite ktPanel = UIUtils.createFormPlaceholder(tableGroup, allowedKeyTypes.length, 1);
// keyTypeCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
for (FKType type : allowedKeyTypes) {
Button keyTypeButton = UIUtils.createRadioButton(ktPanel, type.getName(), type, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectedKeyType = (FKType) e.widget.getData();
updateControlsVisibility();
}
});
if (type == preferredKeyType) {
keyTypeButton.setSelection(true);
}
}
}
if (curRefTable == null) {
try {
if (foreignKey instanceof DBVEntityForeignKey) {
// Virtual key - add container selector
createContainerSelector(tableGroup);
} else if (ownerTableNode != null) {
createSchemaSelector(tableGroup);
}
} catch (Throwable e) {
log.debug("Can't create schema selector", e);
}
} else {
UIUtils.createLabelText(tableGroup, EditorsMessages.dialog_struct_edit_fk_label_ref_table, DBUtils.getObjectFullName(curRefTable, DBPEvaluationContext.UI), SWT.READ_ONLY | SWT.BORDER);
}
}
if (curRefTable == null) {
DBNNode containerNode = ownerTableNode == null ? null : ownerTableNode.getParentNode();
while (containerNode instanceof DBNDatabaseFolder) {
containerNode = containerNode.getParentNode();
}
DBNNode rootNode = containerNode == null ? DBWorkbench.getPlatform().getNavigatorModel().getRoot() : containerNode;
UIUtils.createControlLabel(panel, EditorsMessages.dialog_struct_edit_fk_label_ref_table);
tableList = new Table(panel, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
tableList.setLinesVisible(true);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 150;
tableList.setLayoutData(gd);
tableList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleRefTableSelect((DBNDatabaseNode) e.item.getData());
}
});
if (rootNode instanceof DBNDatabaseNode) {
loadTableList((DBNDatabaseNode) rootNode);
}
}
final Composite pkGroup = UIUtils.createComposite(panel, enableCustomKeys ? 3 : 2);
{
pkGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
uniqueKeyCombo = UIUtils.createLabelCombo(pkGroup, EditorsMessages.dialog_struct_edit_fk_combo_unik, SWT.DROP_DOWN | SWT.READ_ONLY);
// uniqueKeyCombo.setEnabled(false);
uniqueKeyCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleUniqueKeySelect();
updatePageState();
}
});
if (enableCustomKeys) {
customUKButton = UIUtils.createDialogButton(pkGroup, "Create", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
defineRefTableConstraint();
}
});
customUKButton.setEnabled(false);
}
if (supportsCustomName()) {
fkNameText = UIUtils.createLabelText(pkGroup, EditorsMessages.dialog_struct_edit_fk_name, "");
fkNameText.addModifyListener(e -> fkName = fkNameText.getText());
}
}
{
UIUtils.createControlLabel(panel, EditorsMessages.dialog_struct_edit_fk_label_columns);
columnsTable = new Table(panel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
columnsTable.setHeaderVisible(true);
columnsTable.setLinesVisible(true);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 100;
columnsTable.setLayoutData(gd);
UIUtils.createTableColumn(columnsTable, SWT.LEFT, EditorsMessages.dialog_struct_edit_fk_column_column);
UIUtils.createTableColumn(columnsTable, SWT.LEFT, EditorsMessages.dialog_struct_edit_fk_column_col_type);
UIUtils.createTableColumn(columnsTable, SWT.LEFT, EditorsMessages.dialog_struct_edit_fk_column_ref_col);
UIUtils.createTableColumn(columnsTable, SWT.LEFT, EditorsMessages.dialog_struct_edit_fk_column_ref_col_type);
final TableEditor tableEditor = new TableEditor(columnsTable);
tableEditor.horizontalAlignment = SWT.CENTER;
tableEditor.verticalAlignment = SWT.TOP;
tableEditor.grabHorizontal = true;
tableEditor.minimumWidth = 50;
columnsTable.addMouseListener(new ColumnsMouseListener(tableEditor, columnsTable));
}
if (!ArrayUtils.isEmpty(supportedModifyRules)) {
final Composite cascadeGroup = UIUtils.createPlaceholder(panel, 4, 5);
{
// Cascades
cascadeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Combo onDeleteCombo = UIUtils.createLabelCombo(cascadeGroup, EditorsMessages.dialog_struct_edit_fk_combo_on_delete, SWT.DROP_DOWN | SWT.READ_ONLY);
onDeleteCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Combo onUpdateCombo = UIUtils.createLabelCombo(cascadeGroup, EditorsMessages.dialog_struct_edit_fk_combo_on_update, SWT.DROP_DOWN | SWT.READ_ONLY);
onUpdateCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
for (DBSForeignKeyModifyRule modifyRule : supportedModifyRules) {
onDeleteCombo.add(modifyRule.getName());
onUpdateCombo.add(modifyRule.getName());
}
onDeleteCombo.select(0);
onUpdateCombo.select(0);
onDeleteRule = onUpdateRule = supportedModifyRules[0];
onDeleteCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onDeleteRule = supportedModifyRules[onDeleteCombo.getSelectionIndex()];
}
});
onUpdateCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onUpdateRule = supportedModifyRules[onUpdateCombo.getSelectionIndex()];
}
});
}
addPhysicalKeyComponent(cascadeGroup);
}
if (tableList != null) {
tableList.setFocus();
}
return panel;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class EditForeignKeyPage method loadTableList.
private void loadTableList(DBNDatabaseNode newContainerNode) {
tableList.removeAll();
final List<DBNDatabaseNode> entities = new ArrayList<>();
try {
UIUtils.runInProgressService(monitor -> {
try {
loadEntities(monitor, entities, newContainerNode);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Error loading tables", "Error during table load", e);
} catch (InterruptedException e) {
// Ignore
}
for (DBNDatabaseNode entityNode : entities) {
TableItem tableItem = new TableItem(tableList, SWT.LEFT);
tableItem.setText(entityNode.getNodeName());
tableItem.setImage(DBeaverIcons.getImage(entityNode.getNodeIconDefault()));
tableItem.setData(entityNode);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class StatisticsNavigatorNodeRenderer method renderObjectStatistics.
// /////////////////////////////////////////////////////////////////
// Statistics renderer
private void renderObjectStatistics(DBNDatabaseNode element, Tree tree, GC gc, Event event) {
DBSObject object = element.getObject();
if (object instanceof DBPObjectStatistics) {
String sizeText;
int percentFull;
boolean statsWasRead = false;
DBNNode parentNode = getParentItem(element);
DBSObject parentObject = parentNode instanceof DBNDatabaseNode ? DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject()) : null;
if (parentObject instanceof DBPObjectStatisticsCollector) {
// && !((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected()
statsWasRead = ((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected();
} else {
// If there is no stats collector then do not check for stats presence
// Because it will trigger stats read job which won't read any statistics (as there is no way to load it for individual object).
// ((DBPObjectStatistics) object).hasStatistics();
statsWasRead = true;
}
long maxObjectSize = statsWasRead ? getMaxObjectSize((TreeItem) event.item) : -1;
if (statsWasRead && maxObjectSize >= 0) {
long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
if (statObjectSize <= 0) {
// Empty or no size - nothing to show
return;
}
percentFull = maxObjectSize == 0 ? 0 : (int) (statObjectSize * 100 / maxObjectSize);
if (percentFull < 0 || percentFull > 100) {
log.debug("Object stat > 100%!");
percentFull = 100;
}
Format format;
synchronized (classFormatMap) {
format = classFormatMap.get(object.getClass().getName());
if (format == null) {
try {
Method getStatObjectSizeMethod = object.getClass().getMethod("getStatObjectSize");
Property propAnnotation = getStatObjectSizeMethod.getAnnotation(Property.class);
if (propAnnotation != null) {
Class<? extends Format> formatterClass = propAnnotation.formatter();
if (formatterClass != Format.class) {
format = formatterClass.getConstructor().newInstance();
}
}
} catch (Exception e) {
log.debug(e);
}
if (format == null) {
format = numberFormat;
}
classFormatMap.put(object.getClass().getName(), format);
}
}
sizeText = format.format(statObjectSize);
} else {
sizeText = "...";
percentFull = 0;
if (parentNode instanceof DBNDatabaseNode) {
DBSObject realParentObject = DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject());
if (!readObjectStatistics(element.getParentNode(), realParentObject, ((TreeItem) event.item).getParentItem())) {
return;
}
}
}
Point textSize = gc.stringExtent(sizeText);
textSize.x += 4;
// int caWidth = tree.getClientArea().width;
int occupiedWidth = event.x + event.width + 4;
int xWidth = getTreeWidth(tree);
if (xWidth - occupiedWidth > Math.max(PERCENT_FILL_WIDTH, textSize.x)) {
{
CTabFolder tabFolder = UIUtils.getParentOfType(tree, CTabFolder.class);
Color fillColor = tabFolder == null ? UIStyles.getDefaultWidgetBackground() : tabFolder.getBackground();
gc.setBackground(fillColor);
int fillWidth = PERCENT_FILL_WIDTH * percentFull / 100 + 1;
int x = xWidth - fillWidth - 2;
gc.fillRectangle(x, event.y + 2, fillWidth, event.height - 4);
}
gc.setForeground(tree.getForeground());
int x = xWidth - textSize.x - 2;
Font oldFont = gc.getFont();
gc.setFont(tree.getFont());
gc.drawText(sizeText, x + 2, event.y + (event.height - textSize.y) / 2, true);
gc.setFont(oldFont);
}
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class StatisticsNavigatorNodeRenderer method paintNodeDetails.
public void paintNodeDetails(DBNNode node, Tree tree, GC gc, Event event) {
super.paintNodeDetails(node, tree, gc, event);
ScrollBar hSB = tree.getHorizontalBar();
boolean scrollEnabled = (hSB != null && hSB.isVisible());
Object element = event.item.getData();
if (element instanceof DBNDatabaseNode) {
if (element instanceof DBNDataSource) {
int widthOccupied = 0;
if (!scrollEnabled && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS)) {
widthOccupied += renderDataSourceNodeActions((DBNDatabaseNode) element, tree, gc, event);
}
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME)) {
renderDataSourceHostName((DBNDataSource) element, tree, gc, event, widthOccupied);
}
}
if (!scrollEnabled && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO)) {
renderObjectStatistics((DBNDatabaseNode) element, tree, gc, event);
}
}
}
Aggregations