283 lines
8.8 KiB
Java
283 lines
8.8 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.ribbon;
|
||
|
|
||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.StatAlgoImporterRibbonEvent;
|
||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.UIStateEvent;
|
||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources;
|
||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.StatAlgoImporterRibbonType;
|
||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.UIStateType;
|
||
|
|
||
|
import com.allen_sauer.gwt.log.client.Log;
|
||
|
import com.google.gwt.core.client.GWT;
|
||
|
import com.google.gwt.dom.client.Element;
|
||
|
import com.google.gwt.dom.client.NodeList;
|
||
|
import com.google.gwt.user.client.ui.FlexTable;
|
||
|
import com.google.web.bindery.event.shared.EventBus;
|
||
|
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign;
|
||
|
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
|
||
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||
|
import com.sencha.gxt.core.client.dom.XElement;
|
||
|
import com.sencha.gxt.widget.core.client.button.ButtonGroup;
|
||
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
||
|
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||
|
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @author "Giancarlo Panichi" <a
|
||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||
|
*
|
||
|
*/
|
||
|
public class HomeToolBar {
|
||
|
private static final String GROUP_HEIGHT = "80px";
|
||
|
private HomeToolBarMessages msgs;
|
||
|
private EventBus eventBus;
|
||
|
private ToolBar toolBar;
|
||
|
|
||
|
//Home
|
||
|
private TextButton importButton;
|
||
|
|
||
|
//Algorithm
|
||
|
private TextButton createAlgorithmButton;
|
||
|
|
||
|
|
||
|
// Help
|
||
|
private TextButton helpButton;
|
||
|
|
||
|
|
||
|
// private TextButton languageButton;
|
||
|
// private TextButton logsButton;
|
||
|
// private TextButton testButton;
|
||
|
|
||
|
// Language Menu
|
||
|
/*
|
||
|
* private MenuItem enItem; private MenuItem itItem; private MenuItem
|
||
|
* esItem;
|
||
|
*/
|
||
|
|
||
|
public HomeToolBar(EventBus eventBus) {
|
||
|
this.eventBus = eventBus;
|
||
|
msgs = GWT.create(HomeToolBarMessages.class);
|
||
|
build();
|
||
|
}
|
||
|
|
||
|
public ToolBar getToolBar() {
|
||
|
return toolBar;
|
||
|
}
|
||
|
|
||
|
protected void build() {
|
||
|
toolBar = new ToolBar();
|
||
|
toolBar.setSpacing(5);
|
||
|
toolBar.setEnableOverflow(false);
|
||
|
|
||
|
// Home
|
||
|
ButtonGroup homeGroup = new ButtonGroup();
|
||
|
homeGroup.setId("Home");
|
||
|
homeGroup.setHeadingText(msgs.fileGroupHeadingText());
|
||
|
homeGroup.setHeight(GROUP_HEIGHT);
|
||
|
toolBar.add(homeGroup);
|
||
|
|
||
|
FlexTable homeLayout = new FlexTable();
|
||
|
homeGroup.add(homeLayout);
|
||
|
|
||
|
importButton = new TextButton(msgs.importButton(),
|
||
|
StatAlgoImporterResources.INSTANCE.upload32());
|
||
|
importButton.setId("importButton");
|
||
|
importButton.setScale(ButtonScale.MEDIUM);
|
||
|
importButton.setIconAlign(IconAlign.LEFT);
|
||
|
importButton.setArrowAlign(ButtonArrowAlign.BOTTOM);
|
||
|
importButton.setToolTip(msgs.importButtonToolTip());
|
||
|
|
||
|
importButton.addSelectHandler(new SelectHandler() {
|
||
|
|
||
|
public void onSelect(SelectEvent event) {
|
||
|
eventBus.fireEvent(new StatAlgoImporterRibbonEvent(
|
||
|
StatAlgoImporterRibbonType.UPLOAD_CODE));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
homeLayout.setWidget(0, 0, importButton);
|
||
|
homeLayout.getFlexCellFormatter().setRowSpan(0, 0, 2);
|
||
|
|
||
|
// Algorithm
|
||
|
ButtonGroup algorithmGroup = new ButtonGroup();
|
||
|
algorithmGroup.setId("Algorithm");
|
||
|
algorithmGroup.setHeadingText(msgs.algorithmGroupHeadingText());
|
||
|
algorithmGroup.setHeight(GROUP_HEIGHT);
|
||
|
toolBar.add(algorithmGroup);
|
||
|
|
||
|
FlexTable algorithmLayout = new FlexTable();
|
||
|
algorithmGroup.add(algorithmLayout);
|
||
|
|
||
|
createAlgorithmButton = new TextButton(msgs.createAlgorithmButton(),
|
||
|
StatAlgoImporterResources.INSTANCE.algorithm32());
|
||
|
createAlgorithmButton.setId("createAlgorithmButton");
|
||
|
createAlgorithmButton.setScale(ButtonScale.MEDIUM);
|
||
|
createAlgorithmButton.setIconAlign(IconAlign.LEFT);
|
||
|
createAlgorithmButton.setArrowAlign(ButtonArrowAlign.BOTTOM);
|
||
|
createAlgorithmButton.setToolTip(msgs.createAlgorithmButtonToolTip());
|
||
|
|
||
|
createAlgorithmButton.addSelectHandler(new SelectHandler() {
|
||
|
|
||
|
public void onSelect(SelectEvent event) {
|
||
|
eventBus.fireEvent(new StatAlgoImporterRibbonEvent(
|
||
|
StatAlgoImporterRibbonType.CREATE_ALGORITHM));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
algorithmLayout.setWidget(0, 0, createAlgorithmButton);
|
||
|
algorithmLayout.getFlexCellFormatter().setRowSpan(0, 0, 2);
|
||
|
|
||
|
// Help
|
||
|
ButtonGroup helpGroup = new ButtonGroup();
|
||
|
helpGroup.setId("Help");
|
||
|
helpGroup.setHeight(GROUP_HEIGHT);
|
||
|
helpGroup.setHeadingText(msgs.helpGroupHeadingText());
|
||
|
toolBar.add(helpGroup);
|
||
|
|
||
|
FlexTable helpLayout = new FlexTable();
|
||
|
helpGroup.add(helpLayout);
|
||
|
|
||
|
/*
|
||
|
* languageButton = new TextButton(msgs.languageButton(),
|
||
|
* TabularDataResources.INSTANCE.language32()); languageButton.enable();
|
||
|
* languageButton.setScale(ButtonScale.LARGE);
|
||
|
* languageButton.setIconAlign(IconAlign.TOP);
|
||
|
* languageButton.setToolTip(msgs.languageButtonToolTip());
|
||
|
* languageButton.setArrowAlign(ButtonArrowAlign.RIGHT);
|
||
|
* languageButton.setMenu(createLanguageMenu());
|
||
|
*
|
||
|
* helpLayout.setWidget(0, 0, languageButton);
|
||
|
* helpLayout.getFlexCellFormatter().setRowSpan(0, 0, 2);
|
||
|
*/
|
||
|
|
||
|
helpButton = new TextButton(msgs.helpButton(),
|
||
|
StatAlgoImporterResources.INSTANCE.help32());
|
||
|
helpButton.enable();
|
||
|
helpButton.setToolTip(msgs.helpButtonToolTip());
|
||
|
helpButton.setScale(ButtonScale.MEDIUM);
|
||
|
helpButton.setIconAlign(IconAlign.LEFT);
|
||
|
helpButton.setArrowAlign(ButtonArrowAlign.BOTTOM);
|
||
|
helpButton.addSelectHandler(new SelectHandler() {
|
||
|
|
||
|
public void onSelect(SelectEvent event) {
|
||
|
eventBus.fireEvent(new StatAlgoImporterRibbonEvent(
|
||
|
StatAlgoImporterRibbonType.HELP));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
helpLayout.setWidget(0, 1, helpButton);
|
||
|
helpLayout.getFlexCellFormatter().setRowSpan(0, 1, 2);
|
||
|
|
||
|
/*
|
||
|
* logsButton = new TextButton("Logs",
|
||
|
* TabularDataResources.INSTANCE.logs32()); logsButton.enable();
|
||
|
* logsButton.setToolTip("Show Logs");
|
||
|
* logsButton.setScale(ButtonScale.LARGE);
|
||
|
* logsButton.setIconAlign(IconAlign.TOP);
|
||
|
* logsButton.setArrowAlign(ButtonArrowAlign.BOTTOM);
|
||
|
* logsButton.addSelectHandler(new SelectHandler() {
|
||
|
*
|
||
|
* public void onSelect(SelectEvent event) { eventBus.fireEvent(new
|
||
|
* RibbonEvent(RibbonType.LOGS)); } });
|
||
|
*
|
||
|
* helpLayout.setWidget(0, 1, logsButton);
|
||
|
* helpLayout.getFlexCellFormatter().setRowSpan(0, 1, 2);
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
* testButton = new TextButton("Test",
|
||
|
* TabularDataResources.INSTANCE.test32()); testButton.disable();
|
||
|
* testButton.setToolTip("Test");
|
||
|
* testButton.setScale(ButtonScale.LARGE);
|
||
|
* testButton.setIconAlign(IconAlign.TOP);
|
||
|
* testButton.setArrowAlign(ButtonArrowAlign.BOTTOM);
|
||
|
* testButton.addSelectHandler(new SelectHandler() {
|
||
|
*
|
||
|
* public void onSelect(SelectEvent event) { eventBus.fireEvent(new
|
||
|
* RibbonEvent(RibbonType.TEST)); } });
|
||
|
*
|
||
|
* helpLayout.setWidget(0, 2, testButton);
|
||
|
* helpLayout.getFlexCellFormatter().setRowSpan(0, 2, 2);
|
||
|
*/
|
||
|
|
||
|
cleanCells(helpLayout.getElement());
|
||
|
|
||
|
eventBus.addHandler(UIStateEvent.TYPE,
|
||
|
new UIStateEvent.UIStateHandler() {
|
||
|
|
||
|
public void onUIState(UIStateEvent event) {
|
||
|
setUI(event);
|
||
|
|
||
|
}
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
private void cleanCells(Element elem) {
|
||
|
NodeList<Element> tds = elem.<XElement> cast().select("td");
|
||
|
for (int i = 0; i < tds.getLength(); i++) {
|
||
|
Element td = tds.getItem(i);
|
||
|
|
||
|
if (!td.hasChildNodes() && td.getClassName().equals("")) {
|
||
|
td.removeFromParent();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* private Menu createLanguageMenu() { Menu menuReplace = new Menu(); enItem
|
||
|
* = new MenuItem(msgs.english(), TabularDataResources.INSTANCE.flagGB());
|
||
|
* itItem = new MenuItem(msgs.italian(),
|
||
|
* TabularDataResources.INSTANCE.flagIT()); esItem = new
|
||
|
* MenuItem(msgs.spanish(), TabularDataResources.INSTANCE.flagES());
|
||
|
*
|
||
|
* enItem .addSelectionHandler(new SelectionHandler<Item>() {
|
||
|
*
|
||
|
* @Override public void onSelection(SelectionEvent<Item> event) {
|
||
|
* eventBus.fireEvent(new RibbonEvent( RibbonType.LANGUAGE_EN));
|
||
|
*
|
||
|
* } });
|
||
|
*
|
||
|
* itItem .addSelectionHandler(new SelectionHandler<Item>() {
|
||
|
*
|
||
|
* @Override public void onSelection(SelectionEvent<Item> event) {
|
||
|
* eventBus.fireEvent(new RibbonEvent( RibbonType.LANGUAGE_IT));
|
||
|
*
|
||
|
* } });
|
||
|
*
|
||
|
* esItem .addSelectionHandler(new SelectionHandler<Item>() {
|
||
|
*
|
||
|
* @Override public void onSelection(SelectionEvent<Item> event) {
|
||
|
* eventBus.fireEvent(new RibbonEvent( RibbonType.LANGUAGE_ES));
|
||
|
*
|
||
|
* } });
|
||
|
*
|
||
|
* menuReplace.add(enItem); menuReplace.add(esItem);
|
||
|
* menuReplace.add(itItem); return menuReplace; }
|
||
|
*/
|
||
|
|
||
|
public void setUI(UIStateEvent event) {
|
||
|
UIStateType uiStateType = event.getUiStateType();
|
||
|
try {
|
||
|
switch (uiStateType) {
|
||
|
case START:
|
||
|
importButton.enable();
|
||
|
createAlgorithmButton.enable();
|
||
|
helpButton.enable();
|
||
|
|
||
|
// testButton.disable();
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
Log.error("setUI Error : " + e.getLocalizedMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|