Search in sources :

Example 1 with ITypedKey

use of org.jowidgets.util.ITypedKey in project jo-client-platform by jo-source.

the class BeanTabFolderImpl method updateFromModel.

@SuppressWarnings("unchecked")
private void updateFromModel() {
    model.removeBeanSelectionListener(modelSelectionListener);
    tabFolder.removeTabFolderListener(tabFolderSelectionListener);
    final int tabsToAdd = model.getSize() - tabFolder.getItems().size();
    if (tabsToAdd < 0) {
        for (int i = 0; i < -tabsToAdd; i++) {
            final int removeIndex = tabFolder.getItems().size() - 1;
            tabFolder.removeItem(removeIndex);
            beanTabs.remove(Integer.valueOf(removeIndex));
        }
    } else {
        for (int i = 0; i < tabsToAdd; i++) {
            addTab();
        }
    }
    for (int i = 0; i < model.getSize(); i++) {
        final IBeanProxy<BEAN_TYPE> bean = model.getBean(i);
        final ITabItem item = tabFolder.getItem(i);
        bean.addPropertyChangeListener(renderLabelListener);
        for (final Entry<ITypedKey, RenderLabelCustomPropertiesListener> entry : renderLabelCustomPropertiesListeners.entrySet()) {
            bean.addCustomPropertyListener(entry.getKey(), entry.getValue());
        }
        final IBeanTab<BEAN_TYPE> beanTab = beanTabs.get(Integer.valueOf(i));
        beanTab.setBean(bean);
        renderLabel(item, bean);
    }
    tabFolder.addTabFolderListener(tabFolderSelectionListener);
    model.addBeanSelectionListener(modelSelectionListener);
    if (tabFolder.getItems().size() > 0) {
        final Integer selectionIndex = model.getSelectionIndex();
        if (selectionIndex != null) {
            if (selectionIndex.intValue() < tabFolder.getItems().size()) {
                tabFolder.setSelectedItem(selectionIndex.intValue());
            } else {
                model.setSelection(tabFolder.getSelectedIndex());
            }
        } else {
            model.setSelection(tabFolder.getSelectedIndex());
        }
    }
}
Also used : ITabItem(org.jowidgets.api.widgets.ITabItem) ITypedKey(org.jowidgets.util.ITypedKey) IBeanTabFolderBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanTabFolderBluePrint)

Aggregations

ITabItem (org.jowidgets.api.widgets.ITabItem)1 IBeanTabFolderBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanTabFolderBluePrint)1 ITypedKey (org.jowidgets.util.ITypedKey)1