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.LoadingPopup;
021: import org.drools.brms.client.rpc.MetaData;
022: import org.drools.brms.client.rpc.RepositoryServiceFactory;
023: import org.drools.brms.client.rpc.RuleAsset;
024:
025: import com.google.gwt.user.client.Command;
026: import com.google.gwt.user.client.ui.Button;
027: import com.google.gwt.user.client.ui.ClickListener;
028: import com.google.gwt.user.client.ui.DialogBox;
029: import com.google.gwt.user.client.ui.FlexTable;
030: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
031: import com.google.gwt.user.client.ui.Widget;
032: import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
033:
034: /**
035: * This shows a historical read only view of an asset, as a popup.
036: * Why a popup? well, people can drag it around how they want.
037: *
038: * @author Michael Neale
039: */
040: public class VersionViewer extends DialogBox {
041:
042: private String versionUUID;
043: private String headUUID;
044: private Command refresh;
045:
046: public VersionViewer(final MetaData head, String versionUUID,
047: String headUUID, Command refresh) {
048: super (false);
049:
050: this .versionUUID = versionUUID;
051: this .headUUID = headUUID;
052: this .refresh = refresh;
053:
054: setStyleName("version-Popup");
055:
056: LoadingPopup.showMessage("Loading version");
057:
058: RepositoryServiceFactory.getService().loadRuleAsset(
059: versionUUID, new GenericCallback() {
060:
061: public void onSuccess(Object data) {
062:
063: RuleAsset asset = (RuleAsset) data;
064: asset.isreadonly = true;
065: asset.metaData.name = head.name;
066: setText("Version number ["
067: + asset.metaData.versionNumber
068: + "] of [" + asset.metaData.name + "]");
069:
070: FlexTable layout = new FlexTable();
071: FlexCellFormatter formatter = layout
072: .getFlexCellFormatter();
073:
074: Button restore = new Button(
075: "Restore this version");
076: restore.addClickListener(new ClickListener() {
077: public void onClick(Widget w) {
078: restore(w);
079: }
080:
081: });
082: layout.setWidget(0, 0, restore);
083: formatter.setHorizontalAlignment(0, 0,
084: HasHorizontalAlignment.ALIGN_LEFT);
085:
086: Button close = new Button("Close");
087: close.addClickListener(new ClickListener() {
088: public void onClick(Widget w) {
089: hide();
090: }
091: });
092:
093: layout.setWidget(0, 1, close);
094:
095: formatter.setHorizontalAlignment(0, 1,
096: HasHorizontalAlignment.ALIGN_RIGHT);
097:
098: RuleViewer viewer = new RuleViewer(asset, true);
099:
100: viewer.setWidth("100%");
101: layout.setWidget(1, 0, viewer);
102: formatter.setColSpan(1, 1, 2);
103: layout.setWidth("100%");
104: layout.setPixelSize(800, 300);
105: setWidget(layout);
106: }
107: });
108: }
109:
110: private void restore(Widget w) {
111:
112: final CheckinPopup pop = new CheckinPopup(
113: w.getAbsoluteLeft() + 10, w.getAbsoluteTop() + 10,
114: "Restore this version?");
115: pop.setCommand(new Command() {
116: public void execute() {
117: RepositoryServiceFactory.getService().restoreVersion(
118: versionUUID, headUUID, pop.getCheckinComment(),
119: new GenericCallback() {
120: public void onSuccess(Object data) {
121: hide();
122: refresh.execute();
123: }
124: });
125: }
126: });
127: pop.show();
128: }
129:
130: }
|