Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / CredentialsDialog.java @ 0c665202

History | View | Annotate | Download (5.4 kB)

1 1201686b Christos Stathis
/*
2 1201686b Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 1201686b Christos Stathis
 *
4 1201686b Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 1201686b Christos Stathis
 * without modification, are permitted provided that the following
6 1201686b Christos Stathis
 * conditions are met:
7 1201686b Christos Stathis
 *
8 1201686b Christos Stathis
 *   1. Redistributions of source code must retain the above
9 1201686b Christos Stathis
 *      copyright notice, this list of conditions and the following
10 1201686b Christos Stathis
 *      disclaimer.
11 1201686b Christos Stathis
 *
12 1201686b Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 1201686b Christos Stathis
 *      copyright notice, this list of conditions and the following
14 1201686b Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 1201686b Christos Stathis
 *      provided with the distribution.
16 1201686b Christos Stathis
 *
17 1201686b Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 1201686b Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1201686b Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1201686b Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 1201686b Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 1201686b Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 1201686b Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 1201686b Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1201686b Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1201686b Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 1201686b Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1201686b Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 1201686b Christos Stathis
 *
30 1201686b Christos Stathis
 * The views and conclusions contained in the software and
31 1201686b Christos Stathis
 * documentation are those of the authors and should not be
32 1201686b Christos Stathis
 * interpreted as representing official policies, either expressed
33 1201686b Christos Stathis
 * or implied, of GRNET S.A.
34 1201686b Christos Stathis
 */
35 1201686b Christos Stathis
package gr.grnet.pithos.web.client;
36 1201686b Christos Stathis
37 1201686b Christos Stathis
import com.google.gwt.dom.client.NativeEvent;
38 1201686b Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
39 1201686b Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
40 1201686b Christos Stathis
import com.google.gwt.event.dom.client.KeyCodes;
41 1201686b Christos Stathis
import com.google.gwt.user.client.Event.NativePreviewEvent;
42 f20c8701 Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
43 1201686b Christos Stathis
import com.google.gwt.user.client.ui.Button;
44 1201686b Christos Stathis
import com.google.gwt.user.client.ui.DialogBox;
45 1201686b Christos Stathis
import com.google.gwt.user.client.ui.FlexTable;
46 1201686b Christos Stathis
import com.google.gwt.user.client.ui.HTML;
47 1201686b Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
48 1201686b Christos Stathis
import com.google.gwt.user.client.ui.TextBox;
49 1201686b Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
50 1201686b Christos Stathis
51 1201686b Christos Stathis
52 1201686b Christos Stathis
/**
53 1201686b Christos Stathis
 * A dialog box that displays the user credentials for use in other client
54 1201686b Christos Stathis
 * applications.
55 1201686b Christos Stathis
 */
56 1201686b Christos Stathis
public class CredentialsDialog extends DialogBox {
57 1201686b Christos Stathis
58 1201686b Christos Stathis
        private final String WIDTH_FIELD = "35em";
59 1201686b Christos Stathis
        private final String WIDTH_TEXT = "42em";
60 1201686b Christos Stathis
61 1201686b Christos Stathis
        /**
62 1201686b Christos Stathis
         * The widget constructor.
63 1201686b Christos Stathis
         */
64 ebead1b5 Christos Stathis
        public CredentialsDialog(final Pithos app) {
65 f20c8701 Christos Stathis
                Anchor close = new Anchor();
66 f20c8701 Christos Stathis
                close.addStyleName("close");
67 f20c8701 Christos Stathis
                close.addClickHandler(new ClickHandler() {
68 f20c8701 Christos Stathis
                        
69 f20c8701 Christos Stathis
                        @Override
70 f20c8701 Christos Stathis
                        public void onClick(ClickEvent event) {
71 f20c8701 Christos Stathis
                                hide();
72 f20c8701 Christos Stathis
                        }
73 f20c8701 Christos Stathis
                });
74 1201686b Christos Stathis
                // Set the dialog's caption.
75 1201686b Christos Stathis
                setText("User Credentials");
76 1201686b Christos Stathis
                setAnimationEnabled(true);
77 f20c8701 Christos Stathis
                setGlassEnabled(true);
78 f20c8701 Christos Stathis
                setStyleName("pithos-DialogBox");
79 1201686b Christos Stathis
                // A VerticalPanel that contains the 'about' label and the 'OK' button.
80 1201686b Christos Stathis
                VerticalPanel outer = new VerticalPanel();
81 f20c8701 Christos Stathis
                outer.add(close);
82 f20c8701 Christos Stathis
83 f20c8701 Christos Stathis
                VerticalPanel inner = new VerticalPanel();
84 f20c8701 Christos Stathis
                inner.addStyleName("inner");
85 f20c8701 Christos Stathis
86 1201686b Christos Stathis
                // Create the text and set a style name so we can style it with CSS.
87 1201686b Christos Stathis
                HTML text = new HTML("<p>These are the user credentials that are " +
88 6f608df7 Christos Stathis
                                "required for interacting with Pithos+");
89 1201686b Christos Stathis
                text.setStyleName("pithos-credentialsText");
90 1201686b Christos Stathis
                text.setWidth(WIDTH_TEXT);
91 f20c8701 Christos Stathis
                inner.add(text);
92 1201686b Christos Stathis
                FlexTable table = new FlexTable();
93 1201686b Christos Stathis
                table.setText(0, 0, "Username");
94 1201686b Christos Stathis
                table.setText(1, 0, "Token");
95 1201686b Christos Stathis
                TextBox username = new TextBox();
96 1201686b Christos Stathis
                username.setText(app.getUsername());
97 1201686b Christos Stathis
                username.setReadOnly(true);
98 1201686b Christos Stathis
                username.setWidth(WIDTH_FIELD);
99 1201686b Christos Stathis
                username.addClickHandler(new ClickHandler() {
100 1201686b Christos Stathis
                        @Override
101 1201686b Christos Stathis
                        public void onClick(ClickEvent event) {
102 1201686b Christos Stathis
                                Pithos.enableIESelection();
103 1201686b Christos Stathis
                                ((TextBox) event.getSource()).selectAll();
104 1201686b Christos Stathis
                                Pithos.preventIESelection();
105 1201686b Christos Stathis
                        }
106 1201686b Christos Stathis
107 1201686b Christos Stathis
                });
108 1201686b Christos Stathis
                table.setWidget(0, 1, username);
109 1201686b Christos Stathis
110 1201686b Christos Stathis
                TextBox tokenBox = new TextBox();
111 1201686b Christos Stathis
                tokenBox.setText(app.getToken());
112 1201686b Christos Stathis
                tokenBox.setReadOnly(true);
113 1201686b Christos Stathis
                tokenBox.setWidth(WIDTH_FIELD);
114 1201686b Christos Stathis
                tokenBox.addClickHandler(new ClickHandler() {
115 1201686b Christos Stathis
                        @Override
116 1201686b Christos Stathis
                        public void onClick(ClickEvent event) {
117 1201686b Christos Stathis
                                Pithos.enableIESelection();
118 1201686b Christos Stathis
                                ((TextBox) event.getSource()).selectAll();
119 1201686b Christos Stathis
                                Pithos.preventIESelection();
120 1201686b Christos Stathis
                        }
121 1201686b Christos Stathis
122 1201686b Christos Stathis
                });
123 1201686b Christos Stathis
                table.setWidget(1, 1, tokenBox);
124 1201686b Christos Stathis
125 1201686b Christos Stathis
                table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
126 1201686b Christos Stathis
                table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
127 1201686b Christos Stathis
                table.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
128 1201686b Christos Stathis
                table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
129 f20c8701 Christos Stathis
                inner.add(table);
130 1201686b Christos Stathis
131 1201686b Christos Stathis
                // Create the 'OK' button, along with a listener that hides the dialog
132 1201686b Christos Stathis
                // when the button is clicked.
133 1201686b Christos Stathis
                Button confirm = new Button("Close", new ClickHandler() {
134 1201686b Christos Stathis
                        @Override
135 1201686b Christos Stathis
                        public void onClick(ClickEvent event) {
136 1201686b Christos Stathis
                                hide();
137 1201686b Christos Stathis
                        }
138 1201686b Christos Stathis
                });
139 f20c8701 Christos Stathis
                confirm.addStyleName("button");
140 f20c8701 Christos Stathis
                inner.add(confirm);
141 f20c8701 Christos Stathis
                outer.add(inner);
142 f20c8701 Christos Stathis
                outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
143 1201686b Christos Stathis
                setWidget(outer);
144 1201686b Christos Stathis
        }
145 1201686b Christos Stathis
146 1201686b Christos Stathis
        @Override
147 1201686b Christos Stathis
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
148 1201686b Christos Stathis
                super.onPreviewNativeEvent(preview);
149 1201686b Christos Stathis
                NativeEvent evt = preview.getNativeEvent();
150 1201686b Christos Stathis
                if (evt.getType().equals("keydown"))
151 1201686b Christos Stathis
                        // Use the popup's key preview hooks to close the dialog when
152 1201686b Christos Stathis
                        // either enter or escape is pressed.
153 1201686b Christos Stathis
                        switch (evt.getKeyCode()) {
154 1201686b Christos Stathis
                                case KeyCodes.KEY_ENTER:
155 1201686b Christos Stathis
                                case KeyCodes.KEY_ESCAPE:
156 1201686b Christos Stathis
                                        hide();
157 1201686b Christos Stathis
                                        break;
158 1201686b Christos Stathis
                        }
159 1201686b Christos Stathis
        }
160 1201686b Christos Stathis
}