Added an option for user credentials on user menu
authorChristos Stathis <chstath@ebs.gr>
Thu, 6 Oct 2011 16:05:17 +0000 (19:05 +0300)
committerChristos Stathis <chstath@ebs.gr>
Thu, 6 Oct 2011 16:05:17 +0000 (19:05 +0300)
src/gr/grnet/pithos/web/client/CredentialsDialog.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/TopPanel.java
src/gr/grnet/pithos/web/public/gss.css

diff --git a/src/gr/grnet/pithos/web/client/CredentialsDialog.java b/src/gr/grnet/pithos/web/client/CredentialsDialog.java
new file mode 100644 (file)
index 0000000..d294a69
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2011 GRNET S.A. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``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 GRNET S.A 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.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+package gr.grnet.pithos.web.client;
+
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.user.client.Event.NativePreviewEvent;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.DialogBox;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HasHorizontalAlignment;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.VerticalPanel;
+
+
+/**
+ * A dialog box that displays the user credentials for use in other client
+ * applications.
+ */
+public class CredentialsDialog extends DialogBox {
+
+       private final String WIDTH_FIELD = "35em";
+       private final String WIDTH_TEXT = "42em";
+
+       /**
+        * The widget constructor.
+        */
+       public CredentialsDialog(final Pithos app, final MessagePanel.Images images) {
+               // Set the dialog's caption.
+               setText("User Credentials");
+               setAnimationEnabled(true);
+               // A VerticalPanel that contains the 'about' label and the 'OK' button.
+               VerticalPanel outer = new VerticalPanel();
+               // Create the text and set a style name so we can style it with CSS.
+               HTML text = new HTML("<p>These are the user credentials that are " +
+                               "required for interacting with Pithos+");
+               text.setStyleName("pithos-credentialsText");
+               text.setWidth(WIDTH_TEXT);
+               outer.add(text);
+               FlexTable table = new FlexTable();
+               table.setText(0, 0, "Username");
+               table.setText(1, 0, "Token");
+               TextBox username = new TextBox();
+               username.setText(app.getUsername());
+               username.setReadOnly(true);
+               username.setWidth(WIDTH_FIELD);
+               username.addClickHandler(new ClickHandler() {
+                       @Override
+                       public void onClick(ClickEvent event) {
+                               Pithos.enableIESelection();
+                               ((TextBox) event.getSource()).selectAll();
+                               Pithos.preventIESelection();
+                       }
+
+               });
+               table.setWidget(0, 1, username);
+
+               TextBox tokenBox = new TextBox();
+               tokenBox.setText(app.getToken());
+               tokenBox.setReadOnly(true);
+               tokenBox.setWidth(WIDTH_FIELD);
+               tokenBox.addClickHandler(new ClickHandler() {
+                       @Override
+                       public void onClick(ClickEvent event) {
+                               Pithos.enableIESelection();
+                               ((TextBox) event.getSource()).selectAll();
+                               Pithos.preventIESelection();
+                       }
+
+               });
+               table.setWidget(1, 1, tokenBox);
+
+               table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
+               table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
+               table.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
+               table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
+               outer.add(table);
+
+               // Create the 'OK' button, along with a listener that hides the dialog
+               // when the button is clicked.
+               Button confirm = new Button("Close", new ClickHandler() {
+                       @Override
+                       public void onClick(ClickEvent event) {
+                               hide();
+                       }
+               });
+               outer.add(confirm);
+               outer.setCellHorizontalAlignment(confirm, HasHorizontalAlignment.ALIGN_CENTER);
+               outer.setSpacing(8);
+               setWidget(outer);
+       }
+
+       @Override
+       protected void onPreviewNativeEvent(NativePreviewEvent preview) {
+               super.onPreviewNativeEvent(preview);
+               NativeEvent evt = preview.getNativeEvent();
+               if (evt.getType().equals("keydown"))
+                       // Use the popup's key preview hooks to close the dialog when
+                       // either enter or escape is pressed.
+                       switch (evt.getKeyCode()) {
+                               case KeyCodes.KEY_ENTER:
+                               case KeyCodes.KEY_ESCAPE:
+                                       hide();
+                                       break;
+                       }
+       }
+}
index 953f00c..f1842ab 100644 (file)
@@ -93,6 +93,13 @@ public class TopPanel extends Composite {
                                app.logoff();
                        }
                }));
+        userItemMenu.addItem(new MenuItem("API token", new Command() {
+                       
+                       @Override
+                       public void execute() {
+                               new CredentialsDialog(app, images).center();
+                       }
+               }));
         MenuItem userItem = new MenuItem(_app.getUsername(), userItemMenu);
         userItem.addStyleName("pithos-usernameMenu");
         userItem.setWidth("68px");
index 287d20a..f7ccddf 100644 (file)
@@ -216,3 +216,9 @@ table.pithos-permList.props-labels {
     text-align: center;
     color: white;
 }
+
+.pithos-credentialsText {
+       width: 24em;
+       /* Restore the padding we remove when overriding the gwt-DialogBox style */
+       padding: 3px;
+}