001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.web.client.peditor; 017 018import com.google.gwt.core.client.GWT; 019import com.smartgwt.client.types.Alignment; 020import com.smartgwt.client.types.ContentsType; 021import com.smartgwt.client.types.Encoding; 022import com.smartgwt.client.types.FormMethod; 023import com.smartgwt.client.types.VerticalAlignment; 024import com.smartgwt.client.widgets.Button; 025import com.smartgwt.client.widgets.HTMLPane; 026import com.smartgwt.client.widgets.Window; 027import com.smartgwt.client.widgets.events.ClickEvent; 028import com.smartgwt.client.widgets.events.ClickHandler; 029import com.smartgwt.client.widgets.form.DynamicForm; 030import com.smartgwt.client.widgets.form.fields.HiddenItem; 031import com.smartgwt.client.widgets.form.fields.UploadItem; 032import com.smartgwt.client.widgets.layout.HLayout; 033import com.smartgwt.client.widgets.layout.VLayout; 034import org.modeshape.web.shared.JcrNode; 035 036/** 037 * 038 * @author kulikov 039 */ 040public class BinaryValueEditor implements ValueEditor<String> { 041 042 private Window window = new Window(); 043 private HTMLPane htmlPane = new HTMLPane(); 044 private DynamicForm form = new DynamicForm(); 045 private HiddenItem repositoryField = new HiddenItem("repository"); 046 private HiddenItem workspaceField = new HiddenItem("workspace"); 047 private HiddenItem pathField = new HiddenItem("path"); 048 private HiddenItem pNameField = new HiddenItem("pname"); 049 private UploadItem fileItem = new UploadItem("Upload content"); 050 051 public BinaryValueEditor() { 052 super(); 053 054 form.setMethod(FormMethod.POST); 055 form.setAction(GWT.getModuleBaseURL() + "binary-upload/content"); 056 form.setEncoding(Encoding.MULTIPART); 057 058 VLayout vstack = new VLayout(); 059 vstack.setTop(20); 060 061 vstack.setWidth100(); 062 vstack.setHeight(550); 063 064 htmlPane.setLeft(20); 065 htmlPane.setTop(20); 066 htmlPane.setWidth100(); 067 htmlPane.setHeight100(); 068 htmlPane.setContentsType(ContentsType.PAGE); 069 htmlPane.setBorder("inset #d3d3d3 1px"); 070 vstack.addMember(htmlPane); 071 072 window.setTitle("Binary content"); 073 window.setWidth(600); 074 window.setHeight(600); 075 window.setCanDragReposition(true); 076 window.setCanDragResize(false); 077 window.setShowMinimizeButton(false); 078 window.setShowCloseButton(true); 079 080 window.addChild(vstack); 081 window.setAutoCenter(true); 082 083 HLayout panel = new HLayout(); 084 vstack.addMember(panel); 085 086 Button submitButton = new Button("Submit"); 087 submitButton.addClickHandler(new ClickHandler() { 088 @SuppressWarnings( "synthetic-access" ) 089 @Override 090 public void onClick(ClickEvent event) { 091 form.submitForm(); 092 } 093 }); 094 submitButton.setValign(VerticalAlignment.CENTER); 095 fileItem.setStartRow(true); 096 fileItem.setEndRow(false); 097 098 fileItem.setWidth("100%"); 099 submitButton.setTitle("Upload"); 100 101 form.setWidth100(); 102 103 panel.setLayoutAlign(Alignment.LEFT); 104 panel.setLayoutAlign(VerticalAlignment.CENTER); 105 panel.setBackgroundColor(null); 106 panel.addMember(form); 107 panel.addMember(submitButton); 108 } 109 110 @Override 111 public void setValue(JcrNode node, String name, String reference) { 112 repositoryField.setValue(node.getRepository()); 113 workspaceField.setValue(node.getWorkspace()); 114 pathField.setValue(node.getPath()); 115 pNameField.setValue(name); 116 form.setItems(fileItem, repositoryField, workspaceField, pathField, pNameField); 117 htmlPane.setContentsURL(reference); 118 window.show(); 119 } 120 121}