Source Code for “Opening Documents as sub tabs”

By popular request from this post. Here is the source code to that action for opening a Notes document as a sub-tab (Eclipse view part).

There are three keys to this technique.

1. You have to use a non-public API to do this. The com.ibm.csi.types.DocumentSummary, where we get the URL to the selected document.

2. There is a new Topology API – modifyComponent(), that you will use to fill in the component data for the newly opened view. The Notes view part uses the data key “com.ibm.notes.notesurl” to figure out what to show. By simply making that key equal to the selected document the view will show the document in the newly opened Eclipse view part.

3. Lastly, since we are dynamically opening a view, we need to make sure the secondary ID is unique for this URL. This also makes it so if the document is opened twice through this method the view is simply brought to top versus opening a new view part.



import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionDelegate;

import com.ibm.csi.types.DocumentSummary;
import com.ibm.rcp.topology.TopologyHandler;
import com.ibm.rcp.topology.TopologyHandlerServiceFactory;

public class OpenCSIViewAsTab extends ActionDelegate {

private static final String COM_IBM_NOTES_NOTESURL = "com.ibm.notes.notesurl";

IStructuredSelection ss = null;

public void runWithEvent(IAction action, Event event) {

Iterator iter = ss.toList().iterator();
while(iter.hasNext()){
DocumentSummary ds = null;
Object obj = iter.next();

if (obj instanceof DocumentSummary){
ds = (DocumentSummary)obj;
}else
continue;

showView(ds);
}
}

public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof IStructuredSelection){
ss = (IStructuredSelection)selection;
}
}

private void showView(DocumentSummary ds){
final String primaryID = "com.ibm.workplace.noteswc.views.NotesViewData";
String url = ds.getUrl();
final String secondaryID = "clone_" + url.replace('/', '_').replace(':', '-').replace('&', '-').replace('?', '-');

TopologyHandler th = TopologyHandlerServiceFactory.getService();

try{
Map map = new HashMap();
map.put(COM_IBM_NOTES_NOTESURL, ds.getUrl());

if (th != null)
th.modifyComponent(map, secondaryID);

Display d = Display.getDefault();

d.asyncExec(new Runnable(){

public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

if (page != null){
try {
page.showView(primaryID, secondaryID, IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException e) {
}
}
}

});
}catch(Exception e){
e.printStackTrace();
}finally{

}
}
}

7 thoughts on “Source Code for “Opening Documents as sub tabs”

  1. Hi Bob,

    this is a great article. However, it doesn’t seem to work with multiple selections on documents?

    In your code you use an Iterator to loop through the selections. Does this work for you?

    I’m running this both on Windows XP and Linux and everytime — no matter the number of selected documents — it only returns one document.

  2. Thanks for the link. I have tried this but it only seems to work for standard Notes views. Not for Java views like the Notes 8.5 mail inbox.

    Do you have some code that actually works with Java views?

    If it doesn’t work for Java views, do you know why not? And if this is something that Lotus will fix soon?

  3. I know this issue. I think it’s caused by the design of the Java views. There was a special method to get the actual selection provider from the CSI views (don’t have access to the code right now), IBM said it was a performance optimization so they don’t have to transfer the selection data between the processes on each selection change, just to inform Eclipse about the new data. A solution to make this work required either a plugin dependency on the CSI views’s plugin or Java reflection, because you have to call that method on the viewpart. I think it was something like getSelectionProvider, but I’m not sure.

  4. Additional info: 8.5.2 contains an extension in the Notes UI API that gives you easy access to the selection data for both types of view. Unfortunately, that does not help you for earlier releases.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.