Search in sources :

Example 1 with DiagramPart

use of org.jkiss.dbeaver.ext.erd.part.DiagramPart 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 DiagramPart

use of org.jkiss.dbeaver.ext.erd.part.DiagramPart 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;
    }
}
Also used : PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 3 with DiagramPart

use of org.jkiss.dbeaver.ext.erd.part.DiagramPart in project dbeaver by serge-rider.

the class NodeDropTargetListener method createTargetRequest.

@Override
protected Request createTargetRequest() {
    CreateRequest request = new CreateRequest();
    request.setFactory(new CreationFactory() {

        @Override
        public Object getNewObject() {
            Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (objects == null) {
                return null;
            }
            return DiagramObjectCollector.generateEntityList(((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects);
        }

        @Override
        public Object getObjectType() {
            return RequestConstants.REQ_CREATE;
        }
    });
    request.setLocation(getDropLocation());
    return request;
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) CreationFactory(org.eclipse.gef.requests.CreationFactory) Collection(java.util.Collection) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 4 with DiagramPart

use of org.jkiss.dbeaver.ext.erd.part.DiagramPart in project dbeaver by serge-rider.

the class ERDEditorStandalone method loadContentFromFile.

private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor) throws DBException {
    final IFile file = getEditorFile();
    final DiagramPart diagramPart = getDiagramPart();
    EntityDiagram entityDiagram = new EntityDiagram(null, file.getName());
    entityDiagram.clear();
    entityDiagram.setLayoutManualAllowed(true);
    entityDiagram.setLayoutManualDesired(true);
    diagramPart.setModel(entityDiagram);
    try (final InputStream fileContent = file.getContents()) {
        DiagramLoader.load(progressMonitor, file.getProject(), diagramPart, fileContent);
    } catch (Exception e) {
        log.error("Error loading ER diagram from '" + file.getName() + "'", e);
    }
    return entityDiagram;
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DiagramPart (org.jkiss.dbeaver.ext.erd.part.DiagramPart)4 Collection (java.util.Collection)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Point (org.eclipse.draw2d.geometry.Point)1 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 CreationFactory (org.eclipse.gef.requests.CreationFactory)1 PartInitException (org.eclipse.ui.PartInitException)1 DBException (org.jkiss.dbeaver.DBException)1 EntityAddCommand (org.jkiss.dbeaver.ext.erd.command.EntityAddCommand)1 NoteCreateCommand (org.jkiss.dbeaver.ext.erd.command.NoteCreateCommand)1 ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)1 ERDNote (org.jkiss.dbeaver.ext.erd.model.ERDNote)1 EntityDiagram (org.jkiss.dbeaver.ext.erd.model.EntityDiagram)1 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)1 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)1 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)1