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 ;
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 ;
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 ;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel ;
import com.extjs.gxt.ui.client.widget.grid.Grid ;
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 ;
private ListStore < InfoContactModel > storeSource = new ListStore < InfoContactModel > ( ) ;
private ListStore < InfoContactModel > storeTarget = new ListStore < InfoContactModel > ( ) ;
2013-06-07 17:32:53 +02:00
private TextArea textAreaAlreadyShared ;
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 ) ;
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 " ) ) ;
2013-06-12 15:45:58 +02:00
Grid < InfoContactModel > grid = new Grid < InfoContactModel > ( 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 < InfoContactModel > filter = new StoreFilterField < InfoContactModel > ( ) {
@Override
protected boolean doSelect ( Store < InfoContactModel > store , InfoContactModel parent ,
InfoContactModel 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 ) ;
grid . setSize ( 250 , 310 ) ;
2013-02-06 15:40:17 +01:00
grid . setBorders ( false ) ;
2013-03-11 19:06:56 +01:00
grid . setAutoExpandColumn ( InfoContactModel . FULLNAME ) ;
2013-02-06 15:40:17 +01:00
grid . setBorders ( true ) ;
2013-06-12 15:45:58 +02:00
vp . add ( hp ) ;
2013-02-06 15:40:17 +01:00
vp . add ( grid ) ;
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... " ) ) ;
2013-02-06 15:40:17 +01:00
Grid < InfoContactModel > grid2 = new Grid < InfoContactModel > ( storeTarget , createColumnModel ( ) ) ;
2013-06-12 15:45:58 +02:00
StoreFilterField < InfoContactModel > filter2 = new StoreFilterField < InfoContactModel > ( ) {
@Override
protected boolean doSelect ( Store < InfoContactModel > store , InfoContactModel parent ,
InfoContactModel 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 ) ;
grid2 . setSize ( 250 , 310 ) ;
2013-02-06 15:40:17 +01:00
grid2 . setBorders ( false ) ;
2013-03-11 19:06:56 +01:00
grid2 . setAutoExpandColumn ( InfoContactModel . FULLNAME ) ;
2013-06-12 15:45:58 +02:00
grid2 . setBorders ( true ) ;
vp . add ( hp ) ;
2013-02-06 15:40:17 +01:00
vp . add ( grid2 ) ;
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
new GridDragSource ( grid ) ;
new GridDragSource ( grid2 ) ;
dropSource = new GridDropTarget ( grid ) ;
dropSource . setAllowSelfAsSource ( false ) ;
dropTarget = new GridDropTarget ( grid2 ) ;
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 > ( ) ;
ColumnConfig column = new ColumnConfig ( ) ;
2013-03-11 19:06:56 +01:00
column . setId ( InfoContactModel . FULLNAME ) ;
column . setHeader ( " Name " ) ;
2013-02-06 15:40:17 +01:00
column . setWidth ( 200 ) ;
configs . add ( column ) ;
// column = new ColumnConfig();
// column.setId("symbol");
// column.setHeader("Symbol");
// column.setWidth(100);
// configs.add(column);
return new ColumnModel ( configs ) ;
}
public void addSourceContacts ( List < InfoContactModel > listContact ) {
2013-06-12 15:45:58 +02:00
if ( listContact ! = null & & listContact . size ( ) > 0 ) {
for ( InfoContactModel infoContactModel : listContact ) {
if ( infoContactModel . getName ( ) ! = null & & ! infoContactModel . getName ( ) . isEmpty ( ) )
storeSource . add ( infoContactModel ) ;
}
}
2013-02-06 15:40:17 +01:00
}
2013-06-07 17:32:53 +02:00
public void addAlreadySharedContacts ( List < InfoContactModel > listContact ) {
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-02-06 15:40:17 +01:00
public void addTargetContacts ( List < InfoContactModel > listContact ) {
if ( listContact ! = null & & listContact . size ( ) > 0 )
storeTarget . add ( listContact ) ;
}
2013-02-25 19:03:53 +01:00
public void addTargetContact ( InfoContactModel contact ) {
if ( contact ! = null )
storeTarget . add ( contact ) ;
}
2013-02-06 15:40:17 +01:00
public List < InfoContactModel > getTargetListContact ( ) {
return storeTarget . getModels ( ) ;
}
}