Search in sources :

Example 1 with DiagramPart

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

the class ERDEditorStandalone method loadContentFromFile.

private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor) throws DBException {
    IFile resFile = getEditorFile();
    IProject project = resFile == null ? DBWorkbench.getPlatform().getWorkspace().getActiveProject().getEclipseProject() : resFile.getProject();
    final File localFile = EditorUtils.getLocalFileFromInput(getEditorInput());
    final DiagramPart diagramPart = getDiagramPart();
    EntityDiagram entityDiagram = new EntityDiagram(null, localFile.getName(), getContentProvider(), getDecorator());
    entityDiagram.clear();
    entityDiagram.setLayoutManualAllowed(true);
    entityDiagram.setLayoutManualDesired(true);
    diagramPart.setModel(entityDiagram);
    try (final InputStream fileContent = new FileInputStream(localFile)) {
        DiagramLoader.load(progressMonitor, project, diagramPart, fileContent);
    } catch (Exception e) {
        log.error("Error loading ER diagram from '" + localFile.getName() + "'", e);
    }
    return entityDiagram;
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart) FileInputStream(java.io.FileInputStream) PartInitException(org.eclipse.ui.PartInitException) DBException(org.jkiss.dbeaver.DBException)

Example 2 with DiagramPart

use of org.jkiss.dbeaver.erd.ui.part.DiagramPart in project dbeaver by dbeaver.

the class ERDEditorStandalone method loadContentFromFile.

private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor) throws DBException {
    IFile resFile = getEditorFile();
    IProject project = resFile == null ? DBWorkbench.getPlatform().getWorkspace().getActiveProject().getEclipseProject() : resFile.getProject();
    final File localFile = EditorUtils.getLocalFileFromInput(getEditorInput());
    final DiagramPart diagramPart = getDiagramPart();
    EntityDiagram entityDiagram = new EntityDiagram(null, localFile.getName(), getContentProvider(), getDecorator());
    entityDiagram.clear();
    entityDiagram.setLayoutManualAllowed(true);
    entityDiagram.setLayoutManualDesired(true);
    diagramPart.setModel(entityDiagram);
    try (final InputStream fileContent = new FileInputStream(localFile)) {
        DiagramLoader.load(progressMonitor, project, diagramPart, fileContent);
    } catch (Exception e) {
        log.error("Error loading ER diagram from '" + localFile.getName() + "'", e);
    }
    return entityDiagram;
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart) FileInputStream(java.io.FileInputStream) PartInitException(org.eclipse.ui.PartInitException) DBException(org.jkiss.dbeaver.DBException)

Example 3 with DiagramPart

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

use of org.jkiss.dbeaver.erd.ui.part.DiagramPart in project dbeaver by dbeaver.

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).getEntity().getObject());
                }
            }
            tables.sort(DBUtils.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.erd.ui.part.EntityPart) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart)

Example 5 with DiagramPart

use of org.jkiss.dbeaver.erd.ui.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).getEntity().getObject());
                }
            }
            tables.sort(DBUtils.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.erd.ui.part.EntityPart) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart)

Aggregations

DiagramPart (org.jkiss.dbeaver.erd.ui.part.DiagramPart)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)2 PartInitException (org.eclipse.ui.PartInitException)2 DBException (org.jkiss.dbeaver.DBException)2 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)2 ERDNote (org.jkiss.dbeaver.erd.model.ERDNote)2 NoteCreateCommand (org.jkiss.dbeaver.erd.ui.command.NoteCreateCommand)2 EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)2 EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)2 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)2