package org.gcube.portlets.user.workspace.client.view.sharing.multisuggest; import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.model.ExtendedInfoContactModel; import org.gcube.portlets.user.workspace.client.model.InfoContactModel; import org.gcube.portlets.user.workspace.client.resources.Resources; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; import com.extjs.gxt.ui.client.Style.Orientation; import com.extjs.gxt.ui.client.Style.Scroll; import com.extjs.gxt.ui.client.Style.SortDir; import com.extjs.gxt.ui.client.Style.VerticalAlignment; import com.extjs.gxt.ui.client.dnd.GridDragSource; import com.extjs.gxt.ui.client.dnd.GridDropTarget; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.store.Store; import com.extjs.gxt.ui.client.store.StoreSorter; import com.extjs.gxt.ui.client.util.Margins; import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.Dialog; import com.extjs.gxt.ui.client.widget.HorizontalPanel; import com.extjs.gxt.ui.client.widget.Label; import com.extjs.gxt.ui.client.widget.MessageBox; import com.extjs.gxt.ui.client.widget.VerticalPanel; import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.form.StoreFilterField; import com.extjs.gxt.ui.client.widget.form.TextArea; import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; import com.extjs.gxt.ui.client.widget.grid.ColumnData; import com.extjs.gxt.ui.client.widget.grid.ColumnModel; import com.extjs.gxt.ui.client.widget.grid.Grid; import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.extjs.gxt.ui.client.widget.layout.RowData; import com.extjs.gxt.ui.client.widget.layout.RowLayout; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; public class MultiDragContact extends Dialog { private GridDropTarget dropSource; private GridDropTarget dropTarget; private ListStore storeSource = new ListStore(); private ListStore storeTarget = new ListStore(); private TextArea textAreaAlreadyShared; private Grid gridAllContacts; private Grid gridShareWith; public MultiDragContact() { setStyleAttribute("margin", "10px"); setSize(563, 542); setHeading("Group dragging contacts"); setIcon(Resources.getIconUsers()); setModal(true); setScrollMode(Scroll.AUTOY); setBodyStyle("padding: 9px; background: none"); setResizable(true); setButtonAlign(HorizontalAlignment.CENTER); setButtons(Dialog.OKCANCEL); //SORTING STORE setGropUserStoreSorter(storeSource); setGropUserStoreSorter(storeTarget); ContentPanel cpAlreadyShared = new ContentPanel(); cpAlreadyShared.setSize(530, 60); cpAlreadyShared.setHeaderVisible(false); cpAlreadyShared.setLayout(new FitLayout()); VerticalPanel vpShared = new VerticalPanel(); vpShared.setVerticalAlign(VerticalAlignment.MIDDLE); vpShared.setHorizontalAlign(HorizontalAlignment.CENTER); vpShared.setStyleAttribute("padding", "5px"); vpShared.setLayout(new FitLayout()); HorizontalPanel hpSharedContacts = new HorizontalPanel(); hpSharedContacts.setHorizontalAlign(HorizontalAlignment.CENTER); hpSharedContacts.setVerticalAlign(VerticalAlignment.MIDDLE); textAreaAlreadyShared = new TextArea(); // textField.setFieldLabel("Already shared with"); // textField.setHeight(30); textAreaAlreadyShared.setWidth(401); textAreaAlreadyShared.setHeight(43); cpAlreadyShared.setStyleAttribute("padding-bottom", "5px"); textAreaAlreadyShared.setReadOnly(true); cpAlreadyShared.add(textAreaAlreadyShared); Label label = new Label("Already shared with"); label.setStyleAttribute("padding-right", "10px"); hpSharedContacts.add(label); hpSharedContacts.add(textAreaAlreadyShared); vpShared.add(hpSharedContacts); cpAlreadyShared.add(vpShared); add(cpAlreadyShared); ContentPanel cp = new ContentPanel(); cp.setSize(530, 370); cp.setHeaderVisible(false); cp.setLayout(new RowLayout(Orientation.HORIZONTAL)); ToolBar toolBar = new ToolBar(); Button buttonHelp = new Button(); buttonHelp.setIcon(Resources.getIconInfo()); buttonHelp.addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { MessageBox.info("Group dragging action", "Drag one or more contacts from the left (All Contacts) to the right (Share with) to add users in your sharing list.", null); } }); toolBar.add(buttonHelp); setTopComponent(toolBar); VerticalPanel vp = new VerticalPanel(); vp.setHorizontalAlign(HorizontalAlignment.CENTER); vp.add(new Label("All Contacts")); gridAllContacts = new Grid(storeSource, createColumnModel()); storeSource.setDefaultSort(InfoContactModel.FULLNAME, SortDir.ASC); storeSource.sort(InfoContactModel.FULLNAME, SortDir.ASC); storeTarget.setDefaultSort(InfoContactModel.FULLNAME, SortDir.ASC); storeTarget.sort(InfoContactModel.FULLNAME, SortDir.ASC); StoreFilterField filter = new StoreFilterField() { @Override protected boolean doSelect(Store store, ExtendedInfoContactModel parent, ExtendedInfoContactModel record, String property, String filter) { String name = record.getName(); name = name.toLowerCase(); if (name.contains(filter.toLowerCase())) { return true; } return false; } }; // filter.setFieldLabel("Filter Contacts"); filter.setWidth(247); filter.setEmptyText("Filter All Contacts"); HorizontalPanel hp = new HorizontalPanel(); hp.setStyleAttribute("padding-top", "5px"); hp.setStyleAttribute("padding-bottom", "5px"); hp.add(filter); filter.bind(storeSource); gridAllContacts.setSize(250,310); gridAllContacts.setBorders(false); gridAllContacts.getView().setAutoFill(true); // gridAllContacts.setAutoExpandColumn(InfoContactModel.FULLNAME); gridAllContacts.setBorders(true); vp.add(hp); vp.add(gridAllContacts); RowData rowData = new RowData(.5, 1); rowData.setMargins(new Margins(6)); cp.add(vp, rowData); vp = new VerticalPanel(); vp.setHorizontalAlign(HorizontalAlignment.CENTER); vp.add(new Label("Share with...")); gridShareWith = new Grid(storeTarget, createColumnModel()); StoreFilterField filter2 = new StoreFilterField() { @Override protected boolean doSelect(Store store, ExtendedInfoContactModel parent, ExtendedInfoContactModel record, String property, String filter) { String name = record.getName(); name = name.toLowerCase(); if (name.contains(filter.toLowerCase())) { return true; } return false; } }; // filter.setFieldLabel("Filter Contacts"); filter2.setWidth(247); filter2.setEmptyText("Filter Share with"); hp = new HorizontalPanel(); hp.setStyleAttribute("padding-top", "5px"); hp.setStyleAttribute("padding-bottom", "5px"); hp.add(filter2); filter2.bind(storeTarget); gridShareWith.setSize(250, 310); gridShareWith.setBorders(false); gridShareWith.getView().setAutoFill(true); // gridShareWith.setAutoExpandColumn(InfoContactModel.FULLNAME); gridShareWith.setBorders(true); vp.add(hp); vp.add(gridShareWith); rowData = new RowData(.5, 1); rowData.setMargins(new Margins(6, 6, 6, 0)); cp.add(vp, rowData); new GridDragSource(gridAllContacts); new GridDragSource(gridShareWith); dropSource = new GridDropTarget(gridAllContacts); dropSource.setAllowSelfAsSource(false); dropTarget = new GridDropTarget(gridShareWith); dropTarget.setAllowSelfAsSource(false); add(cp); this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { hide(); } }); this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { hide(); } }); } private ColumnModel createColumnModel() { List configs = new ArrayList(); ColumnConfig icon = new ColumnConfig(ExtendedInfoContactModel.ICON, "", 25); configs.add(icon); ColumnConfig columnName = new ColumnConfig(ExtendedInfoContactModel.FULLNAME, "Name", 150); configs.add(columnName); ColumnConfig type = new ColumnConfig(ExtendedInfoContactModel.ISGROUP, "Type", 50); configs.add(type); GridCellRenderer typeRender = new GridCellRenderer() { @Override public String render(ExtendedInfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { Boolean isGroup = (Boolean) model.get(property); String color = "#0F4FA8"; String val = ""; if(isGroup){ val = "Group"; color = "#05316D"; return "" + val + ""; }else{ val = "User"; return "" + val + ""; } } }; type.setRenderer(typeRender); return new ColumnModel(configs); } public void addSourceContacts(List listContact){ gridAllContacts.mask("", ConstantsExplorer.LOADINGSTYLE); if(listContact!=null && listContact.size()>0){ List listExtended = new ArrayList(); //SETTING ICONS for (InfoContactModel infoContactModel : listContact) { ExtendedInfoContactModel ext = new ExtendedInfoContactModel(infoContactModel.getId(), infoContactModel.getLogin(), infoContactModel.getName(), infoContactModel.isGroup()); ext.setIcon(); listExtended.add(ext); } storeSource.add(listExtended); } gridAllContacts.unmask(); } public void addAlreadySharedContacts(List listContact){ gridShareWith.mask("", ConstantsExplorer.LOADINGSTYLE); if(listContact!=null && listContact.size()>0){ String alreadyShared = ""; for (int i=0; i listContact){ if(listContact!=null && listContact.size()>0){ storeTarget.add(convertFromInfoContactModel(listContact)); } } private List convertFromInfoContactModel(List listContact){ if(listContact!=null){ List listExtended = new ArrayList(listContact.size()); //SETTING ICONS for (InfoContactModel infoContactModel : listContact) { listExtended.add(convertFromInfoContactModel(infoContactModel)); } return listExtended; } return new ArrayList(); } private ExtendedInfoContactModel convertFromInfoContactModel(InfoContactModel infoContactModel){ if(infoContactModel!=null){ String fullName = infoContactModel.getName(); if(fullName==null || fullName.isEmpty()) fullName = infoContactModel.getLogin(); ExtendedInfoContactModel ext = new ExtendedInfoContactModel(infoContactModel.getId(), infoContactModel.getLogin(), fullName, infoContactModel.isGroup()); ext.setIcon(); return ext; } return new ExtendedInfoContactModel(); } public void addTargetContact(InfoContactModel contact){ if(contact!=null) storeTarget.add(convertFromInfoContactModel(contact)); } public List getTargetListContact(){ List infoContacts = storeTarget.getModels(); return (List) infoContacts; } private void setGropUserStoreSorter(ListStore store){ // Sorting files store.setStoreSorter(new StoreSorter() { @Override public int compare(Store store, ExtendedInfoContactModel m1, ExtendedInfoContactModel m2, String property) { boolean m1Folder = m1.isGroup(); boolean m2Folder = m2.isGroup(); if (m1Folder && !m2Folder) { return -1; } else if (!m1Folder && m2Folder) { return 1; } return m1.getName().compareToIgnoreCase(m2.getName()); } }); } }