Skip to content

Code used in the How to programmatically manage the titleBarTabs Object Courselet

februari 2, 2012

This page is part of the How to programmatically manage the titleBarTabs Object courselet.

EmployeeApp XPage source code

<xc:ccLayout_1>
  <xp:this.facets>
    xe:dynamicContent id="dynamicContent1" xp:key="facetMiddle"
defaultFacet="employees">
      <xp:this.facets>
        <xc:ccEmployees_1 xp:key="employees"></xc:ccEmployees_1>
        <xc:ccEmployee_1 xp:key="employee"></xc:ccEmployee_1>
      </xp:this.facets>
    </xe:dynamicContent>
  </xp:this.facets>
</xc:ccLayout_1>

Custom control: ccEmployees, viewPanel tag properties

<xp:viewPanel rows="10" var="row" id="viewPanel1">

Custom control: ccEmployees, viewPanel, first column, onclick event

//Get a reference to the titleBarTabs object
var applicationLayout1 = getComponent("applicationLayout1");
var config = applicationLayout1.getConfiguration();
var tab = config.getTitleBarTabs();
//Get the NoteID of the Notes document
var id = row.getNoteID();
//Select an existing tab
var entry;
var isAlreadyCreated;
var iter:java.util.Iterator = tab.iterator();
while (iter.hasNext()) {
  entry = iter.next();
  if (entry.getSubmitValue() == id) {
    isAlreadyCreated = true;
    entry.setSelected(true);
  } else {
    entry.setSelected(false);
  }
}
//Add a new tab
if (!isAlreadyCreated) {
  //Create a new tab
  var newTab = new com.ibm.xsp.extlib.tree.complex.ComplexLeafTreeNode();
  newTab.setSubmitValue(id); // need to remember assiociated noteId
  newTab.setLabel(row.getColumnValue("Firstname"));
  newTab.setImage("/document_edit.png");
  newTab.setSelected(true);
  //add the new tab to the titleBarTabs object
  tab.add(newTab);
}
//Show the data of the Notes document
var dynamicContent1 = getComponent("dynamicContent1");
dynamicContent1.show("employee",{action:'editDocument',documentId:id});

Application Outline control, onItemClick event

var DEFAULT_TAB = "page1";
var DEFAULT_PANEL = "employees"; //Employees_1 custom control
var FORM_PANEL = "employee";     //Employee_1 custom control
var NEW_DOC = "0";
//Get the tab's submit value
var event = context.getSubmittedValue();
//Get the titleBarTabs object
var applicationLayout1 = getComponent("applicationLayout1");
var config = applicationLayout1.getConfiguration();
var tab = config.getTitleBarTabs();
//Deselect all tabs
var iter:java.util.Iterator = tab.iterator();
while (iter.hasNext()) {
  var entry = iter.next();
  entry.setSelected(false);
}
//Get a reference to the Dynamic Content object
var dynamicContent1 = getComponent("dynamicContent1");
//Select the right custom control
if (event == DEFAULT_TAB) {
  //Select the default tab
  tab.get(0).setSelected(true);
  //Show the default tab
  dynamicContent1.show(DEFAULT_PANEL);
}
else if (event == NEW_DOC) {
  //Add a new tab
  var iter:java.util.Iterator = tab.iterator();
  while (iter.hasNext()) {
    var entry = iter.next();
    if (entry.getSubmitValue() == event) {
      entry.setSelected(true);
    }
  }
  //Show an empty form
  dynamicContent1.show(FORM_PANEL,{action:'newDocument'});
}
else {
  //Select an existing tab
  var iter:java.util.Iterator = tab.iterator();
  while (iter.hasNext()) {
    var entry = iter.next();
    if (entry.getSubmitValue() == event) {
      entry.setSelected(true);
    }
  }
  //Show the form with the Notes document data
  dynamicContent1.show(FORM_PANEL,{action:'editDocument',documentId:event});
}

Custom Control Employee_1, Close Button, onclick event

var DEFAULT_CC = "employees";
//Get the titleBarTabs object
var applicationLayout1 = getComponent("applicationLayout1");
var config = applicationLayout1.getConfiguration();
var tab:java.util.List = config.getTitleBarTabs();
//Get the current tab and remove it
var iter:java.util.Iterator = tab.iterator();
var entry;
var index = 0;
while (iter.hasNext()) {
  entry = iter.next();
  if (entry.isSelected()) {
    tab.remove(index);
    break;
  }
 index++;
}
//Select the default custom control
tab.get(0).setSelected(true);
var dynamicContent1 = getComponent("dynamicContent1");
dynamicContent1.show(DEFAULT_CC);
No comments yet

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit / Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit / Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit / Bijwerken )

Verbinden met %s

%d bloggers op de volgende wijze: