001: package org.drools.brms.client.ruleeditor;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.drools.brms.client.common.GenericCallback;
020: import org.drools.brms.client.common.ImageButton;
021: import org.drools.brms.client.rpc.MetaData;
022: import org.drools.brms.client.rpc.RepositoryServiceFactory;
023: import org.drools.brms.client.rpc.TableDataResult;
024: import org.drools.brms.client.rpc.TableDataRow;
025: import org.drools.brms.client.table.DataModel;
026: import org.drools.brms.client.table.SortableTable;
027:
028: import com.google.gwt.user.client.Command;
029: import com.google.gwt.user.client.DeferredCommand;
030: import com.google.gwt.user.client.ui.Button;
031: import com.google.gwt.user.client.ui.ClickListener;
032: import com.google.gwt.user.client.ui.Composite;
033: import com.google.gwt.user.client.ui.FlexTable;
034: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
035: import com.google.gwt.user.client.ui.HorizontalPanel;
036: import com.google.gwt.user.client.ui.Image;
037: import com.google.gwt.user.client.ui.Label;
038: import com.google.gwt.user.client.ui.Widget;
039: import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
040:
041: /**
042: * This widget shows a list of versions.
043: *
044: * @author Michael Neale
045: */
046: public class VersionBrowser extends Composite {
047:
048: private Image refresh;
049: private FlexTable layout;
050: private String uuid;
051: private MetaData metaData;
052: private Command refreshCommand;
053:
054: public VersionBrowser(String uuid, MetaData data, Command ref) {
055:
056: this .uuid = uuid;
057: this .metaData = data;
058: this .refreshCommand = ref;
059:
060: this .uuid = uuid;
061: HorizontalPanel wrapper = new HorizontalPanel();
062:
063: layout = new FlexTable();
064: layout.setWidget(0, 0, new Label("Version history"));
065: FlexCellFormatter formatter = layout.getFlexCellFormatter();
066: formatter.setHorizontalAlignment(0, 0,
067: HasHorizontalAlignment.ALIGN_LEFT);
068:
069: refresh = new ImageButton("images/refresh.gif");
070:
071: refresh.addClickListener(new ClickListener() {
072: public void onClick(Widget w) {
073: clickLoadHistory();
074: }
075: });
076:
077: layout.setWidget(0, 1, refresh);
078: formatter.setHorizontalAlignment(0, 1,
079: HasHorizontalAlignment.ALIGN_RIGHT);
080:
081: wrapper.setStyleName("version-browser-Border");
082:
083: wrapper.add(layout);
084:
085: layout.setWidth("100%");
086: wrapper.setWidth("100%");
087:
088: initWidget(wrapper);
089: }
090:
091: protected void clickLoadHistory() {
092: showBusyIcon();
093: DeferredCommand.add(new Command() {
094: public void execute() {
095: loadHistoryData();
096: }
097: });
098:
099: }
100:
101: private void showBusyIcon() {
102: refresh.setUrl("images/searching.gif");
103: }
104:
105: /**
106: * Actually load the history data, as demanded.
107: */
108: protected void loadHistoryData() {
109:
110: RepositoryServiceFactory.getService().loadAssetHistory(
111: this .uuid, new GenericCallback() {
112:
113: public void onSuccess(Object data) {
114: if (data == null) {
115: layout.setWidget(1, 0, new Label(
116: "No history."));
117: showStaticIcon();
118: return;
119: }
120: TableDataResult table = (TableDataResult) data;
121: final TableDataRow[] rows = table.data;
122:
123: String[] header = new String[] {
124: "Version number", "Comment",
125: "Date Modified", "Status" };
126:
127: DataModel mdl = getTableDataModel(rows);
128:
129: final SortableTable tableWidget = SortableTable
130: .createTableWidget(mdl, header, 0,
131: false);
132:
133: tableWidget.setWidth("100%");
134:
135: layout.setWidget(1, 0, tableWidget);
136: FlexCellFormatter formatter = layout
137: .getFlexCellFormatter();
138:
139: formatter.setColSpan(1, 0, 2);
140:
141: Button open = new Button(
142: "View selected version");
143:
144: open.addClickListener(new ClickListener() {
145: public void onClick(Widget w) {
146: if (tableWidget.getSelectedRow() == 0)
147: return;
148: showVersion(tableWidget
149: .getSelectedKey());
150: }
151:
152: });
153:
154: layout.setWidget(2, 1, open);
155: formatter.setColSpan(2, 1, 3);
156: formatter.setHorizontalAlignment(2, 1,
157: HasHorizontalAlignment.ALIGN_CENTER);
158:
159: showStaticIcon();
160:
161: }
162:
163: });
164:
165: }
166:
167: /**
168: * This should popup a view of the chosen historical version.
169: * @param selectedUUID
170: */
171: private void showVersion(String selectedUUID) {
172:
173: VersionViewer viewer = new VersionViewer(this .metaData,
174: selectedUUID, uuid, refreshCommand);
175: viewer.setPopupPosition(100, 100);
176:
177: viewer.show();
178:
179: }
180:
181: private void showStaticIcon() {
182: refresh.setUrl("images/refresh.gif");
183: }
184:
185: private DataModel getTableDataModel(final TableDataRow[] rows) {
186: return new DataModel() {
187:
188: public int getNumberOfRows() {
189: return rows.length;
190: }
191:
192: public String getRowId(int row) {
193: return rows[row].id;
194: }
195:
196: public Comparable getValue(int row, int col) {
197: return rows[row].values[col];
198: }
199:
200: public Widget getWidget(int row, int col) {
201: return null;
202: }
203:
204: };
205: }
206:
207: }
|