/** * Sets the selected tab, identified by its index. Does nothing if the * position is out of bounds. * * @param index * the index of the tab to select */ public void setSelectedTab(int index) { setSelectedTab(getTab(index)); }
private static int getPositionOfSelectedTab(final TabSheet tabSheet) { return tabSheet.getTabPosition(tabSheet.getTab(tabSheet.getSelectedTab())); }
/** * Returns the {@link Tab} (metadata) with the given index. The {@link Tab} * object can be used for setting caption,icon, etc for the tab. * * @param index * the index of the tab * @return The tab with the given index, or null if the index is out of * bounds. */ public Tab getTab(int index) { if (index >= 0 && index < getComponentCount()) { return getTab(components.get(index)); } else { return null; } }
private static int getPositionOfSelectedTab(final TabSheet tabSheet) { return tabSheet.getTabPosition(tabSheet.getTab(tabSheet.getSelectedTab())); }
/** * Called when a selected tab is removed to specify the new tab to select. * Can be overridden to provide another algorithm that calculates the new * selection. * * Current implementation will choose the first enabled tab to the right of * the removed tab if it's not the last one, otherwise will choose the * closer enabled tab to the left. * * @since 7.4 * @param removedTabIndex * the index of the selected tab which was just remove. * @return the index of the tab to be selected or -1 if there are no more * enabled tabs to select. */ protected int selectedTabIndexAfterTabRemove(int removedTabIndex) { for (int i = removedTabIndex; i < components.size(); i++) { Tab tab = getTab(i); if (tab.isEnabled()) { return i; } } for (int i = removedTabIndex - 1; i >= 0; i--) { Tab tab = getTab(i); if (tab.isEnabled()) { return i; } } return -1; }
/** * Moves all components from another container to this container. The * components are removed from the other container. * * If the source container is a {@link TabSheet}, component captions and * icons are copied from it. * * @param source * the container components are removed from. */ @Override public void moveComponentsFrom(ComponentContainer source) { for (final Iterator<Component> i = source.getComponentIterator(); i .hasNext();) { final Component c = i.next(); String caption = null; Resource icon = null; String iconAltText = ""; if (TabSheet.class.isAssignableFrom(source.getClass())) { Tab tab = ((TabSheet) source).getTab(c); caption = tab.getCaption(); icon = tab.getIcon(); iconAltText = tab.getIconAlternateText(); } source.removeComponent(c); Tab tab = addTab(c, caption, icon); tab.setIconAlternateText(iconAltText); } }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); TabSheet def = designContext.getDefaultInstance(this); Attributes attr = design.attributes(); // write tabs if (!designContext.shouldWriteChildren(this, def)) { return; } for (Component component : this) { Tab tab = this.getTab(component); writeTabToDesign(design, designContext, tab); } }
/** * Sets the selected tab in the TabSheet. Ensures that the selected tab is * repainted if needed. * * @param component * The new selection or null for no selection */ private void setSelected(Component component) { Tab tab = tabs.get(selected); selected = component; // Repaint of the selected component is needed as only the selected // component is communicated to the client. Otherwise this will be a // "cached" update even though the client knows nothing about the // connector if (selected != null) { tab = getTab(component); if (tab != null && tab.getDefaultFocusComponent() != null) { tab.getDefaultFocusComponent().focus(); } getState().selected = keyMapper.key(selected); selected.markAsDirtyRecursive(); } else { getState().selected = null; } }
public void setSwatchesTabCaption(String caption) { ((TabSheet) swatchesTab.getParent()).getTab(swatchesTab).setCaption(caption); }
private static void switchCaption(TabSheet tabSheet, MessageSourceAccessor messageSourceAccessor) { int j=0; for (final Iterator<Component> i = tabSheet.getComponentIterator(); i.hasNext();) { final Component component = i.next(); Tab tab = tabSheet.getTab(j++); String newCaption = getTranslatedCaption(tab.getCaption(),messageSourceAccessor); if (newCaption != null) { tab.setCaption(newCaption); } } } private static void switchCaption(Label label, MessageSourceAccessor messageSourceAccessor)
@Nullable protected TabSheet.Tab findTab() { if (component.isAttached()) { com.vaadin.ui.Component parent = component; while (parent != null) { if (parent.getParent() instanceof TabSheet) { return ((TabSheet) parent.getParent()).getTab(parent); } parent = parent.getParent(); } } return null; }
@Nullable protected TabSheet.Tab asTabWindow() { if (component.isAttached()) { com.vaadin.ui.Component parent = component; while (parent != null) { if (parent.getParent() instanceof TabSheet) { return ((TabSheet) parent.getParent()).getTab(parent); } parent = parent.getParent(); } } return null; }
@Override public void selectedTabChange(SelectedTabChangeEvent event) { TabSheet tabsheet = event.getTabSheet(); Tab tab = tabsheet.getTab(tabsheet.getSelectedTab()); if (tab != null) { Notification.show("Selected tab: " + tab.getCaption()); } }
@Override public void selectedTabChange(SelectedTabChangeEvent event) { TabSheet tabsheet = event.getTabSheet(); Tab tab = tabsheet.getTab(tabsheet.getSelectedTab()); if (tab != null) { Notification.show("Selected tab: " + tab.getCaption()); } }
TabSheet tabsheet= new TabSheet(); // Create an example of tab VerticalLayout tabExample= new VerticalLayout(); tabExample.addComponent(new Embedded(null, new ThemeResource("anyImage.jpg"))); tabExample.setCaption("Example"); tabsheet.addTab(tabExample).setIcon( new ThemeResource("anyIcon.png")); Iterator<Component> componentIterator = tabsheet.getComponentIterator(); while (componentIterator.hasNext()) { Component c = (Component) componentIterator.next(); Tab tab = tabsheet.getTab(c); System.out.println("test: " + tab.getCaption()); }
private void updateTabVisibility() { for (int i=0; i<tabSheet.getComponentCount(); i++) { TabSheet.Tab tab = tabSheet.getTab(i); if (tab.getComponent() instanceof SelectionAwareTable) { ContentType contentType = ((SelectionAwareTable) tab.getComponent()).getContentType(); boolean visible = m_graphContainer.getTopologyServiceClient().contributesTo(contentType); tab.setVisible(visible); } } }
private void updateTabVisibility() { for (int i=0; i<tabSheet.getComponentCount(); i++) { TabSheet.Tab tab = tabSheet.getTab(i); if (tab.getComponent() instanceof SelectionAwareTable) { ContentType contentType = ((SelectionAwareTable) tab.getComponent()).getContentType(); boolean visible = m_graphContainer.getTopologyServiceClient().contributesTo(contentType); tab.setVisible(visible); } } }
/** * Tests if component enabled and visible and its container enabled. * * @param child component * @return component enabled state */ public static boolean isComponentEnabled(Component child) { if (child.getParent() instanceof TabSheet) { TabSheet tabSheet = (TabSheet) child.getParent(); TabSheet.Tab tab = tabSheet.getTab(child); if (!tab.isEnabled()) { return false; } } return child.isEnabled() && (child.getParent() == null || isComponentEnabled(child.getParent())) && isComponentVisible(child); }
/** * Tests if component visible and its container visible. * * @param child component * @return component visibility */ public static boolean isComponentVisible(Component child) { if (child.getParent() instanceof TabSheet) { TabSheet tabSheet = (TabSheet) child.getParent(); TabSheet.Tab tab = tabSheet.getTab(child); if (!tab.isVisible()) { return false; } } if (child.getParent() instanceof CubaGroupBox) { // ignore groupbox content container visibility return isComponentVisible(child.getParent()); } return child.isVisible() && (child.getParent() == null || isComponentVisible(child.getParent())); }