KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > dialogs > ToggleValueFieldEditor


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: ToggleValueFieldEditor.java 390 2007-08-19 12:38:23Z mtnminds $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.ui.dialogs;
9
10 import org.eclipse.jface.preference.BooleanFieldEditor;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13
14 /**
15  * Modified BooleanFieldEditor to toggle between two given string values.
16  *
17  * @author Marc R. Hoffmann
18  * @version $Revision: 390 $
19  */

20 class ToggleValueFieldEditor extends BooleanFieldEditor {
21   
22   private final String JavaDoc onvalue;
23   private final String JavaDoc offvalue;
24   private Button checkbox;
25   
26   public ToggleValueFieldEditor(String JavaDoc name, String JavaDoc label, Composite parent,
27                                 String JavaDoc onvalue, String JavaDoc offvalue) {
28     super(name, label, parent);
29     this.onvalue = onvalue;
30     this.offvalue = offvalue;
31   }
32   
33   public Button getChangeControl(Composite parent) {
34     // we need to grap the control here, as the superclass declares it private
35
return checkbox = super.getChangeControl(parent);
36   }
37   
38   protected void doLoad() {
39     if (checkbox != null) {
40       String JavaDoc value = getPreferenceStore().getString(getPreferenceName());
41       checkbox.setSelection(onvalue.equals(value));
42     }
43   }
44   
45   protected void doLoadDefault() {
46     String JavaDoc value = getPreferenceStore().getDefaultString(getPreferenceName());
47     checkbox.setSelection(onvalue.equals(value));
48   }
49   
50   protected void doStore() {
51     if (checkbox != null) {
52       String JavaDoc value = checkbox.getSelection() ? onvalue : offvalue;
53       getPreferenceStore().setValue(getPreferenceName(), value);
54     }
55   }
56     
57 }
58
59   
60
Popular Tags