01: package org.drools.brms.server.util;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.text.DateFormat;
20: import java.util.ArrayList;
21: import java.util.Calendar;
22: import java.util.Iterator;
23: import java.util.List;
24:
25: import org.drools.brms.client.rpc.TableConfig;
26: import org.drools.brms.client.rpc.TableDataResult;
27: import org.drools.brms.client.rpc.TableDataRow;
28: import org.drools.repository.AssetItem;
29:
30: import com.google.gwt.user.client.rpc.SerializableException;
31:
32: /**
33: * This utility class handles loading of tables.
34: *
35: * This is to give some flexibility in what fields are displayed.
36: * This will likely be dynamic in the future (driven of user config stored in the
37: * repository).
38: *
39: * @author michael neale
40: */
41: public class TableDisplayHandler {
42:
43: private RowLoader ASSET_LIST;
44:
45: public static final String DEFAULT_TABLE_TEMPLATE = "rulelist";
46: public static final String ARCHIVED_RULE_LIST_TABLE_ID = "archivedrulelist";
47:
48: /**
49: * Produce a table dataset for a given iterator.
50: * @param list The iterator.
51: * @param numRows The number of rows to go to. -1 means don't stop.
52: * @throws SerializableException
53: */
54:
55: public TableDisplayHandler(String tableconfig) {
56: ASSET_LIST = new RowLoader(tableconfig);
57: }
58:
59: public TableDataResult loadRuleListTable(Iterator list, int numRows)
60: throws SerializableException {
61: List<TableDataRow> data = new ArrayList<TableDataRow>();
62:
63: for (Iterator iter = list; iter.hasNext();) {
64: AssetItem rule = (AssetItem) iter.next();
65: TableDataRow row = new TableDataRow();
66:
67: row.id = rule.getUUID();
68: row.format = rule.getFormat();
69: row.values = ASSET_LIST.getRow(rule);
70: data.add(row);
71: if (numRows != -1) {
72: if (data.size() == numRows) {
73: break;
74: }
75: }
76: }
77: TableDataResult result = new TableDataResult();
78: result.data = (TableDataRow[]) data
79: .toArray(new TableDataRow[data.size()]);
80: return result;
81: }
82:
83: public String formatDate(Calendar cal) {
84: DateFormat localFormat = DateFormat.getDateInstance();
85:
86: return localFormat.format(cal.getTime());
87: }
88:
89: public TableConfig loadTableConfig() {
90: final TableConfig config = new TableConfig();
91:
92: config.headers = ASSET_LIST.getHeaders();
93: config.rowsPerPage = 30;
94: return config;
95: }
96: }
|