/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.view.admin; import java.io.File; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.easyuploads.MultiFileUpload; import org.vaadin.easyuploads.UploadField; import org.vaadin.easyuploads.UploadField.FieldType; import static com.eventrouter.MessagePublisher.*; import com.vaadin.data.Property; import com.vaadin.ui.AbstractSelect; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.ComboBox; import com.vaadin.ui.Component; import com.vaadin.ui.Label; import serpro.mailarchiver.domain.metaarchive.Folder; import serpro.mailarchiver.service.find.FFolder; import serpro.mailarchiver.session.Session; import serpro.mailarchiver.util.transaction.WithReadOnlyTx; import serpro.mailarchiver.view.BaseComponent; import serpro.mailarchiver.util.Logger; class Upload extends BaseComponent.VerticalLayout { private static final Logger log = Logger.getLocalLogger(); Upload() { new UploadController(getDisplayId()); } @Override public final String getDisplayId() { return "upload"; } @Autowired private FFolder findFolder; private final static int MAX_DEPTH = 20; final ComboBox[] comboStack = new ComboBox[MAX_DEPTH]; private boolean changing; @WithReadOnlyTx private void refreshComboItems(int depth) { Session.setThreadSession(AdminConsoleApp.getInstance().getSession()); ComboBox cbox = comboStack[depth]; cbox.removeAllItems(); String folderId = (depth > 0) ? (String) comboStack[depth-1].getValue() : "home"; Folder folder = findFolder.byId(folderId); for(Folder child : folder.getChildren()) { cbox.addItem(child.getOid()); cbox.setItemCaption(child.getOid(), child.getName()); } cbox.setValue(null); cbox.setEnabled(true); cbox.setVisible(true); } @Override public Upload init() { for(int i = 0; i < MAX_DEPTH; i++) { final ComboBox cbox = new ComboBox(); comboStack[i] = cbox; cbox.setWidth("250px"); cbox.setData(i); cbox.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_OFF); cbox.setImmediate(true); cbox.setEnabled(false); cbox.setVisible(false); cbox.addListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { Object o = valueChangeEvent.getProperty().getValue(); if(changing) { return; } changing = true; int i = ((Integer)cbox.getData()); if(o == null) { for(int j = i + 1; j < MAX_DEPTH; j++) { ComboBox cb = comboStack[j]; if(cb.isVisible()) { cb.removeAllItems(); cb.setEnabled(false); cb.setVisible(false); } } refreshComboItems(i); } else { for(int j = i + 2; j < MAX_DEPTH; j++) { ComboBox cb = comboStack[j]; if(cb.isVisible()) { cb.removeAllItems(); cb.setEnabled(false); cb.setVisible(false); } } refreshComboItems(i + 1); } changing = false; } }); addComponent(cbox); } refreshComboItems(0); addComponent(hr()); final UploadField msgUp = new UploadField(); msgUp.setFieldType(FieldType.BYTE_ARRAY); msgUp.setCaption("Selecione uma mensagem para carregar no meta arquivamento"); Button btnLoad = new Button("Carregar"); btnLoad.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { publish("/mailarchiver/tests/upload", msgUp.getValue(), getSelectedFolderId()); } }); addComponent(msgUp); addComponent(btnLoad); addComponent(hr()); addComponent(new Label("Teste de multifile upload")); final MultiFileUpload multiFileUpload = new MultiFileUpload() { @Override protected void handleFile(File file, String filename, String mimeType, long length) { publish("/mailarchiver/tests/upload", file, filename, getSelectedFolderId()); } }; multiFileUpload.setCaption("MultiFile Upload"); addComponent(multiFileUpload); return this; } private String getSelectedFolderId() { for(int j = MAX_DEPTH - 1; j >= 0; j--) { ComboBox cb = comboStack[j]; if(cb.isVisible()) { Object o = cb.getValue(); if(o != null) { return (String) o; } } } return "home"; } private Component hr() { return new Label("
", Label.CONTENT_XHTML); } }