2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import com.google.gwt.core.client.GWT;
22 import com.google.gwt.user.client.ui.Button;
23 import com.google.gwt.user.client.ui.ClickListener;
24 import com.google.gwt.user.client.ui.DialogBox;
25 import com.google.gwt.user.client.ui.FlexTable;
26 import com.google.gwt.user.client.ui.HTML;
27 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
28 import com.google.gwt.user.client.ui.KeyboardListener;
29 import com.google.gwt.user.client.ui.TextBox;
30 import com.google.gwt.user.client.ui.VerticalPanel;
31 import com.google.gwt.user.client.ui.Widget;
35 * A dialog box that displays the user credentials for use in other client
36 * applications, such as WebDAV clients.
40 public class CredentialsDialog extends DialogBox {
42 private final String WIDTH_FIELD = "35em";
43 private final String WIDTH_TEXT = "42em";
46 * The widget constructor.
48 public CredentialsDialog() {
49 // Set the dialog's caption.
50 setText("User Credentials");
51 setAnimationEnabled(true);
52 // Create a VerticalPanel to contain the 'about' label and the 'OK'
54 VerticalPanel outer = new VerticalPanel();
55 Configuration conf = (Configuration) GWT.create(Configuration.class);
56 String service = conf.serviceName();
57 String webdavUrl = conf.webdavUrl();
58 String tokenNote = conf.tokenTTLNote();
59 // Create the text and set a style name so we can style it with CSS.
60 HTML text = new HTML("<p>These are the user credentials that are required " +
61 "for interacting with " + service + ". " + tokenNote + " " +
62 "You can copy and paste them in the WebDAV client as username/password," +
63 " in order to use " + service + " through the WebDAV interface, at:<br/> " +
65 text.setStyleName("gss-AboutText");
66 text.setWidth(WIDTH_TEXT);
68 FlexTable table = new FlexTable();
69 table.setText(0, 0, "Username");
70 table.setText(1, 0, "Token");
71 TextBox username = new TextBox();
73 username.setText(app.getCurrentUserResource().getUsername());
74 username.setReadOnly(true);
75 username.setWidth(WIDTH_FIELD);
76 username.addClickListener(new ClickListener () {
78 public void onClick(Widget sender) {
79 GSS.enableIESelection();
80 ((TextBox) sender).selectAll();
81 GSS.preventIESelection();
85 table.setWidget(0, 1, username);
86 TextBox tokenBox = new TextBox();
87 tokenBox.setText(app.getToken());
88 tokenBox.setReadOnly(true);
89 tokenBox.setWidth(WIDTH_FIELD);
90 tokenBox.addClickListener(new ClickListener () {
92 public void onClick(Widget sender) {
93 GSS.enableIESelection();
94 ((TextBox) sender).selectAll();
95 GSS.preventIESelection();
99 table.setWidget(1, 1, tokenBox);
100 table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
101 table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
102 table.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
103 table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
106 // Create the 'OK' button, along with a listener that hides the dialog
107 // when the button is clicked.
108 Button confirm = new Button("Close", new ClickListener() {
110 public void onClick(Widget sender) {
115 outer.setCellHorizontalAlignment(confirm, HasHorizontalAlignment.ALIGN_CENTER);
121 public boolean onKeyDownPreview(char key, int modifiers) {
122 // Use the popup's key preview hooks to close the dialog when either
123 // enter or escape is pressed.
125 case KeyboardListener.KEY_ENTER:
126 case KeyboardListener.KEY_ESCAPE: