2016-11-06 11:56:01 +01:00
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection ;
2016-11-11 19:31:05 +01:00
import java.util.ArrayList ;
2017-02-22 17:40:16 +01:00
import java.util.Arrays ;
2016-11-09 19:13:39 +01:00
import java.util.Collections ;
2016-11-07 18:47:06 +01:00
import java.util.Iterator ;
import java.util.List ;
import java.util.Set ;
2016-11-09 19:13:39 +01:00
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean ;
2016-11-11 19:31:05 +01:00
import com.github.gwtbootstrap.client.ui.Breadcrumbs ;
2016-11-06 22:01:43 +01:00
import com.github.gwtbootstrap.client.ui.Button ;
2016-11-11 19:31:05 +01:00
import com.github.gwtbootstrap.client.ui.FluidContainer ;
import com.github.gwtbootstrap.client.ui.NavLink ;
2016-11-13 22:38:27 +01:00
import com.google.gwt.cell.client.ValueUpdater ;
2016-11-06 11:56:01 +01:00
import com.google.gwt.core.client.GWT ;
2016-11-07 18:47:06 +01:00
import com.google.gwt.dom.client.Style.BorderStyle ;
2016-11-14 17:07:03 +01:00
import com.google.gwt.dom.client.Style.FontWeight ;
2016-11-07 18:47:06 +01:00
import com.google.gwt.dom.client.Style.Unit ;
import com.google.gwt.event.dom.client.ClickEvent ;
import com.google.gwt.event.dom.client.ClickHandler ;
2016-11-06 11:56:01 +01:00
import com.google.gwt.uibinder.client.UiBinder ;
2016-11-06 22:01:43 +01:00
import com.google.gwt.uibinder.client.UiField ;
2016-11-07 18:47:06 +01:00
import com.google.gwt.user.cellview.client.CellList ;
import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy ;
2016-11-06 11:56:01 +01:00
import com.google.gwt.user.client.ui.Composite ;
2016-11-14 17:07:03 +01:00
import com.google.gwt.user.client.ui.SimplePanel ;
2016-11-06 22:01:43 +01:00
import com.google.gwt.user.client.ui.VerticalPanel ;
2016-11-06 11:56:01 +01:00
import com.google.gwt.user.client.ui.Widget ;
2016-11-07 18:47:06 +01:00
import com.google.gwt.view.client.ListDataProvider ;
import com.google.gwt.view.client.MultiSelectionModel ;
import com.google.gwt.view.client.SelectionChangeEvent ;
2016-11-06 11:56:01 +01:00
2016-11-06 22:01:43 +01:00
/ * *
* The twin column panels for selection of the files to attach to the catalague product .
* @author Costantino Perciante at ISTI - CNR ( costantino . perciante @isti.cnr.it )
2018-11-20 12:29:41 +01:00
* @author Francesco Mangiacrapa at ISTI - CNR
2016-11-06 22:01:43 +01:00
* /
2016-11-06 11:56:01 +01:00
public class TwinColumnSelectionMainPanel extends Composite {
2016-11-07 18:47:06 +01:00
2018-11-20 12:29:41 +01:00
@UiField
2016-11-07 18:47:06 +01:00
VerticalPanel leftContainer ;
2018-11-20 12:29:41 +01:00
@UiField
2016-11-07 18:47:06 +01:00
VerticalPanel rightContainer ;
@UiField
VerticalPanel buttonsPanel ;
2016-11-06 22:01:43 +01:00
@UiField
2016-11-07 18:47:06 +01:00
Button allToRightButton ;
2016-11-06 22:01:43 +01:00
@UiField
2016-11-07 18:47:06 +01:00
Button toRightButton ;
2016-11-06 22:01:43 +01:00
@UiField
2016-11-07 18:47:06 +01:00
Button toLeftButton ;
@UiField
Button allToLeftButton ;
2016-11-13 22:38:27 +01:00
// @UiField
// Popover popoverResourceSelection;
// @UiField
// Button resourceInfoButton;
2016-11-11 19:31:05 +01:00
@UiField
Breadcrumbs breadcrumbs ;
@UiField
FluidContainer mainContainerResourcesSelection ;
// @UiField
// Button getResources;
2016-11-14 17:07:03 +01:00
@UiField
public static SimplePanel detailContainer ;
2016-11-06 22:01:43 +01:00
2016-11-11 19:31:05 +01:00
/ * *
* The breadcrumb subpath with the linked folder
* @author Costantino Perciante at ISTI - CNR ( costantino . perciante @isti.cnr.it )
* /
private class PathBean {
NavLink link ;
ResourceElementBean resourceFolder ;
PathBean ( NavLink link , ResourceElementBean resourceFolder ) {
this . link = link ;
this . resourceFolder = resourceFolder ;
}
}
2018-11-20 12:29:41 +01:00
private static boolean frozen = false ;
2016-11-11 19:31:05 +01:00
private List < PathBean > pathListBeans = new ArrayList < PathBean > ( ) ;
2016-11-13 22:38:27 +01:00
private static final String PANEL_BORDER_COLOR = " #8899a6 " ;
2016-11-08 15:17:41 +01:00
private static final String PANEL_HEIGHT = " 400px " ;
2016-11-07 18:47:06 +01:00
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel ( ) ;
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel ( ) ;
private CellList < ResourceElementBean > cellListLeft ;
private CellList < ResourceElementBean > cellListRight ;
private ListDataProvider < ResourceElementBean > dataProviderLeft = new ListDataProvider < ResourceElementBean > ( ) ;
private ListDataProvider < ResourceElementBean > dataProviderRight = new ListDataProvider < ResourceElementBean > ( ) ;
private MultiSelectionModel < ResourceElementBean > selectionModelRight ;
private MultiSelectionModel < ResourceElementBean > selectionModelLeft ;
2016-11-11 19:31:05 +01:00
private final ResourceElementBean initialBean ;
2016-11-13 22:38:27 +01:00
// private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>");
// private final static HTML aboutBody = new HTML("<p style='text-align:justify;'>Move the files you want to attach to the product on the right panel below."
// + " Please consider that any complex hierarchy structure you may have will be flatten.</p>");
2016-11-11 19:31:05 +01:00
2016-11-13 22:38:27 +01:00
// private static final short PATH_THRESHOLD = 1; // TODO
2016-11-06 11:56:01 +01:00
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
. create ( TwinColumnSelectionMainPanelUiBinder . class ) ;
interface TwinColumnSelectionMainPanelUiBinder extends
2016-11-06 22:01:43 +01:00
UiBinder < Widget , TwinColumnSelectionMainPanel > {
2016-11-06 11:56:01 +01:00
}
2016-11-11 19:31:05 +01:00
public TwinColumnSelectionMainPanel ( ResourceElementBean initialBean ) {
2016-11-07 18:47:06 +01:00
initWidget ( uiBinder . createAndBindUi ( this ) ) ;
2018-11-20 12:29:41 +01:00
frozen = false ;
2017-02-23 16:25:12 +01:00
GWT . log ( initialBean . toString ( ) ) ;
2016-11-07 18:47:06 +01:00
2016-11-11 19:31:05 +01:00
this . initialBean = initialBean ;
2016-11-07 18:47:06 +01:00
2016-11-13 22:38:27 +01:00
buttonsPanel . getElement ( ) . getStyle ( ) . setMarginTop ( 50 , Unit . PCT ) ;
2016-11-07 18:47:06 +01:00
allToRightButton . getElement ( ) . getStyle ( ) . setMarginBottom ( 4 , Unit . PX ) ;
toRightButton . getElement ( ) . getStyle ( ) . setMarginBottom ( 4 , Unit . PX ) ;
toLeftButton . getElement ( ) . getStyle ( ) . setMarginBottom ( 4 , Unit . PX ) ;
allToLeftButton . getElement ( ) . getStyle ( ) . setMarginBottom ( 4 , Unit . PX ) ;
2016-11-11 19:31:05 +01:00
2016-11-07 18:47:06 +01:00
buttonsPanel . getElement ( ) . setAttribute ( " align " , " center " ) ;
2016-11-13 22:38:27 +01:00
// popoverResourceSelection.setPlacement(Placement.LEFT);
// popoverResourceSelection.setHeading(aboutHeader.getHTML());
// popoverResourceSelection.setText(aboutBody.getHTML());
// resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT);
// resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX);
mainContainerResourcesSelection . getElement ( ) . getStyle ( ) . setPadding ( 10 , Unit . PX ) ;
2016-11-11 19:31:05 +01:00
2016-11-14 17:07:03 +01:00
breadcrumbs . getElement ( ) . getStyle ( ) . setBackgroundColor ( " white " ) ;
breadcrumbs . getElement ( ) . getStyle ( ) . setFontWeight ( FontWeight . BOLD ) ;
breadcrumbs . getElement ( ) . getStyle ( ) . setMarginLeft ( 0 , Unit . PX ) ;
mainContainerResourcesSelection . getElement ( ) . getStyle ( ) . setMarginLeft ( 10 , Unit . PX ) ;
mainContainerResourcesSelection . getElement ( ) . getStyle ( ) . setMarginBottom ( 20 , Unit . PX ) ;
mainContainerResourcesSelection . getElement ( ) . getStyle ( ) . setMarginTop ( 0 , Unit . PX ) ;
2016-11-07 18:47:06 +01:00
prepareHandlers ( ) ;
2016-11-11 19:31:05 +01:00
initLeftSidePanel ( initialBean ) ;
2016-11-08 15:17:41 +01:00
initRightSidePanel ( ) ;
2016-11-07 18:47:06 +01:00
}
2016-11-06 22:01:43 +01:00
/ * *
2016-11-07 18:47:06 +01:00
* Initialize the left side panel
2016-11-06 22:01:43 +01:00
* /
2016-11-11 19:31:05 +01:00
private void initLeftSidePanel ( final ResourceElementBean initialBean ) {
2016-11-07 18:47:06 +01:00
// initialize the left side list
ResourceCellLeft cell = new ResourceCellLeft ( ) ;
2018-11-20 12:29:41 +01:00
// Set a key provider that provides a unique key for each object.
2016-11-07 18:47:06 +01:00
cellListLeft = new CellList < ResourceElementBean > ( cell , ResourceElementBean . KEY_PROVIDER ) ;
2018-11-20 12:29:41 +01:00
cellListLeft . setKeyboardPagingPolicy ( KeyboardPagingPolicy . INCREASE_RANGE ) ;
2017-02-22 17:40:16 +01:00
// set page size
int size = initialBean . isFolder ( ) ? initialBean . getChildren ( ) . size ( ) : 1 ;
cellListLeft . setPageSize ( size ) ;
2016-11-07 18:47:06 +01:00
// Add a selection model so we can select cells.
selectionModelLeft = new MultiSelectionModel < ResourceElementBean > ( ResourceElementBean . KEY_PROVIDER ) ;
cellListLeft . setSelectionModel ( selectionModelLeft ) ;
// perform an action on selection
selectionModelLeft . addSelectionChangeHandler ( new SelectionChangeEvent . Handler ( ) {
2016-11-13 22:38:27 +01:00
2016-11-07 18:47:06 +01:00
public void onSelectionChange ( SelectionChangeEvent event ) {
2016-11-14 17:07:03 +01:00
2018-11-20 12:29:41 +01:00
if ( frozen )
2016-11-14 17:07:03 +01:00
return ;
2016-11-07 18:47:06 +01:00
Iterator < ResourceElementBean > selectedObjectsIterator = selectionModelLeft . getSelectedSet ( ) . iterator ( ) ;
2016-11-11 19:31:05 +01:00
2016-11-07 18:47:06 +01:00
while ( selectedObjectsIterator . hasNext ( ) ) {
2018-11-20 12:29:41 +01:00
ResourceElementBean selectedBean = selectedObjectsIterator . next ( ) ;
2016-11-07 18:47:06 +01:00
if ( selectedBean . isFolder ( ) ) {
2016-11-11 19:31:05 +01:00
// a single folder selected
2016-11-07 18:47:06 +01:00
if ( selectionModelLeft . getSelectedSet ( ) . size ( ) = = 1 ) {
2016-11-11 19:31:05 +01:00
// update path
final NavLink navElem = new NavLink ( selectedBean . getName ( ) ) ;
2016-11-14 17:07:03 +01:00
navElem . getElement ( ) . getStyle ( ) . setFontWeight ( FontWeight . BOLD ) ;
2016-11-11 19:31:05 +01:00
final PathBean pathBean = new PathBean ( navElem , selectedBean ) ;
navElem . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
removeStartingFromBreadcrumbs ( navElem , pathBean ) ;
2016-11-13 22:38:27 +01:00
GWT . log ( " Clicked on element " + pathBean . resourceFolder . getName ( ) ) ;
//breadcrumbsUpdater();
2016-11-11 19:31:05 +01:00
ResourceElementBean folder = pathBean . resourceFolder ;
Collections . sort ( folder . getChildren ( ) ) ;
dataProviderLeft . setList ( folder . getChildren ( ) ) ;
dataProviderLeft . refresh ( ) ;
}
} ) ;
pathListBeans . add ( pathBean ) ;
breadcrumbs . add ( navElem ) ;
2016-11-13 22:38:27 +01:00
//breadcrumbsUpdater();
2016-11-11 19:31:05 +01:00
2016-11-09 19:13:39 +01:00
Collections . sort ( selectedBean . getChildren ( ) ) ;
2017-02-23 16:25:12 +01:00
GWT . log ( " Children " + selectedBean . getChildren ( ) ) ;
2016-11-07 18:47:06 +01:00
dataProviderLeft . setList ( selectedBean . getChildren ( ) ) ;
2017-02-23 16:25:12 +01:00
cellListLeft . setPageSize ( selectedBean . getChildren ( ) . size ( ) ) ;
2016-11-07 18:47:06 +01:00
dataProviderLeft . refresh ( ) ;
}
2016-11-08 15:17:41 +01:00
selectionModelLeft . setSelected ( selectedBean , false ) ;
2016-11-07 18:47:06 +01:00
}
}
// enable the buttons that allows to move the objects to the right
enableMoveToRightButtons ( selectionModelLeft . getSelectedSet ( ) ) ;
}
} ) ;
// set the list into the provider
2017-02-22 17:40:16 +01:00
if ( initialBean . isFolder ( ) ) {
Collections . sort ( this . initialBean . getChildren ( ) ) ;
dataProviderLeft . setList ( this . initialBean . getChildren ( ) ) ;
} else
dataProviderLeft . setList ( Arrays . asList ( this . initialBean ) ) ;
2016-11-11 19:31:05 +01:00
// add root to breadcrumb
final NavLink root = new NavLink ( initialBean . getName ( ) ) ;
final PathBean pathBean = new PathBean ( root , initialBean ) ;
2016-11-14 17:07:03 +01:00
root . getElement ( ) . getStyle ( ) . setFontWeight ( FontWeight . BOLD ) ;
2016-11-11 19:31:05 +01:00
pathListBeans . add ( pathBean ) ;
breadcrumbs . add ( root ) ;
root . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
removeStartingFromBreadcrumbs ( root , pathBean ) ;
2016-11-13 22:38:27 +01:00
//breadcrumbsUpdater();
2016-11-11 19:31:05 +01:00
// set back the root content list
dataProviderLeft . setList ( initialBean . getChildren ( ) ) ;
2017-02-23 16:25:12 +01:00
cellListLeft . setPageSize ( initialBean . getChildren ( ) . size ( ) ) ;
2016-11-11 19:31:05 +01:00
dataProviderLeft . refresh ( ) ;
2018-11-20 12:29:41 +01:00
2016-11-11 19:31:05 +01:00
}
} ) ;
2016-11-07 18:47:06 +01:00
// set the cell list into the provider
dataProviderLeft . addDataDisplay ( cellListLeft ) ;
// manage showMorePanelLeft
showMorePanelLeft . setDisplay ( cellListLeft ) ;
showMorePanelLeft . setHeight ( PANEL_HEIGHT ) ;
showMorePanelLeft . getElement ( ) . getStyle ( ) . setBorderStyle ( BorderStyle . SOLID ) ;
2016-11-13 22:38:27 +01:00
showMorePanelLeft . getElement ( ) . getStyle ( ) . setBorderWidth ( 2 , Unit . PX ) ;
showMorePanelLeft . getElement ( ) . getStyle ( ) . setBorderColor ( PANEL_BORDER_COLOR ) ;
2016-11-07 18:47:06 +01:00
// add the list to the leftContainerPanel
leftContainer . add ( showMorePanelLeft ) ;
}
2016-11-11 19:31:05 +01:00
/ * *
* Update the path
* @param navElem
* @param pathBean
* /
public void removeStartingFromBreadcrumbs ( NavLink navElem , PathBean pathBean ) {
// remove data after
Iterator < Widget > iteratorBreadcrumb = breadcrumbs . iterator ( ) ;
Iterator < PathBean > iteratorListPath = pathListBeans . iterator ( ) ;
boolean delete = false ;
while ( iteratorBreadcrumb . hasNext ( ) ) {
Widget current = iteratorBreadcrumb . next ( ) ;
2016-11-13 22:38:27 +01:00
if ( delete ) {
current . removeFromParent ( ) ;
2016-11-11 19:31:05 +01:00
iteratorBreadcrumb . remove ( ) ;
2016-11-13 22:38:27 +01:00
}
2016-11-11 19:31:05 +01:00
if ( ! delete & & navElem . equals ( current ) )
delete = true ;
}
delete = false ;
while ( iteratorListPath . hasNext ( ) ) {
PathBean current = iteratorListPath . next ( ) ;
if ( delete )
iteratorListPath . remove ( ) ;
if ( ! delete & & pathBean . equals ( current ) )
delete = true ;
}
}
2016-11-07 18:47:06 +01:00
/ * *
* Initialize the left side panel
* /
2016-11-08 15:17:41 +01:00
private void initRightSidePanel ( ) {
2016-11-07 18:47:06 +01:00
// initialize the left side list
ResourceCellRight cell = new ResourceCellRight ( ) ;
2018-11-20 12:29:41 +01:00
// Set a key provider that provides a unique key for each object.
2016-11-07 18:47:06 +01:00
cellListRight = new CellList < ResourceElementBean > ( cell , ResourceElementBean . KEY_PROVIDER ) ;
2018-11-20 12:29:41 +01:00
cellListRight . setKeyboardPagingPolicy ( KeyboardPagingPolicy . INCREASE_RANGE ) ;
2016-11-13 22:38:27 +01:00
cellListRight . setValueUpdater ( new ValueUpdater < ResourceElementBean > ( ) {
2016-11-14 17:07:03 +01:00
2016-11-13 22:38:27 +01:00
@Override
public void update ( ResourceElementBean value ) {
2016-11-14 17:07:03 +01:00
2016-11-13 22:38:27 +01:00
// just redraw the list
cellListRight . redraw ( ) ;
2016-11-14 17:07:03 +01:00
2016-11-13 22:38:27 +01:00
}
} ) ;
2016-11-07 18:47:06 +01:00
// Add a selection model so we can select cells.
selectionModelRight = new MultiSelectionModel < ResourceElementBean > ( ResourceElementBean . KEY_PROVIDER ) ;
cellListRight . setSelectionModel ( selectionModelRight ) ;
// perform an action on selection
selectionModelRight . addSelectionChangeHandler ( new SelectionChangeEvent . Handler ( ) {
public void onSelectionChange ( SelectionChangeEvent event ) {
2016-11-14 17:07:03 +01:00
2018-11-20 12:29:41 +01:00
if ( frozen )
2016-11-14 17:07:03 +01:00
return ;
2016-11-07 18:47:06 +01:00
enableMoveToLeftButtons ( selectionModelRight . getSelectedSet ( ) ) ;
}
} ) ;
// set the cell list into the provider
dataProviderRight . addDataDisplay ( cellListRight ) ;
// manage showMorePanelRight
showMorePanelRight . setDisplay ( cellListRight ) ;
showMorePanelRight . setHeight ( PANEL_HEIGHT ) ;
showMorePanelRight . getElement ( ) . getStyle ( ) . setBorderStyle ( BorderStyle . SOLID ) ;
2016-11-13 22:38:27 +01:00
showMorePanelRight . getElement ( ) . getStyle ( ) . setBorderWidth ( 2 , Unit . PX ) ;
showMorePanelRight . getElement ( ) . getStyle ( ) . setBorderColor ( PANEL_BORDER_COLOR ) ;
2016-11-07 18:47:06 +01:00
// add the list to the leftContainerPanel
rightContainer . add ( showMorePanelRight ) ;
}
/ * *
* Enable / disable the buttons to move objects from left to right properly .
* @param setselectedItemsLeft
* /
private void enableMoveToRightButtons ( Set < ResourceElementBean > setselectedItemsLeft ) {
2016-11-08 15:17:41 +01:00
if ( setselectedItemsLeft = = null | | setselectedItemsLeft . isEmpty ( ) ) {
allToRightButton . setEnabled ( false ) ;
toRightButton . setEnabled ( false ) ;
}
else if ( setselectedItemsLeft . size ( ) > 1 ) {
2016-11-07 18:47:06 +01:00
allToRightButton . setEnabled ( true ) ;
toRightButton . setEnabled ( false ) ;
}
else {
allToRightButton . setEnabled ( false ) ;
toRightButton . setEnabled ( true ) ;
}
}
/ * *
* Enable / disable the buttons to move objects from right to left properly .
* @param setselectedItemsRight
* /
private void enableMoveToLeftButtons ( Set < ResourceElementBean > setselectedItemsRight ) {
2016-11-08 15:17:41 +01:00
if ( setselectedItemsRight = = null | | setselectedItemsRight . isEmpty ( ) ) {
allToLeftButton . setEnabled ( false ) ;
allToLeftButton . setEnabled ( false ) ;
}
else if ( setselectedItemsRight . size ( ) > 1 ) {
2016-11-07 18:47:06 +01:00
allToLeftButton . setEnabled ( true ) ;
toLeftButton . setEnabled ( false ) ;
}
else {
allToLeftButton . setEnabled ( false ) ;
toLeftButton . setEnabled ( true ) ;
}
}
/ * *
* Prepare the buttons ' handlers
* /
private void prepareHandlers ( ) {
allToRightButton . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
moveToRight ( selectionModelLeft . getSelectedSet ( ) ) ;
}
} ) ;
toRightButton . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
moveToRight ( selectionModelLeft . getSelectedSet ( ) ) ;
}
} ) ;
allToLeftButton . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
moveToLeft ( selectionModelRight . getSelectedSet ( ) ) ;
}
} ) ;
toLeftButton . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
moveToLeft ( selectionModelRight . getSelectedSet ( ) ) ;
}
} ) ;
}
/ * *
2016-11-08 15:17:41 +01:00
* Move to right elements
* @param set the elements to move
2016-11-07 18:47:06 +01:00
* /
2016-11-08 15:17:41 +01:00
private void moveToRight ( Set < ResourceElementBean > setSelected ) {
2016-11-07 18:47:06 +01:00
2016-11-08 15:17:41 +01:00
if ( setSelected = = null | | setSelected . isEmpty ( ) )
2016-11-07 18:47:06 +01:00
return ;
2016-11-08 15:17:41 +01:00
Iterator < ResourceElementBean > iterator = setSelected . iterator ( ) ;
2016-11-07 18:47:06 +01:00
while ( iterator . hasNext ( ) ) {
2018-11-20 12:29:41 +01:00
ResourceElementBean resourceElementBean = iterator
2016-11-07 18:47:06 +01:00
. next ( ) ;
2018-11-20 12:29:41 +01:00
resourceElementBean . setToBeAdded ( true ) ;
2016-11-08 23:30:37 +01:00
int indexRight = dataProviderRight . getList ( ) . indexOf ( resourceElementBean ) ;
if ( indexRight > = 0 )
dataProviderRight . getList ( ) . set ( indexRight , resourceElementBean ) ;
2016-11-09 19:13:39 +01:00
else {
2016-11-08 15:17:41 +01:00
dataProviderRight . getList ( ) . add ( resourceElementBean ) ;
2016-11-09 19:13:39 +01:00
Collections . sort ( dataProviderRight . getList ( ) ) ;
dataProviderRight . refresh ( ) ;
}
2016-11-07 18:47:06 +01:00
2016-11-08 23:30:37 +01:00
int indexLeft = dataProviderLeft . getList ( ) . indexOf ( resourceElementBean ) ;
2016-11-08 23:31:57 +01:00
dataProviderLeft . getList ( ) . set ( indexLeft , resourceElementBean ) ;
2016-11-08 23:30:37 +01:00
}
2016-11-07 18:47:06 +01:00
}
/ * *
2016-11-08 15:17:41 +01:00
* Move to left elements
* @param setSelected the elements to move
2016-11-07 18:47:06 +01:00
* /
2016-11-08 15:17:41 +01:00
private void moveToLeft ( Set < ResourceElementBean > setSelected ) {
2016-11-07 18:47:06 +01:00
2016-11-08 15:17:41 +01:00
if ( setSelected = = null | | setSelected . isEmpty ( ) )
2016-11-07 18:47:06 +01:00
return ;
2016-11-08 15:17:41 +01:00
Iterator < ResourceElementBean > iterator = setSelected . iterator ( ) ;
2016-11-07 18:47:06 +01:00
while ( iterator . hasNext ( ) ) {
2018-11-20 12:29:41 +01:00
ResourceElementBean resourceElementBean = iterator . next ( ) ;
resourceElementBean . setToBeAdded ( false ) ;
2016-11-07 18:47:06 +01:00
}
2016-11-09 19:13:39 +01:00
Collections . sort ( dataProviderLeft . getList ( ) ) ;
dataProviderLeft . refresh ( ) ;
dataProviderRight . refresh ( ) ;
}
/ * *
* Freeze the panel
* /
public void freeze ( ) {
2016-11-11 19:31:05 +01:00
2018-11-20 12:29:41 +01:00
frozen = true ;
2016-11-14 17:07:03 +01:00
2016-11-11 19:31:05 +01:00
Iterator < Widget > iteratorOverPath = breadcrumbs . iterator ( ) ;
while ( iteratorOverPath . hasNext ( ) ) {
2018-11-20 12:29:41 +01:00
Widget widget = iteratorOverPath . next ( ) ;
2016-11-11 19:31:05 +01:00
if ( widget instanceof NavLink )
( ( NavLink ) widget ) . setActive ( false ) ;
}
2016-11-14 17:07:03 +01:00
2016-11-09 19:13:39 +01:00
allToRightButton . setEnabled ( false ) ;
toRightButton . setEnabled ( false ) ;
allToLeftButton . setEnabled ( false ) ;
toLeftButton . setEnabled ( false ) ;
}
2016-11-11 19:31:05 +01:00
2016-11-09 19:13:39 +01:00
/ * *
2017-02-22 17:40:16 +01:00
* Returns the root parent with the children as files to save
2016-11-09 19:13:39 +01:00
* @return the resources to save
* /
2017-02-22 17:40:16 +01:00
public ResourceElementBean getResourcesToPublish ( ) {
2018-11-20 12:29:41 +01:00
2016-11-11 19:31:05 +01:00
List < ResourceElementBean > current = dataProviderRight . getList ( ) ;
2018-11-20 12:29:41 +01:00
2017-02-22 17:40:16 +01:00
ResourceElementBean toReturn = new ResourceElementBean ( ) ;
List < ResourceElementBean > children = new ArrayList < ResourceElementBean > ( ) ;
2018-11-20 12:29:41 +01:00
2016-11-13 22:38:27 +01:00
for ( ResourceElementBean resource : current ) {
if ( resource . isToBeAdded ( ) & & ! resource . isFolder ( ) ) { // be sure ...
ResourceElementBean beanWithoutChildren = new ResourceElementBean ( resource ) ;
beanWithoutChildren . setName ( resource . getEditableName ( ) ) ;
2017-02-22 17:40:16 +01:00
children . add ( beanWithoutChildren ) ;
2016-11-11 23:03:39 +01:00
}
2016-11-11 19:31:05 +01:00
}
2018-11-20 12:29:41 +01:00
2017-02-22 17:40:16 +01:00
toReturn . setChildren ( children ) ;
2016-11-11 19:31:05 +01:00
return toReturn ;
2016-11-06 11:56:01 +01:00
}
2018-11-20 12:29:41 +01:00
/ * *
* @return the freezed
* /
public static boolean isFroozen ( ) {
return frozen ;
}
2016-11-11 19:31:05 +01:00
// @UiHandler("getResources")
// void getResources(ClickEvent ce){
// getResourcesToPublish();
// }
2016-11-13 22:38:27 +01:00
//
2016-11-11 19:31:05 +01:00
// /**
2016-11-13 22:38:27 +01:00
// * Short the current path if needed
2016-11-11 19:31:05 +01:00
// */
// private void breadcrumbsUpdater(){
//
// // ignore first and last elem
// boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD;
//
2016-11-13 22:38:27 +01:00
// GWT.log("Is to reduce? " + reduce);
2018-11-20 12:29:41 +01:00
//
2016-11-13 22:38:27 +01:00
// GWT.log("Full size is " + pathListBeans.size());
2016-11-11 19:31:05 +01:00
//
// if(!reduce){
// GWT.log("Restore");
2016-11-13 22:38:27 +01:00
// for(int i = 0; i < pathListBeans.size(); i++){
2016-11-11 19:31:05 +01:00
// PathBean bean = pathListBeans.get(i);
2016-11-13 22:38:27 +01:00
// GWT.log("Elem is " + bean.resourceFolder);
2016-11-11 19:31:05 +01:00
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true);
// }
// }else{
// for(int i = 1; i < pathListBeans.size(); i++){
// PathBean bean = pathListBeans.get(i);
//
// if(i == (pathListBeans.size() - 1)){
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true);
// }else if(i == (pathListBeans.size() - 2)){
2016-11-13 22:38:27 +01:00
// GWT.log("The last to modify ****" + bean.resourceFolder.getName());
2016-11-11 19:31:05 +01:00
// bean.link.setText("...");
// bean.link.setVisible(true);
// }else{
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(false);
// }
// }
// }
// GWT.log("Updated list is " + pathListBeans.toString());
// }
}