use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.
the class ERDGraphicalViewer method setContents.
@Override
public void setContents(EditPart editpart) {
loadContents = true;
try {
super.setContents(editpart);
// Reset palette contents
if (editpart instanceof DiagramPart) {
List<DBSEntity> tables = new ArrayList<>();
for (Object child : editpart.getChildren()) {
if (child instanceof EntityPart) {
tables.add(((EntityPart) child).getTable().getObject());
}
}
Collections.sort(tables, DBUtils.<DBSEntity>nameComparator());
Map<PaletteDrawer, List<ToolEntryTable>> toolMap = new LinkedHashMap<>();
for (DBSEntity table : tables) {
DBPDataSourceContainer container = table.getDataSource().getContainer();
PaletteDrawer drawer = getContainerPaletteDrawer(container);
if (drawer != null) {
List<ToolEntryTable> tools = toolMap.get(drawer);
if (tools == null) {
tools = new ArrayList<>(tables.size());
toolMap.put(drawer, tools);
}
tools.add(new ToolEntryTable(table));
}
}
for (Map.Entry<PaletteDrawer, List<ToolEntryTable>> entry : toolMap.entrySet()) {
entry.getKey().setChildren(entry.getValue());
}
//editor.getPaletteContents().setChildren(tools);
}
} finally {
loadContents = false;
}
}
use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.
the class EntityAddCommand method execute.
@Override
public void execute() {
Point curLocation = location == null ? null : new Point(location);
for (ERDEntity entity : entities) {
diagramPart.getDiagram().addTable(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.getTable() == 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 + 20;
break;
}
}
}
}
}
}
use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.
the class DirectedGraphLayoutVisitor method addEntityNode.
/**
* Adds nodes to the graph object for use by the GraphLayoutAuto
*/
protected void addEntityNode(NodeEditPart nodeEditPart) {
Node entityNode;
if (nodeEditPart instanceof EntityPart && ((EntityPart) nodeEditPart).getTable().hasSelfLinks()) {
entityNode = new Subgraph(nodeEditPart);
} else {
entityNode = new Node(nodeEditPart);
}
Dimension preferredSize = nodeEditPart.getFigure().getPreferredSize(400, 300);
entityNode.width = preferredSize.width;
entityNode.height = preferredSize.height;
entityNode.setPadding(new Insets(20, 20, 10, 20));
partToNodesMap.put(nodeEditPart, entityNode);
graph.nodes.add(entityNode);
if (entityNode instanceof Subgraph) {
Node sourceAnchor = new Node("Fake node for source links", (Subgraph) entityNode);
sourceAnchor.width = 0;
sourceAnchor.height = 0;
Node targetAnchor = new Node("Fake node for target links", (Subgraph) entityNode);
targetAnchor.width = 0;
targetAnchor.height = 0;
}
/*
*/
}
use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.
the class EntityNodeEditPolicy method getConnectionCompleteCommand.
/**
* @see GraphicalNodeEditPolicy#getConnectionCompleteCommand(CreateConnectionRequest)
*/
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
AssociationCreateCommand cmd = (AssociationCreateCommand) request.getStartCommand();
EntityPart part = (EntityPart) request.getTargetEditPart();
cmd.setPrimaryEntity(part.getTable());
return cmd;
}
use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.
the class DiagramXYLayoutPolicy method createChangeConstraintCommand.
/**
* Creates command to move table. Does not allow table to be resized
*/
@Override
protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
if (!(child instanceof NodePart))
return null;
if (!(constraint instanceof Rectangle))
return null;
NodePart nodePart = (NodePart) child;
Figure figure = (Figure) nodePart.getFigure();
Rectangle oldBounds = figure.getBounds();
Rectangle newBounds = (Rectangle) constraint;
// Restrict resize for entities
if (nodePart instanceof EntityPart) {
if (oldBounds.width != newBounds.width && newBounds.width != -1)
return null;
if (oldBounds.height != newBounds.height && newBounds.height != -1)
return null;
}
return new NodeMoveCommand(nodePart, oldBounds.getCopy(), newBounds.getCopy());
}
Aggregations