Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2013 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4635979 to your computer and use it in GitHub Desktop.
Save anonymous/4635979 to your computer and use it in GitHub Desktop.
public with sharing class TabOrderController
{
public String tabRef;
public List<TabInfo> Tabs {get;set;}
public TabOrderController()
{
Tabs = new List<TabInfo>();
for(Integer tabIdx=0; tabIdx<10; tabIdx++)
{
TabInfo ti = new TabInfo();
ti.Name = 'Tab ' + tabIdx;
Tabs.add(ti);
}
}
public String getTabRef()
{
return tabRef;
}
public void setTabRef(String tabRef)
{
this.tabRef = tabRef;
}
public PageReference moveUp()
{
Integer idx = findTabIndex(tabRef);
if(idx<=0)
return null;
TabInfo ti = Tabs.remove(idx);
Tabs.add(idx-1, ti);
return null;
}
public PageReference moveDown()
{
Integer idx = findTabIndex(tabRef);
if(idx==-1 || idx==(Tabs.size()-1))
return null;
TabInfo ti = Tabs.remove(idx);
if(idx == (Tabs.size()-1))
Tabs.add(ti);
else
Tabs.add(idx+1, ti);
return null;
}
private Integer findTabIndex(String tabRef)
{
Integer idx = 0;
for(; idx<Tabs.size(); idx++)
if(Tabs[idx].Name.equals(tabRef))
break;
return idx < Tabs.size() ? idx : -1;
}
public class TabInfo
{
public string Name {get;set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment