001: package org.drools.brms.client.admin;
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.categorynav.CategoryEditor;
020: import org.drools.brms.client.categorynav.CategoryExplorerWidget;
021: import org.drools.brms.client.categorynav.CategorySelectHandler;
022: import org.drools.brms.client.common.FormStyleLayout;
023: import org.drools.brms.client.common.GenericCallback;
024: import org.drools.brms.client.common.ImageButton;
025: import org.drools.brms.client.rpc.RepositoryServiceFactory;
026:
027: import com.google.gwt.user.client.Window;
028: import com.google.gwt.user.client.ui.ClickListener;
029: import com.google.gwt.user.client.ui.Composite;
030: import com.google.gwt.user.client.ui.HTML;
031: import com.google.gwt.user.client.ui.Image;
032: import com.google.gwt.user.client.ui.SimplePanel;
033: import com.google.gwt.user.client.ui.VerticalPanel;
034: import com.google.gwt.user.client.ui.Widget;
035:
036: /**
037: * This controls category administration.
038: * @author Michael Neale
039: */
040: public class CategoryManager extends Composite {
041:
042: public VerticalPanel layout = new VerticalPanel();
043: //public String selectedPath;
044: private CategoryExplorerWidget explorer;
045:
046: public CategoryManager() {
047:
048: FormStyleLayout form = new FormStyleLayout(
049: "images/edit_category.gif", "Edit categories");
050: form
051: .addAttribute(
052: "",
053: new HTML(
054: "<i>Categories aid in managing large numbers of rules/assets. A shallow hierarchy is recommented.</i>"));
055:
056: explorer = new CategoryExplorerWidget(
057: new CategorySelectHandler() {
058: public void selected(String sel) {
059: //don't need this here as we don't do anything on select in this spot
060: }
061: });
062: explorer.setStyleName("category-explorer-Admin");
063:
064: SimplePanel editable = new SimplePanel();
065: editable.setStyleName("metadata-Widget");
066: editable.add(explorer);
067: form.addRow(new HTML("<hr/>"));
068: form.addAttribute("Current categories:", editable);
069:
070: Image refresh = new ImageButton("images/refresh.gif");
071: refresh.setTitle("Refresh categories");
072: refresh.addClickListener(new ClickListener() {
073: public void onClick(Widget w) {
074: explorer.refresh();
075: }
076: });
077: form.addAttribute("Refresh view:", refresh);
078: form.addRow(new HTML("<hr/>"));
079:
080: Image newCat = new ImageButton("images/new.gif");
081: newCat.setTitle("Create a new category");
082: newCat.addClickListener(new ClickListener() {
083: public void onClick(Widget w) {
084: CategoryEditor newCat = new CategoryEditor(explorer
085: .getSelectedPath());
086: newCat.setPopupPosition(w.getAbsoluteLeft(), w
087: .getAbsoluteTop() - 400);
088: newCat.show();
089: }
090: });
091:
092: form.addAttribute("Create a new category:", newCat);
093:
094: Image delete = new ImageButton("images/delete_obj.gif");
095: delete.addClickListener(new ClickListener() {
096: public void onClick(Widget w) {
097: deleteSelected();
098: }
099: });
100: delete
101: .setTitle("Deletes the currently selected category. You won't be able to delete if the category is in use.");
102:
103: form.addAttribute("Delete the currently selected category:",
104: delete);
105:
106: initWidget(form);
107: }
108:
109: private void deleteSelected() {
110: if (Window.confirm("Are you sure you want to delete category: "
111: + explorer.getSelectedPath())) {
112: RepositoryServiceFactory.getService().removeCategory(
113: explorer.getSelectedPath(), new GenericCallback() {
114:
115: public void onSuccess(Object data) {
116: explorer.refresh();
117: }
118:
119: });
120: }
121: }
122:
123: }
|