root / web_client / src / gr / grnet / pithos / web / client / FileTable.java @ ba0078a6
History | View | Annotate | Download (3.4 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 58777026 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 58777026 | Christos Stathis | *
|
4 | 58777026 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 58777026 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 58777026 | Christos Stathis | * conditions are met:
|
7 | 58777026 | Christos Stathis | *
|
8 | 58777026 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 58777026 | Christos Stathis | * disclaimer.
|
11 | 58777026 | Christos Stathis | *
|
12 | 58777026 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 58777026 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 58777026 | Christos Stathis | * provided with the distribution.
|
16 | 58777026 | Christos Stathis | *
|
17 | 58777026 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 58777026 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 58777026 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 58777026 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 58777026 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 58777026 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 58777026 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 58777026 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 58777026 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 58777026 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 58777026 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 58777026 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 58777026 | Christos Stathis | *
|
30 | 58777026 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 58777026 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 58777026 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 58777026 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ab1eb3f8 | Christos Stathis | */
|
35 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | ab1eb3f8 | Christos Stathis | |
37 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.DOM; |
38 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Element; |
39 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Event; |
40 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Grid; |
41 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
42 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Widget; |
43 | ab1eb3f8 | Christos Stathis | |
44 | ab1eb3f8 | Christos Stathis | |
45 | ab1eb3f8 | Christos Stathis | public class FileTable extends Grid{ |
46 | ab1eb3f8 | Christos Stathis | |
47 | ab1eb3f8 | Christos Stathis | /**
|
48 | ab1eb3f8 | Christos Stathis | *
|
49 | ab1eb3f8 | Christos Stathis | */
|
50 | ab1eb3f8 | Christos Stathis | public FileTable() {
|
51 | ab1eb3f8 | Christos Stathis | super();
|
52 | ab1eb3f8 | Christos Stathis | // TODO Auto-generated constructor stub
|
53 | ab1eb3f8 | Christos Stathis | } |
54 | ab1eb3f8 | Christos Stathis | |
55 | ab1eb3f8 | Christos Stathis | /**
|
56 | ab1eb3f8 | Christos Stathis | * @param rows
|
57 | ab1eb3f8 | Christos Stathis | * @param columns
|
58 | ab1eb3f8 | Christos Stathis | */
|
59 | ab1eb3f8 | Christos Stathis | public FileTable(int rows, int columns) { |
60 | ab1eb3f8 | Christos Stathis | super(rows, columns);
|
61 | ab1eb3f8 | Christos Stathis | // TODO Auto-generated constructor stub
|
62 | ab1eb3f8 | Christos Stathis | } |
63 | ab1eb3f8 | Christos Stathis | |
64 | ab1eb3f8 | Christos Stathis | public int getRowForEvent2(Event event) { |
65 | ab1eb3f8 | Christos Stathis | Element td = getEventTargetCell(event);
|
66 | ab1eb3f8 | Christos Stathis | if (td == null) |
67 | ab1eb3f8 | Christos Stathis | return -1; |
68 | ab1eb3f8 | Christos Stathis | |
69 | ab1eb3f8 | Christos Stathis | Element tr = DOM.getParent(td);
|
70 | ab1eb3f8 | Christos Stathis | Element body = DOM.getParent(tr);
|
71 | ab1eb3f8 | Christos Stathis | int row = DOM.getChildIndex(body, tr);
|
72 | ab1eb3f8 | Christos Stathis | return row;
|
73 | ab1eb3f8 | Christos Stathis | } |
74 | ab1eb3f8 | Christos Stathis | |
75 | ab1eb3f8 | Christos Stathis | public static void copyRow(FileTable sourceTable, FileTable targetTable, int sourceRow, int targetRow) { |
76 | ab1eb3f8 | Christos Stathis | targetTable.insertRow(targetRow); |
77 | ab1eb3f8 | Christos Stathis | for (int col = 0; col < sourceTable.getCellCount(sourceRow); col++) { |
78 | ab1eb3f8 | Christos Stathis | HTML html = new HTML(sourceTable.getHTML(sourceRow, col)); |
79 | ab1eb3f8 | Christos Stathis | targetTable.setWidget(targetRow, col, html); |
80 | ab1eb3f8 | Christos Stathis | } |
81 | ab1eb3f8 | Christos Stathis | copyRowStyle(sourceTable, targetTable, sourceRow, targetRow); |
82 | ab1eb3f8 | Christos Stathis | } |
83 | ab1eb3f8 | Christos Stathis | |
84 | ab1eb3f8 | Christos Stathis | private static void copyRowStyle(FileTable sourceTable, FileTable targetTable, int sourceRow, int targetRow) { |
85 | ab1eb3f8 | Christos Stathis | String rowStyle = sourceTable.getRowFormatter().getStyleName(sourceRow);
|
86 | ab1eb3f8 | Christos Stathis | targetTable.getRowFormatter().setStyleName(targetRow, rowStyle); |
87 | ab1eb3f8 | Christos Stathis | } |
88 | ab1eb3f8 | Christos Stathis | |
89 | ab1eb3f8 | Christos Stathis | public static int getWidgetRow(Widget widget, FileTable table) { |
90 | ab1eb3f8 | Christos Stathis | for (int row = 0; row < table.getRowCount(); row++) |
91 | ab1eb3f8 | Christos Stathis | for (int col = 0; col < table.getCellCount(row); col++) { |
92 | ab1eb3f8 | Christos Stathis | Widget w = table.getWidget(row, col); |
93 | ab1eb3f8 | Christos Stathis | if (w == widget)
|
94 | ab1eb3f8 | Christos Stathis | return row;
|
95 | ab1eb3f8 | Christos Stathis | } |
96 | ab1eb3f8 | Christos Stathis | throw new RuntimeException("Unable to determine widget row"); |
97 | ab1eb3f8 | Christos Stathis | } |
98 | ab1eb3f8 | Christos Stathis | |
99 | ab1eb3f8 | Christos Stathis | } |