workspace-tree-widget/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java

284 lines
8.4 KiB
Java

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.FileModel;
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<String> txtName;
private TextArea textAreaDescription = new TextArea();
private FileModel parentFolder = 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, FileModel folder, HandlerManager eventBus) {
initLayout(folderParentName);
this.parentFolder = folder;
this.setIcon(Resources.getIconShareFolder());
setWidth(widthDialog);
setButtons(Dialog.OKCANCEL);
setHeading("Share folder: "+folder.getName());
txtName = new TextField<String>();
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<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> 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 FileModel getParentFolder() {
return parentFolder;
}
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<String>();
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<InfoContactModel> getSharedListUsers() {
return suggestPanel.getSelectedUser();
}
public void addListners(){
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
hide();
}
});
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@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<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
multiDrag.addSourceContacts(exclusiveContacts);
multiDrag.addTargetContacts(suggestPanel.getSelectedUser());
multiDrag.show();
multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@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;
}
}