diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListSnippet.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListSnippet.java index adf58031b..c7a9fe8a2 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListSnippet.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListSnippet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Laurent CARON. + * Copyright (c) 2011-2021 Laurent CARON. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.Shell; /** - * A simple snipper for the ItemSelector Widget + * A simple snipper for the DualList Widget * */ public class DualListSnippet { diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListTextSnippet.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListTextSnippet.java index d47915bf2..fc036114b 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListTextSnippet.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/DualListTextSnippet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Laurent CARON. + * Copyright (c) 2011-2021 Laurent CARON. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,21 +15,34 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil; +import org.eclipse.nebula.widgets.opal.duallist.DLConfiguration; import org.eclipse.nebula.widgets.opal.duallist.DLItem; import org.eclipse.nebula.widgets.opal.duallist.DualList; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** - * A simple snipper for the ItemSelector Widget + * A simple snipper for the DualList Widget * */ public class DualListTextSnippet { + private static final String DOUBLE_DOWN_IMAGE = "double_down.png"; + private static final String DOUBLE_UP_IMAGE = "double_up.png"; + private static final String DOUBLE_LEFT_IMAGE = "double_left.png"; + private static final String DOUBLE_RIGHT_IMAGE = "double_right.png"; + private static final String ARROW_DOWN_IMAGE = "arrow_down.png"; + private static final String ARROW_LEFT_IMAGE = "arrow_left.png"; + private static final String ARROW_UP_IMAGE = "arrow_up.png"; + private static final String ARROW_RIGHT_IMAGE = "arrow_right.png"; + private static DualList dl; public static void main(final String[] args) { final Display display = new Display(); @@ -38,7 +51,7 @@ public static void main(final String[] args) { shell.setSize(600, 600); shell.setLayout(new GridLayout(1, false)); - final DualList dl = new DualList(shell, SWT.NONE); + dl = new DualList(shell, SWT.NONE); dl.setItems(createItems(shell)); dl.addListener(SWT.Selection, e -> { System.out.println("Selection Listener called"); @@ -46,6 +59,30 @@ public static void main(final String[] args) { dl.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); + GridData gdButtons = new GridData(GridData.END, GridData.FILL, true, false); + gdButtons.widthHint = 150; + + Button changeConfiguration = new Button(shell, SWT.PUSH); + changeConfiguration.setText("Change Configuration"); + changeConfiguration.setLayoutData(gdButtons); + changeConfiguration.addListener(SWT.Selection, e -> dl.setConfiguration(createConfiguration())); + + Button hideButtons = new Button(shell, SWT.PUSH); + hideButtons.setText("Hide buttons"); + hideButtons.setLayoutData(gdButtons); + hideButtons.addListener(SWT.Selection, e -> { + DLConfiguration config = new DLConfiguration(); + config.setDoubleDownVisible(false).setDoubleUpVisible(false).// + setDoubleRightVisible(false).setDoubleLeftVisible(false).// + setDownVisible(false).setUpVisible(false); + dl.setConfiguration(config); + }); + + Button resetConfiguration = new Button(shell, SWT.PUSH); + resetConfiguration.setText("Reset Configuration"); + resetConfiguration.setLayoutData(gdButtons); + resetConfiguration.addListener(SWT.Selection, e -> dl.setConfiguration(null)); + shell.pack(); shell.open(); @@ -109,4 +146,33 @@ private static List createItems(final Shell shell) { return list; } + private static DLConfiguration createConfiguration() { + DLConfiguration config = new DLConfiguration(); + Display display = Display.getCurrent(); + // Change colors for both panels + config.setItemsBackgroundColor(display.getSystemColor(SWT.COLOR_BLACK)).// + setItemsForegroundColor(display.getSystemColor(SWT.COLOR_WHITE)).// + setItemsOddLinesColor(display.getSystemColor(SWT.COLOR_GRAY)); + config.setSelectionBackgroundColor(display.getSystemColor(SWT.COLOR_DARK_GREEN)).// + setSelectionForegroundColor(display.getSystemColor(SWT.COLOR_YELLOW)).// + setSelectionOddLinesColor(display.getSystemColor(SWT.COLOR_RED)); + + // Change text alignment + config.setItemsTextAlignment(SWT.RIGHT).setSelectionTextAlignment(SWT.CENTER); + + // Change buttons + config.setDownImage(createImage(ARROW_DOWN_IMAGE)).setUpImage(createImage(ARROW_UP_IMAGE)).// + setRightImage(createImage(ARROW_RIGHT_IMAGE)).setLeftImage(createImage(ARROW_LEFT_IMAGE)).// + setDoubleDownImage(createImage(DOUBLE_DOWN_IMAGE)).setDoubleUpImage(createImage(DOUBLE_UP_IMAGE)).// + setDoubleLeftImage(createImage(DOUBLE_LEFT_IMAGE)).setDoubleRightImage(createImage(DOUBLE_RIGHT_IMAGE)); + + return config; + } + + private static Image createImage(String fileName) { + Image image = new Image(Display.getCurrent(), // + DualListTextSnippet.class.getResourceAsStream("arrows/" + fileName)); + SWTGraphicUtil.addDisposer(dl, image); + return image; + } } diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_down.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_down.png new file mode 100644 index 000000000..c61bf2928 Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_down.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_left.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_left.png new file mode 100644 index 000000000..af4d87059 Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_left.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_right.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_right.png new file mode 100644 index 000000000..c8de442a7 Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_right.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_up.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_up.png new file mode 100644 index 000000000..61a8a506e Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_up.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_down.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_down.png new file mode 100644 index 000000000..c04d1744a Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_down.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_left.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_left.png new file mode 100644 index 000000000..be5362303 Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_left.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_right.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_right.png new file mode 100644 index 000000000..addcba53d Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_right.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_up.png b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_up.png new file mode 100644 index 000000000..fba89b7b9 Binary files /dev/null and b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_up.png differ diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLConfiguration.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLConfiguration.java new file mode 100644 index 000000000..a5b4f03d0 --- /dev/null +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLConfiguration.java @@ -0,0 +1,391 @@ +/******************************************************************************* + * Copyright (c) 2021 Laurent CARON + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: Laurent CARON (laurent.caron at gmail dot com) - initial API + * and implementation + *******************************************************************************/ +package org.eclipse.nebula.widgets.opal.duallist; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +/** + * Configuration class for the DualList widget + */ +public class DLConfiguration { + private Color itemsBackgroundColor, itemsOddLinesColor, itemsForegroundColor, selectionBackgroundColor, selectionOddLinesColor, selectionForegroundColor; + private int itemsTextAlignment = SWT.LEFT, selectionTextAlignment = SWT.LEFT; + private Image doubleDownImage, doubleUpImage, doubleLeftImage, doubleRightImage, // + downImage, leftImage, upImage, rightImage; + + private boolean doubleRightVisible = true; + private boolean doubleLeftVisible = true; + private boolean doubleUpVisible = true; + private boolean upVisible = true; + private boolean doubleDownVisible = true; + private boolean downVisible = true; + + /** + * @return the background color of the items panel + */ + public Color getItemsBackgroundColor() { + return itemsBackgroundColor; + } + + /** + * @param color the background color of the items panel to set + */ + public DLConfiguration setItemsBackgroundColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.itemsBackgroundColor = color; + return this; + } + + /** + * @return the background color of the odd lines for the unselected items list + */ + public Color getItemsOddLinesColor() { + return itemsOddLinesColor; + } + + /** + * @param color the background color of the odd lines for the unselected items list to set + */ + public DLConfiguration setItemsOddLinesColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.itemsOddLinesColor = color; + return this; + } + + /** + * @return the background color of the selected items panel + */ + public Color getSelectionBackgroundColor() { + return selectionBackgroundColor; + } + + /** + * @param color the background color of the items panel to set + */ + public DLConfiguration setSelectionBackgroundColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.selectionBackgroundColor = color; + return this; + } + + /** + * @return the background color of the odd lines for the selected items list + */ + public Color getSelectionOddLinesColor() { + return selectionOddLinesColor; + } + + /** + * @param color the background color of the odd lines for the selected items list to set + */ + public DLConfiguration setSelectionOddLinesColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.selectionOddLinesColor = color; + return this; + } + + /** + * @return the text alignment (SWT.RIGHT, SWT.CENTER, SWT.LEFT) for the unselected items + */ + public int getItemsTextAlignment() { + return itemsTextAlignment; + } + + /** + * @param alignment the text alignment (SWT.RIGHT, SWT.CENTER, SWT.LEFT) for the unselected items to set + */ + public DLConfiguration setItemsTextAlignment(int alignment) { + if (alignment != SWT.NONE && alignment != SWT.LEFT && alignment != SWT.RIGHT && alignment != SWT.CENTER) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.itemsTextAlignment = alignment; + return this; + } + + /** + * @return the text alignment (SWT.RIGHT, SWT.CENTER, SWT.LEFT) for the selected items + */ + public int getSelectionTextAlignment() { + return selectionTextAlignment; + } + + /** + * @param alignment the text alignment (SWT.RIGHT, SWT.CENTER, SWT.LEFT) for the unselected items to set + */ + public DLConfiguration setSelectionTextAlignment(int alignment) { + if (alignment != SWT.NONE && alignment != SWT.LEFT && alignment != SWT.RIGHT && alignment != SWT.CENTER) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.selectionTextAlignment = alignment; + return this; + } + + /** + * @return the image for the "double down" button + */ + public Image getDoubleDownImage() { + return doubleDownImage; + } + + /** + * @param image the image for the "double down" button to set + */ + public DLConfiguration setDoubleDownImage(Image image) { + this.doubleDownImage = image; + return this; + } + + /** + * @return the image for the "double up" button + */ + public Image getDoubleUpImage() { + return doubleUpImage; + } + + /** + * @param image the image for the "double up" button to set + */ + public DLConfiguration setDoubleUpImage(Image image) { + this.doubleUpImage = image; + return this; + } + + /** + * @return the image for the "double left" button + */ + public Image getDoubleLeftImage() { + return doubleLeftImage; + } + + /** + * @param image the image for the "double left" button to set + */ + public DLConfiguration setDoubleLeftImage(Image image) { + this.doubleLeftImage = image; + return this; + } + + /** + * @return the image for the "double right" button + */ + public Image getDoubleRightImage() { + return doubleRightImage; + } + + /** + * @param image the image for the "double right" button to set + */ + public DLConfiguration setDoubleRightImage(Image image) { + this.doubleRightImage = image; + return this; + } + + /** + * @return the image for the "down" button + */ + public Image getDownImage() { + return downImage; + } + + /** + * @param image the image for the "down" button to set + */ + public DLConfiguration setDownImage(Image image) { + this.downImage = image; + return this; + } + + /** + * @return the image for the "left" button + */ + public Image getLeftImage() { + return leftImage; + } + + /** + * @param image the image for the "left" button to set + */ + public DLConfiguration setLeftImage(Image image) { + this.leftImage = image; + return this; + } + + /** + * @return the image for the "up" button + */ + public Image getUpImage() { + return upImage; + } + + /** + * @param image the image for the "up" button to set + */ + public DLConfiguration setUpImage(Image image) { + this.upImage = image; + return this; + } + + /** + * @return the image for the "right" button + */ + public Image getRightImage() { + return rightImage; + } + + /** + * @param image the image for the "right" button to set + */ + public DLConfiguration setRightImage(Image image) { + this.rightImage = image; + return this; + } + + /** + * @return true if the "double right" button is visible, false otherwise + */ + public boolean isDoubleRightVisible() { + return doubleRightVisible; + } + + /** + * @param visible the visibility of the "double right" button + */ + public DLConfiguration setDoubleRightVisible(boolean visible) { + this.doubleRightVisible = visible; + return this; + } + + /** + * @return true if the "double left" button is visible, false otherwise + */ + public boolean isDoubleLeftVisible() { + return doubleLeftVisible; + } + + /** + * @param visible the visibility of the "double left" button + */ + public DLConfiguration setDoubleLeftVisible(boolean visible) { + this.doubleLeftVisible = visible; + return this; + } + + /** + * @return true if the "double up" button is visible, false otherwise + */ + public boolean isDoubleUpVisible() { + return doubleUpVisible; + } + + /** + * @param visible the visibility of the "double up" button + */ + public DLConfiguration setDoubleUpVisible(boolean visible) { + this.doubleUpVisible = visible; + return this; + } + + /** + * @return true if the "up" button is visible, false otherwise + */ + public boolean isUpVisible() { + return upVisible; + } + + /** + * @param visible the visibility of the "up" button + */ + public DLConfiguration setUpVisible(boolean visible) { + this.upVisible = visible; + return this; + } + + /** + * @return true if the "double down" button is visible, false otherwise + */ + public boolean isDoubleDownVisible() { + return doubleDownVisible; + } + + /** + * @param visible the visibility of the "double down" button + */ + public DLConfiguration setDoubleDownVisible(boolean visible) { + this.doubleDownVisible = visible; + return this; + } + + /** + * @return true if the "down" button is visible, false otherwise + */ + public boolean isDownVisible() { + return downVisible; + } + + /** + * @param visible the visibility of the "down" button + */ + public DLConfiguration setDownVisible(boolean visible) { + this.downVisible = visible; + return this; + } + + /** + * @return the foreground color of the items panel + */ + public Color getItemsForegroundColor() { + return itemsForegroundColor; + } + + /** + * @param color the foreground color of the items panel to set + * @return + */ + public DLConfiguration setItemsForegroundColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.itemsForegroundColor = color; + return this; + } + + /** + * @return the foreground color of the items panel + */ + public Color getSelectionForegroundColor() { + return selectionForegroundColor; + } + + /** + * @param color the foreground color of the selection panel to set + * @return + */ + public DLConfiguration setSelectionForegroundColor(Color color) { + if (color != null && color.isDisposed()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.selectionForegroundColor = color; + return this; + } + +} diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLItem.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLItem.java index 1380a2e28..1945d0fea 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLItem.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Laurent CARON + * Copyright (c) 2011-2021 Laurent CARON * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DualList.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DualList.java index 383e32104..f7f735252 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DualList.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DualList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Laurent CARON + * Copyright (c) 2011-2021 Laurent CARON * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -24,6 +24,7 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -62,6 +63,9 @@ public class DualList extends Composite { private Table selectionTable; private List selectionChangeListeners; + private DLConfiguration configuration; + private Button buttonSelectAll, buttonMoveFirst, buttonSelect, buttonMoveUp, // + buttonDeselect, buttonMoveDown, buttonDeselectAll, buttonMoveLast; /** * Constructs a new instance of this class given its parent and a style value @@ -132,7 +136,7 @@ private Table createTable() { } private void createButtonSelectAll() { - final Button buttonSelectAll = createButton(DOUBLE_RIGHT_IMAGE, true, GridData.END); + buttonSelectAll = createButton(DOUBLE_RIGHT_IMAGE, true, GridData.END); buttonSelectAll.addListener(SWT.Selection, e -> { selectAll(); }); @@ -146,49 +150,49 @@ private void createSelectionTable() { } private void createButtonMoveFirst() { - final Button buttonMoveFirst = createButton(DOUBLE_UP_IMAGE, true, GridData.END); + buttonMoveFirst = createButton(DOUBLE_UP_IMAGE, true, GridData.END); buttonMoveFirst.addListener(SWT.Selection, e -> { moveSelectionToFirstPosition(); }); } private void createButtonSelect() { - final Button buttonSelect = createButton(ARROW_RIGHT_IMAGE, false, GridData.CENTER); + buttonSelect = createButton(ARROW_RIGHT_IMAGE, false, GridData.CENTER); buttonSelect.addListener(SWT.Selection, e -> { selectItem(); }); } private void createButtonMoveUp() { - final Button buttonMoveUp = createButton(ARROW_UP_IMAGE, false, GridData.CENTER); + buttonMoveUp = createButton(ARROW_UP_IMAGE, false, GridData.CENTER); buttonMoveUp.addListener(SWT.Selection, e -> { moveUpItem(); }); } private void createButtonDeselect() { - final Button buttonDeselect = createButton(ARROW_LEFT_IMAGE, false, GridData.CENTER); + buttonDeselect = createButton(ARROW_LEFT_IMAGE, false, GridData.CENTER); buttonDeselect.addListener(SWT.Selection, e -> { deselectItem(); }); } private void createButtonMoveDown() { - final Button buttonMoveDown = createButton(ARROW_DOWN_IMAGE, false, GridData.CENTER); + buttonMoveDown = createButton(ARROW_DOWN_IMAGE, false, GridData.CENTER); buttonMoveDown.addListener(SWT.Selection, e -> { moveDownItem(); }); } private void createButtonDeselectAll() { - final Button buttonDeselectAll = createButton(DOUBLE_LEFT_IMAGE, false, GridData.BEGINNING); + buttonDeselectAll = createButton(DOUBLE_LEFT_IMAGE, false, GridData.BEGINNING); buttonDeselectAll.addListener(SWT.Selection, e -> { deselectAll(); }); } private void createButtonMoveLast() { - final Button buttonMoveLast = createButton(DOUBLE_DOWN_IMAGE, true, GridData.BEGINNING); + buttonMoveLast = createButton(DOUBLE_DOWN_IMAGE, true, GridData.BEGINNING); buttonMoveLast.addListener(SWT.Selection, e -> { moveSelectionToLastPosition(); }); @@ -1286,13 +1290,14 @@ private void selectAll(final boolean shouldFireEvents) { @Override public void setBounds(final int x, final int y, final int width, final int height) { super.setBounds(x, y, width, height); + layout(true); final boolean itemsContainImage = itemsContainImage(); final Point itemsTableDefaultSize = itemsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT); final Point selectionTableDefaultSize = selectionTable.computeSize(SWT.DEFAULT, SWT.DEFAULT); int itemsTableSize = itemsTable.getSize().x; if (itemsTableDefaultSize.y > itemsTable.getSize().y) { - itemsTableSize -= itemsTable.getVerticalBar().getSize().x; + itemsTableSize -= itemsTable.getVerticalBar().getSize().x + 1; } int selectionTableSize = selectionTable.getSize().x; @@ -1310,7 +1315,7 @@ public void setBounds(final int x, final int y, final int width, final int heigh } else { itemsTable.getColumn(0).setWidth(0); itemsTable.getColumn(1).setWidth(itemsTableSize); - + selectionTable.getColumn(0).setWidth(0); selectionTable.getColumn(1).setWidth(selectionTableSize); } @@ -1426,7 +1431,6 @@ public void setItems(final DLItem[] items) { * */ public void setItems(final List items) { - checkWidget(); checkWidget(); if (items == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); @@ -1460,8 +1464,9 @@ private void redrawTables() { setRedraw(false); redrawTable(itemsTable, false); redrawTable(selectionTable, true); + Rectangle bounds = getBounds(); + this.setBounds(bounds.x, bounds.y, bounds.width, bounds.height); setRedraw(true); - this.setBounds(getBounds()); } /** @@ -1473,7 +1478,7 @@ private void redrawTables() { */ private void redrawTable(final Table table, final boolean isSelected) { clean(table); - fillData(table, isSelected ? selection : items); + fillData(table, isSelected); } /** @@ -1497,7 +1502,9 @@ private void clean(final Table table) { * @param table table to be filled * @param listOfData list of data */ - private void fillData(final Table table, final List listOfData) { + private void fillData(final Table table, final boolean isSelected) { + List listOfData = isSelected ? selection : items; + int counter = 0; for (final DLItem item : listOfData) { final TableItem tableItem = new TableItem(table, SWT.NONE); tableItem.setData(item); @@ -1517,7 +1524,15 @@ private void fillData(final Table table, final List listOfData) { if (item.getFont() != null) { tableItem.setFont(item.getFont()); } - tableItem.setText(1, item.getText()); + tableItem.setText(1, item.getText()); + if (configuration != null && item.getBackground() == null && counter % 2 == 0) { + if (isSelected) { + tableItem.setBackground(configuration.getSelectionOddLinesColor()); + } else { + tableItem.setBackground(configuration.getItemsOddLinesColor()); + } + } + counter++; } } @@ -1704,4 +1719,149 @@ private void fireSelectionChangeEvent(final List items) { listener.widgetSelected(selectionChangeEvent); } } + + /** + * Returns the configuration of the receiver. + * + * @return the current configuration of the receiver + * + * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the + * thread that created the receiver
  • + *
+ */ + public DLConfiguration getConfiguration() { + checkWidget(); + return configuration; + } + + /** + * Sets the receiver's configuration + * + * @param configuration the new configuration + * + * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the + * thread that created the receiver
  • + *
+ */ + public void setConfiguration(DLConfiguration configuration) { + checkWidget(); + this.configuration = configuration; + applyNewConfiguration(); + } + + private void applyNewConfiguration() { + try { + setRedraw(true); + if (configuration == null) { + resetConfigurationToDefault(); + } else { + modifyPanelsColors(); + modifyTextAlignment(); + modifyButtonImages(); + modifyButtonVisibility(); + } + redrawTables(); + } finally { + setRedraw(true); + } + } + + private void resetConfigurationToDefault() { + itemsTable.setBackground(null); + itemsTable.setForeground(null); + selectionTable.setBackground(null); + selectionTable.setForeground(null); + + recreateTableColumns(itemsTable, SWT.LEFT); + recreateTableColumns(selectionTable, SWT.LEFT); + + resetButton(buttonMoveLast, DOUBLE_DOWN_IMAGE); + resetButton(buttonMoveFirst, DOUBLE_UP_IMAGE); + resetButton(buttonDeselectAll, DOUBLE_LEFT_IMAGE); + resetButton(buttonSelectAll, DOUBLE_RIGHT_IMAGE); + resetButton(buttonMoveDown, ARROW_DOWN_IMAGE); + resetButton(buttonMoveUp, ARROW_UP_IMAGE); + resetButton(buttonDeselect, ARROW_LEFT_IMAGE); + resetButton(buttonSelect, ARROW_RIGHT_IMAGE); + } + + private void resetButton(Button button, String fileName) { + final Image image = SWTGraphicUtil.createImageFromFile("images/" + fileName); + button.setImage(image); + SWTGraphicUtil.addDisposer(button, image); + button.setVisible(true); + } + + private void modifyPanelsColors() { + if (configuration.getItemsBackgroundColor() != null) { + itemsTable.setBackground(configuration.getItemsBackgroundColor()); + } + if (configuration.getItemsForegroundColor() != null) { + itemsTable.setForeground(configuration.getItemsForegroundColor()); + } + if (configuration.getSelectionBackgroundColor() != null) { + selectionTable.setBackground(configuration.getSelectionBackgroundColor()); + } + if (configuration.getSelectionForegroundColor() != null) { + selectionTable.setForeground(configuration.getSelectionForegroundColor()); + } + } + + private void modifyTextAlignment() { + recreateTableColumns(itemsTable, configuration.getItemsTextAlignment()); + recreateTableColumns(selectionTable, configuration.getSelectionTextAlignment()); + } + + private void recreateTableColumns(Table table, int textAlignment) { + for (TableColumn tc : table.getColumns()) { + tc.dispose(); + } + new TableColumn(table, SWT.CENTER); + new TableColumn(table, textAlignment); + } + + private void modifyButtonImages() { + if (configuration.getDoubleDownImage() != null) { + buttonMoveLast.setImage(configuration.getDoubleDownImage()); + } + if (configuration.getDoubleUpImage() != null) { + buttonMoveFirst.setImage(configuration.getDoubleUpImage()); + } + if (configuration.getDoubleLeftImage() != null) { + buttonDeselectAll.setImage(configuration.getDoubleLeftImage()); + } + if (configuration.getDoubleRightImage() != null) { + buttonSelectAll.setImage(configuration.getDoubleRightImage()); + } + if (configuration.getDownImage() != null) { + buttonMoveDown.setImage(configuration.getDownImage()); + } + if (configuration.getUpImage() != null) { + buttonMoveUp.setImage(configuration.getUpImage()); + } + if (configuration.getLeftImage() != null) { + buttonDeselect.setImage(configuration.getLeftImage()); + } + if (configuration.getRightImage() != null) { + buttonSelect.setImage(configuration.getRightImage()); + } + } + + private void modifyButtonVisibility() { + buttonMoveLast.setVisible(configuration.isDoubleDownVisible()); + buttonMoveFirst.setVisible(configuration.isDoubleUpVisible()); + buttonDeselectAll.setVisible(configuration.isDoubleLeftVisible()); + buttonSelectAll.setVisible(configuration.isDoubleRightVisible()); + buttonMoveDown.setVisible(configuration.isDownVisible()); + buttonMoveUp.setVisible(configuration.isUpVisible()); + } + } diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeEvent.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeEvent.java index ced97c1a7..5ab125aef 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeEvent.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Laurent CARON + * Copyright (c) 2014-2021 Laurent CARON * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 diff --git a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeListener.java b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeListener.java index 5799aac38..3a92ce33a 100644 --- a/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeListener.java +++ b/widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/SelectionChangeListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Laurent CARON + * Copyright (c) 2014-2021 Laurent CARON * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at