Revision 3189
Added by berkley almost 18 years ago
lib/ajax/.classpath | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="src" path="test"/> |
|
5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
6 |
<classpathentry kind="lib" path="/Users/berkley/tools/gwt-mac-1.3.3/gwt-user.jar"/> |
|
7 |
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/> |
|
8 |
<classpathentry kind="lib" path="/metacat/lib/metacat-client.jar"/> |
|
9 |
<classpathentry kind="output" path="bin"/> |
|
10 |
</classpath> |
|
0 | 11 |
lib/ajax/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8" ?> |
|
2 |
<projectDescription> |
|
3 |
<name>kepler-web</name> |
|
4 |
<comment>kepler-web project</comment> |
|
5 |
<projects/> |
|
6 |
<buildSpec> |
|
7 |
<buildCommand> |
|
8 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
9 |
<arguments/> |
|
10 |
</buildCommand> |
|
11 |
</buildSpec> |
|
12 |
<natures> |
|
13 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
14 |
</natures> |
|
15 |
</projectDescription> |
|
0 | 16 |
lib/ajax/KeplerClient-shell | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
APPDIR=`dirname $0`; |
|
3 |
java -cp "$APPDIR/src:$APPDIR/bin:/home/berkley/tools/gwt/gwt-user.jar:/home/berkley/tools/gwt/gwt-dev.jar:/home/berkley/project/kepler-web/lib/client.jar:/home/berkley/project/kepler-web/lib/utilities.jar:/home/berkley/project/kepler-web/lib/xalan.jar:/home/berkley/project/kepler-web/lib/xml-apis.jar" com.google.gwt.dev.GWTShell -out "$APPDIR/www" "$@" org.kepler.web.KeplerClient/KeplerClient.html; |
|
0 | 4 |
lib/ajax/KeplerClient-compile | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
APPDIR=`dirname $0`; |
|
3 |
java -cp "$APPDIR/src:$APPDIR/bin:/home/berkley/tools/gwt/gwt-servlet.jar:/home/berkley/tools/gwt/gwt-user.jar:/home/berkley/tools/gwt/gwt-dev.jar:/home/berkley/project/kepler-web/lib/client.jar:/home/berkley/project/kepler-web/lib/utilities.jar" com.google.gwt.dev.GWTCompiler -out "$APPDIR/www" "$@" org.kepler.web.KeplerClient; |
|
0 | 4 |
lib/ajax/src/org/kepler/web/KeplerClient.gwt.xml | ||
---|---|---|
1 |
<module> |
|
2 |
|
|
3 |
<!-- Inherit the core Web Toolkit stuff. --> |
|
4 |
<inherits name='com.google.gwt.user.User'/> |
|
5 |
|
|
6 |
<!-- Specify the app entry point class. --> |
|
7 |
<entry-point class='org.kepler.web.client.KeplerClient'/> |
|
8 |
|
|
9 |
<servlet path="/kepler" class="org.kepler.web.service.KeplerServiceServlet"/> |
|
10 |
</module> |
|
0 | 11 |
lib/ajax/src/org/kepler/web/service/KeplerServiceServlet.java | ||
---|---|---|
1 |
package org.kepler.web.service; |
|
2 |
|
|
3 |
import com.google.gwt.user.client.rpc.*; |
|
4 |
import com.google.gwt.user.server.rpc.*; |
|
5 |
|
|
6 |
import org.kepler.web.client.*; |
|
7 |
|
|
8 |
import edu.ucsb.nceas.metacat.client.*; |
|
9 |
|
|
10 |
import org.w3c.dom.Document; |
|
11 |
import org.w3c.dom.Node; |
|
12 |
import org.w3c.dom.NodeList; |
|
13 |
import org.apache.xpath.XPathAPI; |
|
14 |
import javax.xml.parsers.DocumentBuilder; |
|
15 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
16 |
import org.xml.sax.InputSource; |
|
17 |
|
|
18 |
import java.io.*; |
|
19 |
import java.util.*; |
|
20 |
|
|
21 |
public class KeplerServiceServlet extends RemoteServiceServlet implements KeplerService |
|
22 |
{ |
|
23 |
private String url = "http://localhost:8080/kepler/metacat"; |
|
24 |
|
|
25 |
/** |
|
26 |
* takes in a query string and a sessionid and returns a resultset |
|
27 |
*/ |
|
28 |
public MetacatQueryResult[] query(String query, String sessionid) |
|
29 |
{ |
|
30 |
try |
|
31 |
{ //query metacat |
|
32 |
MetacatClient client = (MetacatClient)MetacatFactory.createMetacatConnection(url); |
|
33 |
String queryDoc = createQueryDocument(query); |
|
34 |
Reader queryResultReader = client.query(new StringReader(queryDoc)); |
|
35 |
//now we have the result document, parse it and return it as MQR[] |
|
36 |
InputSource is = new InputSource(queryResultReader); |
|
37 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
38 |
DocumentBuilder builder = factory.newDocumentBuilder(); |
|
39 |
Document doc = builder.parse(is); |
|
40 |
NodeList docs = XPathAPI.selectNodeList(doc, "/resultset/document"); |
|
41 |
MetacatQueryResult[] mqr = new MetacatQueryResult[docs.getLength()]; |
|
42 |
for(int i=0; i<docs.getLength(); i++) |
|
43 |
{ |
|
44 |
Node docNode = docs.item(i); |
|
45 |
//parse each document result into an MQR |
|
46 |
mqr[i] = new MetacatQueryResult(); |
|
47 |
String docid = XPathAPI.selectSingleNode(docNode, "docid").getFirstChild().getNodeValue(); |
|
48 |
String name = XPathAPI.selectSingleNode(docNode, "param[@name='/entity/@name']").getFirstChild().getNodeValue(); |
|
49 |
|
|
50 |
mqr[i].setDocid(docid); |
|
51 |
mqr[i].setName(name); |
|
52 |
mqr[i].setDescription(""); |
|
53 |
} |
|
54 |
|
|
55 |
return mqr; |
|
56 |
} |
|
57 |
catch(Exception e) |
|
58 |
{ |
|
59 |
return null; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* takes in credentials and returns a sessionid |
|
65 |
*/ |
|
66 |
public String login(String user, String pass) |
|
67 |
{ |
|
68 |
try |
|
69 |
{ |
|
70 |
MetacatClient client = (MetacatClient)MetacatFactory.createMetacatConnection(url); |
|
71 |
return client.login("uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org", "kepler"); |
|
72 |
} |
|
73 |
catch(Exception e) |
|
74 |
{ |
|
75 |
return "error: " + e.getMessage(); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
public String logout() |
|
80 |
{ |
|
81 |
return "logout"; |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* takes in a docid and a sessionid and returns a document |
|
86 |
*/ |
|
87 |
public String read(String docid, String sessionid) |
|
88 |
{ |
|
89 |
return "read"; |
|
90 |
} |
|
91 |
|
|
92 |
private String createQueryDocument(String queryString) |
|
93 |
{ |
|
94 |
String query = "<?xml version=\"1.0\"?>" + |
|
95 |
"<pathquery version=\"1.2\">" + |
|
96 |
"<querytitle>Untitled-Search-1</querytitle>" + |
|
97 |
"<returndoctype>entity</returndoctype>" + |
|
98 |
"<returndoctype>eml://ecoinformatics.org//eml-2.0.0</returndoctype>" + |
|
99 |
"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>" + |
|
100 |
"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>" + |
|
101 |
"<returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype>" + |
|
102 |
"<returndoctype>-//NCEAS//resource//EN</returndoctype>" + |
|
103 |
"<returnfield>/entity/@name</returnfield>" + |
|
104 |
"<querygroup operator=\"INTERSECT\">" + |
|
105 |
"<querygroup operator=\"UNION\">" + |
|
106 |
"<queryterm searchmode=\"contains\" casesensitive=\"false\">" + |
|
107 |
"<value>" + queryString + "</value>" + |
|
108 |
"</queryterm>" + |
|
109 |
"</querygroup>" + |
|
110 |
"</querygroup>" + |
|
111 |
"</pathquery>"; |
|
112 |
return query; |
|
113 |
} |
|
114 |
} |
|
0 | 115 |
lib/ajax/src/org/kepler/web/client/KeplerClient.java | ||
---|---|---|
1 |
package org.kepler.web.client; |
|
2 |
|
|
3 |
//import org.kepler.web.service.*; |
|
4 |
|
|
5 |
import com.google.gwt.core.client.*; |
|
6 |
import com.google.gwt.user.client.rpc.*; |
|
7 |
import com.google.gwt.user.client.ui.Button; |
|
8 |
import com.google.gwt.user.client.ui.ClickListener; |
|
9 |
import com.google.gwt.user.client.ui.Label; |
|
10 |
import com.google.gwt.user.client.ui.RootPanel; |
|
11 |
import com.google.gwt.user.client.ui.Widget; |
|
12 |
|
|
13 |
|
|
14 |
/** |
|
15 |
* Entry point classes define <code>onModuleLoad()</code>. |
|
16 |
*/ |
|
17 |
public class KeplerClient implements EntryPoint |
|
18 |
{ |
|
19 |
|
|
20 |
/** |
|
21 |
* This is the entry point method. |
|
22 |
*/ |
|
23 |
public void onModuleLoad() |
|
24 |
{ |
|
25 |
//add the result widget to the results slot in the html |
|
26 |
MetacatResultsWidget mrwidget = new MetacatResultsWidget(15); |
|
27 |
RootPanel.get("results").add(mrwidget); |
|
28 |
} |
|
29 |
|
|
30 |
} |
|
0 | 31 |
lib/ajax/src/org/kepler/web/client/KeplerServiceAsync.java | ||
---|---|---|
1 |
package org.kepler.web.client; |
|
2 |
|
|
3 |
import com.google.gwt.user.client.rpc.*; |
|
4 |
|
|
5 |
import java.io.*; |
|
6 |
import java.util.*; |
|
7 |
|
|
8 |
public interface KeplerServiceAsync |
|
9 |
{ |
|
10 |
public void query(String query, String sessionid, AsyncCallback callback); |
|
11 |
public void login(String user, String pass, AsyncCallback callback); |
|
12 |
public void logout(AsyncCallback callback); |
|
13 |
public void read(String docid, String sessionid, AsyncCallback callback); |
|
14 |
} |
|
0 | 15 |
lib/ajax/src/org/kepler/web/client/KeplerService.java | ||
---|---|---|
1 |
package org.kepler.web.client; |
|
2 |
|
|
3 |
import java.io.*; |
|
4 |
import java.util.*; |
|
5 |
|
|
6 |
import com.google.gwt.user.client.rpc.*; |
|
7 |
|
|
8 |
public interface KeplerService extends RemoteService |
|
9 |
{ |
|
10 |
public MetacatQueryResult[] query(String query, String sessionid); |
|
11 |
public String login(String user, String pass); |
|
12 |
public String logout(); |
|
13 |
public String read(String docid, String sessionid); |
|
14 |
} |
|
0 | 15 |
lib/ajax/src/org/kepler/web/client/MetacatQueryResult.java | ||
---|---|---|
1 |
package org.kepler.web.client; |
|
2 |
|
|
3 |
import com.google.gwt.user.client.rpc.*; |
|
4 |
import com.google.gwt.user.client.rpc.IsSerializable; |
|
5 |
|
|
6 |
import java.io.*; |
|
7 |
import java.util.*; |
|
8 |
|
|
9 |
public class MetacatQueryResult implements IsSerializable |
|
10 |
{ |
|
11 |
private String name = ""; |
|
12 |
private String docid = ""; |
|
13 |
private String description = ""; |
|
14 |
|
|
15 |
public MetacatQueryResult() |
|
16 |
{ |
|
17 |
|
|
18 |
} |
|
19 |
|
|
20 |
public MetacatQueryResult(String name, String docid, String description) |
|
21 |
{ |
|
22 |
this.name = name; |
|
23 |
this.docid = docid; |
|
24 |
this.description = description; |
|
25 |
} |
|
26 |
|
|
27 |
public String getName() |
|
28 |
{ |
|
29 |
return name; |
|
30 |
} |
|
31 |
|
|
32 |
public String getDocid() |
|
33 |
{ |
|
34 |
return docid; |
|
35 |
} |
|
36 |
|
|
37 |
public String getDescription() |
|
38 |
{ |
|
39 |
return description; |
|
40 |
} |
|
41 |
|
|
42 |
public void setName(String name) |
|
43 |
{ |
|
44 |
this.name = name; |
|
45 |
} |
|
46 |
|
|
47 |
public void setDocid(String docid) |
|
48 |
{ |
|
49 |
this.docid = docid; |
|
50 |
} |
|
51 |
|
|
52 |
public void setDescription(String desc) |
|
53 |
{ |
|
54 |
this.description = description; |
|
55 |
} |
|
56 |
} |
|
0 | 57 |
lib/ajax/src/org/kepler/web/client/MetacatResultsWidget.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2006 Google Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
5 |
* use this file except in compliance with the License. You may obtain a copy of |
|
6 |
* the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
13 |
* License for the specific language governing permissions and limitations under |
|
14 |
* the License. |
|
15 |
*/ |
|
16 |
package org.kepler.web.client; |
|
17 |
|
|
18 |
import com.google.gwt.core.client.GWT; |
|
19 |
import com.google.gwt.user.client.Command; |
|
20 |
import com.google.gwt.user.client.DeferredCommand; |
|
21 |
import com.google.gwt.user.client.rpc.AsyncCallback; |
|
22 |
import com.google.gwt.user.client.rpc.ServiceDefTarget; |
|
23 |
import com.google.gwt.user.client.ui.Composite; |
|
24 |
|
|
25 |
public class MetacatResultsWidget extends Composite { |
|
26 |
|
|
27 |
|
|
28 |
private final MetacatProvider metacatProvider = new MetacatProvider(); |
|
29 |
private final DynaTableWidget dynaTable; |
|
30 |
private Command pendingRefresh; |
|
31 |
private boolean queryPerformed = false; |
|
32 |
private String lastSearch = null; |
|
33 |
|
|
34 |
public class MetacatProvider implements DynaTableDataProvider { |
|
35 |
|
|
36 |
public MetacatProvider() { |
|
37 |
// Initialize the service. |
|
38 |
// |
|
39 |
keplerService = (KeplerServiceAsync) GWT.create(KeplerService.class); |
|
40 |
|
|
41 |
// By default, we assume we'll make RPCs to a servlet, but see |
|
42 |
// updateRowData(). There is special support for canned RPC responses. |
|
43 |
// (Which is a totally demo hack, by the way :-) |
|
44 |
// |
|
45 |
ServiceDefTarget target = (ServiceDefTarget) keplerService; |
|
46 |
|
|
47 |
// Use a module-relative URLs to ensure that this client code can find |
|
48 |
// its way home, even when the URL changes (as might happen when you |
|
49 |
// deploy this as a webapp under an external servlet container). |
|
50 |
String moduleRelativeURL = GWT.getModuleBaseURL() + "kepler"; |
|
51 |
moduleRelativeURL = "http://offhegoes.kicks-ass.net:8080/kepler/gwt"; |
|
52 |
System.out.println("connection url: " + moduleRelativeURL); |
|
53 |
target.setServiceEntryPoint(moduleRelativeURL); |
|
54 |
} |
|
55 |
|
|
56 |
public void updateRowData(final int startRow, final int maxRows, |
|
57 |
final RowDataAcceptor acceptor, String searchTerm) |
|
58 |
{ |
|
59 |
// Check the simple cache first. |
|
60 |
if(searchTerm == null) |
|
61 |
{ |
|
62 |
searchTerm = "%"; |
|
63 |
} |
|
64 |
|
|
65 |
if(queryPerformed && lastSearch.trim().equals(searchTerm.trim())) |
|
66 |
{ |
|
67 |
// Use the cached batch. |
|
68 |
pushResults(acceptor, startRow, maxRows, lastResult); |
|
69 |
return; |
|
70 |
} |
|
71 |
else |
|
72 |
{ |
|
73 |
lastSearch = searchTerm; |
|
74 |
} |
|
75 |
|
|
76 |
/*keplerService.login("uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org", |
|
77 |
new AsyncCallback() { |
|
78 |
public void onFailure(Throwable caught) { |
|
79 |
acceptor.failed(caught); |
|
80 |
} |
|
81 |
|
|
82 |
public void onSuccess(Object result) { |
|
83 |
//handle successful login |
|
84 |
} |
|
85 |
});*/ |
|
86 |
|
|
87 |
//do the query |
|
88 |
if(searchTerm == null) |
|
89 |
{ |
|
90 |
lastSearch = "%"; |
|
91 |
} |
|
92 |
|
|
93 |
keplerService.query(lastSearch, "", new AsyncCallback() { |
|
94 |
public void onFailure(Throwable caught) { |
|
95 |
acceptor.failed(caught); |
|
96 |
} |
|
97 |
|
|
98 |
public void onSuccess(Object result) { |
|
99 |
//handle successful query |
|
100 |
MetacatQueryResult[] queryResult = (MetacatQueryResult[])result; |
|
101 |
lastStartRow = startRow; |
|
102 |
lastMaxRows = maxRows; |
|
103 |
lastResult = queryResult; |
|
104 |
queryPerformed = true; |
|
105 |
dynaTable.setMaxRowCount(queryResult.length); |
|
106 |
pushResults(acceptor, startRow, maxRows, queryResult); |
|
107 |
} |
|
108 |
|
|
109 |
}); |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
private void pushResults(RowDataAcceptor acceptor, int startRow, |
|
114 |
int maxRows, MetacatQueryResult[] queryResults) { |
|
115 |
int offset = (queryResults.length - 0) - startRow; |
|
116 |
if(offset > maxRows) |
|
117 |
{ |
|
118 |
offset = maxRows; |
|
119 |
} |
|
120 |
|
|
121 |
String[][] rows = new String[offset][]; |
|
122 |
for (int i = 0; i < offset; i++) { |
|
123 |
MetacatQueryResult result = queryResults[startRow + i]; |
|
124 |
rows[i] = new String[3]; |
|
125 |
rows[i][0] = " "; |
|
126 |
rows[i][1] = result.getName(); |
|
127 |
rows[i][2] = result.getDocid(); |
|
128 |
} |
|
129 |
acceptor.accept(startRow, rows); |
|
130 |
} |
|
131 |
|
|
132 |
private final KeplerServiceAsync keplerService; |
|
133 |
private int lastMaxRows = -1; |
|
134 |
private MetacatQueryResult[] lastResult; |
|
135 |
private int lastStartRow = -1; |
|
136 |
} |
|
137 |
|
|
138 |
public MetacatResultsWidget(int visibleRows) { |
|
139 |
String[] columns = new String[]{"", "Name", "DocId"}; |
|
140 |
String[] styles = new String[]{"", "name", "docid"}; |
|
141 |
dynaTable = new DynaTableWidget(metacatProvider, columns, styles, visibleRows); |
|
142 |
initWidget(dynaTable); |
|
143 |
} |
|
144 |
|
|
145 |
protected void onLoad() { |
|
146 |
dynaTable.refresh(); |
|
147 |
} |
|
148 |
} |
|
0 | 149 |
lib/ajax/src/org/kepler/web/client/DynaTableWidget.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2006 Google Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
5 |
* use this file except in compliance with the License. You may obtain a copy of |
|
6 |
* the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
13 |
* License for the specific language governing permissions and limitations under |
|
14 |
* the License. |
|
15 |
*/ |
|
16 |
package org.kepler.web.client; |
|
17 |
|
|
18 |
import org.kepler.web.client.DynaTableDataProvider.RowDataAcceptor; |
|
19 |
|
|
20 |
import com.google.gwt.user.client.ui.Button; |
|
21 |
import com.google.gwt.user.client.ui.ClickListener; |
|
22 |
import com.google.gwt.user.client.ui.Composite; |
|
23 |
import com.google.gwt.user.client.ui.DockPanel; |
|
24 |
import com.google.gwt.user.client.ui.Grid; |
|
25 |
import com.google.gwt.user.client.ui.HasAlignment; |
|
26 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
|
27 |
import com.google.gwt.user.client.ui.HTML; |
|
28 |
import com.google.gwt.user.client.ui.Widget; |
|
29 |
import com.google.gwt.user.client.ui.TextBox; |
|
30 |
import com.google.gwt.user.client.ui.TableListener; |
|
31 |
import com.google.gwt.user.client.ui.SourcesTableEvents; |
|
32 |
import com.google.gwt.user.client.ui.Image; |
|
33 |
import com.google.gwt.user.client.ui.DialogBox; |
|
34 |
import com.google.gwt.user.client.ui.Frame; |
|
35 |
|
|
36 |
public class DynaTableWidget extends Composite implements TableListener{ |
|
37 |
|
|
38 |
private class NavBar extends Composite implements ClickListener { |
|
39 |
|
|
40 |
public NavBar() { |
|
41 |
initWidget(bar); |
|
42 |
bar.setStyleName("navbar"); |
|
43 |
status.setStyleName("status"); |
|
44 |
|
|
45 |
HorizontalPanel searchPanel = new HorizontalPanel(); |
|
46 |
searchField.setVisibleLength(12); |
|
47 |
searchButton.setStyleName("searchButton"); |
|
48 |
searchPanel.add(searchField); |
|
49 |
searchPanel.add(searchButton); |
|
50 |
|
|
51 |
HorizontalPanel buttons = new HorizontalPanel(); |
|
52 |
buttons.add(gotoFirst); |
|
53 |
buttons.add(gotoPrev); |
|
54 |
buttons.add(gotoNext); |
|
55 |
buttons.add(gotoLast); |
|
56 |
bar.add(buttons, DockPanel.EAST); |
|
57 |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT); |
|
58 |
|
|
59 |
HorizontalPanel statusPanel = new HorizontalPanel(); |
|
60 |
statusPanel.add(statusImage); |
|
61 |
statusPanel.add(new HTML(" ")); |
|
62 |
statusPanel.add(status); |
|
63 |
bar.add(statusPanel, DockPanel.CENTER); |
|
64 |
|
|
65 |
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); |
|
66 |
bar.setCellHorizontalAlignment(statusPanel, HasAlignment.ALIGN_RIGHT); |
|
67 |
bar.setCellVerticalAlignment(statusPanel, HasAlignment.ALIGN_MIDDLE); |
|
68 |
bar.setCellWidth(statusPanel, "100%"); |
|
69 |
|
|
70 |
bar.add(searchPanel, DockPanel.WEST); |
|
71 |
|
|
72 |
|
|
73 |
// Initialize prev & first button to disabled. |
|
74 |
// |
|
75 |
gotoPrev.setEnabled(false); |
|
76 |
gotoFirst.setEnabled(false); |
|
77 |
} |
|
78 |
|
|
79 |
public void onClick(Widget sender) { |
|
80 |
if (sender == gotoNext) { |
|
81 |
startRow += getDataRowCount(); |
|
82 |
selectRow(-1); |
|
83 |
refresh(); |
|
84 |
} else if (sender == gotoPrev) { |
|
85 |
startRow -= getDataRowCount(); |
|
86 |
if (startRow < 0) { |
|
87 |
startRow = 0; |
|
88 |
} |
|
89 |
selectRow(-1); |
|
90 |
refresh(); |
|
91 |
} else if (sender == gotoFirst) { |
|
92 |
startRow = 0; |
|
93 |
selectRow(-1); |
|
94 |
refresh(); |
|
95 |
} else if (sender == gotoLast) { |
|
96 |
startRow = getMaxRowCount() - (getMaxRowCount() % getRowInc()); |
|
97 |
selectRow(-1); |
|
98 |
refresh(); |
|
99 |
} else if(sender == searchButton) { |
|
100 |
searchString = searchField.getText(); |
|
101 |
startRow = 0; |
|
102 |
selectRow(-1); |
|
103 |
search(searchField.getText()); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
public final DockPanel bar = new DockPanel(); |
|
108 |
public final Button gotoFirst = new Button("<<", this); |
|
109 |
public final Button gotoNext = new Button(">", this); |
|
110 |
public final Button gotoPrev = new Button("<", this); |
|
111 |
public final Button gotoLast = new Button(">>", this); |
|
112 |
public final Button searchButton = new Button("Search", this); |
|
113 |
public final TextBox searchField = new TextBox(); |
|
114 |
public final HTML status = new HTML(); |
|
115 |
public final Image statusImage = new Image("spinner-anim.gif"); |
|
116 |
} |
|
117 |
|
|
118 |
private class RowDataAcceptorImpl implements RowDataAcceptor { |
|
119 |
|
|
120 |
public void accept(int startRow, String[][] data) { |
|
121 |
int destRowCount = getDataRowCount(); |
|
122 |
int destColCount = grid.getCellCount(0); |
|
123 |
assert (data.length <= destRowCount) : "Too many rows"; |
|
124 |
|
|
125 |
int srcRowIndex = 0; |
|
126 |
int srcRowCount = data.length; |
|
127 |
int destRowIndex = 1; // skip navbar row |
|
128 |
for (; srcRowIndex < srcRowCount; ++srcRowIndex, ++destRowIndex) { |
|
129 |
String[] srcRowData = data[srcRowIndex]; |
|
130 |
assert (srcRowData.length == destColCount) : " Column count mismatch"; |
|
131 |
for (int srcColIndex = 0; srcColIndex < destColCount; ++srcColIndex) { |
|
132 |
String cellHTML = srcRowData[srcColIndex]; |
|
133 |
grid.setText(destRowIndex, srcColIndex, cellHTML); |
|
134 |
grid.getCellFormatter().setStyleName(destRowIndex, 0, "infoIcon"); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
// Clear remaining table rows. |
|
139 |
// |
|
140 |
boolean isLastPage = false; |
|
141 |
for (; destRowIndex < destRowCount + 1; ++destRowIndex) { |
|
142 |
isLastPage = true; |
|
143 |
for (int destColIndex = 0; destColIndex < destColCount; ++destColIndex) { |
|
144 |
grid.clearCell(destRowIndex, destColIndex); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
// Synchronize the nav buttons. |
|
149 |
// |
|
150 |
navbar.gotoNext.setEnabled(!isLastPage); |
|
151 |
navbar.gotoFirst.setEnabled(startRow > 0); |
|
152 |
navbar.gotoPrev.setEnabled(startRow > 0); |
|
153 |
navbar.gotoLast.setEnabled(!isLastPage); |
|
154 |
|
|
155 |
// Update the status message. |
|
156 |
// |
|
157 |
setStatusText((startRow + 1) + " - " + (startRow + srcRowCount) + " of " + |
|
158 |
getMaxRowCount()); |
|
159 |
setStatusImage(false); |
|
160 |
currentEndRecordNum = startRow + srcRowCount; |
|
161 |
currentBeginRecordNum = startRow + 1; |
|
162 |
} |
|
163 |
|
|
164 |
public void failed(Throwable caught) { |
|
165 |
String msg = "Failed to access data"; |
|
166 |
if (caught != null) { |
|
167 |
msg += ": " + caught.getMessage(); |
|
168 |
} |
|
169 |
setStatusText(msg); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
private static class InfoDialog extends DialogBox implements ClickListener { |
|
174 |
|
|
175 |
public InfoDialog(String title, String docid) { |
|
176 |
|
|
177 |
setText(title); |
|
178 |
|
|
179 |
Frame iframe = new Frame("http://offhegoes.kicks-ass.net:8080/kepler/metacat?action=read&docid=" + docid + "&qformat=kepler"); |
|
180 |
Button closeButton = new Button("Close", this); |
|
181 |
/*HTML msg = new HTML( |
|
182 |
"<center>This is an example of a standard dialog box component.<br> " |
|
183 |
+ "You can put pretty much anything you like into it,<br>such as the " |
|
184 |
+ "following IFRAME:</center>", true);*/ |
|
185 |
|
|
186 |
DockPanel dock = new DockPanel(); |
|
187 |
dock.setSpacing(4); |
|
188 |
|
|
189 |
dock.add(closeButton, DockPanel.SOUTH); |
|
190 |
//dock.add(msg, DockPanel.NORTH); |
|
191 |
dock.add(iframe, DockPanel.CENTER); |
|
192 |
|
|
193 |
dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_RIGHT); |
|
194 |
dock.setCellWidth(iframe, "100%"); |
|
195 |
dock.setWidth("100%"); |
|
196 |
iframe.setWidth("36em"); |
|
197 |
iframe.setHeight("20em"); |
|
198 |
setWidget(dock); |
|
199 |
} |
|
200 |
|
|
201 |
public void onClick(Widget sender) { |
|
202 |
hide(); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
public DynaTableWidget(DynaTableDataProvider provider, String[] columns, |
|
207 |
String[] columnStyles, int rowCount) { |
|
208 |
rowInc = rowCount; |
|
209 |
if (columns.length == 0) { |
|
210 |
throw new IllegalArgumentException( |
|
211 |
"expecting a positive number of columns"); |
|
212 |
} |
|
213 |
|
|
214 |
if (columnStyles != null && columns.length != columnStyles.length) { |
|
215 |
throw new IllegalArgumentException("expecting as many styles as columns"); |
|
216 |
} |
|
217 |
|
|
218 |
this.provider = provider; |
|
219 |
initWidget(outer); |
|
220 |
grid.setStyleName("table"); |
|
221 |
grid.addTableListener(this); |
|
222 |
outer.add(navbar, DockPanel.NORTH); |
|
223 |
outer.add(grid, DockPanel.CENTER); |
|
224 |
initTable(columns, columnStyles, rowCount); |
|
225 |
setStyleName("DynaTable-DynaTableWidget"); |
|
226 |
} |
|
227 |
|
|
228 |
private void initTable(String[] columns, String[] columnStyles, int rowCount) { |
|
229 |
// Set up the header row. It's one greater than the number of visible rows. |
|
230 |
// |
|
231 |
|
|
232 |
grid.resize(rowCount+1, columns.length); |
|
233 |
for (int i = 0, n = columns.length; i < n; i++) { |
|
234 |
grid.setText(0, i, columns[i]); |
|
235 |
if (columnStyles != null) { |
|
236 |
grid.getCellFormatter().setStyleName(0, i, columnStyles[i] + " header"); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
public void setStatusText(String text) { |
|
242 |
navbar.status.setText(text); |
|
243 |
} |
|
244 |
|
|
245 |
public void clearStatusText() { |
|
246 |
navbar.status.setHTML(" "); |
|
247 |
} |
|
248 |
|
|
249 |
public void setStatusImage(boolean on) |
|
250 |
{ |
|
251 |
//if on turn the image on |
|
252 |
navbar.statusImage.setVisible(on); |
|
253 |
} |
|
254 |
|
|
255 |
public void refresh() { |
|
256 |
// Disable buttons temporarily to stop the user from running off the end. |
|
257 |
// |
|
258 |
search(searchString); |
|
259 |
} |
|
260 |
|
|
261 |
public void search(String searchTerm) { |
|
262 |
navbar.gotoFirst.setEnabled(false); |
|
263 |
navbar.gotoPrev.setEnabled(false); |
|
264 |
navbar.gotoNext.setEnabled(false); |
|
265 |
navbar.gotoLast.setEnabled(false); |
|
266 |
|
|
267 |
setStatusText("Searching..."); |
|
268 |
setStatusImage(true); |
|
269 |
provider.updateRowData(startRow, grid.getRowCount() - 1, acceptor, searchTerm); |
|
270 |
|
|
271 |
for(int i=0; i<grid.getRowCount(); i++) |
|
272 |
{ |
|
273 |
if(grid.getText(i, 1) == null || |
|
274 |
grid.getText(i, 1).trim().equals("") || |
|
275 |
grid.getHTML(i,1).equals(" ")) |
|
276 |
{ //remove the info icon style if there is nothing in the row |
|
277 |
grid.getCellFormatter().removeStyleName(i, 0, "infoIcon"); |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
|
|
282 |
public void setRowCount(int rows) { |
|
283 |
grid.resizeRows(rows); |
|
284 |
} |
|
285 |
|
|
286 |
public void onCellClicked(SourcesTableEvents sender, int row, int cell) { |
|
287 |
// Select the row that was clicked (-1 to account for header row). |
|
288 |
if(((row + currentBeginRecordNum) - 2) < currentEndRecordNum) |
|
289 |
{ |
|
290 |
if (row > 0) |
|
291 |
{ |
|
292 |
selectRow(row - 1); |
|
293 |
} |
|
294 |
|
|
295 |
if(cell == 0) |
|
296 |
{ |
|
297 |
//create the dialog and send the name and docid to the dialog |
|
298 |
DialogBox dlg = new InfoDialog(grid.getText(row,1), grid.getText(row,2)); |
|
299 |
int left = 50; |
|
300 |
int top = 50; |
|
301 |
dlg.setPopupPosition(left, top); |
|
302 |
dlg.show(); |
|
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
/** |
|
308 |
* Selects the given row (relative to the current page). |
|
309 |
* |
|
310 |
* @param row the row to be selected |
|
311 |
*/ |
|
312 |
private void selectRow(int row) { |
|
313 |
|
|
314 |
styleRow(selectedRow, false); |
|
315 |
styleRow(row, true); |
|
316 |
|
|
317 |
selectedRow = row; |
|
318 |
} |
|
319 |
|
|
320 |
private void styleRow(int row, boolean selected) { |
|
321 |
if (row != -1) { |
|
322 |
if (selected) |
|
323 |
{ |
|
324 |
//grid.getRowFormatter().addStyleName(row + 1, "SelectedRow"); |
|
325 |
//don't select the info icon |
|
326 |
grid.getCellFormatter().setStyleName(row + 1, 1, "SelectedRow"); |
|
327 |
grid.getCellFormatter().setStyleName(row + 1, 2, "SelectedRow"); |
|
328 |
} |
|
329 |
else |
|
330 |
{ |
|
331 |
//grid.getRowFormatter().removeStyleName(row + 1, "SelectedRow"); |
|
332 |
grid.getCellFormatter().removeStyleName(row + 1, 1, "SelectedRow"); |
|
333 |
grid.getCellFormatter().removeStyleName(row + 1, 2, "SelectedRow"); |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
|
|
338 |
private int getDataRowCount() { |
|
339 |
return grid.getRowCount() - 1; |
|
340 |
} |
|
341 |
|
|
342 |
public int getMaxRowCount() { |
|
343 |
return maxRowCount; |
|
344 |
} |
|
345 |
|
|
346 |
public void setMaxRowCount(int max) { |
|
347 |
maxRowCount = max; |
|
348 |
} |
|
349 |
|
|
350 |
private int getRowInc() { |
|
351 |
return rowInc; |
|
352 |
} |
|
353 |
|
|
354 |
private final RowDataAcceptor acceptor = new RowDataAcceptorImpl(); |
|
355 |
private final NavBar navbar = new NavBar(); |
|
356 |
private final DockPanel outer = new DockPanel(); |
|
357 |
private final DynaTableDataProvider provider; |
|
358 |
private int startRow = 0; |
|
359 |
private Grid grid = new Grid(); |
|
360 |
private int maxRowCount = 0; |
|
361 |
private int rowInc; |
|
362 |
private int currentEndRecordNum = -1; |
|
363 |
private int currentBeginRecordNum = -1; |
|
364 |
private String searchString = null; |
|
365 |
private int startIndex, selectedRow = -1; |
|
366 |
} |
|
0 | 367 |
lib/ajax/src/org/kepler/web/client/DynaTableDataProvider.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2006 Google Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
5 |
* use this file except in compliance with the License. You may obtain a copy of |
|
6 |
* the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
13 |
* License for the specific language governing permissions and limitations under |
|
14 |
* the License. |
|
15 |
*/ |
|
16 |
package org.kepler.web.client; |
|
17 |
|
|
18 |
public interface DynaTableDataProvider { |
|
19 |
|
|
20 |
interface RowDataAcceptor { |
|
21 |
void accept(int startRow, String[][] rows); |
|
22 |
void failed(Throwable caught); |
|
23 |
} |
|
24 |
|
|
25 |
void updateRowData(int startRow, int maxRows, RowDataAcceptor acceptor, String searchTerm); |
|
26 |
} |
|
0 | 27 |
lib/ajax/src/org/kepler/web/public/KeplerClient.html | ||
---|---|---|
1 |
<html> |
|
2 |
<head> |
|
3 |
<link rel=stylesheet href="DynaTable.css"> |
|
4 |
<!-- --> |
|
5 |
<!-- Any title is fine --> |
|
6 |
<!-- --> |
|
7 |
<title>Kepler Repository</title> |
|
8 |
|
|
9 |
<!-- --> |
|
10 |
<!-- Use normal html, such as style --> |
|
11 |
<!-- --> |
|
12 |
<!--<style> |
|
13 |
body,td,a,div,.p{font-family:arial,sans-serif} |
|
14 |
div,td{color:#000000} |
|
15 |
a:link,.w,.w a:link{color:#0000cc} |
|
16 |
a:visited{color:#551a8b} |
|
17 |
a:active{color:#ff0000} |
|
18 |
</style>--> |
|
19 |
|
|
20 |
<!-- --> |
|
21 |
<!-- The module reference below is the link --> |
|
22 |
<!-- between html and your Web Toolkit module --> |
|
23 |
<!-- --> |
|
24 |
<meta name='gwt:module' content='org.kepler.web.KeplerClient'> |
|
25 |
|
|
26 |
</head> |
|
27 |
|
|
28 |
<!-- --> |
|
29 |
<!-- The body can have arbitrary html, or --> |
|
30 |
<!-- you can leave the body empty if you want --> |
|
31 |
<!-- to create a completely dynamic ui --> |
|
32 |
<!-- --> |
|
33 |
<body> |
|
34 |
|
|
35 |
<!-- --> |
|
36 |
<!-- This script is required bootstrap stuff. --> |
|
37 |
<!-- You can put it in the HEAD, but startup --> |
|
38 |
<!-- is slightly faster if you include it here. --> |
|
39 |
<!-- --> |
|
40 |
<script language="javascript" src="gwt.js"></script> |
|
41 |
|
|
42 |
<!-- OPTIONAL: include this if you want history support --> |
|
43 |
<iframe id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe> |
|
44 |
|
|
45 |
<img src="kepler-logo.png"/><div class="topheader">Kepler Analytical Component Repository</div> |
|
46 |
|
|
47 |
<div id="results"/> |
|
48 |
</body> |
|
49 |
</html> |
|
0 | 50 |
lib/ajax/src/org/kepler/web/public/DynaTable.css | ||
---|---|---|
1 |
|
|
2 |
body { |
|
3 |
background-color: white; |
|
4 |
color: black; |
|
5 |
font-family: Arial, sans-serif; |
|
6 |
font-size: small; |
|
7 |
margin: 8px; |
|
8 |
margin-top: 3px; |
|
9 |
} |
|
10 |
|
|
11 |
img { |
|
12 |
display: inline; |
|
13 |
} |
|
14 |
|
|
15 |
.topheader { |
|
16 |
color: black; |
|
17 |
font-size: 30px; |
|
18 |
display: inline; |
|
19 |
vertical-align: top; |
|
20 |
margin-left:5%; |
|
21 |
} |
|
22 |
|
|
23 |
.DynaTable-DynaTableWidget { |
|
24 |
width: 100%; |
|
25 |
border: 1px solid #ACA899; |
|
26 |
} |
|
27 |
|
|
28 |
|
|
29 |
.DynaTable-DynaTableWidget .navbar { |
|
30 |
width: 100%; |
|
31 |
background-color: #ECE9D8; |
|
32 |
vertical-align: middle; |
|
33 |
border-bottom: 1px solid #ACA899; |
|
34 |
} |
|
35 |
|
|
36 |
.DynaTable-DynaTableWidget .navbar button { |
|
37 |
|
|
38 |
text-align: center; |
|
39 |
vertical-align: middle; |
|
40 |
} |
|
41 |
|
|
42 |
.DynaTable-DynaTableWidget .searchButton { |
|
43 |
|
|
44 |
text-align: center; |
|
45 |
vertical-align: middle; |
|
46 |
} |
|
47 |
|
|
48 |
.DynaTable-DynaTableWidget .navbar .status { |
|
49 |
vertical-align: middle; |
|
50 |
padding-right: 10px; |
|
51 |
} |
|
52 |
|
|
53 |
.DynaTable-DynaTableWidget .table { |
|
54 |
margin: 10px; |
|
55 |
} |
|
56 |
|
|
57 |
.DynaTable-DynaTableWidget .table td.header { |
|
58 |
text-align: left; |
|
59 |
font-weight: bold; |
|
60 |
text-decoration: underline; |
|
61 |
} |
|
62 |
|
|
63 |
.DynaTable-DynaTableWidget .table td.name { |
|
64 |
width: 100em; |
|
65 |
} |
|
66 |
|
|
67 |
.DynaTable-DynaTableWidget .table td.docid { |
|
68 |
width: 20%; |
|
69 |
} |
|
70 |
|
|
71 |
.DynaTable-DynaTableWidget .table td { |
|
72 |
vertical-align: top; |
|
73 |
} |
|
74 |
|
|
75 |
.SelectedRow { |
|
76 |
background-image: url(blue_gradient.gif); |
|
77 |
background-repeat: repeat-x; |
|
78 |
} |
|
79 |
|
|
80 |
.infoIcon { |
|
81 |
background-image: url(infoIcon.png); |
|
82 |
background-repeat: no-repeat; |
|
83 |
width: 70px; |
|
84 |
vertical-align: bottom; |
|
85 |
margin-left: 10%; |
|
86 |
margin-top: 20%; |
|
87 |
} |
|
88 |
|
|
89 |
.gwt-DialogBox { |
|
90 |
sborder: 8px solid #C3D9FF; |
|
91 |
border: 2px outset; |
|
92 |
background-color: white; |
|
93 |
} |
|
94 |
|
|
95 |
.gwt-DialogBox .Caption { |
|
96 |
background-color: #C3D9FF; |
|
97 |
padding: 3px; |
|
98 |
margin: 2px; |
|
99 |
font-weight: bold; |
|
100 |
cursor: default; |
|
101 |
} |
|
0 | 102 |
lib/ajax/tomcat/webapps/ROOT/WEB-INF/web.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<web-app> |
|
3 |
|
|
4 |
<servlet> |
|
5 |
<servlet-name>shell</servlet-name> |
|
6 |
<servlet-class>com.google.gwt.dev.shell.GWTShellServlet</servlet-class> |
|
7 |
</servlet> |
|
8 |
|
|
9 |
<servlet-mapping> |
|
10 |
<servlet-name>shell</servlet-name> |
|
11 |
<url-pattern>/*</url-pattern> |
|
12 |
</servlet-mapping> |
|
13 |
|
|
14 |
</web-app> |
|
0 | 15 |
lib/ajax/tomcat/conf/web.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- A tweaked version of the default Tomcat web.xml to remove everything except the stuff we want to use --> |
|
3 |
<web-app version="2.4"> |
|
4 |
|
|
5 |
<session-config> |
|
6 |
<session-timeout>30</session-timeout> |
|
7 |
</session-config> |
|
8 |
|
|
9 |
<mime-mapping> |
|
10 |
<extension>abs</extension> |
|
11 |
<mime-type>audio/x-mpeg</mime-type> |
|
12 |
</mime-mapping> |
|
13 |
<mime-mapping> |
|
14 |
<extension>ai</extension> |
|
15 |
<mime-type>application/postscript</mime-type> |
|
16 |
</mime-mapping> |
|
17 |
<mime-mapping> |
|
18 |
<extension>aif</extension> |
|
19 |
<mime-type>audio/x-aiff</mime-type> |
|
20 |
</mime-mapping> |
|
21 |
<mime-mapping> |
|
22 |
<extension>aifc</extension> |
|
23 |
<mime-type>audio/x-aiff</mime-type> |
|
24 |
</mime-mapping> |
|
25 |
<mime-mapping> |
|
26 |
<extension>aiff</extension> |
|
27 |
<mime-type>audio/x-aiff</mime-type> |
|
28 |
</mime-mapping> |
|
29 |
<mime-mapping> |
|
30 |
<extension>aim</extension> |
|
31 |
<mime-type>application/x-aim</mime-type> |
|
32 |
</mime-mapping> |
|
33 |
<mime-mapping> |
|
34 |
<extension>art</extension> |
Also available in: Unified diff
initial checkin of the kepler ajax metacat interface. these files may need to be moved later, but they need to be in cvs all together for now.