Home » Eclipse Projects » Eclipse Platform » Radio Buttons on Wizards 
| Radio Buttons on Wizards [message #68465] | 
Mon, 09 June 2003 18:57   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Is it possible to get several groups of Radio buttons on a Wizard page. I 
cannot find a way to do so. For example, this is what i am trying to do on 
a single Wizard page. 
Ask the User 2 questions:- 
Question 1 
Choices Y or N 
 
Question 2 
Choices Y or N. 
 
However the Wizard control page allows either 1 of the 4 radio buttons to 
be selected. I want the Page to allow Y or No for Question 1 AND allow Y 
or No for Question 2 to be selected.
 |  
 |  
  |   |  
| Re: Radio Buttons on Wizards [message #68568 is a reply to message #68494] | 
Mon, 09 June 2003 22:22   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: pdrolet.mac.com 
 
Or more easily, I think, is by using a class that extends  
FieldEditorPreferencePage and in the createFieldEditors method, you add  
2 RadioGroupFieldEditor. Here is a snippet (code not cleaned...):  
 
 
********* 
package ca.infodata.fmedx.preferences; 
 
import java.util.Calendar; 
 
import org.eclipse.jface.preference.*; 
import org.eclipse.ui.IWorkbenchPreferencePage; 
import org.eclipse.ui.IWorkbench; 
import org.eclipse.jface.preference.IPreferenceStore; 
import org.eclipse.swt.events.VerifyListener; 
import org.eclipse.jface.util.PropertyChangeEvent; 
import org.eclipse.jface.util.IPropertyChangeListener; 
import org.eclipse.swt.widgets.*; 
import org.eclipse.swt.events.VerifyEvent; 
import org.eclipse.swt.events.MouseEvent; 
import org.eclipse.swt.events.MouseListener; 
 
import org.apache.commons.validator.GenericValidator; 
import org.apache.commons.lang.StringUtils; 
 
import ca.infodata.fmedx.FmedxPlugin; 
import ca.infodata.util.Vfp; 
import ca.infodata.util.Messages; 
import ca.infodata.fmedx.listeners.*; 
 
/** 
  * This class represents a preference page that 
  * is contributed to the Preferences dialog. By 
  * subclassing <samp>FieldEditorPreferencePage</samp>, we 
  * can use the field support built into JFace that allows 
  * us to create a page that is small and knows how to 
  * save, restore and apply itself. 
  * <p> 
  * This page is used to modify preferences only. They 
  * are stored in the preference store that belongs to 
  * the main plug-in class. That way, preferences can 
  * be accessed directly via the preference store. 
  */ 
 
public class AgencePreferencePage extends MyPreferencePage { 
	 
	public static final String P_AGENCE = "agence"; 
	public static final String P_PASSEAGENCE = "passeAgence"; 
	public static final String P_LOGONID = "logonId"; 
	public static final String P_LICENCE = "licence";	// 1 ou 2 
	public static final String P_NBMD = "nbMd"; 
	public static final String P_DATEFIN = "dateFin"; 
	public static final String P_MOT1 = "mot1"; 
	public static final String P_MOT2 = "mot2"; 
	 
	NumberField agence; 
// NumberField is an extension of StringFieldEditor 
	StringFieldEditor passeagence; 
	LimitField logonid; 
// LimitField is an extension of StringFieldEditor that limit the  
length of the entered data  
 
	DateFinField dateFin; 
// DateFinField is an extension of StringFieldEditor for dates (calls a  
calendar, configure keyboard)  
 
	RadioGroupFieldEditor licence; 
	String sLicence; 
	int intLicenceValue; 
	RadioGroupFieldEditor nbmd; 
	String sNbMd; 
	int intNbMd; 
	NumberField mot1; 
	NumberField mot2; 
	 
	boolean modAdmin=false; 
	 
	public AgencePreferencePage() { 
		super(GRID); 
		System.out.println("Apres le super"); 
		Vfp.ps_modeAdmin=false; 
		setDescription("Donnees sur l'agence cliente de Logiciels INFO-DATA inc."); 
		initializeDefaults(); 
	} 
/** 
  * Sets the default values of the preferences. 
  */ 
	private void initializeDefaults() { 
		System.out.println("initializeDefaults"); 
		IPreferenceStore store = getPreferenceStore(); 
		store.setDefault(P_AGENCE, ""); 
		store.setDefault(P_PASSEAGENCE, "motPasse"); 
		store.setDefault(P_LICENCE, "moduleActe"); 
		store.setDefault(P_NBMD, "nbMd2"); 
		store.setDefault(P_DATEFIN, Vfp.dtoc(Calendar.getInstance()) ); 
		store.setDefault(P_MOT1,"" ); 
		store.setDefault(P_MOT2, ""); 
	} 
	public void performDefaults() { 
		super.performDefaults(); 
	} 
	 
	public void createFieldEditors() { 
		IPreferenceStore store = getPreferenceStore(); 
		sLicence = store.getString(P_LICENCE); 
		sNbMd = store.getString(P_NBMD); 
 
		agence = new NumberField(P_AGENCE, "Numero d'agence (5  
chiffres):",6,5,0, getFieldEditorParent());  
 
		 agence.getTextControl(getFieldEditorParent()).addMouseListen er(new  
MouseListener(){  
 
			public void mouseDoubleClick(MouseEvent arg0) {} 
			public void mouseDown(MouseEvent me) { 
				System.out.println("Cle="+me.stateMask); 
				if (me.stateMask==393216) {	//CTRL+MAJ for debugging purposes... 
					System.out.println("ModAdmin..."); 
					modAdmin=true; 
					setValid(true); 
					performApply(); 
					checkState(); 
				} 
			} 
			public void mouseUp(MouseEvent arg0) {} 
		}); 
						 
		addField(agence); 
		 
		passeagence = new StringFieldEditor(P_PASSEAGENCE, "Mot de passe de  
l'agence (respecter la casse!):",11, getFieldEditorParent());  
 
		addField(passeagence); 
 
/*****  HERE IS THE RADIOGROUPFIELD THAT YOU WANT *********/ 
/* it has a title "Type de licence" and each choice has a label */ 
		licence = new RadioGroupFieldEditor(P_LICENCE, "Type de  
licence:",1,new String[][] { { "Facturation a l'acte  
seulement","moduleActe"},{"Tous les modules de facturation (acte, fixe,  
tarif horaire, vacation, RMX)","moduleTous"}},  
getFieldEditorParent(),true);  
 
		addField(licence); 
 
/* another one with more choices on 2 columns instead of one */ 
		nbmd = new RadioGroupFieldEditor(P_NBMD, "Nombre de medecins:",2,new  
String[][] { { "Un ou 2 medecins","nbMd2"},{"Trois ou 4  
medecins","nbMd4"},{"Cinq a 9 medecins","nbMd9"},{"Nombre illimite de  
medecins","nbMds"}}, getFieldEditorParent(),true);  
 
		addField(nbmd); 
 
		dateFin = new DateFinField(P_DATEFIN, "Date de fin de location  
(format AAAA/MM/JJ):",11,0, getFieldEditorParent());  
 
		addField(dateFin); 
		 
		mot1 = new NumberField(P_MOT1, "Premier mot de passe:",  
26,24,0,getFieldEditorParent());  
 
		addField(mot1); 
		 
		mot2 = new NumberField(P_MOT2, "Deuxieme mot de passse:",26,12,0,  
getFieldEditorParent());  
 
		addField(mot2); 
 
	} 
	 
	public void performApply () { 
		System.out.println("isValid de page"); 
		boolean valid; 
		if (modAdmin){ 
			System.out.println("isValid modAdmin"); 
			// en mode admin, il met les valeurs dans les variables static ds Vfp 
			valid = Vfp.validLocation( 
			agence.getStringValue(), 
			passeagence.getStringValue(), 
			dateFin.getStringValue(), 
			sLicence, 
			sNbMd, 
			mot1.getStringValue(), 
			mot2.getStringValue(),true 
			); 
			passeagence.setStringValue(Vfp.ps_passeAgence); 
			mot1.setStringValue(Vfp.ps_mot1); 
			mot2.setStringValue(Vfp.ps_mot2); 
			return; 
		} else { 
			System.out.println("isValid non admin"); 
			valid = Vfp.validLocation( 
			agence.getStringValue(), 
			passeagence.getStringValue(), 
			dateFin.getStringValue(), 
			sLicence, 
			sNbMd, 
			mot1.getStringValue(), 
			mot2.getStringValue() 
			); 
		} 
		if (valid){ 
			// isValid verifie les valeurs separement 
			if (okToLeave()){ 
				// okToLeave call validLocation 
				Messages.infoAlert("Preferences Factura-MedX", "Les parametres sont  
valides!");  
 
			} else { 
				Messages.warningAlert("Preferences Factura-MedX", "Les parametres  
ne sont PAS valides! Veuillez les corriger.");  
 
			} 
		} else { 
			Messages.warningAlert("Preferences Factura-MedX", "Les parametres ne  
sont PAS valides! Veuillez les corriger.");  
 
		} 
		 
	} 
 
	public void propertyChange(PropertyChangeEvent e) { 
		System.out.println("PropertyChangeEvent"); 
		if (e.getSource() instanceof StringFieldEditor) { 
 
		} else if (e.getSource() instanceof RadioGroupFieldEditor) { 
			String p = ((RadioGroupFieldEditor)e.getSource()).getPreferenceName(); 
			if (p.equals(P_LICENCE)) { 
				sLicence = e.getNewValue().toString(); 
			} else if (p.equals(P_NBMD)) { 
				sNbMd = e.getNewValue().toString(); 
			} 
		} 
		checkState(); 
	} 
 
	public boolean okToLeave() { 
		return true; 
	} 
	class AgenceField extends IntegerFieldEditor { 
		public AgenceField (String name, String labelText, int width, int  
strategy, Composite parent){  
 
			super(name,labelText,parent,5); 
			setErrorMessage("No d'agence non valide!"); 
		} 
		public boolean isValid() { 
			return true; 
		} 
	} 
		 
} 
 
 
****************** 
AND myPreferencePage starts like this (and I added some personnal  
functions into it):  
 
 
public class MyPreferencePage 
	extends FieldEditorPreferencePage 
	implements IWorkbenchPreferencePage, IPropertyChangeListener { 
 
	public VerifyListener dateVerifyListener = DateVerifyListener.getListener(); 
	public VerifyListener numberVerifyListener =  
NumberVerifyListener.getInstance();  
 
	public MouseListener dateMouseListener = DateMouseListener.getInstance(); 
		 
	public MyPreferencePage(int style) { 
		super(style);	// GRID 
		 setPreferenceStore(FmedxPlugin.getDefault().getPreferenceSto re()); 
	} 
 
 
 
I hope this helps! 
 
Patrice Drolet
 |  
 |  
  |   
Goto Forum:
 
 Current Time: Mon Nov 03 20:47:05 EST 2025 
 Powered by  FUDForum. Page generated in 0.25562 seconds  
 |