Commits

Sebastian Sdorra committed 5215343

added icon for rename action

  • Participants
  • Parent commits 98303a3

Comments (0)

Files changed (4)

File src/main/java/sonia/scm/user/IconServlet.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.user;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.common.io.Closeables;
+import com.google.common.io.Resources;
+import com.google.inject.Singleton;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.net.URL;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@Singleton
+public class IconServlet extends HttpServlet
+{
+
+  /** Field description */
+  private static final String CONTENT_TYPE = "image/png";
+
+  /** Field description */
+  private static final String ICON = "icons/user_rename.png";
+
+  /**
+   * the logger for IconServlet
+   */
+  private static final Logger logger =
+    LoggerFactory.getLogger(IconServlet.class);
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param request
+   * @param response
+   *
+   * @throws IOException
+   * @throws ServletException
+   */
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse response)
+    throws ServletException, IOException
+  {
+
+    URL url = getResource(ICON);
+
+    if (url != null)
+    {
+      response.setContentType(CONTENT_TYPE);
+
+      OutputStream output = null;
+
+      try
+      {
+        output = response.getOutputStream();
+        Resources.copy(url, output);
+      }
+      finally
+      {
+        Closeables.closeQuietly(output);
+      }
+
+    }
+    else
+    {
+      if (logger.isWarnEnabled())
+      {
+        logger.warn("could not find icon {}", ICON);
+      }
+
+      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+    }
+
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param icon
+   *
+   * @return
+   */
+  private URL getResource(String icon)
+  {
+    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+    if (cl == null)
+    {
+      cl = IconServlet.class.getClassLoader();
+    }
+
+    return cl.getResource(icon);
+  }
+}

File src/main/java/sonia/scm/user/UserRenameModule.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.user;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.inject.servlet.ServletModule;
+
+import sonia.scm.plugin.ext.Extension;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@Extension
+public class UserRenameModule extends ServletModule
+{
+
+  /** Field description */
+  private static final String URL =
+    "/resources/plugins/userrename/icons/user_rename.png";
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   */
+  @Override
+  protected void configureServlets()
+  {
+    serve(URL).with(IconServlet.class);
+  }
+}

File src/main/resources/icons/user_rename.png

Added
New image

File src/main/resources/sonia/scm/user/scm.userrename.js

 // override initComponent method of Sonia.repository.Panel
 Ext.override(Sonia.user.Panel, {
   
+  renameIcon: 'resources/plugins/userrename/icons/user_rename.png',
   renameText: 'Rename',
   
+  
   initComponent: function(){
     // call original initComponent method
     this.initComponentExt();
     toolbar.add({
       xtype: 'tbbutton', 
       text: this.renameText, 
-      icon: this.addIcon, 
+      icon: this.renameIcon, 
       scope: this, 
       handler: this.rename
     });