Skip to content

Instantly share code, notes, and snippets.

/gist:4635979

Created Jan 25, 2013
Embed
What would you like to do?
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