001: package org.drools.brms.client.common;
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.rpc.RepositoryServiceFactory;
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.ChangeListener;
024: import com.google.gwt.user.client.ui.ClickListener;
025: import com.google.gwt.user.client.ui.DialogBox;
026: import com.google.gwt.user.client.ui.HorizontalPanel;
027: import com.google.gwt.user.client.ui.ListBox;
028: import com.google.gwt.user.client.ui.Widget;
029:
030: /**
031: * Well this one should be pretty obvious what it does.
032: * I feel like I have wasted valuable time writing this comment, but I hope
033: * you enjoyed reading it.
034: *
035: * @author Michael Neale
036: *
037: */
038: public class StatusChangePopup extends DialogBox {
039:
040: private boolean isPackage;
041: private String uuid;
042: private String newStatus;
043: private Command changedStatus;
044:
045: public StatusChangePopup(String uuid, boolean isPackage) {
046: super (true);
047:
048: this .uuid = uuid;
049: this .isPackage = isPackage;
050:
051: setStyleName("ks-popups-Popup");
052:
053: setHTML("<img src='images/status_small.gif'/><b>Change status</b>");
054: HorizontalPanel horiz = new HorizontalPanel();
055: final ListBox box = new ListBox();
056:
057: LoadingPopup.showMessage("Please wait...");
058: RepositoryServiceFactory.getService().listStates(
059: new GenericCallback() {
060: public void onSuccess(Object data) {
061: String[] list = (String[]) data;
062: box.addItem("-- Choose one --");
063: for (int i = 0; i < list.length; i++) {
064: box.addItem(list[i]);
065: }
066: LoadingPopup.close();
067: }
068: });
069:
070: box.addChangeListener(new ChangeListener() {
071: public void onChange(Widget w) {
072: newStatus = box.getItemText(box.getSelectedIndex());
073: }
074: });
075:
076: horiz.add(box);
077: Button ok = new Button("Change status");
078: ok.addClickListener(new ClickListener() {
079: public void onClick(Widget w) {
080: String newState = box.getItemText(box
081: .getSelectedIndex());
082: changeState(newState);
083: hide();
084: }
085: });
086: horiz.add(ok);
087:
088: Button close = new Button("Cancel");
089: close.addClickListener(new ClickListener() {
090: public void onClick(Widget w) {
091: hide();
092: }
093: });
094: horiz.add(close);
095:
096: setWidget(horiz);
097: }
098:
099: /** Apply the state change */
100: private void changeState(String newState) {
101: LoadingPopup.showMessage("Updating status...");
102: RepositoryServiceFactory.getService().changeState(uuid,
103: newStatus, isPackage, new GenericCallback() {
104: public void onSuccess(Object data) {
105: changedStatus.execute();
106: LoadingPopup.close();
107: }
108: });
109: }
110:
111: /**
112: * Get what the state was changed to.
113: */
114: public String getState() {
115: return this .newStatus;
116: }
117:
118: /**
119: * set the status change event
120: */
121: public void setChangeStatusEvent(Command command) {
122: this.changedStatus = command;
123: }
124: }
|