My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Copyright 2011 stanislawbartkowski@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.ibm.sampledb.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.SimplePager.Resources;
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ibm.sampledb.shared.GetField;
import com.ibm.sampledb.shared.GetField.FieldValue;
import com.ibm.sampledb.shared.GetRowsInfo;
import com.ibm.sampledb.shared.IResourceType;
import com.ibm.sampledb.shared.OneRecord;

public class AttachmentDialog extends Composite {

private static AttachmentDialogUiBinder uiBinder = GWT
.create(AttachmentDialogUiBinder.class);

@UiField
Label title;

@UiField
Button upload;

@UiField
Button download;

@UiField(provided = true)
SimplePager pager = new SimplePager(TextLocation.LEFT,
(Resources) GWT.create(SimplePager.Resources.class), false, 0, true);

@UiField(provided = true)
final CellTable<OneRecord> table = new CellTable<OneRecord>();

interface AttachmentDialogUiBinder extends
UiBinder<Widget, AttachmentDialog> {
}

private final OneRecord iR;
private final GetRowsInfo rInfo;
private final RecordPresentation rPresentation;

class PutResource implements AsyncCallback<GetRowsInfo> {

@Override
public void onFailure(Throwable caught) {
String mess = M.getM().ErrorMessage();
Window.alert(mess);
}

@Override
public void onSuccess(GetRowsInfo result) {
rPresentation.setRInfo(result);
}

}

private void drawFailure(Throwable caught) {
String mess = M.getM().ErrorMessage();
Window.alert(mess);
}

class DrawList implements AsyncCallback<List<OneRecord>> {

@Override
public void onFailure(Throwable caught) {
drawFailure(caught);
}

@Override
public void onSuccess(List<OneRecord> result) {
rPresentation.drawList(result);
}
}

private void drawList() {
FieldValue empno = GetField.getValue(IResourceType.EMPNO, rInfo, iR);
M.getSampleService().getAttachmentList(empno.getsField(),
new DrawList());
}

public AttachmentDialog(OneRecord iR, GetRowsInfo rInfo) {
initWidget(uiBinder.createAndBindUi(this));
this.iR = iR;
this.rInfo = rInfo;
String l = M.getM().AttachmentInfo();
FieldValue empno = GetField.getValue(IResourceType.EMPNO, rInfo, iR);
FieldValue fName = GetField.getValue(IResourceType.FIRSTNME, rInfo, iR);
FieldValue lName = GetField.getValue(IResourceType.LASTNAME, rInfo, iR);
l += empno.getsField() + " " + fName.getsField() + " "
+ lName.getsField();
title.setText(l);
rPresentation = new RecordPresentation(table, pager, true);
M.getSampleService().getInfo(IResourceType.ATTACHMENTS,
new PutResource());
drawList();
}

private class Close implements IAction {

private PopupDraw p;

@Override
public void execute() {
drawList();
p.hide();
}

public void setP(PopupDraw p) {
this.p = p;
}

}

@UiHandler("upload")
void onUploadClick(ClickEvent event) {
FieldValue empno = GetField.getValue(IResourceType.EMPNO, rInfo, iR);
Close cl = new Close();
PopupDraw p = new PopupDraw(new UploadFile(empno.getsField(), cl), true);
cl.setP(p);
p.draw(event.getClientX(), event.getClientY());
}

private FieldValue getSelected() {
OneRecord selected = rPresentation.getSelected();
if (selected == null) {
Window.alert(M.getM().SelectOne());
return null;

}
FieldValue id = GetField.getValue(IResourceType.ATTACHID,
rPresentation.getrInfo(), selected);
return id;
}

@UiHandler("remove")
void onRemoveClick(ClickEvent event) {
FieldValue id = getSelected();
if (id == null) { return; }
FieldValue filename = GetField.getValue(IResourceType.FILENAME,
rPresentation.getrInfo(), rPresentation.getSelected());
if (!Window.confirm(filename.getsField() + " "
+ M.getM().RemoveQuestion())) {
return;
}
AsyncCallback<Void> callback = new AsyncCallback<Void>() {

@Override
public void onFailure(Throwable caught) {
drawFailure(caught);
}

@Override
public void onSuccess(Void result) {
drawList();
}

};
M.getSampleService().removeAttachment(id.getiField(), callback);

}

private String getLink(FieldValue id) {
String link = GWT.getHostPageBaseURL() + "/downLoadHandler?" + IResourceType.ATTACHID + "=" + id.getiField();
return link;
}

private class DownLoad extends Composite {

private final VerticalPanel vp = new VerticalPanel();


DownLoad(FieldValue id) {
String link = getLink(id);
// Anchor a = new Anchor("Download","/downloadServlet?fileId=123");
Anchor a = new Anchor("Download",link);
vp.add(a);
initWidget(vp);
}
}

@UiHandler("download")
void onDownloadClick(ClickEvent event) {
FieldValue id = getSelected();
if (id == null) { return; }
String link = getLink(id);
// Window.open(link, "123", "");
PopupDraw p = new PopupDraw(new DownLoad(id), false);
Close cl = new Close();
cl.setP(p);
p.draw(event.getClientX(), event.getClientY());
}
}

Change log

r407 by stanislawbartkowski on Jul 6, 2011   Diff
new version with attachments
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 6265 bytes, 222 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting