2013-02-06 15:40:17 +01:00
package org.gcube.portlets.user.workspace.client.view.sharing.multisuggest ;
import java.util.ArrayList ;
import java.util.List ;
2013-06-12 16:30:45 +02:00
import org.gcube.portlets.user.workspace.client.ConstantsExplorer ;
2014-03-10 17:33:33 +01:00
import org.gcube.portlets.user.workspace.client.model.ExtendedInfoContactModel ;
2013-02-06 15:40:17 +01:00
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 ;
2013-06-12 15:45:58 +02:00
import com.extjs.gxt.ui.client.Style.SortDir ;
2013-06-07 17:32:53 +02:00
import com.extjs.gxt.ui.client.Style.VerticalAlignment ;
2013-02-06 15:40:17 +01:00
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 ;
2013-06-12 15:45:58 +02:00
import com.extjs.gxt.ui.client.store.Store ;
2014-03-10 17:33:33 +01:00
import com.extjs.gxt.ui.client.store.StoreSorter ;
2013-02-06 15:40:17 +01:00
import com.extjs.gxt.ui.client.util.Margins ;
import com.extjs.gxt.ui.client.widget.ContentPanel ;
import com.extjs.gxt.ui.client.widget.Dialog ;
2013-06-07 17:32:53 +02:00
import com.extjs.gxt.ui.client.widget.HorizontalPanel ;
2013-02-06 15:40:17 +01:00
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 ;
2013-06-12 15:45:58 +02:00
import com.extjs.gxt.ui.client.widget.form.StoreFilterField ;
2013-06-07 17:32:53 +02:00
import com.extjs.gxt.ui.client.widget.form.TextArea ;
2013-02-06 15:40:17 +01:00
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig ;
2014-03-10 17:33:33 +01:00
import com.extjs.gxt.ui.client.widget.grid.ColumnData ;
2013-02-06 15:40:17 +01:00
import com.extjs.gxt.ui.client.widget.grid.ColumnModel ;
import com.extjs.gxt.ui.client.widget.grid.Grid ;
2014-03-10 17:33:33 +01:00
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer ;
2013-06-07 17:32:53 +02:00
import com.extjs.gxt.ui.client.widget.layout.FitLayout ;
2013-02-06 15:40:17 +01:00
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 ;
2014-03-10 17:33:33 +01:00
private ListStore < ExtendedInfoContactModel > storeSource = new ListStore < ExtendedInfoContactModel > ( ) ;
private ListStore < ExtendedInfoContactModel > storeTarget = new ListStore < ExtendedInfoContactModel > ( ) ;
2013-06-07 17:32:53 +02:00
private TextArea textAreaAlreadyShared ;
2014-03-10 17:33:33 +01:00
private Grid < ExtendedInfoContactModel > gridAllContacts ;
private Grid < ExtendedInfoContactModel > gridShareWith ;
2013-02-06 15:40:17 +01:00
2013-06-12 15:45:58 +02:00
public MultiDragContact ( ) {
2013-02-06 15:40:17 +01:00
setStyleAttribute ( " margin " , " 10px " ) ;
2013-06-12 15:45:58 +02:00
setSize ( 563 , 542 ) ;
2013-02-06 15:40:17 +01:00
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 ) ;
2014-03-10 17:33:33 +01:00
//SORTING STORE
setGropUserStoreSorter ( storeSource ) ;
setGropUserStoreSorter ( storeTarget ) ;
2013-02-06 15:40:17 +01:00
2013-06-07 17:32:53 +02:00
ContentPanel cpAlreadyShared = new ContentPanel ( ) ;
2013-06-12 15:45:58 +02:00
cpAlreadyShared . setSize ( 530 , 60 ) ;
2013-06-07 17:32:53 +02:00
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 ) ;
2013-06-12 15:45:58 +02:00
textAreaAlreadyShared . setHeight ( 43 ) ;
2013-06-07 17:32:53 +02:00
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 ) ;
2013-02-06 15:40:17 +01:00
ContentPanel cp = new ContentPanel ( ) ;
2013-06-12 15:45:58 +02:00
cp . setSize ( 530 , 370 ) ;
2013-02-06 15:40:17 +01:00
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 < ButtonEvent > ( ) {
@Override
public void componentSelected ( ButtonEvent ce ) {
2013-06-07 17:32:53 +02:00
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 ) ;
2013-02-06 15:40:17 +01:00
}
} ) ;
toolBar . add ( buttonHelp ) ;
setTopComponent ( toolBar ) ;
VerticalPanel vp = new VerticalPanel ( ) ;
vp . setHorizontalAlign ( HorizontalAlignment . CENTER ) ;
vp . add ( new Label ( " All Contacts " ) ) ;
2014-03-10 17:33:33 +01:00
gridAllContacts = new Grid < ExtendedInfoContactModel > ( storeSource , createColumnModel ( ) ) ;
2013-06-12 15:45:58 +02:00
storeSource . setDefaultSort ( InfoContactModel . FULLNAME , SortDir . ASC ) ;
storeSource . sort ( InfoContactModel . FULLNAME , SortDir . ASC ) ;
storeTarget . setDefaultSort ( InfoContactModel . FULLNAME , SortDir . ASC ) ;
storeTarget . sort ( InfoContactModel . FULLNAME , SortDir . ASC ) ;
2014-03-10 17:33:33 +01:00
StoreFilterField < ExtendedInfoContactModel > filter = new StoreFilterField < ExtendedInfoContactModel > ( ) {
2013-06-12 16:53:19 +02:00
@Override
2014-03-10 17:33:33 +01:00
protected boolean doSelect ( Store < ExtendedInfoContactModel > store ,
ExtendedInfoContactModel parent , ExtendedInfoContactModel record ,
2013-06-12 16:53:19 +02:00
String property , String filter ) {
String name = record . getName ( ) ;
name = name . toLowerCase ( ) ;
if ( name . contains ( filter . toLowerCase ( ) ) ) {
return true ;
}
return false ;
}
} ;
2013-06-12 15:45:58 +02:00
// 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 ) ;
2013-06-12 16:30:45 +02:00
gridAllContacts . setSize ( 250 , 310 ) ;
2014-03-10 17:33:33 +01:00
gridAllContacts . setBorders ( false ) ;
gridAllContacts . getView ( ) . setAutoFill ( true ) ;
// gridAllContacts.setAutoExpandColumn(InfoContactModel.FULLNAME);
2013-06-12 16:30:45 +02:00
gridAllContacts . setBorders ( true ) ;
2013-02-06 15:40:17 +01:00
2013-06-12 15:45:58 +02:00
vp . add ( hp ) ;
2013-06-12 16:30:45 +02:00
vp . add ( gridAllContacts ) ;
2013-06-12 15:45:58 +02:00
2013-02-06 15:40:17 +01:00
2013-06-12 15:45:58 +02:00
RowData rowData = new RowData ( . 5 , 1 ) ;
rowData . setMargins ( new Margins ( 6 ) ) ;
cp . add ( vp , rowData ) ;
2013-02-06 15:40:17 +01:00
vp = new VerticalPanel ( ) ;
vp . setHorizontalAlign ( HorizontalAlignment . CENTER ) ;
2013-06-07 17:32:53 +02:00
vp . add ( new Label ( " Share with... " ) ) ;
2014-03-10 17:33:33 +01:00
gridShareWith = new Grid < ExtendedInfoContactModel > ( storeTarget , createColumnModel ( ) ) ;
2013-06-12 15:45:58 +02:00
2014-03-10 17:33:33 +01:00
StoreFilterField < ExtendedInfoContactModel > filter2 = new StoreFilterField < ExtendedInfoContactModel > ( ) {
2013-06-12 16:53:19 +02:00
@Override
2014-03-10 17:33:33 +01:00
protected boolean doSelect ( Store < ExtendedInfoContactModel > store ,
ExtendedInfoContactModel parent , ExtendedInfoContactModel record ,
2013-06-12 16:53:19 +02:00
String property , String filter ) {
String name = record . getName ( ) ;
name = name . toLowerCase ( ) ;
if ( name . contains ( filter . toLowerCase ( ) ) ) {
return true ;
}
return false ;
}
} ;
2013-06-12 15:45:58 +02:00
// 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 ) ;
2013-06-12 16:30:45 +02:00
gridShareWith . setSize ( 250 , 310 ) ;
gridShareWith . setBorders ( false ) ;
2014-03-10 17:33:33 +01:00
gridShareWith . getView ( ) . setAutoFill ( true ) ;
// gridShareWith.setAutoExpandColumn(InfoContactModel.FULLNAME);
2013-06-12 16:30:45 +02:00
gridShareWith . setBorders ( true ) ;
2013-06-12 15:45:58 +02:00
vp . add ( hp ) ;
2013-06-12 16:30:45 +02:00
vp . add ( gridShareWith ) ;
2013-02-06 15:40:17 +01:00
2013-06-12 15:45:58 +02:00
rowData = new RowData ( . 5 , 1 ) ;
rowData . setMargins ( new Margins ( 6 , 6 , 6 , 0 ) ) ;
cp . add ( vp , rowData ) ;
2013-02-06 15:40:17 +01:00
2013-06-12 16:30:45 +02:00
new GridDragSource ( gridAllContacts ) ;
new GridDragSource ( gridShareWith ) ;
2013-02-06 15:40:17 +01:00
2013-06-12 16:30:45 +02:00
dropSource = new GridDropTarget ( gridAllContacts ) ;
2013-02-06 15:40:17 +01:00
dropSource . setAllowSelfAsSource ( false ) ;
2013-06-12 16:30:45 +02:00
dropTarget = new GridDropTarget ( gridShareWith ) ;
2013-02-06 15:40:17 +01:00
dropTarget . setAllowSelfAsSource ( false ) ;
add ( cp ) ;
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 ) {
hide ( ) ;
}
} ) ;
}
private ColumnModel createColumnModel ( ) {
List < ColumnConfig > configs = new ArrayList < ColumnConfig > ( ) ;
2014-03-10 17:33:33 +01:00
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 < ExtendedInfoContactModel > typeRender = new GridCellRenderer < ExtendedInfoContactModel > ( ) {
@Override
public String render ( ExtendedInfoContactModel model , String property , ColumnData config , int rowIndex , int colIndex , ListStore < ExtendedInfoContactModel > store , Grid < ExtendedInfoContactModel > grid ) {
Boolean isGroup = ( Boolean ) model . get ( property ) ;
String color = " #0F4FA8 " ;
String val = " " ;
if ( isGroup ) {
val = " Group " ;
color = " #05316D " ;
return " <span style='font-weight: bold; color: " + color + " '> " + val + " </span> " ;
} else {
val = " User " ;
return " <span style='font-weight: bold; color: " + color + " '> " + val + " </span> " ;
}
}
} ;
type . setRenderer ( typeRender ) ;
return new ColumnModel ( configs ) ;
2013-02-06 15:40:17 +01:00
}
public void addSourceContacts ( List < InfoContactModel > listContact ) {
2013-06-12 16:30:45 +02:00
gridAllContacts . mask ( " " , ConstantsExplorer . LOADINGSTYLE ) ;
2013-06-12 15:45:58 +02:00
if ( listContact ! = null & & listContact . size ( ) > 0 ) {
2014-03-10 17:33:33 +01:00
List < ExtendedInfoContactModel > listExtended = new ArrayList < ExtendedInfoContactModel > ( ) ;
//SETTING ICONS
for ( InfoContactModel infoContactModel : listContact ) {
ExtendedInfoContactModel ext = new ExtendedInfoContactModel ( infoContactModel . getId ( ) , infoContactModel . getLogin ( ) , infoContactModel . getName ( ) , infoContactModel . isGroup ( ) ) ;
ext . setIcon ( ) ;
listExtended . add ( ext ) ;
}
2013-06-12 15:45:58 +02:00
2014-03-10 17:33:33 +01:00
storeSource . add ( listExtended ) ;
2013-06-12 15:45:58 +02:00
}
2013-06-12 16:30:45 +02:00
gridAllContacts . unmask ( ) ;
2013-02-06 15:40:17 +01:00
}
2013-06-07 17:32:53 +02:00
public void addAlreadySharedContacts ( List < InfoContactModel > listContact ) {
2013-06-12 16:30:45 +02:00
gridShareWith . mask ( " " , ConstantsExplorer . LOADINGSTYLE ) ;
2013-06-07 17:32:53 +02:00
if ( listContact ! = null & & listContact . size ( ) > 0 ) {
String alreadyShared = " " ;
for ( int i = 0 ; i < listContact . size ( ) - 1 ; i + + )
alreadyShared + = listContact . get ( i ) . getName ( ) + " , " ;
alreadyShared + = listContact . get ( listContact . size ( ) - 1 ) . getName ( ) ;
textAreaAlreadyShared . setValue ( alreadyShared ) ;
}
2013-06-12 16:30:45 +02:00
gridShareWith . unmask ( ) ;
2013-06-07 17:32:53 +02:00
}
2013-02-06 15:40:17 +01:00
public void addTargetContacts ( List < InfoContactModel > listContact ) {
2014-03-10 17:33:33 +01:00
if ( listContact ! = null & & listContact . size ( ) > 0 ) {
2014-03-10 18:47:49 +01:00
storeTarget . add ( convertFromInfoContactModel ( listContact ) ) ;
2014-03-10 17:33:33 +01:00
}
}
2014-03-10 18:47:49 +01:00
private List < ExtendedInfoContactModel > convertFromInfoContactModel ( List < InfoContactModel > listContact ) {
2014-03-10 17:33:33 +01:00
if ( listContact ! = null ) {
List < ExtendedInfoContactModel > listExtended = new ArrayList < ExtendedInfoContactModel > ( listContact . size ( ) ) ;
//SETTING ICONS
for ( InfoContactModel infoContactModel : listContact ) {
2014-03-10 18:47:49 +01:00
listExtended . add ( convertFromInfoContactModel ( infoContactModel ) ) ;
2014-03-10 17:33:33 +01:00
}
return listExtended ;
}
return new ArrayList < ExtendedInfoContactModel > ( ) ;
}
2014-03-10 18:47:49 +01:00
private ExtendedInfoContactModel convertFromInfoContactModel ( InfoContactModel infoContactModel ) {
2014-03-10 17:33:33 +01:00
if ( infoContactModel ! = null ) {
2014-03-10 18:16:48 +01:00
String fullName = infoContactModel . getName ( ) ;
if ( fullName = = null | | fullName . isEmpty ( ) )
fullName = infoContactModel . getLogin ( ) ;
ExtendedInfoContactModel ext = new ExtendedInfoContactModel ( infoContactModel . getId ( ) , infoContactModel . getLogin ( ) , fullName , infoContactModel . isGroup ( ) ) ;
2014-03-10 17:33:33 +01:00
ext . setIcon ( ) ;
return ext ;
}
return new ExtendedInfoContactModel ( ) ;
2013-02-06 15:40:17 +01:00
}
2013-02-25 19:03:53 +01:00
public void addTargetContact ( InfoContactModel contact ) {
if ( contact ! = null )
2014-03-10 18:47:49 +01:00
storeTarget . add ( convertFromInfoContactModel ( contact ) ) ;
2013-02-25 19:03:53 +01:00
}
2013-02-06 15:40:17 +01:00
public List < InfoContactModel > getTargetListContact ( ) {
2014-03-10 17:33:33 +01:00
List < ? extends InfoContactModel > infoContacts = storeTarget . getModels ( ) ;
return ( List < InfoContactModel > ) infoContacts ;
2013-02-06 15:40:17 +01:00
}
2014-03-10 17:33:33 +01:00
private void setGropUserStoreSorter ( ListStore < ExtendedInfoContactModel > store ) {
// Sorting files
store . setStoreSorter ( new StoreSorter < ExtendedInfoContactModel > ( ) {
@Override
public int compare ( Store < ExtendedInfoContactModel > 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 ( ) ) ;
}
} ) ;
}
2013-02-06 15:40:17 +01:00
}