Created
January 25, 2013 16:51
-
-
Save anonymous/4635979 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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