use of org.jkiss.dbeaver.erd.model.ERDEntity in project dbeaver by dbeaver.
the class EntityFigure method createToolTip.
@NotNull
private IFigure createToolTip() {
ERDEntity entity = part.getEntity();
DBPDataSourceContainer dataSource = entity.getDataSource().getContainer();
Figure toolTip = new Figure();
toolTip.setOpaque(true);
// toolTip.setPreferredSize(300, 200);
toolTip.setBorder(getBorder());
toolTip.setLayoutManager(new GridLayout(1, false));
{
Label dsLabel = new Label(dataSource.getName());
dsLabel.setIcon(DBeaverIcons.getImage(dataSource.getDriver().getIcon()));
dsLabel.setBorder(new MarginBorder(2));
toolTip.add(dsLabel);
}
{
Label entityLabel = new Label(DBUtils.getObjectFullName(entity.getObject(), DBPEvaluationContext.UI));
entityLabel.setIcon(DBeaverIcons.getImage(entity.getObject().getEntityType().getIcon()));
entityLabel.setBorder(new MarginBorder(2));
toolTip.add(entityLabel);
}
return toolTip;
}
use of org.jkiss.dbeaver.erd.model.ERDEntity in project dbeaver by dbeaver.
the class ERDHandlerPaste method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (!CommonUtils.isEmpty(objects)) {
try {
UIUtils.runInProgressService(monitor -> {
final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(monitor, editor.getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
if (!CommonUtils.isEmpty(erdEntities)) {
UIUtils.syncExec(() -> {
Command command = editor.getDiagramPart().createEntityAddCommand(erdEntities, new Point(10, 10));
editor.getCommandStack().execute(command);
});
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
} catch (InterruptedException e) {
// ignore
}
}
}
}
return null;
}
use of org.jkiss.dbeaver.erd.model.ERDEntity 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.erd.model.ERDEntity in project dbeaver by dbeaver.
the class DiagramContainerEditPolicy method getCreateCommand.
/**
* @see ContainerEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
*/
@Override
protected Command getCreateCommand(CreateRequest request) {
DiagramPart diagramPart = (DiagramPart) getHost();
Point location = request.getLocation();
diagramPart.getFigure().translateToRelative(location);
Object newObject = request.getNewObject();
if (newObject instanceof ERDNote) {
return new NoteCreateCommand(diagramPart, (ERDNote) newObject, location, request.getSize());
}
List<ERDEntity> entities = null;
if (newObject instanceof ERDEntity) {
entities = Collections.singletonList((ERDEntity) newObject);
} else if (newObject instanceof Collection) {
entities = new ArrayList<>((Collection<ERDEntity>) newObject);
}
if (CommonUtils.isEmpty(entities)) {
return null;
}
// EditPart host = getTargetEditPart(request);
Command entityAddCommand = diagramPart.createEntityAddCommand(entities, location);
if (!entityAddCommand.canExecute()) {
return null;
}
return entityAddCommand;
}
use of org.jkiss.dbeaver.erd.model.ERDEntity in project dbeaver by dbeaver.
the class EntityPart method revertNameChange.
/**
* Reverts to existing name in model when exiting from a direct edit
* (possibly before a commit which will result in a change in the label
* value)
*/
public void revertNameChange() {
EntityFigure entityFigure = getFigure();
EditableLabel label = entityFigure.getNameLabel();
ERDEntity entity = getEntity();
label.setText(entity.getObject().getName());
label.setVisible(true);
refreshVisuals();
}
Aggregations