01: package org.drools.brms.client.common;
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.util.Iterator;
20:
21: import org.drools.brms.client.rpc.PackageConfigData;
22: import org.drools.brms.client.rpc.RepositoryServiceFactory;
23:
24: import com.google.gwt.user.client.rpc.AsyncCallback;
25: import com.google.gwt.user.client.ui.Composite;
26: import com.google.gwt.user.client.ui.ListBox;
27:
28: /**
29: * A rule package selector widget.
30: * @author michael neale
31: */
32: public class RulePackageSelector extends Composite {
33:
34: private ListBox packageList;
35: private String currentlySelectedPackage;
36:
37: public RulePackageSelector() {
38: packageList = new ListBox();
39:
40: RepositoryServiceFactory.getService().listPackages(
41: new AsyncCallback() {
42:
43: public void onFailure(Throwable arg0) {
44: ErrorPopup
45: .showMessage("Unable to load list of packages.");
46: }
47:
48: public void onSuccess(Object o) {
49: PackageConfigData[] list = (PackageConfigData[]) o;
50:
51: for (int i = 0; i < list.length; i++) {
52: packageList.addItem(list[i].name);
53: if (currentlySelectedPackage != null
54: && list[i].name
55: .equals(currentlySelectedPackage)) {
56: packageList.setSelectedIndex(i);
57: }
58: }
59:
60: }
61:
62: });
63:
64: initWidget(packageList);
65: }
66:
67: /**
68: * Returns the selected package.
69: */
70: public String getSelectedPackage() {
71: return packageList.getItemText(packageList.getSelectedIndex());
72: }
73:
74: public void selectPackage(String currentlySelectedPackage) {
75: this.currentlySelectedPackage = currentlySelectedPackage;
76: }
77:
78: }
|