Skip to content

Commit

Permalink
Merge pull request #470 from eclipse/bugfix/Issue_454_MultiChoice_Wid…
Browse files Browse the repository at this point in the history
…get_adding_Select_all_as_an_entry

Bug #454 - MultiChoice Widget adding Select all as an entry
  • Loading branch information
lcaron authored Jul 2, 2022
2 parents ffa0b91 + 44ace57 commit 8967dc4
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ public class ResourceManager {

public static final String MULTICHOICE_MESSAGE = "multichoice.message";
public static final String MULTICHOICE_MESSAGE_PLURAL = "multichoice.message.plural";

public static final String APPLY = "apply";

public static final String SELECT_ALL = "selectAll";
public static final String DESELECT_ALL = "deselectAll";

/**
* Get a translated label
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Apply
apply=Apply
selectAll=Select All
deselectAll=Deselect All
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Anwenden
apply=Anwenden
selectAll=Wählen Sie Alle
deselectAll=Alle abwählen
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Aplicar
apply=Aplicar
selectAll=Seleccionar todo
deselectAll=Deseleccionar todo
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Cancel=Annuler
Close=Fermer
Yes=Oui
No=Non
MoreDetails=Plus de détails
FewerDetails=Moins de détails
Details=Détails
MoreDetails=Plus de d\u00e9tails
FewerDetails=Moins de d\u00e9tails
Details=D\u00e9tails
Information=Information
Error=Erreur
Question=Question
Warning=Avertissement
Exception=Exception
Choice=Choix
Select=Sélection
Input=Entrée
Select=S\u00e9lection
Input=Entr\u00e9e
ApplicationError=Erreur applicative
megabytes=Mo
performGC=Lancer le ramasse-miettes (GC)
Expand All @@ -24,36 +24,38 @@ rememberPassword=Se souvenir de mon mot de passe
loginFailed=Echec de l'authentification
tipOfTheDay=Astuce du jour
didYouKnow=Le savez-vous ?
showTipAtStartup=Afficher les astuces au démarrage
previousTip=< Astuce précédente
showTipAtStartup=Afficher les astuces au d\u00e9marrage
previousTip=< Astuce pr\u00e9c\u00e9dente
nextTip=Astuce suivante >
choose=Choisir
preferences=Préférences
preferences=Pr\u00e9f\u00e9rences
validURL=Merci de saisir une URL valide s'il vous plait
chooseDirectory=Veuillez choisir un répertoire
chooseDirectory=Veuillez choisir un r\u00e9pertoire
bold=gras
italic=italique
category.shortDescription = Alterner entre vue par Cat\u00e9gorie et liste
description.shortDescription = Afficher/Cacher le panneau de Description
sort.shortDescription = Trier les Propri\u00e9t\u00e9s et Cat\u00e9gories par Nom
property=Propriété
property=Propri\u00e9t\u00e9
value=Valeur
editProperty=Edition de la valeur de la propriété
editProperty=Edition de la valeur de la propri\u00e9t\u00e9
width=Largeur
height=Hauteur
top=Haut
bottom=Bas
left=Gauche
right=Droite
eraseProperty=Efface la valeur de cette propriété
physicalMemory=Mémoire physique
heapMemory=Mémoire Heap
eraseProperty=Efface la valeur de cette propri\u00e9t\u00e9
physicalMemory=M\u00e9moire physique
heapMemory=M\u00e9moire Heap
threads=Threads
cpuUsage=Utilisation CPU
peak=Max
mb=Mo
calculator.dividebyzero=Division par zéro impossible !
calculator.invalid=Entrée invalide pour cette fonction !
multichoice.message=L'entrée %s n'est pas valide, merci de la v\u00e9rifier !
calculator.dividebyzero=Division par z\u00e9ro impossible !
calculator.invalid=Entr\u00e9e invalide pour cette fonction !
multichoice.message=L'entr\u00e9e %s n'est pas valide, merci de la v\u00e9rifier !
multichoice.message.plural=Les entr\u00e9es %s ne sont pas valides, merci de les v\u00e9rifier!
apply=Appliquer
apply=Appliquer
selectAll=Tout s\u00e9lectionner
deselectAll=Tout d\u00e9selectionner
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Applicare
apply=Applicare
selectAll=Seleziona tutto
deselectAll=Deselezionare tutto
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Van toepassing zijn
apply=Van toepassing zijn
selectAll=Selecteer alles
deselectAll=Deselecteer alles
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Nie można dzielić przez zero !
calculator.invalid=Nieprawidłowe parametry funkcji !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Zastosować
apply=Zastosować
selectAll=Zaznacz wszystko
deselectAll=Odznacz wszystkie
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=Aplique
apply=Aplique
selectAll=Selecionar tudo
deselectAll=Desmarcar todos
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ calculator.dividebyzero=Cannot divide by zero !
calculator.invalid=Invalid input for function !
multichoice.message=The entry %s is invalid, please check it!
multichoice.message.plural=The entries %s are invalid, please check it!
apply=\u5E94\u7528
apply=\u5E94\u7528
selectAll=\u5168\u9009
deselectAll=\u53D6\u6D88\u5168\u9009
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;

import org.eclipse.nebula.widgets.opal.multichoice.MultiChoice;
import org.eclipse.nebula.widgets.opal.multichoice.MultiChoiceLabelProvider;
import org.eclipse.nebula.widgets.opal.multichoice.MultiChoiceSelectionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
Expand Down Expand Up @@ -95,6 +94,16 @@ public static void main(final String[] args) {
mcSimple.addAll(euroZone);
addButons(mcSimple);

drawLabel(shell, "Simple Multichoice with select/deselect all links:");
final MultiChoice<String> mcSelectDeselectAll = new MultiChoice<>(shell, SWT.READ_ONLY);
mcSelectDeselectAll.setEditable(false);
mcSelectDeselectAll.setShowSelectUnselectAll(true);
final GridData gridDataSelectDeselectAll = new GridData(GridData.FILL, GridData.BEGINNING, true, true);
gridDataSelectDeselectAll.widthHint = 200;
mcSelectDeselectAll.setLayoutData(gridDataSelectDeselectAll);
mcSelectDeselectAll.addAll(euroZone);
addButons(mcSelectDeselectAll);

drawLabel(shell, "Multichoice with beans :");
final MultiChoice<Country> mcBeans = new MultiChoice<>(shell, SWT.READ_ONLY);
mcBeans.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
Expand Down Expand Up @@ -157,14 +166,11 @@ public void handle(final MultiChoice<Country> parent, final Country receiver, fi
}
final MultiChoice<String> mcLotOfData = new MultiChoice<>(shell, SWT.NONE);
mcLotOfData.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
mcLotOfData.setLabelProvider(new MultiChoiceLabelProvider() {
@Override
public String getText(final Object element) {
if (element == null) {
return "";
}
return (String) element;
mcLotOfData.setLabelProvider(element -> {
if (element == null) {
return "";
}
return (String) element;
});
mcLotOfData.addAll(data);
addButons(mcLotOfData);
Expand All @@ -177,8 +183,8 @@ public String getText(final Object element) {
mcNotEditable.addAll(euroZone);
mcNotEditable.setEditable(false);
addButons(mcNotEditable);


drawLabel(shell, "Not Enabled Multichoice :");
final MultiChoice<String> mcNotEnabled = new MultiChoice<>(shell, SWT.READ_ONLY);
final GridData gridDataNotEnabled = new GridData(GridData.FILL, GridData.BEGINNING, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class MultiChoice<T> extends Composite {
private String separator;
private MultiChoiceLabelProvider labelProvider;
private int preferredHeightOfPopup;
private boolean showSelectUnselectAll;

/**
* Constructs a new instance of this class given its parent.
Expand Down Expand Up @@ -176,14 +178,11 @@ private void createGlobalListener() {
}

if (getShell() == event.widget) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (isDisposed()) {
return;
}
handleFocusEvents(SWT.FocusOut);
getDisplay().asyncExec(() -> {
if (isDisposed()) {
return;
}
handleFocusEvents(SWT.FocusOut);
});
}
};
Expand Down Expand Up @@ -1022,8 +1021,7 @@ public void updateSelection() {
return;
}

for (int i = 0; i < this.checkboxes.size(); i++) {
final Button currentButton = this.checkboxes.get(i);
for (final Button currentButton : this.checkboxes) {
if (!currentButton.isDisposed()) {
final Object content = currentButton.getData();
currentButton.setSelection(this.selection.contains(content));
Expand Down Expand Up @@ -1051,7 +1049,18 @@ Shell getPopup() {
*/
private void createPopup() {
this.popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
this.popup.setLayout(new FillLayout());

Composite parent;
if (showSelectUnselectAll) {
popup.setLayout(new FillLayout());
parent = new Composite(popup, SWT.BORDER);
} else {
parent = popup;
}
final GridLayout gridLayout = new GridLayout(2, true);
gridLayout.marginWidth = gridLayout.marginHeight = gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 10;
parent.setLayout(gridLayout);

final int[] popupEvents = { SWT.Close, SWT.Deactivate, SWT.Dispose };
for (final int popupEvent : popupEvents) {
Expand All @@ -1062,7 +1071,24 @@ private void createPopup() {
return;
}

this.scrolledComposite = new ScrolledComposite(this.popup, SWT.BORDER | SWT.V_SCROLL);
if (showSelectUnselectAll) {
final Link selectAllLink = new Link(parent, SWT.NONE);
selectAllLink.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
selectAllLink.setText("<a>" + ResourceManager.getLabel(ResourceManager.SELECT_ALL) + "</a>");
selectAllLink.addListener(SWT.Selection, e -> {
changeButtonState(true);
});

final Link deselectAllLink = new Link(parent, SWT.NONE);
deselectAllLink.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
deselectAllLink.setText("<a>" + ResourceManager.getLabel(ResourceManager.DESELECT_ALL) + "</a>");
deselectAllLink.addListener(SWT.Selection, e -> {
changeButtonState(false);
});
}

this.scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | (showSelectUnselectAll ? SWT.NONE : SWT.BORDER));
this.scrolledComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
final Composite content = new Composite(this.scrolledComposite, SWT.NONE);
content.setLayout(new GridLayout(this.numberOfColumns, true));

Expand Down Expand Up @@ -1107,6 +1133,12 @@ private void createPopup() {
this.preferredHeightOfPopup = content.getSize().y;
}

private void changeButtonState(final boolean checked) {
for (final Button checkBoxButton : checkboxes) {
checkBoxButton.setSelection(checked);
}
}

/**
* Set the value of the label, based on the selected items
*/
Expand Down Expand Up @@ -1374,4 +1406,25 @@ public String getText() {
checkNullElement();
return text.getText();
}

/**
* @return <code>true</code> if the hyperlinks "Select all" and "Deselect all" are displayted
*/
public boolean isShowSelectUnselectAll() {
checkWidget();
return showSelectUnselectAll;
}

/**
* @param showSelectUnselectAll set to "true" to display the hyperlinks "Select all" and "Deselect all"
*/
public void setShowSelectUnselectAll(final boolean showSelectUnselectAll) {
checkWidget();
this.showSelectUnselectAll = showSelectUnselectAll;
if (popup != null && !popup.isDisposed()) {
popup.dispose();
}
createPopup();
}

}

0 comments on commit 8967dc4

Please sign in to comment.