/** * Selects the tab corresponding to the widget for the tab. To be clear the * widget for the tab is not the widget INSIDE of the tab; it is the widget * used to represent the tab itself. * * @param tabWidget The widget for the tab to be selected * @return true if the tab corresponding to the widget for the tab could * located and selected, false otherwise */ private boolean selectTabByTabWidget(Widget tabWidget) { int numTabs = panel.getWidgetCount() - 1; for (int i = 1; i < numTabs; ++i) { if (panel.getWidget(i) == tabWidget) { return selectTab(i - 1); } } return false; }
/** * <b>Affected Elements:</b> * <ul> * <li>-# = the cell at the given index.</li> * </ul> * * @see UIObject#onEnsureDebugId(String) */ @Override protected void onEnsureDebugId(String baseID) { super.onEnsureDebugId(baseID); int numChildren = getWidgetCount(); for (int i = 0; i < numChildren; i++) { ensureDebugId(getWidgetTd(getWidget(i)), baseID, "" + i); } }
/** * Gets the given tab. * * This method is final because the Tab interface will expand. Therefore * it is highly likely that subclasses which implemented this method would end up * breaking. * * @param index the tab's index * @return the tab wrapper */ public final Tab getTab(int index) { if (index >= getTabCount()) { return null; } ClickDelegatePanel p = (ClickDelegatePanel) panel.getWidget(index + 1); return p; }
@Override public void onMouseOut( MouseOutEvent event ) { add.setResource( HexaFramework.images.ellipsis() ); int nb = buttonBar.getWidgetCount(); for( int i = 0; i < nb; i++ ) { Widget w = buttonBar.getWidget( i ); if( w != add ) w.getElement().getStyle().setDisplay( Display.NONE ); } } }, MouseOutEvent.getType() );
/** * Check if a tab is enabled or disabled. If disabled, the user cannot select * the tab. * * @param index the index of the tab * @return true if the tab is enabled, false if disabled */ public boolean isTabEnabled(int index) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); return delPanel.isEnabled(); }
@Override public void onMouseOver( MouseOverEvent event ) { add.setResource( HexaFramework.images.add() ); int nb = buttonBar.getWidgetCount(); for( int i = 0; i < nb; i++ ) { Widget w = buttonBar.getWidget( i ); if( w != add ) w.getElement().getStyle().clearDisplay(); } } } );
/** * Removes the tab at the specified index. * * @param index the index of the tab to be removed */ public void removeTab(int index) { checkTabIndex(index); // (index + 1) to account for 'first' placeholder widget. Widget toRemove = panel.getWidget(index + 1); if (toRemove == selectedTab) { selectedTab = null; } panel.remove(toRemove); }
@Override public void onMouseOut( MouseOutEvent event ) { add.setResource( HexaFramework.images.ellipsis() ); int nb = buttonBar.getWidgetCount(); for( int i = 0; i < nb; i++ ) { Widget w = buttonBar.getWidget( i ); if( w != add ) w.getElement().getStyle().setDisplay( Display.NONE ); } } }, MouseOutEvent.getType() );
/** * Sets a tab's text contents. * * @param index the index of the tab whose text is to be set * @param text the object's new text */ public void setTabText(int index, String text) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); SimplePanel focusablePanel = delPanel.getFocusablePanel(); // It is not safe to check if the current widget is an instanceof Label and // reuse it here because HTML is an instanceof Label. Leaving an HTML would // throw off the results of getTabHTML(int). focusablePanel.setWidget(new Label(text, false)); }
HorizontalPanel panel = new HorizontalPanel(); Widget w = new Widget(); //We add the one widget to the panel panel.add(w); //One more widget added w = new Widget(); panel.add(w); //Now we remove all the widgets from the panel for(int i = 0; i < panel.getWidgetCount(); i++){ panel.remove(panel.getWidget(i)); }
/** * Sets a tab's contents via HTML. * * Use care when setting an object's HTML; it is an easy way to expose * script-based security problems. Consider using * {@link #setTabText(int, String)} or {@link #setTabHTML(int, SafeHtml)} * whenever possible. * * @param index the index of the tab whose HTML is to be set * @param html the tab new HTML */ public void setTabHTML(int index, @IsSafeHtml String html) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); SimplePanel focusablePanel = delPanel.getFocusablePanel(); focusablePanel.setWidget(new HTML(html, false)); }
/** * Enable or disable a tab. When disabled, users cannot select the tab. * * @param index the index of the tab to enable or disable * @param enabled true to enable, false to disable */ public void setTabEnabled(int index, boolean enabled) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; // Style the wrapper ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); delPanel.setEnabled(enabled); setStyleName(delPanel.getElement(), "gwt-TabBarItem-disabled", !enabled); setStyleName(delPanel.getElement().getParentElement(), "gwt-TabBarItem-wrapper-disabled", !enabled); }
/** * Programmatically selects the specified tab. Use index -1 to specify that no * tab should be selected. * * @param index the index of the tab to be selected * @param fireEvents true to fire events, false not to * @return <code>true</code> if successful, <code>false</code> if the change * is denied by the {@link BeforeSelectionHandler}. */ public boolean selectTab(int index, boolean fireEvents) { checkTabIndex(index); if (fireEvents) { BeforeSelectionEvent<?> event = BeforeSelectionEvent.fire(this, index); if (event != null && event.isCanceled()) { return false; } } // Check for -1. setSelectionStyle(selectedTab, false); if (index == -1) { selectedTab = null; return true; } selectedTab = panel.getWidget(index + 1); setSelectionStyle(selectedTab, true); if (fireEvents) { SelectionEvent.fire(this, index); } return true; }
/** * <b>Affected Elements:</b> * <ul> * <li>-tab# = The element containing the contents of the tab.</li> * <li>-tab-wrapper# = The cell containing the tab at the index.</li> * </ul> * * @see UIObject#onEnsureDebugId(String) */ @Override protected void onEnsureDebugId(String baseID) { super.onEnsureDebugId(baseID); int numTabs = getTabCount(); for (int i = 0; i < numTabs; i++) { ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(i + 1); SimplePanel focusablePanel = delPanel.getFocusablePanel(); ensureDebugId(focusablePanel.getContainerElement(), baseID, "tab" + i); ensureDebugId(DOM.getParent(delPanel.getElement()), baseID, "tab-wrapper" + i); } }
/** * Gets the specified tab's HTML. * * @param index the index of the tab whose HTML is to be retrieved * @return the tab's HTML */ public String getTabHTML(int index) { if (index >= getTabCount()) { return null; } ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); SimplePanel focusablePanel = delPanel.getFocusablePanel(); Widget widget = focusablePanel.getWidget(); if (widget instanceof HTML) { return ((HTML) widget).getHTML(); } else if (widget instanceof Label) { return ((Label) widget).getText(); } else { // This will be a focusable panel holding a user-supplied widget. return focusablePanel.getElement().getParentElement().getInnerHTML(); } }
/** * Check if a tab is enabled or disabled. If disabled, the user cannot select * the tab. * * @param index the index of the tab * @return true if the tab is enabled, false if disabled */ public boolean isTabEnabled(int index) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); return delPanel.isEnabled(); }
@Override public void setSelectedRendererIndex(int index) { unselectCurrent(); selectedRadio = (RadioButton) radioButtonsPanel.getWidget(index); selectedRadio.setValue(true); }
/** * Check if a tab is enabled or disabled. If disabled, the user cannot select * the tab. * * @param index the index of the tab * @return true if the tab is enabled, false if disabled */ public boolean isTabEnabled(int index) { assert (index >= 0) && (index < getTabCount()) : "Tab index out of bounds"; ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1); return delPanel.isEnabled(); }
@Override public void setSelectedRendererIndex(int index) { unselectCurrent(); selectedRadio = (RadioButton) radioButtonsPanel.getWidget(index); selectedRadio.setValue(true); }