package org.gcube.portlets.user.workspace.client.view.sharing; import java.util.List; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.model.FolderModel; import org.gcube.portlets.user.workspace.client.model.InfoContactModel; import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiDragContact; import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiValuePanel; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; import com.extjs.gxt.ui.client.Style.Scroll; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.Dialog; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.form.TextArea; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.layout.FormLayout; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Label; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * */ public class DialogShareFolder extends Dialog { private int widthDialog = 530; private int heightTextArea = 100; private TextField txtName; private TextArea textAreaDescription = new TextArea(); private FolderModel folder = null; private UserStore userStore = new UserStore(); private MultiValuePanel suggestPanel = new MultiValuePanel(userStore); private Button buttonMultiDrag = new Button("Choose Contacts"); /** * Use to modify a shared folder or share an existing folder * @param folder * @param type */ public DialogShareFolder(String folderParentName, FolderModel folder, HandlerManager eventBus) { initLayout(folderParentName); this.folder = folder; this.setIcon(Resources.getIconShareFolder()); setWidth(widthDialog); setButtons(Dialog.OKCANCEL); setHeading("Share folder: "+folder.getName()); txtName = new TextField(); txtName.setAllowBlank(false); txtName.setValue(folder.getName()); txtName.setReadOnly(true); txtName.setAutoValidate(true); txtName.setFieldLabel("Folder Name"); textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION); textAreaDescription.setHeight(heightTextArea); textAreaDescription.setWidth(380); final LayoutContainer lc = new LayoutContainer(); lc.setStyleAttribute("margin-top", "10px"); lc.setStyleAttribute("margin-bottom", "10px"); lc.setSize(480, 50); FlexTable flexTable = new FlexTable(); flexTable.setStyleName("userssuggest"); Label labelShareWith = new Label("Share with users"); flexTable.setWidget(0, 0, labelShareWith); flexTable.setWidget(0, 1, suggestPanel); buttonMultiDrag.setStyleName("wizardButton"); // buttonMultiDrag.setIcon(Resources.getIconUsers()); flexTable.setWidget(1, 0, new Label("Add contacts by group dragging")); flexTable.setWidget(1, 1, buttonMultiDrag); Label labelDescription = new Label("Description"); flexTable.setWidget(2, 0, labelDescription); flexTable.setWidget(2, 1, textAreaDescription); lc.add(flexTable); lc.mask(); userStore.getListSharedUserByFolderId(folder.getIdentifier(), new AsyncCallback>() { @Override public void onSuccess(List result) { for (InfoContactModel infoContactModel : result) { suggestPanel.addRecipient(infoContactModel.getLogin()); } lc.unmask(); } @Override public void onFailure(Throwable caught) { lc.unmask(); } }); setFocusWidget(suggestPanel.getBox()); add(txtName); add(lc); addListners(); this.show(); } public FolderModel getFolder() { return folder; } public void initLayout(String folderParentName){ FormLayout layout = new FormLayout(); layout.setLabelWidth(90); layout.setDefaultWidth(380); setLayout(layout); setModal(true); setScrollMode(Scroll.AUTOY); setBodyStyle("padding: 9px; background: none"); setWidth(widthDialog); setHeight(380); setResizable(true); setButtonAlign(HorizontalAlignment.CENTER); setWidth(widthDialog); setButtons(Dialog.OKCANCEL); } /** * Use to create a new shared folder */ public DialogShareFolder(String folderParentName, HandlerManager eventBus) { initLayout(folderParentName); this.setIcon(Resources.getIconSharedFolder()); setHeading("Create a new shared folder in: "+folderParentName); setWidth(widthDialog); setButtons(Dialog.OKCANCEL); txtName = new TextField(); txtName.setAllowBlank(false); txtName.setAutoValidate(true); txtName.setFieldLabel("Folder Name"); textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION); textAreaDescription.setHeight(heightTextArea); textAreaDescription.setWidth(380); LayoutContainer lc = new LayoutContainer(); lc.setStyleAttribute("margin-top", "10px"); lc.setStyleAttribute("margin-bottom", "10px"); lc.setSize(480, 50); FlexTable flexTable = new FlexTable(); flexTable.setStyleName("userssuggest"); Label lableShareWith = new Label("Share with users"); flexTable.setWidget(0, 0, lableShareWith); flexTable.setWidget(0, 1, suggestPanel); buttonMultiDrag.setStyleName("wizardButton"); // buttonMultiDrag.setIcon(Resources.getIconUsers()); flexTable.setWidget(1, 0, new Label("Add contacts by group dragging")); flexTable.setWidget(1, 1, buttonMultiDrag); Label labelDescription = new Label("Description"); flexTable.setWidget(2, 0, labelDescription); flexTable.setWidget(2, 1, textAreaDescription); lc.add(flexTable); setFocusWidget(txtName); add(txtName); add(lc); addListners(); this.show(); } public List getSharedListUsers() { return suggestPanel.getSelectedUser(); } public void addListners(){ this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { hide(); } }); this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { if(isValidForm(false)) hide(); } }); buttonMultiDrag.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { final MultiDragContact multiDrag = new MultiDragContact(); List exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser()); multiDrag.addSourceContacts(exclusiveContacts); multiDrag.addTargetContacts(suggestPanel.getSelectedUser()); multiDrag.show(); multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { suggestPanel.resetItemSelected(); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { suggestPanel.addRecipient(infoContactModel.getLogin()); } suggestPanel.boxSetFocus(); } }); } }); } public String getName() { return txtName.getValue(); } public String getDescription() { if(textAreaDescription.getValue()==null) return ""; return textAreaDescription.getValue(); } /** * * @param displayAlert * @return */ public boolean isValidForm(boolean displayAlert){ if(!txtName.isValid()){ if(displayAlert) new MessageBoxAlert("Attention", "Name must not be empty", null); txtName.focus(); return false; } if(getSharedListUsers().size()==0){ if(displayAlert) new MessageBoxAlert("Attention", "You must pick at least one user with which share the folder", null); suggestPanel.boxSetFocus(); return false; } return true; } }