Search in sources :

Example 6 with ERDEntity

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;
}
Also used : ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) NotNull(org.jkiss.code.NotNull)

Example 7 with ERDEntity

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;
}
Also used : Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart) Command(org.eclipse.gef.commands.Command) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) DiagramCollectSettingsDefault(org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with ERDEntity

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);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) Point(org.eclipse.draw2d.geometry.Point) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 9 with ERDEntity

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;
}
Also used : NoteCreateCommand(org.jkiss.dbeaver.erd.ui.command.NoteCreateCommand) NoteCreateCommand(org.jkiss.dbeaver.erd.ui.command.NoteCreateCommand) Command(org.eclipse.gef.commands.Command) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) ERDNote(org.jkiss.dbeaver.erd.model.ERDNote) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Point(org.eclipse.draw2d.geometry.Point) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart)

Example 10 with ERDEntity

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();
}
Also used : EditableLabel(org.jkiss.dbeaver.erd.ui.figures.EditableLabel) EntityFigure(org.jkiss.dbeaver.erd.ui.figures.EntityFigure) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity)

Aggregations

ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)16 Point (org.eclipse.draw2d.geometry.Point)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Collection (java.util.Collection)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 Command (org.eclipse.gef.commands.Command)4 EntityFigure (org.jkiss.dbeaver.erd.ui.figures.EntityFigure)4 DiagramCollectSettingsDefault (org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault)4 EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)4 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)4 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 CreateRequest (org.eclipse.gef.requests.CreateRequest)2 CreationFactory (org.eclipse.gef.requests.CreationFactory)2 Control (org.eclipse.swt.widgets.Control)2 NotNull (org.jkiss.code.NotNull)2