Create folder panel (forgot to add).
authorErik Brakkee <erik@brakkee.org>
Wed, 25 Sep 2013 21:32:14 +0000 (23:32 +0200)
committerErik Brakkee <erik@brakkee.org>
Wed, 25 Sep 2013 21:32:14 +0000 (23:32 +0200)
src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.html [new file with mode: 0644]
src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.java [new file with mode: 0644]

diff --git a/src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.html b/src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.html
new file mode 100644 (file)
index 0000000..c1e5aa2
--- /dev/null
@@ -0,0 +1,26 @@
+<html
+        xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
+<head>
+    <title>Wicket Quickstart Archetype Homepage</title>
+</head>
+<body>
+
+<wicket:panel>
+    <form wicket:id="createFolderForm">
+        <table>
+            <tbody>
+            <tr>
+                <td>
+                    <input wicket:id="name" type="text" size="40"/>
+                </td>
+                <td>
+                    <input type="submit" value="Create folder"/>
+                </td>
+            </tr>
+            </tbody>
+        </table>
+    </form>
+</wicket:panel>
+
+</body>
+</html>
diff --git a/src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.java b/src/main/java/org/wamblee/photos/wicket/CreateFolderPanel.java
new file mode 100644 (file)
index 0000000..547d809
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2005-2011 the original author or authors.
+ * 
+ * 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 org.wamblee.photos.wicket;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.inject.Inject;
+
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.Model;
+import org.wamblee.photos.model.Album;
+import org.wamblee.photos.model.plumbing.AuthorizedPhotos;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: erik
+ * Date: 9/23/13
+ * Time: 8:33 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class CreateFolderPanel extends Panel {
+
+    private static final Logger LOGGER = Logger.getLogger(CreateFolderPanel.class.getName());
+
+    @Inject
+    @AuthorizedPhotos
+    private transient Album _authorized;
+
+    private String _path;
+
+    /**
+     * Upload field.
+     */
+    private TextField _field;
+
+    public CreateFolderPanel(String aId, String aPath) {
+        super(aId);
+
+        _path = aPath;
+
+        Form form = new Form("createFolderForm") {
+            protected void onSubmit() {
+                String folder = _field.getValue();
+                Album album = (Album) _authorized.getEntry(_path);
+                try {
+                    album.addAlbum(folder);
+                    info("Folder '" + folder + "' created");
+                    _field.setModel(new Model());
+                }
+                catch (IOException e) {
+                    error("Could not add folder '" + folder + "'");
+                    LOGGER.log(Level.INFO, "Could not add folder '" + folder + "'", e);
+                }
+            }
+        };
+        add(form);
+        _field = new TextField("name", new Model());
+        form.add(_field);
+    }
+}