Classes in this Package | Line Coverage | Branch Coverage | Complexity | ||||||||
FileOverwriteListener |
|
| 2.75;2,75 |
1 | /** |
|
2 | * Redistribution and use in source and binary forms, with or without |
|
3 | * modification, are permitted provided that the following conditions are |
|
4 | * met : |
|
5 | * |
|
6 | * . Redistributions of source code must retain the above copyright |
|
7 | * notice, this list of conditions and the following disclaimer. |
|
8 | * |
|
9 | * . Redistributions in binary form must reproduce the above copyright |
|
10 | * notice, this list of conditions and the following disclaimer in the |
|
11 | * documentation and/or other materials provided with the distribution. |
|
12 | * |
|
13 | * . The name of the author may not be used to endorse or promote products |
|
14 | * derived from this software without specific prior written permission. |
|
15 | * |
|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
25 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
27 | * |
|
28 | * $Id: FileOverwriteListener.java 359 2005-12-23 14:26:53Z mat007 $ |
|
29 | */ |
|
30 | ||
31 | package palmed; |
|
32 | ||
33 | import javax.microedition.lcdui.Display; |
|
34 | import javax.microedition.lcdui.Displayable; |
|
35 | import palmed.file.IFile; |
|
36 | import palmed.file.IFileBrowserListener; |
|
37 | import palmed.ui.ConfirmationDialog; |
|
38 | import palmed.ui.IConfirmationListener; |
|
39 | ||
40 | /** |
|
41 | * This class wraps a file browser listener to prompt the user for confirmation. |
|
42 | * |
|
43 | * @author Mathieu Champlon |
|
44 | * @version $Revision: 359 $ $Date: 2005-12-23 23:26:53 +0900 (ven., 23 déc. 2005) $ |
|
45 | */ |
|
46 | 0 | public final class FileOverwriteListener implements IFileBrowserListener |
47 | { |
|
48 | /** |
|
49 | * The confirmation dialog title. |
|
50 | */ |
|
51 | private static final String TITLE = "File Overwrite Confirmation"; |
|
52 | /** |
|
53 | * The confirmation dialog question. |
|
54 | */ |
|
55 | private static final String QUESTION = "Are you sure you want to overwrite it ?"; |
|
56 | /** |
|
57 | * The display. |
|
58 | */ |
|
59 | private final Display display_; |
|
60 | /** |
|
61 | * The displayable to show upon cancelation. |
|
62 | */ |
|
63 | private final Displayable next_; |
|
64 | /** |
|
65 | * The wrapped listener. |
|
66 | */ |
|
67 | private final IFileBrowserListener listener_; |
|
68 | ||
69 | /** |
|
70 | * Create a file overwrite listener. |
|
71 | * |
|
72 | * @param display the display |
|
73 | * @param next the displayable to show upon cancelation |
|
74 | * @param listener the wrapped listener |
|
75 | */ |
|
76 | public FileOverwriteListener( final Display display, final Displayable next, final IFileBrowserListener listener ) |
|
77 | 0 | { |
78 | 0 | if( display == null ) |
79 | 0 | throw new IllegalArgumentException( "parameter 'display' is null" ); |
80 | 0 | if( next == null ) |
81 | 0 | throw new IllegalArgumentException( "parameter 'next' is null" ); |
82 | 0 | if( listener == null ) |
83 | 0 | throw new IllegalArgumentException( "parameter 'listener' is null" ); |
84 | 0 | display_ = display; |
85 | 0 | next_ = next; |
86 | 0 | listener_ = listener; |
87 | 0 | } |
88 | ||
89 | /** |
|
90 | * {@inheritDoc} |
|
91 | */ |
|
92 | public void select( final IFile file ) |
|
93 | { |
|
94 | 0 | if( !file.exists() ) |
95 | 0 | listener_.select( file ); |
96 | else |
|
97 | { |
|
98 | 0 | final IConfirmationListener listener = new IConfirmationListener() |
99 | { |
|
100 | public void accept() |
|
101 | { |
|
102 | 0 | listener_.select( file ); |
103 | 0 | } |
104 | ||
105 | 0 | public void refuse() |
106 | { |
|
107 | 0 | display_.setCurrent( next_ ); |
108 | 0 | } |
109 | }; |
|
110 | 0 | final String description = "The file " + file.toString() + " already exists."; |
111 | 0 | display_.setCurrent( new ConfirmationDialog( TITLE, description, QUESTION, listener ) ); |
112 | } |
|
113 | 0 | } |
114 | } |