164 lines
4.3 KiB
Java
164 lines
4.3 KiB
Java
package org.gcube.portlets.user.td.mainboxwidget.client;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.user.td.mainboxwidget.client.tdx.TDXPanel;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.DataViewActiveEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.dataview.DataView;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.dataview.TabularResourceDataView;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.event.logical.shared.SelectionEvent;
|
|
import com.google.gwt.event.logical.shared.SelectionHandler;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.sencha.gxt.widget.core.client.TabItemConfig;
|
|
import com.sencha.gxt.widget.core.client.TabPanel;
|
|
import com.sencha.gxt.widget.core.client.event.BeforeCloseEvent;
|
|
import com.sencha.gxt.widget.core.client.event.BeforeCloseEvent.BeforeCloseHandler;
|
|
|
|
/**
|
|
*
|
|
* @author giancarlo email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class MainBox extends TabPanel {
|
|
|
|
protected EventBus eventBus;
|
|
protected MainBoxPanel mainBoxPanel;
|
|
protected ArrayList<TDXPanel> tdxPanelList;
|
|
|
|
public MainBox(String name, EventBus eventBus, MainBoxPanel mainBoxPanel) {
|
|
super();
|
|
Log.debug("Create MainBox");
|
|
setId(name);
|
|
this.eventBus = eventBus;
|
|
this.mainBoxPanel = mainBoxPanel;
|
|
init();
|
|
|
|
|
|
}
|
|
|
|
protected void init(){
|
|
setBodyBorder(false);
|
|
setBorders(false);
|
|
setAnimScroll(true);
|
|
setTabScroll(true);
|
|
setCloseContextMenu(true);
|
|
|
|
tdxPanelList = new ArrayList<TDXPanel>();
|
|
// setResizeTabs(true);
|
|
addSelectionHandler(new SelectionHandler<Widget>() {
|
|
|
|
@Override
|
|
public void onSelection(SelectionEvent<Widget> event) {
|
|
Widget widget=event.getSelectedItem();
|
|
if(widget instanceof TDXPanel){
|
|
TDXPanel tdxPanel=(TDXPanel) widget;
|
|
TabularResourceDataView tabularResourceDataView=tdxPanel.getTabularResourceDataView();
|
|
DataViewActiveEvent dataViewActiveEvent=new DataViewActiveEvent(tabularResourceDataView);
|
|
eventBus.fireEvent(dataViewActiveEvent);
|
|
} else {
|
|
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void startTabs() {
|
|
Log.debug("Start MainBox Tabs");
|
|
|
|
}
|
|
|
|
public void openTDXTab(DataView dataView) {
|
|
if (dataView instanceof TabularResourceDataView) {
|
|
TabularResourceDataView tabularResourceDataView = (TabularResourceDataView) dataView;
|
|
Log.debug("Open TDX Tab");
|
|
if (tdxPanelList == null) {
|
|
tdxPanelList = new ArrayList<TDXPanel>();
|
|
}
|
|
addTDXPanel(tabularResourceDataView);
|
|
}
|
|
|
|
}
|
|
|
|
// Close
|
|
public void closePanel() {
|
|
Log.debug("Close TDX Tabs");
|
|
if (tdxPanelList != null) {
|
|
for (TDXPanel tdxPanel : tdxPanelList) {
|
|
remove(tdxPanel);
|
|
|
|
}
|
|
tdxPanelList.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
public void updateTabs(DataView dataView) {
|
|
try {
|
|
Log.debug("Update MainBox Tabs");
|
|
|
|
if (dataView instanceof TabularResourceDataView) {
|
|
TabularResourceDataView tabularResourceDataView = (TabularResourceDataView) dataView;
|
|
boolean found=false;
|
|
|
|
for (TDXPanel tdxPanel : tdxPanelList) {
|
|
if(tdxPanel.isDataViewRequest(tabularResourceDataView)){
|
|
tdxPanel.update(tabularResourceDataView);
|
|
found=true;
|
|
break;
|
|
}
|
|
}
|
|
if(!found){
|
|
addTDXPanel(tabularResourceDataView);
|
|
}
|
|
|
|
}
|
|
forceLayout();
|
|
} catch (Throwable e) {
|
|
Log.error("Error in MainBox: " + e.getLocalizedMessage());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected void addTDXPanel(TabularResourceDataView tabularResourceDataView) {
|
|
for (TDXPanel tdxPanel : tdxPanelList) {
|
|
if (tdxPanel.getTabularResourceDataView().getTrId().getId()
|
|
.compareTo(tabularResourceDataView.getTrId().getId()) == 0) {
|
|
tdxPanel.update(tabularResourceDataView);
|
|
setActiveWidget(tdxPanel);
|
|
return;
|
|
}
|
|
}
|
|
|
|
TabItemConfig tdxPanelItemConf = new TabItemConfig(
|
|
tabularResourceDataView.getTrId().getId(), true);
|
|
|
|
final TDXPanel tdxPanel = new TDXPanel(eventBus);
|
|
tdxPanel.open(tabularResourceDataView);
|
|
tdxPanelList.add(tdxPanel);
|
|
add(tdxPanel, tdxPanelItemConf);
|
|
|
|
addBeforeCloseHandler(new BeforeCloseHandler<Widget>() {
|
|
|
|
public void onBeforeClose(BeforeCloseEvent<Widget> event) {
|
|
if (tdxPanel == event.getItem()) {
|
|
remove(tdxPanel);
|
|
tdxPanelList.remove(tdxPanel);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
setActiveWidget(tdxPanel);
|
|
};
|
|
|
|
}
|