this.delegate = createDefaultTabPanel(interactionUnit, eventBus);
}
}
private TabPanelContract createEditorPanel(final InteractionUnit interactionUnit, final EventBus eventBus) {
final DefaultTabLayoutPanel tabLayoutpanel = new DefaultTabLayoutPanel(40, Style.Unit.PX);
tabLayoutpanel.addStyleName("default-tabpanel");
tabLayoutpanel.addBeforeSelectionHandler(new NavigationHandler(interactionUnit, childUnits, tabLayoutpanel));
/* tabLayoutpanel.addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent attachEvent) {
if(attachEvent.isAttached() && tabLayoutpanel.getWidgetCount()>0)
tabLayoutpanel.selectTab(0);
}
});*/
TabPanelContract tabPanelContract = new TabPanelContract() {
@Override
public void add(InteractionUnit unit, Widget widget) {
final VerticalPanel vpanel = new VerticalPanel();
vpanel.setStyleName("rhs-content-panel");
vpanel.add(widget);
ScrollPanel scroll = new ScrollPanel(vpanel);
tabLayoutpanel.add(scroll, unit.getLabel());
// register tab2index mapping
childUnits.put(tabLayoutpanel.getWidgetCount() - 1, unit.getId());
}
@Override
public Widget as() {
return tabLayoutpanel;
}
};
// activation listener
eventBus.addHandler(SystemEvent.TYPE,
new ChildActivationHandler<DefaultTabLayoutPanel>(tabLayoutpanel, childUnits, new ChildUnitCommand<DefaultTabLayoutPanel>() {
@Override
public void execute(DefaultTabLayoutPanel parent, int key) {
tabLayoutpanel.selectTab(key, false);
}
})
);
eventBus.addHandler(SystemEvent.TYPE,
new SystemEvent.Handler() {
@Override
public boolean accepts(SystemEvent event) {
return event.getId().equals(CommonQNames.ACTIVATION_ID)
&& childUnits.containsValue(event.getPayload()
);
}
@Override
public void onSystemEvent(SystemEvent event) {
QName id = (QName) event.getPayload();
Set<Integer> keys = childUnits.keySet();
for (Integer key : keys) {
if (childUnits.get(key).equals(id)) {
tabLayoutpanel.selectTab(key, false);
break;
}
}
}
}