Package com.puzzlebazar.client.ui

Source Code of com.puzzlebazar.client.ui.BaseTabPanel

/**
* Copyright 2010 Philippe Beaudoin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.puzzlebazar.client.ui;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.Tab;
import com.gwtplatform.mvp.client.TabData;
import com.gwtplatform.mvp.client.TabPanel;

/**
* @author Philippe Beaudoin
*/
public abstract class BaseTabPanel extends Composite implements TabPanel {

  @UiField
  FlowPanel tabPanel;

  @UiField
  FlowPanel tabContentContainer;

  private final List<Tab> tabList = new ArrayList<Tab>();
  Tab currentActiveTab;

  public BaseTabPanel() {
    super();
  }

  @Override
  public Tab addTab(TabData tabData, String historyToken) {
    Tab newTab = createNewTab(tabData.getPriority());
    int beforeIndex;
    for (beforeIndex = 0; beforeIndex < tabList.size(); ++beforeIndex) {
      if (newTab.getPriority() < tabList.get(beforeIndex).getPriority()) {
        break;
      }
    }
    tabPanel.insert(newTab.asWidget(), beforeIndex);
    tabList.add(beforeIndex, newTab);
    newTab.setText(tabData.getLabel());
    newTab.setTargetHistoryToken(historyToken);
    return newTab;
  }

  @Override
  public void removeTab(Tab tab) {
    tabPanel.getElement().removeChild(tab.asWidget().getElement());
    tabList.remove(tab);
  }

  @Override
  public void removeTabs() {
    for (Tab tab : tabList) {
      tabPanel.getElement().removeChild(tab.asWidget().getElement());
    }
    tabList.clear();
  }

  @Override
  public void setActiveTab(Tab tab) {
    if (currentActiveTab != null) {
      currentActiveTab.deactivate();
    }
    if (tab != null) {
      tab.activate();
    }
    currentActiveTab = tab;
  }

  /**
   * Sets the content displayed in the main panel.
   *
   * @param panelContent The {@link Widget} to set in the main panel, or {@code null} to clear the panel.
   */
  public void setPanelContent(Widget panelContent) {
    tabContentContainer.clear();
    if (panelContent != null) {
      tabContentContainer.add(panelContent);
    }
  }

  /**
   * Returns a new tab of the type specific for this tab panel.
   *
   * @param priority The desired priority of the new tab.
   * @return The new tab.
   */
  protected abstract Tab createNewTab(float priority);

}
TOP

Related Classes of com.puzzlebazar.client.ui.BaseTabPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.