IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SWT/JFace Java Discussion :

[comboViewer] remplir liste de choix / Récup de ce choix + databinding


Sujet :

SWT/JFace Java

  1. #1
    Membre actif
    Inscrit en
    Juin 2002
    Messages
    409
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 409
    Points : 234
    Points
    234
    Par défaut [comboViewer] remplir liste de choix / Récup de ce choix + databinding
    Bonjour,
    Désolé si doublon. Je créé une 2ieme fois une nouvelle discussion car je ne vois pas celle que je viens de faire.

    Je suis sur le pb depuis plusieurs jours et je craque ! Initialement je veux simplement créer une combo box dans un composite, je veux lier cette combo avec mon data model (classe) pour remplir la liste de choix de la combo et pour binder le choix utilisateur avec le champ object de mon data model.
    Mes contraintes =
    1. tenir dynamiquement à jour la liste de choix de la combo en fonction de la valeur d'une List<Object>. A l'affichage la combo offre les choix String[] suivant Object.getName()
    2. récupérer dynamiquement le choix de l'utilisateur et tenir à jour la valeur d'une primitive (Object) dans une autre classe.


    Voilà.

    Je sens que je tourne autour du pot mais impossible de trouver la solution.
    J'ai essayé un tas de truc. J'arrive à populer la liste de choix de la combo et le binding est ok dans le sens model->UI (dans l'autre sens ??? pour l'instant). Mais impossible de récupérer l'objet correspondant au choix du user et faire le databinding.


    J'ai récupérer ce matin la version Eclipse Neon sensée intégrer les generics sur les comboviewer (voir http://blog.vogella.com/2013/08/12/g...d-tableviewer/), mais non ce n'est pas le cas. Il faut encore télécharger autre chose ?

    Merci d'avance pour vos réponses.
    Cordialement.

  2. #2
    Membre actif
    Inscrit en
    Juin 2002
    Messages
    409
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 409
    Points : 234
    Points
    234
    Par défaut Code
    Bonjour,
    J'ai un peu avancé, et j'ai réussi à binder l'élément selectionné, puis j'ai réécrit mon code pour le "générisé". Le voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
     
    package net.myAppli.graphicInterface.ressources;
     
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.Collection;
    import java.util.List;
     
    import org.eclipse.core.databinding.beans.BeanProperties;
    import org.eclipse.core.databinding.observable.list.IObservableList;
    import org.eclipse.core.databinding.observable.value.IObservableValue;
    import org.eclipse.jface.viewers.ComboViewer;
    import org.eclipse.jface.viewers.ISelectionChangedListener;
    import org.eclipse.jface.viewers.IStructuredContentProvider;
    import org.eclipse.jface.viewers.IStructuredSelection;
    import org.eclipse.jface.viewers.LabelProvider;
    import org.eclipse.jface.viewers.SelectionChangedEvent;
    import org.eclipse.jface.viewers.Viewer;
    import org.eclipse.swt.widgets.Composite;
     
    /**
     * Extension of <i>org.eclipse.jface.viewers.ComboViewer</i> which support data binding for the list of choice and the selected element.
     * The class is generic
     * 
     * @author kase74
     *
     * @param <T> Type of the elements the combo must display.
     */
    public class MyComboViewerDataBinded<T> extends ComboViewer
    {
    	private final ViewModel _viewModel = new ViewModel(); 
     
    	/**
             * Data model to store the list of choice elements and the selected elements by user
             * @author kase74
             *
             * @param <T> Generic support
             */
    	private class ViewModel extends AbstractModelObjectData4JavaBeanSupport
    	{
    		private List<T> _listOfChoices;
    		private T _selectedElement;
     
    		@SuppressWarnings("unused")
    		public List<T> get_listOfChoices() {
    			return _listOfChoices;
    		}
     
    		@SuppressWarnings("unused")
    		public void set_listOfChoices(List<T> listOfChoices) {
    			if(this._listOfChoices==null) 
    			{
    				MyComboViewerDataBinded.this.setInput(listOfChoices); // To set the real content of the comboviewer
    				firePropertyChange("_listOfChoices", _listOfChoices, _listOfChoices = listOfChoices);
    			}
    			else if (! this._listOfChoices.equals(listOfChoices))
    			{
    				MyComboViewerDataBinded.this.setInput(listOfChoices); // To set the real content of the comboviewer
    				firePropertyChange("_listOfChoices", _listOfChoices, _listOfChoices = listOfChoices);
    			}
    		}
     
    		@SuppressWarnings("unused")
    		public T get_selectedElement() {
    			return _selectedElement;
    		}
     
    		public void set_selectedElement(T selectedElement) {
    			if(this._selectedElement == null)
    			{
    //				MyComboViewerDataBinded.this.setSelection(new StructuredSelection(selectedElement)); // To select the real element into the comboviewer
    				firePropertyChange("_selectedElement", _selectedElement, _selectedElement = selectedElement);
    			}
    			else if (! this._selectedElement.equals(selectedElement)) 
    			{
    //				MyComboViewerDataBinded.this.setSelection(new StructuredSelection(selectedElement)); // To select the real element into the comboviewer
    				firePropertyChange("_selectedElement", _selectedElement, _selectedElement = selectedElement);
    			}
    		}
    	}
     
    	/**
             * Label provider adapted to support generic and several label for each element in the list of choice.
             * @author kase74
             *
             */
    	private class MyLabelProvider extends LabelProvider
    	{
    		private final String[] _stringTab;
    		private final String _attributesSeparator = " - "; // represents the separator of attributes for each items string representation
     
    		@SuppressWarnings("unused")
    		private MyLabelProvider()
    		{ // Private constructor to avoid instantiation with no parameter
    			_stringTab = null; // never execute !  Just to avoid the compilation message "The blank final field _stringTab may not have been initialized"
    		}
     
    		protected MyLabelProvider(String attributesAccessors) {
    			super();
    			_stringTab =  attributesAccessors.split(" ");
    		}
     
    	    @SuppressWarnings("unchecked")
    		@Override
    	    public String getText(Object element) {
    			Method method=null;
    			StringBuilder stringbuilder = new StringBuilder();
    			try {
    				for(String s : _stringTab)
    				{
    					if(stringbuilder.length()>0) 
    						stringbuilder.append(_attributesSeparator); // Separator if more than one attribute
    					method = ((T)element).getClass().getMethod(s); // Call the corresponding methods in the T instance object 
    					stringbuilder.append((String) method.invoke(element)); // append of the result to construct the final presentation string to add in the list of choice
    				}
    			} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
    					| NoSuchMethodException | SecurityException e) {
    				e.printStackTrace();
    			}
    	    	return stringbuilder.toString();
    	    }
    	}
     
    	/**
             * Object permitting Java bean data binding to populate items in a combo box and retrieve 
             * the corresponding object of the source list.
             * An IObservableList object can be bind with the widget combo box.
             * 
             * @param parent as org.eclipse.jface.viewers.ComboViewer
             * @param style as org.eclipse.jface.viewers.ComboViewer
             * @param objectList is the list of object the combo box must propose.
             * @param attributesAccessors is a string which enumerate attributes the items must display. 
             * Each accessor must corresponds to the getter method name (e.g. <i>getIndex<i>) and must be 
             * separated by a space character (e.g. <i>getIndex getName<i>). Be careful to syntax and uppercase characters
             */
    	public MyComboViewerDataBinded(Composite parent, int style,
    			List<T> objectList, String attributesAccessors)
    	{
    		super(parent, style);
    		//this.setContentProvider(ArrayContentProvider.getInstance());
    		this.setContentProvider(new IStructuredContentProvider() {
    			@Override
    			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    			}
     
    			@SuppressWarnings("unchecked")
    			@Override
    			public Object[] getElements(Object inputElement) { // identical to ArrayContentProvider.getElements
    				if (inputElement instanceof Object[]) {
    					return (Object[]) inputElement;
    				}
    		        if (inputElement instanceof Collection) {
    					return ((Collection<T>) inputElement).toArray();
    				}
    		        return new Object[0];			}
    		});
     
    		this.setLabelProvider(new MyLabelProvider(attributesAccessors));
    		this.addSelectionChangedListener(new ISelectionChangedListener() {
    			@SuppressWarnings("unchecked")
    			@Override
    			public void selectionChanged(SelectionChangedEvent event) {
    				IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    				if(selection.size()>0)
    					_viewModel.set_selectedElement((T) selection.getFirstElement());
    			}
    		});
    //		_viewModel.set_listOfChoice(objectList); manage by the bean bind with getIObservableList which should be bind with data model
    	}
     
    	@SuppressWarnings("unchecked")
    	public IObservableList<List<T>> getIObservableList()
    	{
    		return BeanProperties.list("_listOfChoices").observe(this._viewModel);
    	}
     
    	@SuppressWarnings("unchecked")
    	public IObservableValue<T> getIObservableValue()
    	{
    		return BeanProperties.value("_selectedElement").observe(this._viewModel);
    	}
     
    }
    Avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
    package net.myAppli.graphicInterface.ressources;
     
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
     
    /**
     * Class used to manage java beans bindings
     * A model should extends this class to create a correct java beans structure
     * 
     * @author Kase74
     *
     */
    abstract class AbstractModelObjectData4JavaBeanSupport {
        protected PropertyChangeSupport _propertyChangeSupport = new PropertyChangeSupport(this);
     
    	public void addPropertyChangeListener(PropertyChangeListener listener) {
            _propertyChangeSupport.addPropertyChangeListener(listener);
        }
     
        public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
            _propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
        }
     
        public void removePropertyChangeListener(PropertyChangeListener listener) {
            _propertyChangeSupport.removePropertyChangeListener(listener);
        }
     
        public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
            _propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
        }
     
        protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
            _propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
        }
    }
    Et pour utiliser tout ça, depuis une classe dérivée de TitleAreaDialog :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    (...)
    	comboJetFanInstalled = new MyComboViewerDataBinded<JetFan>(groupJetFanSelection, SWT.READ_ONLY,
    			mylistOfObjectInModel, "getIndex getName");
     
     
    	IObservableList<JetFan> IOjetFanListInModel = PojoObservables.observeList(mylistOfObjectInModel,"jetFan");
    	bindingContext.bindList(comboJetFanInstalled.getIObservableList(), IOjetFanListInModel, null, null);
     
    	IObservableValue<JetFan> IOjetFanSelectedInModel = PojoProperties.value("fan").observe(_jetFanElement);
    	bindingContext.bindValue(comboJetFanInstalled.getIObservableValue(), IOjetFanSelectedInModel, null, null);
    Voici à quoi ça ressemble :
    Nom : comboViewer.jpg
Affichages : 318
Taille : 7,5 Ko

    Je précise que le binding est correcte pour la valeur de l'objet sélectionné dans les deux sens, la liste de choix est bien chargée à l'init de la fenetre, mais impossible de faire en sorte que la liste de choix de la combo soit mise à jour automatiquement si je modifie la liste d'objet dans le model !!!

    Si vous avez des remarques sur ce qui est écrit, n'hésitez pas.
    Par exemple, PojoObservables.observeList est deprecated, mais je n'ai pas trouvé ce qui lui correspond ...

    Encore merci.
    Cdt.

  3. #3
    Membre actif
    Inscrit en
    Juin 2002
    Messages
    409
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 409
    Points : 234
    Points
    234
    Par défaut
    Bonjour,
    J'ai finalement obtenu quelque chose qui me convient. Je n'aurais pas réussi à binder correctement le update de la liste de choix, mais je vais m'en contenter.
    Je partage donc le composant que j'ai finalisé. Voir code ci-dessous. Tout est correctement commenté (je pense), je ne m'étendrai donc pas sur plus d'explications.

    Si vous avez des remarques ou suggestions, n'hésitez pas. J'aime bien aller au fond des choses (mon côté maniaque), alors si il y a moyen d'optimiser encore, je suis preneur. Dans le même temps ça me perfectionne. Donc merci d'avance.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    package net.zephyr.graphicInterface.ressources;
     
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.List;
     
    import org.eclipse.core.databinding.beans.BeanProperties;
    import org.eclipse.core.databinding.observable.list.IObservableList;
    import org.eclipse.core.databinding.observable.value.IObservableValue;
    import org.eclipse.jface.viewers.ArrayContentProvider;
    import org.eclipse.jface.viewers.ComboViewer;
    import org.eclipse.jface.viewers.ISelectionChangedListener;
    import org.eclipse.jface.viewers.IStructuredSelection;
    import org.eclipse.jface.viewers.LabelProvider;
    import org.eclipse.jface.viewers.SelectionChangedEvent;
    import org.eclipse.jface.viewers.StructuredSelection;
    import org.eclipse.swt.widgets.Composite;
     
    /**
     * Extension of <i>org.eclipse.jface.viewers.ComboViewer</i> which support data binding for the list of choice and the selected element.
     * The class is generic
     * 
     * @author kase74
     *
     * @param <T> Type of the elements the combo must display.
     */
    public class MyComboViewerDataBinded<T> extends ComboViewer
    {
    	private final ViewModel _viewModel = new ViewModel();
    	private List<T> _originalListOfChoices;
    	private final String _attributesAccessors;
     
    	/**
             * Data model to store the list of choice elements and the selected elements by user
             * @author kase74
             *
             * @param <T> Generic support
             */
    	private class ViewModel extends AbstractModelObjectData4JavaBeanSupport
    	{
    		private List<T> _listOfChoices;
    		private T _selectedElement;
     
    		@SuppressWarnings("unused")
    		public List<T> get_listOfChoices() {
    			return _listOfChoices;
    		}
     
    		@SuppressWarnings("unused")
    		public void set_listOfChoices(List<T> listOfChoices) {
    			if(this._listOfChoices==null)
    			{
    				MyComboViewerDataBinded.this.setInput(listOfChoices); // To set the real content of the comboviewer
    				firePropertyChange("_listOfChoices", _listOfChoices, _listOfChoices = listOfChoices);
    			}
    			else if (! this._listOfChoices.equals(listOfChoices))
    			{
    				MyComboViewerDataBinded.this.setInput(listOfChoices); // To set the real content of the comboviewer
    				firePropertyChange("_listOfChoices", _listOfChoices, _listOfChoices = listOfChoices);
    			}
    		}
     
    		public T get_selectedElement() {
    			return _selectedElement;
    		}
     
    		public void set_selectedElement(T selectedElement) {
    			if( (this._selectedElement == null) || (! this._selectedElement.equals(selectedElement)) )
    				firePropertyChange("_selectedElement", _selectedElement, _selectedElement = selectedElement);
    		}
    	}
     
    	/**
             * Label provider adapted to support generic and several label for each element in the list of choice.
             * @author kase74
             *
             */
    	private class MyLabelProvider extends LabelProvider
    	{
    		private final String[] _stringTab;
    		private final String _attributesSeparator = " - "; // represents the separator of attributes for each items string representation
     
    		@SuppressWarnings("unused")
    		private MyLabelProvider()
    		{ // Private constructor to avoid instantiation with no parameter
    			_stringTab = null; // never execute !  Just to avoid the compilation message "The blank final field _stringTab may not have been initialized"
    		}
     
    		protected MyLabelProvider(String attributesAccessors) {
    			super();
    			_stringTab =  attributesAccessors.split(" ");
    		}
     
    	    @SuppressWarnings("unchecked")
    		@Override
    	    public String getText(Object element) {
    			Method method=null;
    			StringBuilder stringbuilder = new StringBuilder();
    			try {
    				for(String s : _stringTab)
    				{
    					if(stringbuilder.length()>0) 
    						stringbuilder.append(_attributesSeparator); // Separator if more than one attribute
    					method = ((T)element).getClass().getMethod(s); // Call the corresponding methods in the T instance object 
    					stringbuilder.append((String) method.invoke(element)); // append of the result to construct the final presentation string to add in the list of choice
    				}
    			} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
    					| NoSuchMethodException | SecurityException e) {
    				e.printStackTrace();
    			}
    	    	return stringbuilder.toString();
    	    }
    	}
     
    	/**
             * Object permitting Java bean data binding to populate items in a combo box and retrieve 
             * the corresponding object of the source list.
             * An IObservableList object can be bind with the widget combo box.
             * 
             * @param parent as org.eclipse.jface.viewers.ComboViewer
             * @param style as org.eclipse.jface.viewers.ComboViewer
             * @param listOfChoices is the list of object the combo box must propose.
             * @param attributesAccessors is a string which enumerate accessors of attributes the items must display.<br> 
             * Each accessor must corresponds to the getter method name of the corresponding field (e.g. <i>getIndex</i>) and must be 
             * separated by a space character (e.g. <i>getIndex getName</i>).<br>
             * Of course, getters must exists in the class of the object, <U>and be careful to syntax and uppercase characters in the string.</U>
             * <p> 
             * usage example :
             * <p><code>// Creation of the object combo viewer :<br>
             * combo = new MyComboViewerDataBinded<Type of the object to list>(widgetParent, SWT.READ_ONLY,
                                    TheList, "getIndex getName");</code><br>
                    (...)<br>
             *      <code>
             * // Make binding of the combo box with a jet fan element list and the selection of one of them.<br>
                    IObservableList<JetFan> jetFanListInModel = PojoProperties.list("jetFan").observe(_scenario.getResources());<br>
                    bindingContext.bindList(combo.getIObservableList(), jetFanListInModel, null, null);<br>
                    <br>
                    IObservableValue<JetFan> jetFanSelectedInModel = PojoProperties.value("fan").observe(_jetFanElement);<br>
                    bindingContext.bindValue(combo.getIObservableValue(), jetFanSelectedInModel, null, null);<br>
                    </code>
                    <p><B>/!\ Be careful : if the model list is changed, the combo doesn't see this change automatically.<br>
                    You have to update the content list with call to :</B><br> 
                    <li>combo.refreshListOfChoices(), if the original list is the same object and just elements insides was updated.</li>
                    <li>combo.changeListOfChoices(List<T> newList), if the object representing the list change.</li><br>
                    <B>otherwise, MyComboViewerDataBinded doesn't work properly. Unfortunately the method comboviewer.setInput() of the mother class is not "overidable" and so impossible to hide.</B>
             */
    	public MyComboViewerDataBinded(Composite parent, int style,
    			List<T> listOfChoices, String attributesAccessors)
    	{
    		super(parent, style);
    		this._originalListOfChoices = listOfChoices;
    		this.setContentProvider(ArrayContentProvider.getInstance());
    		this._attributesAccessors = attributesAccessors;
    		this.setLabelProvider(new MyLabelProvider(attributesAccessors));
    		this.addSelectionChangedListener(new ISelectionChangedListener() {
    			@SuppressWarnings("unchecked")
    			@Override
    			public void selectionChanged(SelectionChangedEvent event) {
    				IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    				if(selection.size()>0)
    					_viewModel.set_selectedElement((T) selection.getFirstElement());
    			}
    		});
    	}
     
    	/**
             * refresh the content list of choices with the original object list passed on creation. 
             * The content of the list should have been changed before. <br>
             * If an item is selected before, the method try to select again the same item after refresh. Tests of equality of items is done on combination of attributes equality.
             */
    	public void refreshListOfChoices()
    	{
    		T selectedElement = this._viewModel.get_selectedElement();
    		this.setInput(_originalListOfChoices);
    		MyComboViewerDataBinded.this.setSelection(null);
    		this.refresh();
    		String[] tab =  this._attributesAccessors.split(" ");
    		Method method=null;
    		boolean testEqual = false;
    		for(T element : _originalListOfChoices)
    		{ // tests equality on combination of attributes equality.
    			testEqual = true;
    			for(String s : tab)
    			{ // Scan all attributes
    				try 
    				{   
    					method = ((T)element).getClass().getMethod(s); // Call the corresponding methods in the T instance object
    					if(!method.invoke(element).equals(method.invoke(selectedElement)))
    					{
    						testEqual = false;
    						break; // Exit from for(String s : tab)
    					}
    				} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
    						| NoSuchMethodException | SecurityException e) {
    					e.printStackTrace();
    				}
    			}
    			if(testEqual)
    			{
    				MyComboViewerDataBinded.this.setSelection(new StructuredSelection(selectedElement)); // To select the real element into the comboviewer
    				break; // Exit from for(T element : _originalListOfChoices)
    			}
    		}
    	}
     
    	/**
             * Change the object list on which the list of choices is based on. The combo lost its selection.
             * @param newList replace the old list.
             */
    	public void changeListOfChoices(List<T> newList)
    	{
    		this.setInput(newList);
    		MyComboViewerDataBinded.this.setSelection(null);
    		_originalListOfChoices = newList;
    		this.refresh();
    	}
     
    	/**
             * @return a bean IObservableList to binding the list of choice of the combo viewer with a data model.<br>
             * <br>
             * usage :<br>
             * <code>bindingContext.bindList(combo.getIObservableList(), <i>DataModelListOfElement</i>, null, null);</code><br>
             */
    	@SuppressWarnings("unchecked")
    	public IObservableList<List<T>> getIObservableList()
    	{
    		return BeanProperties.list("_listOfChoices").observe(this._viewModel);
    	}
     
    	/**
             * @return a bean IObservableValue to binding the selected item of the combo viewer with a data model.<br>
             * <br>
             * usage :<br>
             * <code>bindingContext.bindList(combo.getIObservableValue(), <i>DataModelElementToUpdate</i>, null, null);</code><br>
             */
    	@SuppressWarnings("unchecked")
    	public IObservableValue<T> getIObservableValue()
    	{
    		return BeanProperties.value("_selectedElement").observe(this._viewModel);
    	}
     
    }
    Avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    package net.zephyr.graphicInterface.ressources;
     
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
     
    /**
     * Class used to manage java beans bindings
     * A model should extends this class to create a correct java beans structure
     * 
     * @author Kase74
     *
     */
    abstract class AbstractModelObjectData4JavaBeanSupport {
        protected PropertyChangeSupport _propertyChangeSupport = new PropertyChangeSupport(this);
     
    	public void addPropertyChangeListener(PropertyChangeListener listener) {
            _propertyChangeSupport.addPropertyChangeListener(listener);
        }
     
        public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
            _propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
        }
     
        public void removePropertyChangeListener(PropertyChangeListener listener) {
            _propertyChangeSupport.removePropertyChangeListener(listener);
        }
     
        public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
            _propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
        }
     
        protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
            _propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
        }
    }
    Ca peut toujours servir ...
    A+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. remplir list avec choix de la Combo
    Par Netpasnet dans le forum ASP.NET
    Réponses: 4
    Dernier message: 18/04/2011, 12h44
  2. Réponses: 1
    Dernier message: 11/11/2010, 16h48
  3. liste déroulante : comment rester sur mon choix
    Par sam01 dans le forum Langage
    Réponses: 2
    Dernier message: 09/09/2006, 17h18
  4. Réponses: 8
    Dernier message: 16/06/2006, 18h48
  5. Html : liste de choix par rapport à des choix
    Par Djwaves dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 22/03/2006, 16h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo