managed event close all tabs

This commit is contained in:
Francesco Mangiacrapa 2021-06-22 18:09:16 +02:00
parent 199d4f1566
commit 814a0c6661
6 changed files with 129 additions and 13 deletions

View File

@ -7,6 +7,8 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CheckBoxSel
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CheckBoxSelectIemsEventHandler;
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.events.CloseAllTabsEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CloseAllTabsEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEvent;
@ -43,7 +45,6 @@ public class CkanContentModeratorWidgetController {
private ContentModeratorToolbar toolbar;
private MainTabPanel mainTabPanel = new MainTabPanel();
private Boolean isContentModeratorEnabled = null;
private ContentModeratorPaginatedView paginatedView;
public final static HandlerManager eventBus = new HandlerManager(null);
private HomeView howeView;
@ -119,6 +120,14 @@ public class CkanContentModeratorWidgetController {
howeView.setCheckedCheckboxSelectAll(false);
}
});
eventBus.addHandler(CloseAllTabsEvent.TYPE, new CloseAllTabsEventHandler() {
@Override
public void onClick(CloseAllTabsEvent closeAllTabsEvent) {
mainTabPanel.closeTabs();
}
});
}
/**

View File

@ -0,0 +1,45 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.events;
import com.google.gwt.event.shared.GwtEvent;
// TODO: Auto-generated Javadoc
/**
* The Class CloseAllTabsEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 22, 2021
*/
public class CloseAllTabsEvent extends GwtEvent<CloseAllTabsEventHandler> {
public static Type<CloseAllTabsEventHandler> TYPE = new Type<CloseAllTabsEventHandler>();
/**
* Instantiates a new close all tabs event.
*/
public CloseAllTabsEvent() {
}
/**
* Gets the associated type.
*
* @return the associated type
*/
@Override
public Type<CloseAllTabsEventHandler> getAssociatedType() {
return TYPE;
}
/**
* Dispatch.
*
* @param handler the handler
*/
@Override
protected void dispatch(CloseAllTabsEventHandler handler) {
handler.onClick(this);
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface CloseAllTabsEventHandler.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 22, 2021
*/
public interface CloseAllTabsEventHandler extends EventHandler {
/**
* On click.
*
* @param closeAllTabsEvent the close all tabs event
*/
void onClick(CloseAllTabsEvent closeAllTabsEvent);
}

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CloseAllTabsEvent;
import com.github.gwtbootstrap.client.ui.Dropdown;
import com.github.gwtbootstrap.client.ui.NavLink;
@ -23,12 +24,28 @@ public class ContentModeratorToolbar extends Composite {
@UiField
Dropdown dropdownSelectStatus;
@UiField
NavLink closeAllTabs;
private HandlerManager eventBus;
public ContentModeratorToolbar(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
fillItemStatusOptions();
bindEvents();
}
private void bindEvents() {
closeAllTabs.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
eventBus.fireEvent(new CloseAllTabsEvent());
}
});
}
private void fillItemStatusOptions() {

View File

@ -13,7 +13,7 @@
<b:Dropdown text="Select Items with status..."
ui:field="dropdownSelectStatus">
</b:Dropdown>
<b:NavLink>Close All Tabs
<b:NavLink ui:field="closeAllTabs">Close All Tabs
</b:NavLink>
</b:NavPills>
</g:HTMLPanel>

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.UtilFunct;
@ -18,12 +19,13 @@ import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* The Class MainTabPanel.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 18, 2021
* Jun 18, 2021
*/
public class MainTabPanel extends Composite {
@ -34,7 +36,7 @@ public class MainTabPanel extends Composite {
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 18, 2021
* Jun 18, 2021
*/
interface MainTabPanelUiBinder extends UiBinder<Widget, MainTabPanel> {
}
@ -68,39 +70,39 @@ public class MainTabPanel extends Composite {
* Adds the tab.
*
* @param heading the heading
* @param w the w
* @param w the w
* @return the tab
*/
public Tab addTab(String heading, Widget w){
public Tab addTab(String heading, Widget w) {
Tab tab = new Tab();
tab.setIcon(IconType.BOOK);
tab.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
}
});
String shortTitle = UtilFunct.ellipsis(heading, 20, false);
tab.asWidget().setTitle(heading);
tab.setHeading(shortTitle);
if(w!=null)
if (w != null)
tab.add(w);
results.add(tab);
mainTabPanel.add(tab);
activeTabPanels(false);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
mainTabPanel.selectTab(results.size()-1); //+1 because the first tab is "Home"
mainTabPanel.selectTab(results.size() - 1);
}
});
return tab;
}
@ -125,4 +127,26 @@ public class MainTabPanel extends Composite {
return results.size();
}
/**
* Close tabs.
*/
public void closeTabs() {
int tabSize = results.size();
GWT.log("tab size is: " + tabSize);
for (int i = 1; i < tabSize; i++) {
//each remove shifts any subsequent elements to the left, so I'm removing always the first element
mainTabPanel.remove(1);
results.remove(1);
}
//selecting Home Tab
selectTab(0);
}
private void selectTab(int tabIndex) {
if (tabIndex <= results.size()) {
mainTabPanel.selectTab(tabIndex);
}
}
}