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.FocusListener;
27 import com.google.gwt.user.client.ui.HTML;
28 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
29 import com.google.gwt.user.client.ui.KeyboardListener;
30 import com.google.gwt.user.client.ui.TextBox;
31 import com.google.gwt.user.client.ui.VerticalPanel;
32 import com.google.gwt.user.client.ui.Widget;
36 * A dialog box that displays the user credentials for use in other client
37 * applications, such as WebDAV clients.
41 public class CredentialsDialog extends DialogBox {
43 private final String WIDTH_FIELD = "35em";
44 private final String WIDTH_TEXT = "42em";
47 * The widget constructor.
49 public CredentialsDialog() {
50 // Set the dialog's caption.
51 setText("User Credentials");
52 setAnimationEnabled(true);
53 // Create a VerticalPanel to contain the 'about' label and the 'OK'
55 VerticalPanel outer = new VerticalPanel();
56 String token = GSS.get().getToken();
59 int contextIndex = GWT.getModuleBaseURL().lastIndexOf("gss/");
60 String webdavUrl = GWT.getModuleBaseURL().substring(0, contextIndex) + "webdav";
61 // Create the text and set a style name so we can style it with CSS.
62 HTML text = new HTML("<p>These are the user credentials that are required " +
63 "for interacting with GSS. You can copy and paste them in the WebDAV " +
64 "client as username/password, in order to use GSS through the WebDAV " +
65 "interface, at:<br/> " + webdavUrl + "</p>");
66 text.setStyleName("gss-AboutText");
67 text.setWidth(WIDTH_TEXT);
69 FlexTable table = new FlexTable();
70 table.setText(0, 0, "Username");
71 table.setText(1, 0, "Token");
72 TextBox username = new TextBox();
73 username.setText(GSS.get().getCurrentUserResource().getUsername());
74 username.setReadOnly(true);
75 username.setWidth(WIDTH_FIELD);
76 username.addFocusListener(new FocusListener() {
77 public void onFocus(Widget sender) {
78 ((TextBox) sender).selectAll();
80 public void onLostFocus(Widget sender) {
81 ((TextBox) sender).setSelectionRange(0, 0);
84 table.setWidget(0, 1, username);
85 TextBox tokenBox = new TextBox();
86 tokenBox.setText(token);
87 tokenBox.setReadOnly(true);
88 tokenBox.setWidth(WIDTH_FIELD);
89 tokenBox.addFocusListener(new FocusListener() {
90 public void onFocus(Widget sender) {
91 ((TextBox) sender).selectAll();
93 public void onLostFocus(Widget sender) {
94 ((TextBox) sender).setSelectionRange(0, 0);
97 table.setWidget(1, 1, tokenBox);
98 table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
99 table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
100 table.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
101 table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
104 // Create the 'OK' button, along with a listener that hides the dialog
105 // when the button is clicked.
106 Button confirm = new Button("Close", new ClickListener() {
108 public void onClick(Widget sender) {
113 outer.setCellHorizontalAlignment(confirm, HasHorizontalAlignment.ALIGN_CENTER);
119 public boolean onKeyDownPreview(char key, int modifiers) {
120 // Use the popup's key preview hooks to close the dialog when either
121 // enter or escape is pressed.
123 case KeyboardListener.KEY_ENTER:
124 case KeyboardListener.KEY_ESCAPE: