Search in sources :

Example 11 with NodePart

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

the class EntityConnectionEditPolicy method getReconnectSourceCommand.

@Override
protected Command getReconnectSourceCommand(ReconnectRequest request) {
    AssociationReconnectSourceCommand cmd = makeReconnectSourceCommand();
    cmd.setAssociation((ERDAssociation) request.getConnectionEditPart().getModel());
    NodePart entityPart = (NodePart) getHost();
    cmd.setSourceEntity(entityPart.getElement());
    return cmd;
}
Also used : AssociationReconnectSourceCommand(org.jkiss.dbeaver.erd.ui.command.AssociationReconnectSourceCommand) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart)

Example 12 with NodePart

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

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 13 with NodePart

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

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 14 with NodePart

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

the class EntityConnectionEditPolicy method getConnectionCreateCommand.

@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
    AssociationCreateCommand cmd = makeCreateCommand();
    NodePart part = (NodePart) getHost();
    cmd.setSourceEntity(part.getElement());
    request.setStartCommand(cmd);
    return cmd;
}
Also used : AssociationCreateCommand(org.jkiss.dbeaver.erd.ui.command.AssociationCreateCommand) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart)

Example 15 with NodePart

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

the class EntityConnectionEditPolicy method getReconnectTargetCommand.

@Override
protected Command getReconnectTargetCommand(ReconnectRequest request) {
    AssociationReconnectTargetCommand cmd = makeReconnectTargetCommand();
    cmd.setRelationship((ERDAssociation) request.getConnectionEditPart().getModel());
    NodePart entityPart = (NodePart) getHost();
    cmd.setTargetEntity(entityPart.getElement());
    return cmd;
}
Also used : AssociationReconnectTargetCommand(org.jkiss.dbeaver.erd.ui.command.AssociationReconnectTargetCommand) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart)

Aggregations

NodePart (org.jkiss.dbeaver.erd.ui.part.NodePart)16 EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)6 IFigure (org.eclipse.draw2d.IFigure)4 Command (org.eclipse.gef.commands.Command)4 AssociationCreateCommand (org.jkiss.dbeaver.erd.ui.command.AssociationCreateCommand)4 NotePart (org.jkiss.dbeaver.erd.ui.part.NotePart)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Figure (org.eclipse.draw2d.Figure)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 AssociationReconnectSourceCommand (org.jkiss.dbeaver.erd.ui.command.AssociationReconnectSourceCommand)2 AssociationReconnectTargetCommand (org.jkiss.dbeaver.erd.ui.command.AssociationReconnectTargetCommand)2 NodeMoveCommand (org.jkiss.dbeaver.erd.ui.command.NodeMoveCommand)2 EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)2 ICustomizablePart (org.jkiss.dbeaver.erd.ui.part.ICustomizablePart)2