/** * */ package org.gcube.portlets.widgets.wsexplorer.client.explore; import java.util.List; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants; import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEventHandler; import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEventHandler; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEventHandler; import org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorerPaginated; import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; import com.google.gwt.core.shared.GWT; import com.google.gwt.user.client.ui.DockPanel; /** * The Class WorkspaceResourcesExplorerPanelPaginated. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Jul 5, 2017 */ public class WorkspaceResourcesExplorerPanelPaginated extends WorkspaceResourcesExplorerPanel { private static final int ITEMS_PER_PAGE = WorkspaceExplorerConstants.ITEMS_PER_PAGE; protected WorkspaceExplorerPaginated wsExplorer; public static int ITEM_START_INDEX = 0; /** * Instantiates a new workspace resources explorer panel paginated. * * @param folderId the folder id * @param showOnlyFolders the show only folders * @throws Exception the exception */ public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders) throws Exception { super(folderId, showOnlyFolders); } /** * Instantiates a new workspace resources explorer panel paginated. * * @param folderId the folder id * @param folderName the folder name * @throws Exception the exception */ public WorkspaceResourcesExplorerPanelPaginated(String folderId, String folderName) throws Exception { super(folderId, folderName); } /** * Instantiates a new workspace resources explorer panel paginated. * * @param folderId the folder id * @param showOnlyFolders the show only folders * @param showProperties the show properties * @param filter the filter * @throws Exception the exception */ public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders, List showProperties, FilterCriteria filter) throws Exception { super(folderId, showOnlyFolders, showProperties, filter); } /** * Instantiates a new workspace resources explorer panel paginated. * * @param folderId the folder id * @param showOnlyFolders the show only folders * @param showProperties the show properties * @param filter the filter * @param showGcubeInfo the show gcube info * @param sortByColumn the sort by column * @throws Exception the exception */ public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders, List showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception { super(folderId, showOnlyFolders, showProperties, filter, showGcubeInfo, sortByColumn); } /** * Inits the explorer. * * @param folderId the folder id * @param folderName the folder name * @param selectableTypes the selectable types * @param showableTypes the showable types * @param showProperties the show properties * @param filter the filter * @param showGcubeInfo the show gcube info - shows all the properties associated to a file (or a gcube item) stored into related gcube item by opening a popup window when clicking on the item * @param sortByColumn the sort by column * @throws Exception the exception */ @Override protected void initExplorer(String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes, List showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception{ setParameters(folderId, folderName, showProperties, filter); bindEvents(); wsExplorer = new WorkspaceExplorerPaginated(eventBus, filter, showableTypes, selectableTypes, showProperties, showGcubeInfo, sortByColumn, new DISPLAY_FIELD[]{DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.CREATION_DATE}); wsExplorer.initPagination(ITEMS_PER_PAGE); Item item = new Item(folderId, folderName, true); wsExplorer.loadFolder(item, true, ITEM_START_INDEX, ITEMS_PER_PAGE); initPanel(""); } /** * Inits the panel. * * @param captionTxt the caption txt is the tool-tip */ protected void initPanel(String captionTxt) { super.captionTxt = captionTxt; if(super.captionTxt!=null && !super.captionTxt.isEmpty()) setTitle(super.captionTxt); add(breadcrumbs, DockPanel.NORTH); setCellHeight(breadcrumbs, offsetBreadcrumb+"px"); centerScrollable.add(wsExplorer.getPagerPanel()); add(centerScrollable, DockPanel.CENTER); } /** * Bind events. */ private void bindEvents(){ eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() { @Override public void onClick(final ClickItemEvent clickItemEvent) { isSelect = false; Item item = wsExplorer.getItemSelected(); //Return if item is not selectable if(!itemIsSelectable(item)){ notifyNotValidSelection(); return; } notifySelectedItem(wsExplorer.getItemSelected()); isSelect = true; } }); eventBus.addHandler(LoadFolderEvent.TYPE, new LoadFolderEventHandler() { @Override public void onLoadFolder(LoadFolderEvent loadFolderEvent) { if(loadFolderEvent.getTargetItem()!=null){ if(loadFolderEvent.getTargetItem() instanceof Item){ Item item = (Item) loadFolderEvent.getTargetItem(); if(item.isFolder()){ try { wsExplorer.loadFolder(item, true, ITEM_START_INDEX, ITEMS_PER_PAGE); loadParentBreadcrumbByItemId(item.getId(), true); clearMoreInfo(); } catch (Exception e) { GWT.log(e.getMessage()); } } } } } }); eventBus.addHandler(BreadcrumbClickEvent.TYPE, new BreadcrumbClickEventHandler() { @Override public void onBreadcrumbClick(BreadcrumbClickEvent breadcrumbClickEvent) { eventBus.fireEvent(new LoadFolderEvent(breadcrumbClickEvent.getTargetItem())); } }); } }