use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CompareObjectsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection ss = (IStructuredSelection) selection;
if (ss.size() < 2) {
DBWorkbench.getPlatformUI().showError("Just one object selected", "At least two objects must be selected to perform structure compare");
return null;
}
List<DBNDatabaseNode> nodes = new ArrayList<>();
Class<?> firstType = null;
DBXTreeNode firstMeta = null;
for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
DBNDatabaseNode node = (DBNDatabaseNode) iter.next();
DBXTreeNode meta = null;
if (node instanceof DBNDatabaseFolder) {
meta = node.getMeta();
if (firstMeta == null) {
firstMeta = meta;
}
}
if (node.getObject() == null) {
log.error("Bad node with null object");
return null;
}
Class<?> itemType = node.getObject().getClass();
if (firstType == null) {
firstType = itemType;
} else {
if (firstType != itemType || firstMeta != meta) {
DBWorkbench.getPlatformUI().showError("Different object types", "Objects of different types were selected. You may compare only objects of the same type");
return null;
}
}
nodes.add(node);
}
CompareWizardDialog dialog = new CompareWizardDialog(workbenchWindow, new CompareObjectsWizard(nodes));
dialog.open();
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CompareObjectsPageSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
final CompareObjectsSettings settings = getWizard().getSettings();
{
Group sourceSettings = new Group(composite, SWT.NONE);
sourceSettings.setText("Objects");
gl = new GridLayout(1, false);
sourceSettings.setLayout(gl);
sourceSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
nodesTable = new Table(sourceSettings, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
nodesTable.setLayoutData(new GridData(GridData.FILL_BOTH));
nodesTable.setHeaderVisible(true);
UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Name");
UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Type");
UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Full qualified name");
for (DBNDatabaseNode node : settings.getNodes()) {
TableItem item = new TableItem(nodesTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
item.setText(0, node.getNodeName());
item.setText(1, node.getNodeType());
item.setText(2, node.getNodeFullName());
}
}
{
Group compareSettings = new Group(composite, SWT.NONE);
compareSettings.setText("Compare settings");
compareSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
compareSettings.setLayout(new GridLayout(1, false));
skipSystemObjects = UIUtils.createCheckbox(compareSettings, "Skip system objects", settings.isSkipSystemObjects());
skipSystemObjects.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setSkipSystemObjects(skipSystemObjects.getSelection());
}
});
compareLazyProperties = UIUtils.createCheckbox(compareSettings, "Compare expensive properties", settings.isCompareLazyProperties());
compareLazyProperties.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setCompareLazyProperties(compareLazyProperties.getSelection());
}
});
compareOnlyStructure = UIUtils.createCheckbox(compareSettings, "Compare only structure (ignore properties)", settings.isCompareOnlyStructure());
compareOnlyStructure.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setCompareOnlyStructure(compareOnlyStructure.getSelection());
}
});
compareScriptProperties = UIUtils.createCheckbox(compareSettings, "Compare scripts/procedures", settings.isCompareScripts());
compareScriptProperties.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setCompareScripts(compareScriptProperties.getSelection());
}
});
}
setControl(composite);
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DebugUtils method getSourceName.
public static String getSourceName(Object object) throws CoreException {
if (object instanceof DatabaseStackFrame) {
DatabaseStackFrame frame = (DatabaseStackFrame) object;
Object sourceIdentifier = frame.getSourceIdentifier();
DBSObject dbsObject;
try {
dbsObject = findDatabaseObject(frame.getController(), sourceIdentifier, new VoidProgressMonitor());
} catch (DBException e) {
Status error = DebugUtils.newErrorStatus(e.getMessage(), e);
throw new CoreException(error);
}
if (dbsObject == null) {
return null;
}
final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
DBNDatabaseNode node = navigatorModel.getNodeByObject(new VoidProgressMonitor(), dbsObject, false);
if (node != null) {
return node.getNodeItemPath();
}
}
if (object instanceof String) {
// well, let's be positive and assume it's a node path already
return (String) object;
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DiagramCreateWizard method performFinish.
@Override
public boolean performFinish() {
try {
Collection<DBNNode> initialContent = pageContent.getInitialContent();
List<DBSObject> rootObjects = new ArrayList<>();
for (DBNNode node : initialContent) {
if (node instanceof DBNDatabaseNode) {
rootObjects.add(((DBNDatabaseNode) node).getObject());
}
}
DiagramCreator creator = new DiagramCreator(rootObjects);
UIUtils.run(getContainer(), true, true, creator);
DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(creator.diagramFile);
if (handler != null) {
handler.openResource(creator.diagramFile);
}
} catch (InterruptedException ex) {
return false;
} catch (Throwable ex) {
if (ex instanceof InvocationTargetException) {
ex = ((InvocationTargetException) ex).getTargetException();
}
DBWorkbench.getPlatformUI().showError("Create error", "Cannot create diagram", ex);
return false;
}
return true;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
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);
}
Aggregations