Use an exponential backoff strategy for retrying rolled back transactions.
[pithos] / src / gr / ebs / gss / client / CredentialsDialog.java
1 /*
2  * Copyright 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 package gr.ebs.gss.client;
20
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;
32
33
34 /**
35  * A dialog box that displays the user credentials for use in other client
36  * applications, such as WebDAV clients.
37  *
38  * @author kman
39  */
40 public class CredentialsDialog extends DialogBox {
41
42         private final String WIDTH_FIELD = "35em";
43         private final String WIDTH_TEXT = "42em";
44
45         /**
46          * The widget constructor.
47          */
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'
53                 // button.
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/> " +
64                                 webdavUrl + "</p>");
65                 text.setStyleName("gss-AboutText");
66                 text.setWidth(WIDTH_TEXT);
67                 outer.add(text);
68                 FlexTable table = new FlexTable();
69                 table.setText(0, 0, "Username");
70                 table.setText(1, 0, "Token");
71                 TextBox username = new TextBox();
72                 GSS app = GSS.get();
73                 username.setText(app.getCurrentUserResource().getUsername());
74                 username.setReadOnly(true);
75                 username.setWidth(WIDTH_FIELD);
76                 username.addClickListener(new ClickListener () {
77
78                         public void onClick(Widget sender) {
79                                 GSS.enableIESelection();
80                                 ((TextBox) sender).selectAll();
81                                 GSS.preventIESelection();
82                         }
83
84                 });
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 () {
91
92                         public void onClick(Widget sender) {
93                                 GSS.enableIESelection();
94                                 ((TextBox) sender).selectAll();
95                                 GSS.preventIESelection();
96                         }
97
98                 });
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");
104                 outer.add(table);
105
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() {
109
110                         public void onClick(Widget sender) {
111                                 hide();
112                         }
113                 });
114                 outer.add(confirm);
115                 outer.setCellHorizontalAlignment(confirm, HasHorizontalAlignment.ALIGN_CENTER);
116                 outer.setSpacing(8);
117                 setWidget(outer);
118         }
119
120         @Override
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.
124                 switch (key) {
125                         case KeyboardListener.KEY_ENTER:
126                         case KeyboardListener.KEY_ESCAPE:
127                                 hide();
128                                 break;
129                 }
130                 return true;
131         }
132
133 }