package org.gcube.portlets.widgets.ckancontentmoderator.client; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ClickItemEvent; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ClickItemEventHandler; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.CkanFramePanel; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorPaginatedView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemBaseView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorToolbar; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.MainTabPanel; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.VerticalPanel; /** * The Class CkanContentModeratorWidget. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Jun 15, 2021 */ public class CkanContentModeratorWidgetController { public final static CkanContentModeratorServiceAsync contentModeratorService = GWT .create(CkanContentModeratorService.class); private FlowPanel mainPanel = new FlowPanel(); // private ItemsTable itemsTable; private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView(); private ContentModeratorToolbar toolbar; private MainTabPanel mainTabPanel = new MainTabPanel(); private Boolean isContentModeratorEnabled = null; private ContentModeratorPaginatedView paginatedView; public final static HandlerManager eventBus = new HandlerManager(null); /** * Instantiates a new ckan content moderator widget. * * @param status the status * @param displayFields the display fields * @param sortByField the sort by field */ public CkanContentModeratorWidgetController(ItemStatus status, DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) { // itemsTable = new ItemsTable(null, displayFields, sortByField); // itemsTable.initTable(null, null, new ListDataProvider()); // cmsPanel.add(itemsTable.getCellTable()); toolbar = new ContentModeratorToolbar(eventBus); paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField); // cmsPanel.addToTop(new LoadingPanel(new HTML("Loading..."))); //cmsPanel.addToTop(toolbar); cmsPanel.addToCenter(paginatedView.getCellPanel()); cmsPanel.addToBottom(paginatedView.getPagerPanel()); mainTabPanel.addHomeWidget(cmsPanel.getPanel()); mainPanel.add(toolbar); mainPanel.add(mainTabPanel); bindEvents(); } /** * Bind events. */ private void bindEvents() { eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() { @Override public void onClick(ClickItemEvent clickItemEvent) { if (clickItemEvent.getItem() instanceof CatalogueDataset) { CatalogueDataset clickedDataset = (CatalogueDataset) clickItemEvent.getItem(); CkanFramePanel cfp = new CkanFramePanel(eventBus); cfp.instanceFrame(clickedDataset.getUrl(), null); mainTabPanel.addTab(clickedDataset.getName(), cfp); // Window.open(clickedDataset.getUrl(), null, "_blank"); } } }); } /** * Checks if is content moderator enabled. * * @return true, if is content moderator enabled * @throws Exception the exception */ public boolean isContentModeratorEnabled() throws Exception { if (isContentModeratorEnabled == null) throw new Exception("Please, first check if the content moderator is enabled in this context"); return isContentModeratorEnabled; } /** * Check content moderator configuration. * * @param whenDone the when done * @throws Exception the exception */ public void checkContentModeratorConfiguration(final Command whenDone) throws Exception { contentModeratorService.isContentModeratorEnabled(new AsyncCallback() { @Override public void onFailure(Throwable caught) { whenDone.execute(); } @Override public void onSuccess(Boolean result) { isContentModeratorEnabled = result; if(whenDone!=null) whenDone.execute(); } }); } /** * Gets the main panel. * * @return the main panel */ public ComplexPanel getMainPanel() { return mainPanel; } }