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 | |
15 | package net.sourceforge.hiveboard.dialog; |
16 | |
17 | import javax.swing.JLabel; |
18 | import javax.swing.JPasswordField; |
19 | |
20 | import org.jdesktop.application.Action; |
21 | import org.jdesktop.application.Task; |
22 | |
23 | import net.sourceforge.hiveboard.Account; |
24 | import net.sourceforge.hiveboard.WhiteBoardUserService; |
25 | import net.sourceforge.hiveboard.command.AbstractTask; |
26 | import net.sourceforge.hivegui.component.TextListener; |
27 | |
28 | import zappini.designgridlayout.DesignGridLayout; |
29 | |
30 | public class ChangeAccountPasswordPanel extends AbstractAccountPanel |
31 | { |
32 | static private final String NAME = "account-password"; |
33 | |
34 | public ChangeAccountPasswordPanel(WhiteBoardUserService service, Account target) |
35 | { |
36 | super(NAME); |
37 | _service = service; |
38 | _account = target; |
39 | |
40 | _lblPassword.setName(NAME + "-new-password-label"); |
41 | _pwfPassword.setName(NAME + "-new-password"); |
42 | |
43 | _lblPassword.setLabelFor(_pwfPassword); |
44 | |
45 | DesignGridLayout layout = new DesignGridLayout(this); |
46 | setLayout(layout); |
47 | layout.row().label(_lblPassword).add(_pwfPassword); |
48 | |
49 | TextListener listener = new TextListener() |
50 | { |
51 | @Override protected void contentUpdated() |
52 | { |
53 | setAcceptEnabled(_pwfPassword.getPassword().length != 0); |
54 | } |
55 | }; |
56 | _pwfPassword.getDocument().addDocumentListener(listener); |
57 | } |
58 | |
59 | @Override public void reset() |
60 | { |
61 | _pwfPassword.setText(""); |
62 | setAcceptEnabled(false); |
63 | } |
64 | |
65 | @Action(enabledProperty = "acceptEnabled", block = Task.BlockingScope.WINDOW) |
66 | public Task accept() |
67 | { |
68 | final String pwd = new String(_pwfPassword.getPassword()); |
69 | return new AbstractTask<Void, Void>(_application, _parent) |
70 | { |
71 | @Override protected Void doInBackground() throws Exception |
72 | { |
73 | _service.changeAccountPassword(_account.getId(), pwd); |
74 | return null; |
75 | } |
76 | }; |
77 | } |
78 | |
79 | final private WhiteBoardUserService _service; |
80 | final private JLabel _lblPassword = new JLabel(); |
81 | final private JPasswordField _pwfPassword = new JPasswordField(20); |
82 | } |