Search in sources :

Example 6 with EntityPart

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

the class SetPartSettingsAction method createColorCommand.

private Command createColorCommand(final Object[] objects) {
    return new Command() {

        private ViewSettings newSettings;

        private final Map<ICustomizablePart, ViewSettings> oldSettings = new HashMap<>();

        @Override
        public void execute() {
            final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
            try {
                NodePart nodePart = null;
                boolean hasNotes = false, hasEntities = false;
                for (Object item : objects) {
                    if (item instanceof NodePart) {
                        if (nodePart == null) {
                            nodePart = (NodePart) item;
                        }
                        if (item instanceof NotePart) {
                            hasNotes = true;
                        } else if (item instanceof EntityPart) {
                            hasEntities = true;
                        }
                    }
                }
                PartSettingsDialog settingsDialog = new PartSettingsDialog(shell, nodePart, hasNotes, hasEntities);
                if (settingsDialog.open() != IDialogConstants.OK_ID) {
                    return;
                }
                newSettings = settingsDialog.newSettings;
                for (Object item : objects) {
                    if (item instanceof ICustomizablePart) {
                        ICustomizablePart part = (ICustomizablePart) item;
                        ViewSettings oldSettings = new ViewSettings();
                        oldSettings.transparency = part.getCustomTransparency();
                        oldSettings.background = part.getCustomBackgroundColor();
                        oldSettings.foreground = part.getCustomForegroundColor();
                        oldSettings.borderWidth = part.getCustomBorderWidth();
                        oldSettings.fontInfo = SharedFonts.toString(part.getCustomFont());
                        this.oldSettings.put(part, oldSettings);
                        setNodeSettings(part, newSettings);
                    }
                }
            } finally {
                UIUtils.disposeCenteredShell(shell);
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    ViewSettings viewSettings = oldSettings.get(colorizedPart);
                    if (viewSettings != null) {
                        setNodeSettings(colorizedPart, viewSettings);
                    }
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    setNodeSettings((ICustomizablePart) item, newSettings);
                }
            }
        }

        private void setNodeSettings(ICustomizablePart part, ViewSettings settings) {
            if (part instanceof NotePart) {
                part.setCustomTransparency(settings.transparency);
            }
            part.setCustomBackgroundColor(settings.background);
            if (part instanceof NotePart) {
                part.setCustomForegroundColor(settings.foreground);
                part.setCustomBorderWidth(settings.borderWidth);
                part.setCustomFont(UIUtils.getSharedFonts().getFont(Display.getCurrent(), settings.fontInfo));
            }
        }
    };
}
Also used : NotePart(org.jkiss.dbeaver.erd.ui.part.NotePart) Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with EntityPart

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

the class ERDEditorPart method restoreVisualSettings.

private boolean restoreVisualSettings(DiagramPart oldDiagram, EntityDiagram newDiagram) {
    boolean hasChanges = false;
    // Collect visual settings from old diagram and apply them to the new one
    for (ERDEntity newEntity : newDiagram.getEntities()) {
        NodePart oldEntity = oldDiagram.getChildByObject(newEntity.getObject());
        if (oldEntity instanceof EntityPart) {
            EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldEntity);
            newDiagram.addVisualInfo(newEntity.getObject(), vi);
            hasChanges = true;
        }
    }
    for (ERDNote newNote : newDiagram.getNotes()) {
        NodePart oldNotePart = oldDiagram.getChildByObject(newNote.getObject());
        if (oldNotePart instanceof NotePart) {
            EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldNotePart);
            vi.initBounds = oldNotePart.getBounds();
            newDiagram.addVisualInfo(newNote, vi);
            hasChanges = true;
        }
    }
    return hasChanges;
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) NotePart(org.jkiss.dbeaver.erd.ui.part.NotePart) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart)

Example 8 with EntityPart

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

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

the class DiagramXYLayoutPolicy method createChangeConstraintCommand.

/**
 * Creates command to move table. Does not allow table to be resized
 */
@Override
protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
    if (!(child instanceof NodePart))
        return null;
    if (!(constraint instanceof Rectangle))
        return null;
    NodePart nodePart = (NodePart) child;
    Figure figure = (Figure) nodePart.getFigure();
    Rectangle oldBounds = figure.getBounds();
    Rectangle newBounds = (Rectangle) constraint;
    // Restrict resize for entities
    if (!ALLOW_ENTITY_RESIZE && nodePart instanceof EntityPart) {
        if (oldBounds.width != newBounds.width && newBounds.width != -1)
            return null;
        if (oldBounds.height != newBounds.height && newBounds.height != -1)
            return null;
    }
    return new NodeMoveCommand(nodePart, oldBounds.getCopy(), newBounds.getCopy());
}
Also used : NodeMoveCommand(org.jkiss.dbeaver.erd.ui.command.NodeMoveCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) Figure(org.eclipse.draw2d.Figure) IFigure(org.eclipse.draw2d.IFigure)

Example 10 with EntityPart

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

the class ERDEditorPart method fillAttributeVisibilityMenu.

public void fillAttributeVisibilityMenu(IMenuManager menu) {
    MenuManager asMenu = new MenuManager(ERDUIMessages.menu_view_style);
    asMenu.add(new ChangeAttributePresentationAction(ERDViewStyle.ICONS));
    asMenu.add(new ChangeAttributePresentationAction(ERDViewStyle.TYPES));
    asMenu.add(new ChangeAttributePresentationAction(ERDViewStyle.NULLABILITY));
    asMenu.add(new ChangeAttributePresentationAction(ERDViewStyle.COMMENTS));
    asMenu.add(new ChangeAttributePresentationAction(ERDViewStyle.ENTITY_FQN));
    menu.add(asMenu);
    if (getDiagram().getDecorator().supportsAttributeVisibility()) {
        MenuManager avMenu = new MenuManager(ERDUIMessages.menu_attribute_visibility);
        avMenu.add(new EmptyAction(ERDUIMessages.menu_attribute_visibility_default));
        avMenu.add(new ChangeAttributeVisibilityAction(true, ERDAttributeVisibility.ALL));
        avMenu.add(new ChangeAttributeVisibilityAction(true, ERDAttributeVisibility.KEYS));
        avMenu.add(new ChangeAttributeVisibilityAction(true, ERDAttributeVisibility.PRIMARY));
        avMenu.add(new ChangeAttributeVisibilityAction(true, ERDAttributeVisibility.NONE));
        ISelection selection = getGraphicalViewer().getSelection();
        if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
            int totalEntities = 0;
            for (Object item : ((IStructuredSelection) selection).toArray()) {
                if (item instanceof EntityPart) {
                    totalEntities++;
                }
            }
            if (totalEntities > 0) {
                avMenu.add(new Separator());
                String avaTitle = ERDUIMessages.menu_attribute_visibility_entity;
                if (((IStructuredSelection) selection).size() == 1) {
                    avaTitle += " (" + ((IStructuredSelection) selection).getFirstElement() + ")";
                } else {
                    avaTitle += " (" + totalEntities + ")";
                }
                avMenu.add(new EmptyAction(avaTitle));
                avMenu.add(new ChangeAttributeVisibilityAction(false, ERDAttributeVisibility.ALL));
                avMenu.add(new ChangeAttributeVisibilityAction(false, ERDAttributeVisibility.KEYS));
                avMenu.add(new ChangeAttributeVisibilityAction(false, ERDAttributeVisibility.PRIMARY));
                avMenu.add(new ChangeAttributeVisibilityAction(false, ERDAttributeVisibility.NONE));
            }
        }
        menu.add(avMenu);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) EventObject(java.util.EventObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart)

Aggregations

EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)20 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 NodePart (org.jkiss.dbeaver.erd.ui.part.NodePart)6 HashMap (java.util.HashMap)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)4 NotePart (org.jkiss.dbeaver.erd.ui.part.NotePart)4 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)4 FileOutputStream (java.io.FileOutputStream)2 EventObject (java.util.EventObject)2 Map (java.util.Map)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Figure (org.eclipse.draw2d.Figure)2 IFigure (org.eclipse.draw2d.IFigure)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2