From 86c8a95f052ebf416da503513869fd06002bee05 Mon Sep 17 00:00:00 2001 From: Laurent CARON Date: Sat, 12 Jun 2021 15:10:57 +0200 Subject: [PATCH] Issue 328 - DualList should be configuable --- .../duallist/snippets/DualListSnippet.java | 4 +- .../snippets/DualListTextSnippet.java | 72 +++- .../duallist/snippets/arrows/arrow_down.png | Bin 0 -> 229 bytes .../duallist/snippets/arrows/arrow_left.png | Bin 0 -> 213 bytes .../duallist/snippets/arrows/arrow_right.png | Bin 0 -> 190 bytes .../duallist/snippets/arrows/arrow_up.png | Bin 0 -> 196 bytes .../duallist/snippets/arrows/double_down.png | Bin 0 -> 227 bytes .../duallist/snippets/arrows/double_left.png | Bin 0 -> 232 bytes .../duallist/snippets/arrows/double_right.png | Bin 0 -> 238 bytes .../duallist/snippets/arrows/double_up.png | Bin 0 -> 214 bytes .../opal/duallist/DLConfiguration.java | 391 ++++++++++++++++++ .../nebula/widgets/opal/duallist/DLItem.java | 2 +- .../widgets/opal/duallist/DualList.java | 192 ++++++++- .../opal/duallist/SelectionChangeEvent.java | 2 +- .../duallist/SelectionChangeListener.java | 2 +- 15 files changed, 641 insertions(+), 24 deletions(-) create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_down.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_left.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_right.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/arrow_up.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_down.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_left.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_right.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist.snippets/src/org/eclipse/nebula/widgets/opal/duallist/snippets/arrows/double_up.png create mode 100644 widgets/opal/duallist/org.eclipse.nebula.widgets.opal.duallist/src/org/eclipse/nebula/widgets/opal/duallist/DLConfiguration.java 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 0000000000000000000000000000000000000000..c61bf2928e42f263bae486f82fdbd97945a4f9a6 GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFreK^Hple RR8OFJ44$rjF6*2UngC5DKpX%7 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..af4d8705981723ccc058ac8d373a06225b82a27b GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPF>@JPSL!T8eQSPz`5+M`SSrgWLfS zW)#%hwjC&_@9E+gB5^tS06)t@lgXYEQ&fYvQVn)-9B7eQ$a5`;HAHZS)C`8noeZ;1 dYBV%5GH{77@Bg*Z`4CVmgQu&X%Q~loCIIdwFs1+i literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..61a8a506e80153dbefa8d3144fbbf982454a5758 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPF=YxAO9=)R3J(Wt;^bk;M!Q zatA<|QBZH&cA%hO>_%)lUb0E8I@^|oyX3VM6GIEF}EPCmdUk;s$E&bG`zznRz)=L?=`8F42fiL7%{i3Rahi**lp+rn4PNVq;^NpvSpqy6JHp Pps@^|u6{1-oD!M6kyy5+SwO&Gr$#~3RihOahCYQ%hC5=+3wGr-NLg@hFXiE3;F05A U*{S821vHq!)78&qol`;+0FgF8A^-pY literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..addcba53d637e4234ee54981b7fd6c7635bb684f GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFovYv0atrue 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