001: package org.drools.brms.client.packages;
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.FormStylePopup;
020:
021: import com.google.gwt.user.client.Command;
022: import com.google.gwt.user.client.ui.Button;
023: import com.google.gwt.user.client.ui.ClickListener;
024: import com.google.gwt.user.client.ui.FlexTable;
025: import com.google.gwt.user.client.ui.Image;
026: import com.google.gwt.user.client.ui.ListBox;
027: import com.google.gwt.user.client.ui.TextBox;
028: import com.google.gwt.user.client.ui.Widget;
029:
030: /**
031: * For building fact templates,. as a wizard.
032: * Sheesh you would think the name says enough.
033: *
034: * @author Michael Neale
035: */
036: public class FactTemplateWizard extends FormStylePopup {
037:
038: private FlexTable attributes;
039:
040: private Command okClick;
041:
042: private TextBox name;
043:
044: public FactTemplateWizard() {
045:
046: super ("images/new_wiz.gif", "Create a new fact template");
047: attributes = new FlexTable();
048: name = new TextBox();
049: addAttribute("Name:", name);
050: addAttribute("Fact attributes:", attributes);
051: Image newAttr = new Image("images/new_item.gif");
052: newAttr.addClickListener(new ClickListener() {
053: public void onClick(Widget w) {
054: addAttribute();
055: }
056: });
057: addAttribute("Add a new attribute", newAttr);
058:
059: Button ok = new Button("Create");
060: ok.addClickListener(new ClickListener() {
061: public void onClick(Widget w) {
062: okClick.execute();
063: hide();
064: }
065: });
066:
067: addAttribute("", ok);
068: }
069:
070: public void setOKClick(Command com) {
071: this .okClick = com;
072: }
073:
074: private void addAttribute() {
075: int row = attributes.getRowCount();
076: attributes.setWidget(row, 0, new TextBox());
077: attributes.setWidget(row, 1, typeList());
078:
079: }
080:
081: private Widget typeList() {
082: ListBox list = new ListBox();
083: list.addItem("String");
084: list.addItem("Integer");
085: list.addItem("Float");
086: list.addItem("Date");
087: list.addItem("Boolean");
088: return list;
089: }
090:
091: /**
092: * This will return a text version of the template to add in.
093: */
094: public String getTemplateText() {
095: String result = "template " + name.getText() + "\n";
096: for (int i = 0; i < attributes.getRowCount(); i++) {
097: ListBox type = (ListBox) attributes.getWidget(i, 1);
098: String typeName = type.getItemText(type.getSelectedIndex());
099: String slotName = ((TextBox) attributes.getWidget(i, 0))
100: .getText();
101: result = result + "\t" + typeName + " " + slotName + "\n";
102: }
103:
104: return result + "end";
105: }
106:
107: }
|