use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class PostgreDebugPanelFunction method createFunctionGroup.
private void createFunctionGroup(Composite parent) {
Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
UIUtils.createControlLabel(functionGroup, "Function");
functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
}
@Override
public String getText(Object element) {
if (element == null) {
return "N/A";
}
return ((PostgreProcedure) element).getFullQualifiedSignature();
}
}) {
@Override
protected void dropDown(boolean drop) {
if (drop) {
DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
if (dsNode != null) {
DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
DBNNode node = DBWorkbench.getPlatformUI().selectObject(parent.getShell(), "Select function to debug", dsNode, curNode, new Class[] { DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class }, new Class[] { PostgreProcedure.class }, null);
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
functionCombo.removeAll();
selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
functionCombo.addItem(selectedFunction);
functionCombo.select(selectedFunction);
updateParametersTable();
container.updateDialogState();
}
parametersTable.setEnabled(selectedFunction != null);
}
}
}
};
functionCombo.addItem(null);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
functionCombo.setLayoutData(gd);
processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
processIdText.setLayoutData(gd);
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DatabaseLazyEditorInput method initializeRealInput.
public IDatabaseEditorInput initializeRealInput(final DBRProgressMonitor monitor) throws DBException {
// Get the node path.
if (project != null) {
dataSourceContainer = project.getDataSourceRegistry().getDataSource(dataSourceId);
}
if (dataSourceContainer == null) {
// $NON-NLS-2$
log.error("Can't find data source '" + dataSourceId + "'");
return null;
}
if (project == null) {
project = dataSourceContainer.getRegistry().getProject();
}
final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
navigatorModel.ensureProjectLoaded(project);
// dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId
DBPDataSource dataSource;
while (!dataSourceContainer.isConnected()) {
try {
dataSourceContainer.connect(monitor, true, true);
} catch (final DBException e) {
// Connection error
final Integer result = new UITask<Integer>() {
@Override
protected Integer runTask() {
ConnectionLostDialog clDialog = new ConnectionLostDialog(UIUtils.getActiveWorkbenchShell(), dataSourceContainer, e, "Close");
return clDialog.open();
}
}.execute();
if (result == IDialogConstants.STOP_ID) {
// Close editor
return null;
} else if (result == IDialogConstants.RETRY_ID) {
continue;
} else {
return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
}
}
break;
}
try {
dataSource = dataSourceContainer.getDataSource();
if (dataSource == null) {
throw new DBException("Connection to '" + dataSourceContainer.getName() + "' canceled");
}
final DBNNode[] editorNodeResult = new DBNNode[1];
DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
try {
DBNDataSource dsNode = (DBNDataSource) navigatorModel.getNodeByObject(monitor, this.dataSourceContainer, true);
if (dsNode == null) {
throw new DBException("Datasource '" + this.dataSourceContainer.getName() + "' navigator node not found");
}
dsNode.initializeNode(monitor, null);
editorNodeResult[0] = navigatorModel.getNodeByPath(monitor, project, nodePath);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
});
DBNNode node = editorNodeResult[0];
if (node == null) {
throw new DBException("Navigator node '" + nodePath + "' not found");
}
if (node instanceof DBNDatabaseNode) {
DatabaseNodeEditorInput realInput = new DatabaseNodeEditorInput((DBNDatabaseNode) node);
realInput.setDefaultFolderId(activeFolderId);
realInput.setDefaultPageId(activePageId);
return realInput;
} else {
throw new DBException("Database node has bad type: " + node.getClass().getName());
}
} catch (DBException e) {
return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
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 EntityAddCommand method execute.
@Override
public void execute() {
VoidProgressMonitor monitor = new VoidProgressMonitor();
Point curLocation = location == null ? null : new Point(location);
for (ERDEntity entity : entities) {
boolean resolveRelations = false;
if (entity.getObject() == null) {
// Entity is not initialized
if (entity.getDataSource() != null) {
DBSObject selectedObject = DBUtils.getSelectedObject(DBUtils.getDefaultContext(entity.getDataSource(), false));
DBNDatabaseNode dsNode = DBNUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
if (dsNode != null) {
DBNNode tableNode = DBWorkbench.getPlatformUI().selectObject(UIUtils.getActiveWorkbenchShell(), "Select a table", dsNode, null, new Class[] { DBSTable.class }, new Class[] { DBSTable.class }, null);
if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
entity = ERDUtils.makeEntityFromObject(monitor, diagramPart.getDiagram(), Collections.emptyList(), (DBSEntity) ((DBNDatabaseNode) tableNode).getObject(), null);
// This actually only loads unresolved relations.
// This happens only with entities added on diagram during editing
entity.addModelRelations(monitor, diagramPart.getDiagram(), false, false);
}
}
}
}
if (entity.getObject() == null) {
continue;
}
diagramPart.getDiagram().addEntity(entity, true);
if (curLocation != null) {
// Put new entities in specified location
for (Object diagramChild : diagramPart.getChildren()) {
if (diagramChild instanceof EntityPart) {
EntityPart entityPart = (EntityPart) diagramChild;
if (entityPart.getEntity() == entity) {
final Rectangle newBounds = new Rectangle();
final Dimension size = entityPart.getFigure().getPreferredSize();
newBounds.x = curLocation.x;
newBounds.y = curLocation.y;
newBounds.width = size.width;
newBounds.height = size.height;
entityPart.modifyBounds(newBounds);
curLocation.x += size.width + (size.width / 2);
break;
}
}
}
}
handleEntityChange(entity, false);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DataTransferPagePipes method createInputsTable.
private void createInputsTable(Composite composite) {
Composite panel = UIUtils.createComposite(composite, 1);
// UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
inputsTable.getTable().setLinesVisible(true);
inputsTable.getTable().setHeaderVisible(true);
inputsTable.setContentProvider(new ListContentProvider());
UIUtils.createTableContextMenu(inputsTable.getTable(), null);
DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject element = (DBSObject) cell.getElement();
if (cell.getColumnIndex() == 0) {
DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
cell.setImage(DBeaverIcons.getImage(icon));
cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
} else if (element.getDescription() != null) {
cell.setText(element.getDescription());
}
}
};
{
TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
columnName.setLabelProvider(labelProvider);
columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
columnDesc.setLabelProvider(labelProvider);
columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
}
}
Aggregations