001: package org.drools.brms.client.categorynav;
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.ErrorPopup;
020: import org.drools.brms.client.common.ImageButton;
021: import org.drools.brms.client.rpc.RepositoryServiceFactory;
022:
023: import com.google.gwt.user.client.rpc.AsyncCallback;
024: import com.google.gwt.user.client.ui.Button;
025: import com.google.gwt.user.client.ui.ClickListener;
026: import com.google.gwt.user.client.ui.FlexTable;
027: import com.google.gwt.user.client.ui.Label;
028: import com.google.gwt.user.client.ui.PopupPanel;
029: import com.google.gwt.user.client.ui.TextArea;
030: import com.google.gwt.user.client.ui.TextBox;
031: import com.google.gwt.user.client.ui.Widget;
032:
033: /**
034: * This provides a popup for editing a category (name etc).
035: * Mainly this is for creating a new category.
036: */
037: public class CategoryEditor extends PopupPanel {
038:
039: private String path;
040: private FlexTable table = new FlexTable(); //Using this table for the form layout
041: private TextBox name = new TextBox();
042: private TextArea description = new TextArea();
043:
044: /** This is used when creating a new category */
045: public CategoryEditor(String catPath) {
046: super (true);
047: path = catPath;
048:
049: table.setWidget(0, 0, new ImageButton(
050: "images/edit_category.gif"));
051:
052: table.setWidget(0, 1, new Label(getTitle(path)));
053:
054: table.setWidget(1, 0, new Label("Cateogory name"));
055: table.setWidget(1, 1, name);
056:
057: description.setVisibleLines(4);
058: table.setWidget(2, 0, new Label("Description"));
059: table.setWidget(2, 1, description);
060:
061: Button ok = new Button("OK");
062: ok.addClickListener(new ClickListener() {
063: public void onClick(Widget arg0) {
064: ok();
065: }
066:
067: });
068:
069: table.setWidget(3, 0, ok);
070:
071: Button cancel = new Button("Cancel");
072: cancel.addClickListener(new ClickListener() {
073: public void onClick(Widget w) {
074: cancel();
075: }
076:
077: });
078:
079: table.setWidget(3, 1, cancel);
080:
081: add(table);
082: setStyleName("ks-popups-Popup");
083: }
084:
085: private String getTitle(String catPath) {
086: if (catPath == null) {
087: return "Create a new top level category.";
088: } else {
089: return "Create new category under: [" + catPath + "]";
090: }
091: }
092:
093: void ok() {
094:
095: AsyncCallback cb = new AsyncCallback() {
096:
097: public void onFailure(Throwable arg0) {
098: ErrorPopup
099: .showMessage("Unable to create new category (server error). ");
100: }
101:
102: public void onSuccess(Object result) {
103: if (((Boolean) result).booleanValue()) {
104: hide();
105: } else {
106: ErrorPopup
107: .showMessage("Category was not successfully created. ");
108:
109: }
110: }
111: };
112:
113: if (this .name.equals("")) {
114: ErrorPopup
115: .showMessage("Can't have an empty category name.");
116: } else {
117: RepositoryServiceFactory.getService().createCategory(path,
118: name.getText(), description.getText(), cb);
119:
120: }
121: }
122:
123: void cancel() {
124: hide();
125: }
126: }
|