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 String token = GSS.get().getToken();
58 int contextIndex = GWT.getModuleBaseURL().lastIndexOf("gss/");
59 String webdavUrl = GWT.getModuleBaseURL().substring(0, contextIndex) + "webdav";
60 Configuration conf = (Configuration) GWT.create(Configuration.class);
61 String service = conf.serviceName();
62 // Create the text and set a style name so we can style it with CSS.
63 HTML text = new HTML("<p>These are the user credentials that are required " +
64 "for interacting with " + service + ". You can copy and paste them in the WebDAV " +
65 "client as username/password, in order to use " + service + " through the WebDAV " +
66 "interface, at:<br/> " + webdavUrl + "</p>");
67 text.setStyleName("gss-AboutText");
68 text.setWidth(WIDTH_TEXT);
70 FlexTable table = new FlexTable();
71 table.setText(0, 0, "Username");
72 table.setText(1, 0, "Token");
73 TextBox username = new TextBox();
74 username.setText(GSS.get().getCurrentUserResource().getUsername());
75 username.setReadOnly(true);
76 username.setWidth(WIDTH_FIELD);
77 username.addClickListener(new ClickListener () {
79 public void onClick(Widget sender) {
80 GSS.enableIESelection();
81 ((TextBox) sender).selectAll();
82 GSS.preventIESelection();
86 table.setWidget(0, 1, username);
87 TextBox tokenBox = new TextBox();
88 tokenBox.setText(token);
89 tokenBox.setReadOnly(true);
90 tokenBox.setWidth(WIDTH_FIELD);
91 tokenBox.addClickListener(new ClickListener () {
93 public void onClick(Widget sender) {
94 GSS.enableIESelection();
95 ((TextBox) sender).selectAll();
96 GSS.preventIESelection();
100 table.setWidget(1, 1, tokenBox);
101 table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
102 table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
103 table.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
104 table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
107 // Create the 'OK' button, along with a listener that hides the dialog
108 // when the button is clicked.
109 Button confirm = new Button("Close", new ClickListener() {
111 public void onClick(Widget sender) {
116 outer.setCellHorizontalAlignment(confirm, HasHorizontalAlignment.ALIGN_CENTER);
122 public boolean onKeyDownPreview(char key, int modifiers) {
123 // Use the popup's key preview hooks to close the dialog when either
124 // enter or escape is pressed.
126 case KeyboardListener.KEY_ENTER:
127 case KeyboardListener.KEY_ESCAPE: