EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.dialog]

COVERAGE SUMMARY FOR SOURCE FILE [AccountPanel.java]

nameclass, %method, %block, %line, %
AccountPanel.java100% (3/3)100% (18/18)100% (598/601)99%  (108/109)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountPanel$ModifyAccountTask100% (1/1)100% (3/3)94%  (49/52)92%  (12/13)
failed (Throwable): void 100% (1/1)86%  (19/22)80%  (4/5)
AccountPanel$ModifyAccountTask (AccountPanel, HiveGuiApplicationMain, Generic... 100% (1/1)100% (8/8)100% (3/3)
doInBackground (): Void 100% (1/1)100% (22/22)100% (5/5)
     
class AccountPanel100% (1/1)100% (13/13)100% (495/495)100% (88/88)
AccountPanel (WhiteBoardUserService): void 100% (1/1)100% (6/6)100% (2/2)
AccountPanel (WhiteBoardUserService, Account): void 100% (1/1)100% (7/7)100% (2/2)
AccountPanel (WhiteBoardUserService, Account, boolean): void 100% (1/1)100% (216/216)100% (42/42)
accept (): Task 100% (1/1)100% (11/11)100% (2/2)
access$000 (AccountPanel): JTextField 100% (1/1)100% (3/3)100% (1/1)
access$100 (AccountPanel): JTextField 100% (1/1)100% (3/3)100% (1/1)
access$200 (AccountPanel): boolean 100% (1/1)100% (3/3)100% (1/1)
access$300 (AccountPanel): JPasswordField 100% (1/1)100% (3/3)100% (1/1)
access$400 (AccountPanel): WhiteBoardUserService 100% (1/1)100% (3/3)100% (1/1)
initComponentNames (): void 100% (1/1)100% (136/136)100% (14/14)
refresh (): void 100% (1/1)100% (43/43)100% (10/10)
reset (): void 100% (1/1)100% (14/14)100% (5/5)
updateAccount (): void 100% (1/1)100% (47/47)100% (10/10)
     
class AccountPanel$1100% (1/1)100% (2/2)100% (54/54)100% (8/8)
AccountPanel$1 (AccountPanel): void 100% (1/1)100% (6/6)100% (1/1)
contentUpdated (): void 100% (1/1)100% (48/48)100% (7/7)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveboard.dialog;
16 
17import javax.swing.ButtonGroup;
18import javax.swing.JCheckBox;
19import javax.swing.JLabel;
20import javax.swing.JPasswordField;
21import javax.swing.JRadioButton;
22import javax.swing.JTextField;
23 
24import org.jdesktop.application.Action;
25import org.jdesktop.application.Task;
26 
27import net.sourceforge.hiveboard.Account;
28import net.sourceforge.hiveboard.AccountRole;
29import net.sourceforge.hiveboard.WhiteBoardUserService;
30import net.sourceforge.hiveboard.command.AbstractTask;
31import net.sourceforge.hivegui.application.HiveGuiApplicationMain;
32import net.sourceforge.hivegui.component.TextListener;
33import net.sourceforge.hivegui.dialog.GenericDialog;
34import net.sourceforge.hivetranse.exception.DuplicateKeyException;
35 
36import zappini.designgridlayout.DesignGridLayout;
37import zappini.designgridlayout.Row;
38 
39public class AccountPanel extends AbstractAccountPanel
40{
41        static private final String        NAME_CREATE = "account-creation";
42        static private final String        NAME_MODIFY = "account-modification";
43        
44        public AccountPanel(WhiteBoardUserService service)
45        {
46                this(service, null, true);
47        }
48        
49        public AccountPanel(WhiteBoardUserService service, Account account)
50        {
51                this(service, account.copy(), false);
52        }
53        
54        private AccountPanel(        WhiteBoardUserService        service,
55                                                        Account                                        account,
56                                                        boolean                                        create)
57        {
58                super(create ? NAME_CREATE : NAME_MODIFY);
59                _service = service;
60                _account = account;
61                _create = create;
62                
63                DesignGridLayout layout = new DesignGridLayout(this); 
64                setLayout(layout);
65                
66                initComponentNames();
67 
68                _lblVisa.setLabelFor(_txfVisa);
69                _lblPassword.setLabelFor(_txfPassword);
70                _lblName.setLabelFor(_txfName);
71                _lblEmail.setLabelFor(_txfEmail);
72                _lblRole.setLabelFor(_rbnRoleBasic);
73 
74                ButtonGroup group = new ButtonGroup();
75                group.add(_rbnRoleBasic);
76                group.add(_rbnRoleInitiator);
77                
78                // Add widgets to the panel
79                layout.row().label(_lblVisa).add(_txfVisa).add(Row.EMPTY);
80                if (_create)
81                {
82                        layout.row().label(_lblPassword).add(_txfPassword).add(Row.EMPTY);
83                }
84                layout.row().label(_lblName).add(_txfName);
85                layout.row().label(_lblEmail).add(_txfEmail);
86                layout.row().label(_lblRole).add(_rbnRoleBasic).add(_rbnRoleInitiator);
87                layout.row().add(_cbxAdmin);
88 
89                TextListener listener = new TextListener()
90                {
91                        @Override protected void contentUpdated()
92                        {
93                                boolean enabled = true;
94                                if (        _txfVisa.getText() == null
95                                        ||        _txfVisa.getText().length() == 0
96                                        ||        _txfName.getText() == null
97                                        ||        _txfName.getText().length() == 0)
98                                {
99                                        enabled = false;
100                                }
101                                if (        _create
102                                        &&        (        _txfPassword.getPassword() == null
103                                                ||        _txfPassword.getPassword().length == 0))
104                                {
105                                        enabled = false;
106                                }
107                                setAcceptEnabled(enabled);
108                        }
109                };
110 
111                _txfVisa.getDocument().addDocumentListener(listener);
112                _txfPassword.getDocument().addDocumentListener(listener);
113                _txfName.getDocument().addDocumentListener(listener);
114 
115                if (!_create)
116                {
117                        _lblPassword.setVisible(false);
118                        _txfPassword.setVisible(false);
119                }
120        }
121        
122        private void initComponentNames()
123        {
124                String name = getName();
125                _lblVisa.setName(name + "-visa-label");
126                _txfVisa.setName(name + "-visa");
127                _lblPassword.setName(name + "-password-label");
128                _txfPassword.setName(name + "-password");
129                _lblName.setName(name + "-name-label");
130                _txfName.setName(name + "-name");
131                _lblEmail.setName(name + "-email-label");
132                _txfEmail.setName(name + "-email");
133                _cbxAdmin.setName(name + "-isadmin");
134                _lblRole.setName(name + "-role-label");
135                _rbnRoleBasic.setName(name + "-role-basic");
136                _rbnRoleInitiator.setName(name + "-role-initiator");
137        }
138 
139        @Override public void reset()
140        {
141                if (_create)
142                {
143                        // If dialog for account creation, reinitialize a new Account
144                        _account = new Account();
145                        setAcceptEnabled(false);
146                }
147                refresh();
148        }
149        
150        @Action(enabledProperty = "acceptEnabled", block = Task.BlockingScope.WINDOW)
151        public Task accept()
152        {
153                updateAccount();
154                return new ModifyAccountTask(_application, _parent);
155        }
156 
157        private void        updateAccount()
158        {
159                _account.setVisa(_txfVisa.getText());
160                _account.setPassword(new String(_txfPassword.getPassword()));
161                _account.setName(_txfName.getText());
162                _account.setEmail(_txfEmail.getText());
163                if (_rbnRoleInitiator.isSelected())
164                {
165                        _account.setRole(AccountRole.INITIATOR);
166                }
167                else
168                {
169                        _account.setRole(AccountRole.BASIC);
170                }
171                _account.setAdmin(_cbxAdmin.isSelected());
172        }
173        
174        private void        refresh()
175        {
176                _txfVisa.setText(_account.getVisa());
177                _txfPassword.setText("");
178                _txfName.setText(_account.getName());
179                _txfEmail.setText(_account.getEmail());
180                if (_account.getRole() == AccountRole.BASIC)
181                {
182                        _rbnRoleBasic.setSelected(true);
183                }
184                else
185                {
186                        _rbnRoleInitiator.setSelected(true);
187                }
188                _cbxAdmin.setSelected(_account.isAdmin());
189        }
190        
191        private class ModifyAccountTask extends AbstractTask<Void, Void>
192        {
193                public ModifyAccountTask(HiveGuiApplicationMain application, GenericDialog parent)
194                {
195                        super(application, parent);
196                }
197 
198                @Override protected Void doInBackground() throws Exception
199                {
200                        if (_account.getId() == 0)
201                        {
202                                _service.createAccount(_account);
203                        }
204                        else
205                        {
206                                _service.modifyAccount(_account);
207                        }
208                        return null;
209                }
210 
211                @Override protected void failed(Throwable cause)
212                {
213                        if (cause instanceof DuplicateKeyException)
214                        {
215                                // Display Message
216                                _application.showMessage("duplicate-account-visa", _account.getVisa());
217                        }
218                        else
219                        {
220                                super.failed(cause);
221                        }
222                }
223        }
224        
225        private final WhiteBoardUserService        _service;
226        private final boolean                                _create;
227        private final JLabel                                _lblVisa = new JLabel();
228        private final JTextField                        _txfVisa = new JTextField();
229        private final JLabel                                _lblPassword = new JLabel();
230        private final JPasswordField                _txfPassword = new JPasswordField();
231        private final JLabel                                _lblName = new JLabel();
232        private final JTextField                        _txfName = new JTextField();
233        private final JLabel                                _lblEmail = new JLabel();
234        private final JTextField                        _txfEmail = new JTextField();
235        private final JLabel                                _lblRole = new JLabel();
236        private final JRadioButton                        _rbnRoleBasic = new JRadioButton();
237        private final JRadioButton                        _rbnRoleInitiator = new JRadioButton();
238        private final JCheckBox                                _cbxAdmin = new JCheckBox();
239}

[all classes][net.sourceforge.hiveboard.dialog]
EMMA 2.0.5312 (C) Vladimir Roubtsov