enhancements on ACLs
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@91369 82a268e6-3cf1-43bd-a215-b396298e98cftask/19600
parent
39f6487f91
commit
173e2451c3
@ -0,0 +1,285 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.view.sharing;
|
||||
|
||||
import com.extjs.gxt.ui.client.data.BaseModelData;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class StringNameFilterModel extends BaseModelData {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public StringNameFilterModel() {
|
||||
|
||||
}
|
||||
|
||||
public StringNameFilterModel(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
set("name", name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package org.gcube.portlets.user.workspace.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author francesco
|
||||
*
|
||||
*/
|
||||
public class WorkspaceACL implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1682851324671600049L;
|
||||
|
||||
private String id;
|
||||
private String label;
|
||||
public enum USER_TYPE{ADMINISTRATOR, GROUP, OWNER, OTHER};
|
||||
|
||||
public WorkspaceACL(String id, String label) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public WorkspaceACL() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("WorkspaceACL [id=");
|
||||
builder.append(id);
|
||||
builder.append(", label=");
|
||||
builder.append(label);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue