Search in sources :

Example 1 with IColorizedPart

use of org.jkiss.dbeaver.ext.erd.part.IColorizedPart in project dbeaver by dbeaver.

the class SetPartColorAction method createColorCommand.

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

        private final Map<IColorizedPart, 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 IColorizedPart) {
                        IColorizedPart colorizedPart = (IColorizedPart) item;
                        oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
                        colorizedPart.customizeBackgroundColor(newColor);
                    }
                }
            } finally {
                shell.dispose();
            }
        }

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

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

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Command (org.eclipse.gef.commands.Command)1 Color (org.eclipse.swt.graphics.Color)1 RGB (org.eclipse.swt.graphics.RGB)1 ColorDialog (org.eclipse.swt.widgets.ColorDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 IColorizedPart (org.jkiss.dbeaver.ext.erd.part.IColorizedPart)1