package org.gcube.portlets.user.workspace.client.view.sharing; import java.util.List; import org.gcube.portlets.user.workspace.client.util.GetPermissionIconByACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL.USER_TYPE; import com.extjs.gxt.ui.client.Style.ButtonScale; import com.extjs.gxt.ui.client.Style.IconAlign; import com.extjs.gxt.ui.client.Style.VerticalAlignment; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.HorizontalPanel; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.button.ToggleButton; import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig; import com.google.gwt.core.shared.GWT; import com.google.gwt.user.client.ui.AbstractImagePrototype; public class PanelTogglePermission extends LayoutContainer { protected static final String WORKSPACEACLGROUP = "WORKSPACEACLGROUP"; // private ButtonGroup buttonGroup; private HorizontalPanel hp = new HorizontalPanel(); private WorkspaceACL selectedAcl = null; public PanelTogglePermission(List acls) { // setStyleAttribute("margin-top", "10px"); setStyleAttribute("margin-bottom", "15px"); setSize(350, 40); hp.mask("Loading ACLs"); hp.setVerticalAlign(VerticalAlignment.MIDDLE); hp.setStyleAttribute("padding-left", "35px"); for (WorkspaceACL acl : acls) { if(acl.getUserType().equals(USER_TYPE.OTHER)){ ToggleButton toggle = createToggle(acl); toggle.setToggleGroup(WORKSPACEACLGROUP); toggle.setStyleAttribute("margin-right", "10px"); // buttonGroup.add(toggle); // listToogle.add(toggle); // add(toggle); hp.add(toggle); } } hp.unmask(); add(hp); layout(); } private ToggleButton createToggle(final WorkspaceACL acl) { final ToggleButton bToggle = new ToggleButton(acl.getLabel()); bToggle.setScale(ButtonScale.MEDIUM); bToggle.setId(acl.getId()); bToggle.setAllowDepress(false); bToggle.toggle(acl.getDefaultValue()); bToggle.setIconAlign(IconAlign.TOP); bToggle.addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { if(bToggle.isPressed()){ selectedAcl = acl; } } }); bToggle.setToolTip(new ToolTipConfig(acl.getDescription())); AbstractImagePrototype img = GetPermissionIconByACL.getImage(acl); if(img!=null) bToggle.setIcon(img); // setIcon(bToggle, acl.getId()); return bToggle; } // private void setIcon(ToggleButton bToggle, String id){ // // if(id.compareTo("ADMINISTRATOR")==0){ // // }else if(id.compareTo("READ_ONLY")==0){ // bToggle.setIcon(Resources.getIconReadOnly()); // }else if(id.compareTo("WRITE_OWNER")==0){ // bToggle.setIcon(Resources.getIconWriteOwn()); // }else if(id.compareTo("WRITE_ALL")==0){ // bToggle.setIcon(Resources.getIconWriteAll()); // } // // } public WorkspaceACL getSelectedACL() { GWT.log("Selected ACL is: "+selectedAcl); return selectedAcl; } /* public List getCheckedGroupList() { List listDS = new ArrayList(); List values = new ArrayList(); if (radioGroup.getValue()!=null){ Radio radio = radioGroup.getValue(); values.add((Radio) radio); } else { List> listChecks = radioGroup.getAll(); for (Field field : listChecks) { values.add((Radio) field); } } for (Radio radio : values) { if (radio.isEnabled()){ WorkspaceACL acl = (WorkspaceACL) radio.getData(WORKSPACEACL); listDS.add(acl); } } if (listDS.size() == 0) return null; return listDS; } */ }