2014-03-03 19:17:26 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
|
2014-03-04 12:12:03 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiValuePanel;
|
2014-03-03 19:17:26 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
|
|
|
|
|
|
|
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;
|
2014-03-04 15:07:29 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.Html;
|
2014-02-25 15:58:42 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
|
|
|
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.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
|
2014-03-03 19:17:26 +01:00
|
|
|
* @Mar 3, 2014
|
2014-02-25 15:58:42 +01:00
|
|
|
*
|
|
|
|
*/
|
2014-03-04 17:49:15 +01:00
|
|
|
public class SmartShare extends Dialog implements SmartDialogInterface{
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
private TextField<String> txtName;
|
2014-02-27 16:03:30 +01:00
|
|
|
private FileModel fileToShare = null;
|
2014-02-25 15:58:42 +01:00
|
|
|
private UserStore userStore = new UserStore();
|
2014-06-23 12:27:21 +02:00
|
|
|
private MultiValuePanel suggestPanel = null;
|
2014-02-25 15:58:42 +01:00
|
|
|
private Button buttonMultiDrag = new Button("Choose Contacts");
|
2014-06-23 12:27:21 +02:00
|
|
|
private boolean readGroupsFromHL;
|
|
|
|
private boolean readGroupsFromPortal;
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
/**
|
2014-06-23 17:02:57 +02:00
|
|
|
* SmartShare base constructor by default does not retrieve groupss
|
2014-03-03 19:17:26 +01:00
|
|
|
*/
|
|
|
|
public SmartShare() {
|
2014-06-23 15:18:02 +02:00
|
|
|
this(false, false);
|
2014-06-23 12:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2014-06-23 15:18:02 +02:00
|
|
|
* @param readGroupsFromHL - if true read group names from HL
|
|
|
|
* @param readGroupsFromPortal - if true read group names from Portal (as VRE)
|
|
|
|
*
|
2014-06-23 12:27:21 +02:00
|
|
|
*/
|
|
|
|
public SmartShare(boolean readGroupsFromHL, boolean readGroupsFromPortal) {
|
|
|
|
this.readGroupsFromHL = readGroupsFromHL;
|
|
|
|
this.readGroupsFromPortal = readGroupsFromPortal;
|
|
|
|
suggestPanel = new MultiValuePanel(userStore, readGroupsFromHL, readGroupsFromPortal);
|
2014-03-03 19:17:26 +01:00
|
|
|
initLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>(){
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare Login
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean contains(Object o) {
|
|
|
|
|
|
|
|
if(o==null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InfoContactModel contact = (InfoContactModel) o;
|
|
|
|
|
|
|
|
for (int i = 0; i < listAlreadyShared.size(); i++){
|
|
|
|
if (contact.getName().compareTo(listAlreadyShared.get(i).getName())==0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2014-03-03 19:17:26 +01:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use to modify a shared folder or share an existing folder
|
2014-02-27 16:03:30 +01:00
|
|
|
* @param fileModel
|
2014-02-25 15:58:42 +01:00
|
|
|
* @param type
|
|
|
|
*/
|
2014-03-03 19:17:26 +01:00
|
|
|
|
|
|
|
public void updateSharingDialog(FileModel fileModel, List<CredentialModel> listAlreadySharedContact){
|
|
|
|
this.fileToShare = fileModel;
|
2014-03-04 12:12:03 +01:00
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
String heading = "Share";
|
2014-02-27 16:03:30 +01:00
|
|
|
if(fileModel.isDirectory())
|
|
|
|
heading+=" folder: ";
|
|
|
|
else
|
2014-03-04 19:26:09 +01:00
|
|
|
heading+= " : ";
|
2014-02-27 16:03:30 +01:00
|
|
|
|
|
|
|
setHeading(heading+fileModel.getName());
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
txtName = new TextField<String>();
|
|
|
|
txtName.setAllowBlank(false);
|
2014-02-27 16:03:30 +01:00
|
|
|
txtName.setValue(fileModel.getName());
|
2014-02-25 15:58:42 +01:00
|
|
|
txtName.setReadOnly(true);
|
|
|
|
txtName.setAutoValidate(true);
|
2014-03-03 19:17:26 +01:00
|
|
|
txtName.setFieldLabel("Item Name");
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
final LayoutContainer lc = new LayoutContainer();
|
|
|
|
lc.setStyleAttribute("margin-top", "10px");
|
|
|
|
lc.setStyleAttribute("margin-bottom", "10px");
|
|
|
|
lc.setSize(480, 50);
|
|
|
|
|
|
|
|
final 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");
|
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
flexTable.setWidget(1, 0, new Label("Add more"));
|
|
|
|
flexTable.setWidget(1, 1, buttonMultiDrag);
|
|
|
|
|
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
if(listAlreadySharedContact!=null && listAlreadySharedContact.size()>0){
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
userStore.getInfoContactModelsFromCredential(listAlreadySharedContact, new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> result) {
|
|
|
|
for (InfoContactModel infoContactModel : result) {
|
2014-02-25 15:58:42 +01:00
|
|
|
if(infoContactModel.getName()!=null){
|
2014-03-04 15:07:29 +01:00
|
|
|
listAlreadyShared.add(infoContactModel);
|
|
|
|
suggestPanel.addRecipient(infoContactModel.getName(),false);
|
2014-03-03 19:17:26 +01:00
|
|
|
layout();
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lc.unmask();
|
2014-03-03 19:17:26 +01:00
|
|
|
lc.layout();
|
|
|
|
layout();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
lc.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
lc.add(flexTable);
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
setFocusWidget(suggestPanel.getBox());
|
|
|
|
add(txtName);
|
2014-03-03 19:17:26 +01:00
|
|
|
// add(txtOwner);
|
2014-02-25 15:58:42 +01:00
|
|
|
add(lc);
|
2014-06-23 12:27:21 +02:00
|
|
|
addListeners();
|
2014-02-27 16:03:30 +01:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public FileModel getFileToShare() {
|
2014-02-27 16:03:30 +01:00
|
|
|
return fileToShare;
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
public void initLayout(){
|
2014-02-25 15:58:42 +01:00
|
|
|
FormLayout layout = new FormLayout();
|
|
|
|
layout.setLabelWidth(90);
|
|
|
|
layout.setDefaultWidth(380);
|
|
|
|
setLayout(layout);
|
|
|
|
setModal(true);
|
|
|
|
setScrollMode(Scroll.AUTOY);
|
|
|
|
setBodyStyle("padding: 9px; background: none");
|
2014-03-03 19:17:26 +01:00
|
|
|
setWidth(ConstantsSharing.WIDTH_DIALOG);
|
|
|
|
setHeight(ConstantsSharing.HEIGHT_DIALOG);
|
2014-02-25 15:58:42 +01:00
|
|
|
setResizable(true);
|
|
|
|
setButtonAlign(HorizontalAlignment.CENTER);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
2014-03-04 12:12:03 +01:00
|
|
|
setIcon(Resources.getIconShare());
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-04 12:12:03 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the selected contacts (as InfoContactModel)
|
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
public List<InfoContactModel> getSharedListUsers() {
|
|
|
|
// printSelectedUser();
|
2014-03-04 12:12:03 +01:00
|
|
|
|
|
|
|
List<InfoContactModel> contacts = new ArrayList<InfoContactModel>();
|
|
|
|
|
|
|
|
for (InfoContactModel wsuser : suggestPanel.getSelectedUser()) {
|
|
|
|
CredentialModel credential = getCredentialModelFromInfoContactModel(wsuser);
|
|
|
|
wsuser.setReferenceCredential(credential);
|
|
|
|
contacts.add(wsuser);
|
|
|
|
}
|
|
|
|
|
|
|
|
return contacts;
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2014-03-03 19:17:26 +01:00
|
|
|
|
|
|
|
|
2014-03-04 12:12:03 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the selected contacts (as CredentialModel)
|
|
|
|
*/
|
2014-03-03 19:17:26 +01:00
|
|
|
public List<CredentialModel> getSharedListUsersCredential() {
|
2014-03-04 12:12:03 +01:00
|
|
|
|
|
|
|
List<CredentialModel> toReturn = new ArrayList<CredentialModel>();
|
|
|
|
|
|
|
|
for (InfoContactModel wsuser : suggestPanel.getSelectedUser()) {
|
|
|
|
CredentialModel credential = wsuser.getReferenceCredential();
|
|
|
|
|
|
|
|
if(credential==null)
|
|
|
|
credential = new CredentialModel(null, "UNKWNOWN LOGIN", wsuser.isGroup());
|
|
|
|
|
|
|
|
toReturn.add(credential);
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
private CredentialModel getCredentialModelFromInfoContactModel(InfoContactModel infoContact){
|
|
|
|
|
|
|
|
if(infoContact==null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if(infoContact.getReferenceCredential()==null){
|
|
|
|
return new CredentialModel(null, infoContact.getLogin(), infoContact.isGroup());
|
|
|
|
}else if(infoContact.getReferenceCredential()!=null)
|
|
|
|
return infoContact.getReferenceCredential();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2014-03-03 19:17:26 +01:00
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
|
2014-06-23 12:27:21 +02:00
|
|
|
public void addListeners(){
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
multiDrag.show();
|
|
|
|
|
|
|
|
List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
|
|
|
|
multiDrag.addSourceContacts(exclusiveContacts);
|
|
|
|
|
|
|
|
|
|
|
|
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
|
|
|
|
if(!listAlreadyShared.contains(infoContactModel))
|
|
|
|
multiDrag.addTargetContact(infoContactModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser());
|
|
|
|
|
|
|
|
// multiDrag.addTargetContacts(suggestPanel.getSelectedUser());
|
|
|
|
|
|
|
|
multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
initSuggestContacts();
|
|
|
|
|
|
|
|
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
|
|
|
|
suggestPanel.addRecipient(infoContactModel.getName(),true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
|
|
|
|
//
|
|
|
|
// if(!listAlreadySharedContains(infoContactModel))
|
|
|
|
// suggestPanel.addRecipient(infoContactModel.getName(),true);
|
|
|
|
// }
|
|
|
|
|
|
|
|
suggestPanel.boxSetFocus();
|
|
|
|
|
|
|
|
// printSelectedUser();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean listAlreadySharedContains(InfoContactModel contact){
|
|
|
|
|
|
|
|
if(contact==null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (InfoContactModel ct : listAlreadyShared) {
|
|
|
|
|
|
|
|
if(ct.getLogin().compareTo(contact.getLogin())==0){
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//DEBUG
|
|
|
|
private void printSelectedUser(){
|
|
|
|
|
|
|
|
System.out.println("SELETECTED USERS: ");
|
|
|
|
for (InfoContactModel contact : suggestPanel.getSelectedUser())
|
|
|
|
System.out.println(contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initSuggestContacts(){
|
|
|
|
|
|
|
|
suggestPanel.resetItemSelected();
|
|
|
|
|
|
|
|
for (InfoContactModel contact : listAlreadyShared) {
|
|
|
|
suggestPanel.addRecipient(contact.getName(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2014-03-04 15:07:29 +01:00
|
|
|
|
|
|
|
public void setAsError(String message){
|
|
|
|
enableFormDialog(false);
|
|
|
|
this.add(new Html("<br/> <p style=\"color:red; font-family:verdana, arial; font-size:14px;\">"+message+"</p>"));
|
|
|
|
this.layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableFormDialog(boolean bool){
|
|
|
|
getButtonById(Dialog.OK).setEnabled(bool);
|
|
|
|
buttonMultiDrag.setEnabled(bool);
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return txtName.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2014-03-04 12:12:03 +01:00
|
|
|
* @param displayAlert in case of error
|
2014-02-25 15:58:42 +01:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean isValidForm(boolean displayAlert){
|
|
|
|
|
|
|
|
if(!txtName.isValid()){
|
|
|
|
if(displayAlert)
|
|
|
|
MessageBox.alert("Attention", "Name must not be empty", null);
|
|
|
|
txtName.focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(getSharedListUsers().size()==0){
|
|
|
|
if(displayAlert)
|
|
|
|
MessageBox.alert("Attention", "You must pick at least one user with which share the folder", null);
|
|
|
|
suggestPanel.boxSetFocus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
2014-03-03 19:17:26 +01:00
|
|
|
|
2014-06-23 15:18:02 +02:00
|
|
|
|
|
|
|
public boolean isReadGroupsFromHL() {
|
|
|
|
return readGroupsFromHL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isReadGroupsFromPortal() {
|
|
|
|
return readGroupsFromPortal;
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|