Search in sources :

Example 1 with EntityAddCommand

use of org.jkiss.dbeaver.ext.erd.command.EntityAddCommand in project dbeaver by serge-rider.

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);
    }
    Collection<ERDEntity> entities = null;
    if (newObject instanceof ERDEntity) {
        entities = Collections.singletonList((ERDEntity) newObject);
    } else if (newObject instanceof Collection) {
        entities = (Collection<ERDEntity>) newObject;
    }
    if (CommonUtils.isEmpty(entities)) {
        return null;
    }
    return new EntityAddCommand(diagramPart, entities, location);
}
Also used : NoteCreateCommand(org.jkiss.dbeaver.ext.erd.command.NoteCreateCommand) ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) ERDNote(org.jkiss.dbeaver.ext.erd.model.ERDNote) Collection(java.util.Collection) Point(org.eclipse.draw2d.geometry.Point) EntityAddCommand(org.jkiss.dbeaver.ext.erd.command.EntityAddCommand) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 2 with EntityAddCommand

use of org.jkiss.dbeaver.ext.erd.command.EntityAddCommand in project dbeaver by serge-rider.

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)) {
                final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(editor.getDiagram(), objects);
                if (!CommonUtils.isEmpty(erdEntities)) {
                    EntityAddCommand command = new EntityAddCommand(editor.getDiagramPart(), erdEntities, new Point(10, 10));
                    editor.getCommandStack().execute(command);
                }
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) ERDEditorPart(org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart) ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) Point(org.eclipse.draw2d.geometry.Point) EntityAddCommand(org.jkiss.dbeaver.ext.erd.command.EntityAddCommand)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 EntityAddCommand (org.jkiss.dbeaver.ext.erd.command.EntityAddCommand)2 ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)2 Collection (java.util.Collection)1 Control (org.eclipse.swt.widgets.Control)1 NoteCreateCommand (org.jkiss.dbeaver.ext.erd.command.NoteCreateCommand)1 ERDEditorPart (org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart)1 ERDNote (org.jkiss.dbeaver.ext.erd.model.ERDNote)1 DiagramPart (org.jkiss.dbeaver.ext.erd.part.DiagramPart)1 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)1