Advanced GWT Components

Community Support
It is currently Thu Dec 17, 2009 11:35 am

All times are UTC



Welcome
Welcome to <strong>Advanced GWT Components Forum</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view some discussions and access our other features. By joining our free community, you will have access to communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: upgraded tab panel...
PostPosted: Sat Oct 31, 2009 4:51 am 
Offline

Joined: Sun Oct 25, 2009 1:03 am
Posts: 13
Hi Sergey,

I extended AdvancedTabPanel to allow setTabEnabled method. Feel free to incorporate into your next release. I had to do some extra work because some of the variables are private in AdvancedTabPanel. Somehow this forum is not allowing uploading both .java and .txt. I have cut&paste the code below...

Thx

pady



/**
*
* Code given as is. Use at your own risk.
*
*/

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

import org.gwt.advanced.client.ui.widget.AdvancedTabPanel;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SourcesTabEvents;
import com.google.gwt.user.client.ui.TabListener;
import com.google.gwt.user.client.ui.Widget;

/**
* @author pady
*
*/
public class FramesTabPanel extends AdvancedTabPanel {


public FramesTabPanel() {

addTabListener(tabListener);
}

private TabListener tabListener = new TabListener() {
@Override
public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
for (TabState tabState : tabStateLst) {
if ( tabIndex == tabState.index && !tabState.enable ) {
return false;
}
}
return true;
}

@Override
public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
}
};

private int tabCnt = 0;

public void addTab(Widget tab, Widget content) {
super.addTab(tab, content);
tabCnt++;
TabState tabState = new TabState();
tabState.index = tabCnt;
tabState.tabWidget = tab;
tabState.enable = true;
tabStateLst.add(tabState);
}

@Override
public void removeTab(Widget tab) {
super.removeTab(tab);
TabState selState = null;
for (TabState tabState : tabStateLst) {
if ( tabState.tabWidget.equals(tab) )
selState = tabState;
}

if ( selState != null ) {
int selIndex = selState.index;
tabStateLst.remove(selState);
for (TabState tabState : tabStateLst) {
if ( tabState.index > selIndex )
tabState.index--;
}
}
}

public void setTabEnabled(int tabIndex, boolean enable) {
Widget w = getTab(tabIndex);
if ( enable ) {
w.removeStyleName("disableTab");
} else {
w.addStyleName("disableTab");
}
for (TabState tabState : tabStateLst) {
if ( tabState.index == tabIndex )
tabState.enable = enable;
}
}

private List<TabListener> tabListeners = new ArrayList<TabListener>();

@Override
public void addTabListener(TabListener listener) {
//super.addTabListener(listener);
tabListeners.add(listener);
}

private int selected = -1;
public int getSelected() {
return selected;
}

public void setSelected(int index) {
if (index >= tabStateLst.size())
return;
boolean continueTabSelection = true;
for (TabListener tabList : tabListeners) {
if ( !tabList.onBeforeTabSelected(this, index) )
continueTabSelection = false;
}

if ( !continueTabSelection )
return;

selected = index;
renderTabs();

for (TabListener tabList : tabListeners) {
tabList.onTabSelected(this, index);
}
resize();
}

private List<TabState> tabStateLst = new ArrayList<TabState>();

private class TabState {
int index;
public Widget tabWidget;
public boolean enable;
}
}


Top
 Profile  
 
 Post subject: Re: upgraded tab panel...
PostPosted: Sat Oct 31, 2009 4:58 am 
Offline

Joined: Sun Oct 25, 2009 1:03 am
Posts: 13
Hi Sergey,

I forgot 2 more methods ( this helps in changing from gwt TabPanel to AdvancedTabPanel very easy...minimal changes )...

public void add(Widget content, Widget tab) {
addTab(tab, content);
}

public void selectTab(int index) {
setSelected(index);
}


Thanks

pady


Top
 Profile  
 
 Post subject: Re: upgraded tab panel...
PostPosted: Sun Nov 01, 2009 5:48 pm 
Offline
Site Admin

Joined: Mon Mar 24, 2008 8:39 pm
Posts: 89
Done, but I modified your source code to provide GWT 1.4, 1.5 support


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron