XTextFrame second =null;
Object oFrame1 = null;
Object oFrame2 = null;
try {
XText oText = xTextDoc.getText();
XTextCursor oCursor = oText.createTextCursor();
oFrame1 = SOF.createInstance
(xTextDoc, "com.sun.star.text.TextFrame" );
first = (XTextFrame)UnoRuntime.queryInterface
( XTextFrame.class, oFrame1);
oText.insertTextContent(oCursor,first, false);
first.getText().setString("Frame 1");
oFrame2 = SOF.createInstance(xTextDoc, "com.sun.star.text.TextFrame" );
second = (XTextFrame)UnoRuntime.queryInterface
( XTextFrame.class, oFrame2);
oText.insertTextContent(oCursor,second, false);
second.getText().setString("Frame 2");
oText.insertString( oCursor,
"SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
oText.insertControlCharacter( oCursor,
ControlCharacter.PARAGRAPH_BREAK, false);
oText.insertString( oCursor,
"bla...bla...", false);
} catch (Exception Ex ) {
Ex.printStackTrace(log);
throw new StatusException("Couldn't insert text table ", Ex);
}
XSearchable oSearch = (XSearchable)UnoRuntime.queryInterface
(XSearchable.class, xTextDoc);
XSearchDescriptor xSDesc = oSearch.createSearchDescriptor();
xSDesc.setSearchString("SwXTextRanges");
XIndexAccess textRanges1 = oSearch.findAll(xSDesc);
xSDesc.setSearchString("bla");
XIndexAccess textRanges2 = oSearch.findAll(xSDesc);
tEnv.addObjRelation("Selections", new Object[] {
oFrame1, oFrame2, textRanges1, textRanges2});
tEnv.addObjRelation("Comparer", new Comparator() {
public int compare(Object o1, Object o2) {
XServiceInfo serv1 = (XServiceInfo)
UnoRuntime.queryInterface(XServiceInfo.class, o1);
XServiceInfo serv2 = (XServiceInfo)
UnoRuntime.queryInterface(XServiceInfo.class, o2);
String implName1 = serv1.getImplementationName();
String implName2 = serv2.getImplementationName();
if (!implName1.equals(implName2)) {
return -1;
}
XIndexAccess indAc1 = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, o1);
XIndexAccess indAc2 = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, o2);
if (indAc1 != null && indAc2 != null) {
int c1 = indAc1.getCount();
int c2 = indAc2.getCount();
return c1 == c2 ? 0 : 1;
}
XText text1 = (XText)
UnoRuntime.queryInterface(XText.class, o1);
XText text2 = (XText)
UnoRuntime.queryInterface(XText.class, o2);
if (text1 != null && text2 != null) {
return text1.getString().equals(text2.getString()) ? 0 : 1;
}
return -1;
}
public boolean equals(Object obj) {