Category Archives: Tips

Sync Multiple Eclipse to a Single GitHub Repository

I configured eclipse and eGit in two different laptops to integrate my git repository with my development copy of source code. Now I can easily make changes in local repository and push it to github. But the problem is if I am editing something in first laptop and pushed it to github. Now on the second laptop I dont have the latest code. So I need to pull from github. I search a lot in eclipse but unable to find anything useful. After putting a lot of efforts I finally found a way to pull the code from github using command line. I just need to add a new repository. Let us call it upstream. To do this I issued following command:

XPage – Sort View Column

I was searching for a work around to allow view column to be sortable by clicking on column header but I was not able to find any reliable solution using View Panel. Now I found a way to provide this feature using Repeat Control or Data Table.

Please go through the following code.
[javascript]
var loView:NotesView = null;
var loEntryColl:NotesViewEntryCollection = null;
var loTreeMap:java.util.TreeMap = new java.util.TreeMap();
var lsSortBy = viewScope.get(“sortBy”);
try {
loView = database.getView(“view”);
if(null == lsSortBy || “” == lsSortBy) {
lsSortBy = 0;
}

if(null != loView && loView.getEntryCount() > 0) {
loEntryColl = loView.getAllEntries();
var loEntry:NotesViewEntry = loEntryColl.getFirstEntry();
var loTempEntry:NotesViewEntry = null;
while(null != loEntry) {
loDoc = loEntry.getDocument();
var lsKey = loEntry.getColumnValues().get(lsSortBy);

while(loTreeMap.containsKey(lsKey)) {
lsKey += “~”;
}

loTreeMap.put(lsKey, loEntry.getColumnValues());

loTempEntry = loEntryColl.getNextEntry(loEntry);
loEntry.recycle();
loEntry = loTempEntry;
}
}
} catch(e) {
print(“Error : ” + e);
} finally {
if(null != loView) loView.recycle();
if(null != loEntryColl) loEntryColl.recycle();
}

return loTreeMap.values();
[/javascript]

In line 3 I am defining a TreeMap data structure. By definition TreeMap is sorted according to its natural ordering of its keys.

Since the data structure is always sorted so we can insert NotesViewEntry column values to the TreeMap and the corresponding column value (by which the view needs to be sorted) should be passed as key.

Look at line no 17 I am forming the key by which the view needs to be sorted. By default it is first column value.

At this point of time the only thing which creates problem is the duplicate values of the key. In TreeMap the value is overwritten if the key is already existing.

From line 18-21 I am appending additional character to make the key unique.

In line 37 I am returning value set from the TreeMap which is already sorted by key.

Rest of the code is quite easy to understand. I hope it may help in your application.

Optimization of the above code is discussed in next blog.

Debug Java From Lotus Notes Designer

We do not prefer to write agents in Java just because we are not able to debug the Java agent in Lotus Notes Designer. As we think Designer do not have any debugger for Java, but let me clarify that Lotus Notes Designer 8.5.x (also known as Domino Designer in Eclipse) has in-built Java debugger.

It is very clear that to write a Java agent we must extend AgentBase class and implement notesmain() function. So if our Java agent requires Domino Infrastructure to execute then how can we debug it? We have to make it a Java application to debug it. So we must define main function in our Java agent.

I am assuming the name of the agent class is MyAgent.

 
[java]
protected Session _goSession;
protected AgentContext _goCtx;

public MyAgent(){}

public MyAgent(Session s, AgentContext c) {
_goSession = s;
_goCtx = c;
}

public static void main(String[] args) {
Session s = null;

NotesThread.sinitThread();

try {
s = NotesFactory.createSession();
// NotesMain(), the way Domino does
MyAgent a = new MyAgent(s, s.getAgentContext());

a.NotesMain();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (s != null) s.recycle();
} catch (Exception x) {}
NotesThread.stermThread();
}
} // end main

[/java]

After adding above code to your Java agent switch to Java Debugger Perspective and goto Debug Configuration and double click on Java Application in left side. Check stop in main option and click on debug button to start debugging.

I hope this helps you in debugging your Java agent. If any query feel free to write me back…:)

Disable X in Dojo Dialog

I found a trick to disable [x] on the top right corner of dojo dialog and force user to click on the close button to close the dialog box. Create a div element in your html web page and pass its id to following function to achieve this:

How to Bind Multiline Editbox Through Repeat Control

I have a multi-line edit-box on my xpage which is hidden. I want to allow the user to edit its value through repeat control. I don’t want to allow the user to enter multiple values separated by comma.
To achieve this functionality follow these instructions:

  • Add a multi-line edit-box and a repeat control on your xpage. I assume that there is some value already in the edit-box.
  • Set var = item and indexVar = indexItem
  • Go to the iterator code of the repeat control and return the values of the multi-line edit-box as an array.
  • Add an edit-box inside repeat control.
  • To bind it with the multi-line edit-box, select advanced in data tab then select expression language.
  • Write item[index] in the scriptbox.
  • Preview your xpage.

Sample code

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:script src="/General_SSJS.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:table style="font-family:arial;font-size:8pt;width:100%" id="xc_MainTable">
<xp:tr>
<xp:td style="width:143.0px" colspan="2">
<xp:inputTextarea id="xc_ccSections" multipleSeparator=",">
<xp:this.defaultValue><![CDATA[#{javascript:["1-10","10-20","20-30"]}]]></xp:this.defaultValue>
</xp:inputTextarea>
</xp:td>
</xp:tr>
</xp:table>
<xp:repeat id="xc_Repeat" rows="30" var="sectionRange" indexVar="rowIndex">
<xp:this.value><![CDATA[#{javascript:var lsRange:Array = fpfSLGetArrayFromMV("xc_ccSections");

var ls2DArray:Array = new Array(lsRange.length);

var liCnt = 0;
var lsRow:Array = null;
for(liCnt = 0;liCnt < lsRange.length;liCnt++) {
lsRow = lsRange[liCnt].split("-");
ls2DArray[liCnt] = new Array(lsRow[0], lsRow[1]);
}
return ls2DArray;}]]></xp:this.value>
<xp:table style="width:100.0%" cellpadding="0" cellspacing="0">
<xp:tr>
<xp:td style="width:50.0%;text-align:center;border-left:1px solid #99B7D8; border-bottom:1px solid #99B7D8;border-right:1px solid #99B7D8;height:23px" align="center">
<xp:inputText id="xc_cc_Start" style="width:90%;font-family:Arial;font-size:8pt">
<xp:this.value><![CDATA[#{sectionRange[0]}]]></xp:this.value>
</xp:inputText>
</xp:td>
<xp:td style="width:50.0%;border-bottom:1px solid #99B7D8;border-right:1px solid #99B7D8" align="center">
<xp:inputText id="xc_cc_End" style="width:90%;font-family:Arial;font-size:8pt">
<xp:this.value><![CDATA[#{sectionRange[1]}]]></xp:this.value>
</xp:inputText>
</xp:td>
</xp:tr>
</xp:table>
</xp:repeat>
</xp:view>