286 lines
7.5 KiB
Java
286 lines
7.5 KiB
Java
package org.gcube.portlets.user.workspace.client.view.sharing;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
|
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.MultiValuePanel;
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
|
|
|
|
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.CheckBox;
|
|
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
|
|
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
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 DialogPermission extends Dialog {
|
|
|
|
private int widthDialog = 530;
|
|
private FileModel parentFolder = null;
|
|
private UserStore userStore = new UserStore();
|
|
private MultiValuePanel suggestPanel = new MultiValuePanel(userStore);
|
|
private CheckBoxGroup checkGroup = new CheckBoxGroup();
|
|
private LayoutContainer lc = new LayoutContainer();
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
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(200);
|
|
setResizable(true);
|
|
setButtonAlign(HorizontalAlignment.CENTER);
|
|
setWidth(widthDialog);
|
|
setButtons(Dialog.OKCANCEL);
|
|
lc.setStyleAttribute("margin-top", "10px");
|
|
lc.setStyleAttribute("margin-bottom", "10px");
|
|
lc.setSize(480, 50);
|
|
}
|
|
|
|
/**
|
|
* Use to create a new shared folder
|
|
*/
|
|
public DialogPermission(String folderParentName, HandlerManager eventBus) {
|
|
|
|
initLayout(folderParentName);
|
|
this.setIcon(Resources.getIconSharedFolder());
|
|
setHeading("Set permission to folder: "+folderParentName);
|
|
|
|
setWidth(widthDialog);
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
FlexTable flexTable = new FlexTable();
|
|
flexTable.setStyleName("userssuggest");
|
|
Label lableShareWith = new Label("Administrators");
|
|
flexTable.setWidget(0, 0, lableShareWith);
|
|
flexTable.setWidget(0, 1, suggestPanel);
|
|
|
|
checkGroup.mask("Loading");
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
|
|
|
|
@Override
|
|
public void onSuccess(List<WorkspaceACL> result) {
|
|
for (WorkspaceACL acl : result) {
|
|
CheckBox box = createCheckBox(acl);
|
|
checkGroup.add(box);
|
|
}
|
|
checkGroup.unmask();
|
|
lc.layout();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
checkGroup.unmask();
|
|
|
|
}
|
|
});
|
|
|
|
|
|
Label labelOthers = new Label("Others");
|
|
flexTable.setWidget(2, 0, labelOthers);
|
|
flexTable.setWidget(2, 1, checkGroup);
|
|
|
|
lc.add(flexTable);
|
|
|
|
add(lc);
|
|
addListners();
|
|
}
|
|
|
|
private CheckBox createCheckBox(WorkspaceACL acl){
|
|
|
|
CheckBox check = new CheckBox();
|
|
// check.setId(dsm.getId());
|
|
// check.setBoxLabel(dsm.getName() + " ("+property+")");
|
|
check.setBoxLabel(acl.getLabel());
|
|
check.setValueAttribute(acl.getLabel());
|
|
check.setData("WORKSPACEACL", acl);
|
|
check.setToolTip(new ToolTipConfig(acl.getLabel()));
|
|
return check;
|
|
|
|
}
|
|
|
|
|
|
public List<InfoContactModel> getSharedListUsers() {
|
|
// printSelectedUser();
|
|
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();
|
|
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);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param displayAlert
|
|
* @return
|
|
*/
|
|
public boolean isValidForm(boolean displayAlert){
|
|
|
|
/*
|
|
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;
|
|
|
|
}
|
|
}
|