Create folder panel (forgot to add).
[photos] / src / main / java / org / wamblee / photos / wicket / CreateFolderPanel.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.photos.wicket;
17
18 import java.io.IOException;
19 import java.util.logging.Level;
20 import java.util.logging.Logger;
21 import javax.inject.Inject;
22
23 import org.apache.wicket.markup.html.form.Form;
24 import org.apache.wicket.markup.html.form.TextField;
25 import org.apache.wicket.markup.html.panel.Panel;
26 import org.apache.wicket.model.Model;
27 import org.wamblee.photos.model.Album;
28 import org.wamblee.photos.model.plumbing.AuthorizedPhotos;
29
30 /**
31  * Created with IntelliJ IDEA.
32  * User: erik
33  * Date: 9/23/13
34  * Time: 8:33 PM
35  * To change this template use File | Settings | File Templates.
36  */
37 public class CreateFolderPanel extends Panel {
38
39     private static final Logger LOGGER = Logger.getLogger(CreateFolderPanel.class.getName());
40
41     @Inject
42     @AuthorizedPhotos
43     private transient Album _authorized;
44
45     private String _path;
46
47     /**
48      * Upload field.
49      */
50     private TextField _field;
51
52     public CreateFolderPanel(String aId, String aPath) {
53         super(aId);
54
55         _path = aPath;
56
57         Form form = new Form("createFolderForm") {
58             protected void onSubmit() {
59                 String folder = _field.getValue();
60                 Album album = (Album) _authorized.getEntry(_path);
61                 try {
62                     album.addAlbum(folder);
63                     info("Folder '" + folder + "' created");
64                     _field.setModel(new Model());
65                 }
66                 catch (IOException e) {
67                     error("Could not add folder '" + folder + "'");
68                     LOGGER.log(Level.INFO, "Could not add folder '" + folder + "'", e);
69                 }
70             }
71         };
72         add(form);
73         _field = new TextField("name", new Model());
74         form.add(_field);
75     }
76 }