2013-02-06 15:40:17 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.sharing;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
2013-02-12 16:02:00 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
2013-02-06 15:40:17 +01:00
|
|
|
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();
|
2013-02-12 16:02:00 +01:00
|
|
|
private FileModel parentFolder = null;
|
2013-02-06 15:40:17 +01:00
|
|
|
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
|
|
|
|
*/
|
2013-02-12 16:02:00 +01:00
|
|
|
public DialogShareFolder(String folderParentName, FileModel folder, HandlerManager eventBus) {
|
2013-02-06 15:40:17 +01:00
|
|
|
initLayout(folderParentName);
|
2013-02-12 16:02:00 +01:00
|
|
|
this.parentFolder = folder;
|
2013-02-06 15:40:17 +01:00
|
|
|
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) {
|
2013-02-08 17:31:14 +01:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
for (InfoContactModel infoContactModel : result) {
|
2013-02-18 16:47:37 +01:00
|
|
|
suggestPanel.addRecipient(infoContactModel.getLogin(),false);
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lc.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
lc.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-08 17:31:14 +01:00
|
|
|
setFocusWidget(suggestPanel.getBox());
|
2013-02-06 15:40:17 +01:00
|
|
|
add(txtName);
|
|
|
|
add(lc);
|
|
|
|
addListners();
|
|
|
|
|
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
|
2013-02-12 16:02:00 +01:00
|
|
|
public FileModel getParentFolder() {
|
|
|
|
return parentFolder;
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2013-02-08 17:31:14 +01:00
|
|
|
|
|
|
|
suggestPanel.resetItemSelected();
|
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
|
2013-02-18 16:47:37 +01:00
|
|
|
suggestPanel.addRecipient(infoContactModel.getLogin(),true);
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
2013-02-08 17:31:14 +01:00
|
|
|
|
|
|
|
suggestPanel.boxSetFocus();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|