Subversion Repository Public Repository

litesoft

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
/*
 * Copyright 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.gen2.table.client;

import java.util.*;

import com.google.gwt.core.client.*;
import com.google.gwt.user.client.ui.*;

/**
 * An {@link InlineCellEditor} that allows the user to select a {@link String}
 * from a list of {@link RadioButton RadioButtons}.
 *
 * @param <ColType> the data type of the column
 */
public class RadioCellEditor<ColType> extends InlineCellEditor<ColType>
{
    /**
     * A mapping of {@link RadioButton RadioButtons} to the value for the buttons.
     */
    private Map<RadioButton, ColType> radioMap = new HashMap<RadioButton, ColType>();

    /**
     * The vertical panel used to layout the contents.
     */
    private VerticalPanel vpanel = new VerticalPanel();

    /**
     * Construct a new {@link RadioCellEditor}.
     */
    public RadioCellEditor()
    {
        this( GWT.<InlineCellEditorImages>create( InlineCellEditorImages.class ) );
    }

    /**
     * Construct a new {@link RadioCellEditor} with the specified images.
     *
     * @param images the images to use for the accept/cancel buttons
     */
    public RadioCellEditor( InlineCellEditorImages images )
    {
        this( new VerticalPanel(), images );
    }

    /**
     * Constructor.
     *
     * @param images the images to use for the accept/cancel buttons
     */
    private RadioCellEditor( VerticalPanel vPanel, InlineCellEditorImages images )
    {
        super( vPanel, images );
        this.vpanel = vPanel;
    }

    /**
     * Add a {@link RadioButton} to the editor.
     *
     * @param radio the radio button to add
     * @param value the value associated with the {@link RadioButton}
     */
    public void addRadioButton( RadioButton radio, ColType value )
    {
        vpanel.add( radio );
        radioMap.put( radio, value );
    }

    @Override
    public void editCell( CellEditInfo cellEditInfo, ColType cellValue, Callback<ColType> callback )
    {
        super.editCell( cellEditInfo, cellValue, callback );
        Iterator<Widget> it = vpanel.iterator();
        while ( it.hasNext() )
        {
            RadioButton radio = (RadioButton) it.next();
            if ( radio.getValue() )
            {
                radio.setFocus( true );
                return;
            }
        }
    }

    /**
     * Insert a {@link RadioButton} at the specified index.
     *
     * @param radio       the radio button to add
     * @param value       the value associated with the {@link RadioButton}
     * @param beforeIndex the index before which it will be inserted
     *
     * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of
     *                                   range
     */
    public void insertRadioButton( RadioButton radio, ColType value, int beforeIndex )
            throws IndexOutOfBoundsException
    {
        vpanel.insert( radio, beforeIndex );
        radioMap.put( radio, value );
    }

    /**
     * Remove a {@link RadioButton} from the editor.
     *
     * @param radio the radio button to remove
     */
    public void removeRadioButton( RadioButton radio )
    {
        vpanel.remove( radio );
        radioMap.remove( radio );
    }

    @Override
    protected ColType getValue()
    {
        Iterator<Widget> it = vpanel.iterator();
        while ( it.hasNext() )
        {
            RadioButton radio = (RadioButton) it.next();
            if ( radio.getValue() )
            {
                return radioMap.get( radio );
            }
        }
        return null;
    }

    @Override
    protected void setValue( ColType cellValue )
    {
        for ( Map.Entry<RadioButton, ColType> entry : radioMap.entrySet() )
        {
            if ( entry.getValue().equals( cellValue ) )
            {
                entry.getKey().setValue( true );
            }
            else
            {
                entry.getKey().setValue( false );
            }
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/RadioCellEditor.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

475 Diff Diff GeorgeS picture GeorgeS Sat 03 Sep, 2011 13:54:51 +0000
282 GeorgeS picture GeorgeS Fri 17 Jun, 2011 13:54:39 +0000