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.common.FormStyleLayout;
020: import org.drools.brms.client.common.GenericCallback;
021: import org.drools.brms.client.common.LoadingPopup;
022: import org.drools.brms.client.rpc.RepositoryServiceFactory;
023:
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.Composite;
027: import com.google.gwt.user.client.ui.HTML;
028: import com.google.gwt.user.client.ui.HorizontalPanel;
029: import com.google.gwt.user.client.ui.ListBox;
030: import com.google.gwt.user.client.ui.TextBox;
031: import com.google.gwt.user.client.ui.Widget;
032:
033: public class StateManager extends Composite {
034:
035: private ListBox currentStatuses;
036:
037: public StateManager() {
038: FormStyleLayout form = new FormStyleLayout(
039: "images/status_large.png", "Manage statuses");
040: form
041: .addAttribute(
042: "",
043: new HTML(
044: "<i>Status tags are for the lifecycle of an asset.</i>"));
045:
046: currentStatuses = new ListBox();
047: currentStatuses.setVisibleItemCount(7);
048: currentStatuses.setWidth("50%");
049:
050: refreshList();
051:
052: form.addAttribute("Current statuses:", currentStatuses);
053:
054: form.addAttribute("Add new status:", newStatusEditor());
055: initWidget(form);
056: }
057:
058: private void refreshList() {
059: LoadingPopup.showMessage("Loading statuses...");
060: RepositoryServiceFactory.getService().listStates(
061: new GenericCallback() {
062: public void onSuccess(Object data) {
063: currentStatuses.clear();
064: String[] statii = (String[]) data;
065: for (int i = 0; i < statii.length; i++) {
066: currentStatuses.addItem(statii[i]);
067: }
068: LoadingPopup.close();
069: }
070: });
071: }
072:
073: private Widget newStatusEditor() {
074: HorizontalPanel horiz = new HorizontalPanel();
075: final TextBox box = new TextBox();
076:
077: Button create = new Button("Create");
078: create.addClickListener(new ClickListener() {
079: public void onClick(Widget w) {
080: createStatus(box);
081: }
082: });
083:
084: horiz.add(box);
085: horiz.add(create);
086:
087: return horiz;
088: }
089:
090: private void createStatus(final TextBox box) {
091: LoadingPopup.showMessage("Creating status");
092: RepositoryServiceFactory.getService().createState(
093: box.getText(), new GenericCallback() {
094: public void onSuccess(Object data) {
095: box.setText("");
096: refreshList();
097: LoadingPopup.close();
098: }
099: });
100:
101: }
102:
103: }
|