001: package org.drools.brms.client.rulelist;
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 java.util.Collections;
020: import java.util.Map;
021:
022: import org.drools.brms.client.categorynav.CategoryExplorerWidget;
023: import org.drools.brms.client.categorynav.CategorySelectHandler;
024: import org.drools.brms.client.common.GenericCallback;
025: import org.drools.brms.client.common.ImageButton;
026: import org.drools.brms.client.common.LoadingPopup;
027: import org.drools.brms.client.rpc.RepositoryServiceFactory;
028: import org.drools.brms.client.rpc.TableDataResult;
029: import org.drools.brms.client.ruleeditor.EditorLauncher;
030: import org.drools.brms.client.ruleeditor.NewAssetWizard;
031:
032: import com.google.gwt.user.client.Command;
033: import com.google.gwt.user.client.DeferredCommand;
034: import com.google.gwt.user.client.ui.ClickListener;
035: import com.google.gwt.user.client.ui.Composite;
036: import com.google.gwt.user.client.ui.FlexTable;
037: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
038: import com.google.gwt.user.client.ui.HasVerticalAlignment;
039: import com.google.gwt.user.client.ui.HorizontalPanel;
040: import com.google.gwt.user.client.ui.Image;
041: import com.google.gwt.user.client.ui.TabPanel;
042: import com.google.gwt.user.client.ui.Widget;
043: import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
044:
045: /**
046: * This is the category based asset browser (ie it has a category tree browser, as well as
047: * a search box).
048: *
049: * @author Michael Neale
050: */
051: public class AssetBrowser extends Composite {
052:
053: public static final int EDITOR_TAB = 1;
054: private TabPanel tab;
055: private Map openedViewers = Collections.EMPTY_MAP;
056: private AssetItemListViewer list;
057:
058: public AssetBrowser() {
059: tab = new TabPanel();
060: tab.setWidth("100%");
061: tab.setHeight("100%");
062:
063: FlexTable explorePanel = doExplorer();
064:
065: tab.add(explorePanel, "<img src='images/explore.gif'/>Explore",
066: true);
067:
068: tab.selectTab(0);
069: initWidget(tab);
070: }
071:
072: /** This will setup the explorer tab */
073: private FlexTable doExplorer() {
074: final FlexTable table = new FlexTable();
075: //and the the delegate to open an editor for a rule resource when
076: //chosen to
077: list = new AssetItemListViewer(new EditItemEvent() {
078: public void open(String key) {
079: showLoadEditor(key);
080: }
081: }, AssetItemListViewer.RULE_LIST_TABLE_ID);
082:
083: FlexCellFormatter formatter = table.getFlexCellFormatter();
084:
085: //setup the nav, which will drive the list
086: CategoryExplorerWidget nav = new CategoryExplorerWidget(
087: new CategorySelectHandler() {
088: public void selected(final String selectedPath) {
089: Command load = getRuleListLoadingCommand(list,
090: selectedPath);
091: table.setWidget(0, 1, list);
092: LoadingPopup
093: .showMessage("Retrieving list, please wait...");
094: DeferredCommand.add(load);
095: list.setRefreshCommand(load);
096: }
097:
098: });
099:
100: final QuickFindWidget quick = new QuickFindWidget(
101: new EditItemEvent() {
102: public void open(String key) {
103: showLoadEditor(key);
104: }
105: });
106:
107: table.setWidget(1, 0, nav);
108: table.setWidget(0, 1, quick);
109:
110: formatter.setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT,
111: HasVerticalAlignment.ALIGN_TOP);
112: formatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT,
113: HasVerticalAlignment.ALIGN_TOP);
114: formatter.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT,
115: HasVerticalAlignment.ALIGN_TOP);
116: formatter.setRowSpan(0, 1, 3);
117: formatter.setWidth(0, 0, "30%");
118: formatter.setWidth(0, 1, "70%");
119:
120: formatter.setHeight(0, 0, "90%");
121:
122: table.setText(2, 0, "");
123:
124: Image newRule = new ImageButton("images/new_rule.gif");
125: newRule.setTitle("Create new rule");
126:
127: newRule.addClickListener(new ClickListener() {
128: public void onClick(Widget w) {
129: showNewAssetWizard();
130: }
131: });
132:
133: Image showFinder = new ImageButton(
134: "images/system_search_small.png");
135: showFinder.setTitle("Show the name finder.");
136: showFinder.addClickListener(new ClickListener() {
137: public void onClick(Widget w) {
138: table.setWidget(0, 1, quick);
139: }
140: });
141:
142: HorizontalPanel actions = new HorizontalPanel();
143: actions.add(showFinder);
144: actions.add(newRule);
145: table.setWidget(0, 0, actions);
146: formatter.setHeight(0, 0, "5%");
147: formatter.setAlignment(0, 0,
148: HasHorizontalAlignment.ALIGN_CENTER,
149: HasVerticalAlignment.ALIGN_TOP);
150: formatter.setStyleName(0, 0, "new-asset-Icons");
151:
152: return table;
153: }
154:
155: private Command getRuleListLoadingCommand(
156: final AssetItemListViewer list, final String selectedPath) {
157: return new Command() {
158: public void execute() {
159: LoadingPopup
160: .showMessage("Loading list, please wait...");
161: RepositoryServiceFactory.getService()
162: .loadRuleListForCategories(selectedPath,
163: new GenericCallback() {
164: public void onSuccess(Object o) {
165: TableDataResult result = (TableDataResult) o;
166: list.loadTableData(result);
167: LoadingPopup.close();
168: }
169: });
170: }
171: };
172: }
173:
174: public void showLoadEditor(String uuid) {
175: EditorLauncher.showLoadEditor(openedViewers, tab, uuid, false);
176: }
177:
178: private void showNewAssetWizard() {
179: int left = 70;
180: int top = 100;
181:
182: NewAssetWizard pop = new NewAssetWizard(new EditItemEvent() {
183: public void open(String key) {
184: showLoadEditor(key);
185:
186: }
187: }, true, null, "Create a new rule");
188: pop.setPopupPosition(left, top);
189:
190: pop.show();
191: }
192:
193: public void setOpenedViewersContainer(Map openedViewers) {
194: this.openedViewers = openedViewers;
195: }
196: }
|