use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class CompareReportRenderer method renderBody.
private void renderBody(DBRProgressMonitor monitor) throws IOException {
// Table head
xml.startElement("tr");
xml.startElement("th");
xml.addText("Structure");
xml.endElement();
for (DBNDatabaseNode node : report.getNodes()) {
xml.startElement("th");
xml.addText(node.getNodeFullName());
xml.endElement();
}
xml.endElement();
// Table body
boolean showOnlyDifferences = settings.isShowOnlyDifferences();
int objectCount = report.getNodes().size();
List<CompareReportLine> reportLines = report.getReportLines();
int reportLinesSize = reportLines.size();
for (int i = 0; i < reportLinesSize; i++) {
monitor.worked(1);
CompareReportLine line = reportLines.get(i);
if (showOnlyDifferences && !line.hasDifference) {
continue;
}
boolean onlyStructure = line.structure instanceof DBNDatabaseFolder && !line.hasDifference;
// Skip empty folders
if (onlyStructure && (i >= reportLinesSize - 1 || reportLines.get(i + 1).depth <= line.depth)) {
continue;
}
xml.startElement("tr");
xml.addAttribute("class", "object level" + line.depth);
xml.startElement("td");
xml.addText(line.structure.getNodeType());
xml.endElement();
if (onlyStructure) {
xml.startElement("td");
xml.addAttribute("colspan", line.nodes.length);
xml.addText(" ", false);
xml.endElement();
} else {
for (int k = 0; k < objectCount; k++) {
xml.startElement("td");
if (line.nodes[k] == null) {
xml.addAttribute("class", "missing");
xml.addText("N/A");
} else {
xml.addText(line.nodes[k].getName());
}
xml.endElement();
}
}
xml.endElement();
if (line.properties != null) {
for (CompareReportProperty reportProperty : line.properties) {
boolean differs = false;
Object firstValue = null;
boolean hasValue = false;
for (int k = 0; k < reportProperty.values.length; k++) {
if (line.nodes[k] == null) {
// Ignore properties of missing objects
continue;
}
Object value = reportProperty.values[k];
if (value != null) {
hasValue = true;
if (firstValue == null) {
firstValue = value;
}
}
if (!CompareUtils.equalPropertyValues(value, firstValue)) {
differs = true;
break;
}
}
if (!hasValue) {
// Skip[ properties when nobody have it's value
continue;
}
if (showOnlyDifferences && !differs) {
continue;
}
xml.startElement("tr");
xml.addAttribute("class", "property level" + (line.depth + 1) + (differs ? " differs" : ""));
xml.startElement("td");
xml.addText(reportProperty.property.getDisplayName());
xml.endElement();
for (int k = 0; k < objectCount; k++) {
xml.startElement("td");
String stringValue = "";
if (reportProperty.values[k] != null) {
stringValue = reportProperty.values[k].toString();
}
if (CommonUtils.isEmpty(stringValue)) {
xml.addText(" ", false);
} else {
xml.addText(stringValue);
}
xml.endElement();
}
xml.endElement();
}
}
}
// Table footer
xml.startElement("tr");
xml.addAttribute("class", "object");
xml.startElement("td");
xml.addAttribute("colspan", report.getNodes().size() + 1);
xml.addText("" + reportLines.size() + " objects compared");
xml.endElement();
xml.endElement();
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class NavigatorHandlerCopyAbstract method copySelection.
private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
ClipboardData clipboardData = new ClipboardData();
{
IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
if (clipboardSource != null) {
clipboardSource.addClipboardData(getCopyMode(), clipboardData);
}
}
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
List<DBNNode> selectedNodes = new ArrayList<>();
List<DBPNamedObject> selectedObjects = new ArrayList<>();
List<String> selectedFiles = new ArrayList<>();
StringBuilder buf = new StringBuilder();
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
String objectValue = getObjectDisplayString(object);
if (objectValue == null) {
continue;
}
DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
DBPNamedObject dbObject = null;
if (node instanceof DBNDatabaseNode) {
dbObject = ((DBNDatabaseNode) node).getObject();
}
if (dbObject == null) {
dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
}
if (node != null) {
selectedNodes.add(node);
}
if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
final IFile file = (IFile) ((DBNResource) node).getResource();
if (file != null) {
selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
}
}
if (dbObject != null) {
selectedObjects.add(dbObject);
}
if (buf.length() > 0) {
buf.append(GeneralUtils.getDefaultLineSeparator());
}
buf.append(objectValue);
}
{
if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
}
if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
}
if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
}
if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
}
}
}
if (clipboardData.hasData()) {
clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
// ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class NavigatorHandlerObjectMove method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node == null || !(node.getParentNode() instanceof DBNContainer)) {
return null;
}
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (!(object instanceof DBPOrderedObject)) {
return null;
}
@SuppressWarnings("unchecked") DBEObjectReorderer<DBSObject> objectReorderer = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectReorderer.class);
if (objectReorderer == null) {
return null;
}
DBPOrderedObject orderedObject = (DBPOrderedObject) object;
try {
// Sibling objects - they are involved in reordering process
List<DBSObject> siblingObjects = new ArrayList<>();
for (DBNNode siblingNode : node.getParentNode().getChildren(new VoidProgressMonitor())) {
if (siblingNode instanceof DBNDatabaseNode) {
DBSObject siblingObject = ((DBNDatabaseNode) siblingNode).getObject();
if (siblingObject.getClass() != object.getClass()) {
log.warn("Sibling object class " + siblingObject.getClass() + " differs from moving object class " + object.getClass().getName());
} else {
siblingObjects.add(siblingObject);
}
} else {
log.warn("Wrong sibling node type: " + siblingNode);
}
}
CommandTarget commandTarget = getCommandTarget(HandlerUtil.getActiveWorkbenchWindow(event), node.getParentNode(), object.getClass(), false);
String actionId = event.getCommand().getId();
switch(actionId) {
case NavigatorCommands.CMD_OBJECT_MOVE_UP:
objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() - 1);
break;
case NavigatorCommands.CMD_OBJECT_MOVE_DOWN:
objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() + 1);
break;
}
if (object.isPersisted() && commandTarget.getEditor() == null) {
Map<String, Object> options = DBPScriptObject.EMPTY_OPTIONS;
if (!showScript(HandlerUtil.getActiveWorkbenchWindow(event), commandTarget.getContext(), options, "Reorder script")) {
commandTarget.getContext().resetChanges(true);
return false;
} else {
ObjectSaver orderer = new ObjectSaver(commandTarget.getContext(), options);
TasksJob.runTask("Change object '" + object.getName() + "' position", orderer);
}
}
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Object move", "Error during object reposition", e);
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class NNAHDataSourceReadOnly method handleNodeAction.
@Override
public void handleNodeAction(INavigatorModelView view, DBNNode node, Event event, boolean defaultAction) {
if (node instanceof DBNDatabaseNode) {
DBPDataSourceContainer dataSourceContainer = ((DBNDatabaseNode) node).getDataSourceContainer();
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
if (serviceConnections != null) {
serviceConnections.openConnectionEditor(dataSourceContainer, "ConnectionPageGeneral");
}
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
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);
}
}
Aggregations