137 lines
4.4 KiB
Java
137 lines
4.4 KiB
Java
|
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.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.Anchor;
|
||
|
import com.google.gwt.user.client.ui.Composite;
|
||
|
import com.google.gwt.user.client.ui.Frame;
|
||
|
|
||
|
// TODO: Auto-generated Javadoc
|
||
|
/**
|
||
|
* 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 ItemsTable<CatalogueDataset> itemsTable;
|
||
|
private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView();
|
||
|
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<CatalogueDataset>(null, displayFields, sortByField);
|
||
|
// itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>());
|
||
|
// cmsPanel.add(itemsTable.getCellTable());
|
||
|
|
||
|
paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField);
|
||
|
// cmsPanel.addToTop(new LoadingPanel(new HTML("Loading...")));
|
||
|
cmsPanel.addToCenter(paginatedView.getCellPanel());
|
||
|
cmsPanel.addToBottom(paginatedView.getPagerPanel());
|
||
|
mainTabPanel.addHomeWidget(cmsPanel.getPanel());
|
||
|
bindEvents();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Bind events.
|
||
|
*/
|
||
|
private void bindEvents() {
|
||
|
|
||
|
eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() {
|
||
|
|
||
|
@Override
|
||
|
public <T> void onClick(ClickItemEvent<T> 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<Boolean>() {
|
||
|
|
||
|
@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 Composite getMainPanel() {
|
||
|
return mainTabPanel;
|
||
|
}
|
||
|
|
||
|
}
|