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.rpc.RuleAsset;
020: import org.drools.brms.client.ruleeditor.RuleViewer;
021:
022: /**
023: * This wraps a file uploader utility for model packages.
024: * Model packages are jar files.
025: *
026: * @author Michael Neale
027: * @author Fernando Meyer
028: */
029:
030: public class ModelAttachmentFileWidget extends
031: AssetAttachmentFileWidget {
032:
033: public ModelAttachmentFileWidget(RuleAsset asset, RuleViewer viewer) {
034: super (asset, viewer);
035: }
036:
037: public String getIcon() {
038: return "images/model_large.png";
039: }
040:
041: public String getOverallStyleName() {
042: return "editable-Surface";
043: }
044:
045: }
046:
047: /*Composite {
048:
049:
050: private FormPanel form;
051: private Button ok;
052: private HorizontalPanel busy;
053: private RuleViewer viewer;
054:
055:
056: public ModelAttachmentFileWidget(final RuleAsset asset, final RuleViewer viewer) {
057: this.viewer = viewer;
058: initWidgets(asset.uuid, asset.metaData.name);
059: initAssetHandlers();
060: }
061:
062: protected void initWidgets(final String uuid, String formName) {
063: form = new FormPanel();
064: form.setAction( GWT.getModuleBaseURL() + "asset" );
065: form.setEncoding( FormPanel.ENCODING_MULTIPART );
066: form.setMethod( FormPanel.METHOD_POST );
067:
068: FileUpload up = new FileUpload();
069: up.setName( HTMLFileManagerFields.UPLOAD_FIELD_NAME_ATTACH );
070: HorizontalPanel fields = new HorizontalPanel();
071: fields.add( getHiddenField(HTMLFileManagerFields.FORM_FIELD_UUID, uuid) );
072:
073: ok = new Button("Upload");
074:
075: fields.add( up );
076: fields.add( ok );
077:
078: form.add( fields );
079:
080: FormStyleLayout layout = new FormStyleLayout("images/model_large.png",
081: formName);
082:
083:
084: layout.addAttribute( "Upload new version:", form );
085: Button dl = new Button("Download");
086: dl.addClickListener( new ClickListener() {
087: public void onClick(Widget w) {
088: Window.open( GWT.getModuleBaseURL() + "asset?" + HTMLFileManagerFields.FORM_FIELD_UUID + "=" + uuid,
089: "downloading...", "" );
090: }
091: });
092: layout.addAttribute( "Download current version:", dl );
093:
094: busy = new HorizontalPanel();
095: busy.setVisible( false );
096: busy.add( new Label("Uploading file...") );
097: busy.add( new Image("images/spinner.gif") );
098:
099: layout.addRow( busy );
100: ok.addClickListener( new ClickListener() {
101: public void onClick(Widget w) {
102: showUploadingBusy();
103: submitUpload();
104: }
105: });
106:
107: initWidget( layout );
108:
109: this.setStyleName( "editable-Surface" );
110: }
111:
112: void initAssetHandlers( ) {
113: form.addFormHandler( new FormHandler() {
114:
115: public void onSubmit(FormSubmitEvent ev) {
116: }
117:
118: public void onSubmitComplete(FormSubmitCompleteEvent ev) {
119: if (ev.getResults().indexOf( "OK" ) > -1) {
120: viewer.refreshDataAndView();
121: } else {
122: ErrorPopup.showMessage( "Unable to upload the file." );
123: }
124: }
125:
126: });
127: }
128:
129: protected void submitUpload() {
130: DeferredCommand.add( new Command() {
131: public void execute() {
132: form.submit();
133: }
134: });
135: }
136:
137: protected void showUploadingBusy() {
138: this.ok.setVisible( false );
139: this.form.setVisible( false );
140: this.busy.setVisible( true );
141: }
142:
143: private TextBox getHiddenField(String name, String value) {
144: TextBox t = new TextBox();
145: t.setName( name );
146: t.setText( value );
147: t.setVisible( false );
148: return t;
149: }
150:
151: }
152:
153: */
|