Search in sources :

Example 1 with ICustomizablePart

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

the class ResetPartColorAction method createColorCommand.

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

        private final Map<ICustomizablePart, Color> oldColors = new HashMap<>();

        @Override
        public void execute() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
                    colorizedPart.setCustomBackgroundColor(null);
                }
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(oldColors.get(colorizedPart));
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(null);
                }
            }
        }
    };
}
Also used : Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ICustomizablePart

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

the class SetPartColorAction method createColorCommand.

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

        private final Map<ICustomizablePart, Color> oldColors = new HashMap<>();

        private Color newColor;

        @Override
        public void execute() {
            final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
            try {
                ColorDialog colorDialog = new ColorDialog(shell);
                RGB color = colorDialog.open();
                if (color == null) {
                    return;
                }
                newColor = new Color(Display.getCurrent(), color);
                for (Object item : objects) {
                    if (item instanceof ICustomizablePart) {
                        ICustomizablePart colorizedPart = (ICustomizablePart) item;
                        oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
                        colorizedPart.setCustomBackgroundColor(newColor);
                    }
                }
            } finally {
                UIUtils.disposeCenteredShell(shell);
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(oldColors.get(colorizedPart));
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(newColor);
                }
            }
        }
    };
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ICustomizablePart

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

the class ResetPartColorAction method createColorCommand.

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

        private final Map<ICustomizablePart, Color> oldColors = new HashMap<>();

        @Override
        public void execute() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
                    colorizedPart.setCustomBackgroundColor(null);
                }
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(oldColors.get(colorizedPart));
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(null);
                }
            }
        }
    };
}
Also used : Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ICustomizablePart

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

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

the class SetPartColorAction method createColorCommand.

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

        private final Map<ICustomizablePart, Color> oldColors = new HashMap<>();

        private Color newColor;

        @Override
        public void execute() {
            final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
            try {
                ColorDialog colorDialog = new ColorDialog(shell);
                RGB color = colorDialog.open();
                if (color == null) {
                    return;
                }
                newColor = new Color(Display.getCurrent(), color);
                for (Object item : objects) {
                    if (item instanceof ICustomizablePart) {
                        ICustomizablePart colorizedPart = (ICustomizablePart) item;
                        oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
                        colorizedPart.setCustomBackgroundColor(newColor);
                    }
                }
            } finally {
                UIUtils.disposeCenteredShell(shell);
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(oldColors.get(colorizedPart));
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    colorizedPart.setCustomBackgroundColor(newColor);
                }
            }
        }
    };
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)6 Map (java.util.Map)6 Command (org.eclipse.gef.commands.Command)6 ICustomizablePart (org.jkiss.dbeaver.erd.ui.part.ICustomizablePart)6 Color (org.eclipse.swt.graphics.Color)2 RGB (org.eclipse.swt.graphics.RGB)2 ColorDialog (org.eclipse.swt.widgets.ColorDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)2 NodePart (org.jkiss.dbeaver.erd.ui.part.NodePart)2 NotePart (org.jkiss.dbeaver.erd.ui.part.NotePart)2