View Javadoc
1   package org.argeo.connect.ui.util;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.apache.commons.logging.Log;
7   import org.apache.commons.logging.LogFactory;
8   import org.argeo.connect.ui.ConnectUiConstants;
9   import org.argeo.connect.ui.SystemWorkbenchService;
10  import org.eclipse.swt.events.SelectionAdapter;
11  import org.eclipse.swt.events.SelectionEvent;
12  
13  /**
14   * Listener to add to a tableViewer or a label that displays RWT link that
15   * conform to the syntax commandId/param1=value1/param2=value2/.../paramN=valueN
16   * 
17   * It will call the corresponding command with the given parameters.
18   */
19  public class HtmlListRwtAdapter extends SelectionAdapter {
20  	private static final long serialVersionUID = -3867410418907732579L;
21  	private final static Log log = LogFactory.getLog(HtmlListRwtAdapter.class);
22  
23  	private final SystemWorkbenchService systemWorkbenchService;
24  
25  	public HtmlListRwtAdapter(SystemWorkbenchService systemWorkbenchService) {
26  		this.systemWorkbenchService = systemWorkbenchService;
27  	}
28  
29  	public void widgetSelected(SelectionEvent event) {
30  		if (event.detail == ConnectUiConstants.MARKUP_VIEWER_HYPERLINK) {
31  			String string = event.text;
32  			String[] token = string.split("/");
33  			if (token.length > 0) {
34  				Map<String, String> params = new HashMap<String, String>();
35  				for (int i = 1; i < token.length; i++) {
36  					String[] currParam = token[i].split("=");
37  					params.put(currParam[0], currParam[1]);
38  				}
39  				try {
40  					// CommandUtils.callCommand(token[0], params);
41  					systemWorkbenchService.callCommand(token[0], params);
42  				} catch (Exception nde) {
43  					log.warn("Error while trying to call " + "a command using a RWT.HYPERLINK.\n Retrieved href:"
44  							+ string + "\n" + nde.getMessage());
45  					nde.printStackTrace();
46  				}
47  			}
48  		}
49  	}
50  }