View Javadoc
1   package org.argeo.connect.e4.handlers;
2   
3   import javax.inject.Inject;
4   import javax.inject.Named;
5   import javax.jcr.Node;
6   import javax.jcr.Repository;
7   import javax.jcr.RepositoryException;
8   import javax.jcr.Session;
9   
10  import org.argeo.connect.ConnectException;
11  import org.argeo.connect.ui.ConnectEditor;
12  import org.argeo.connect.ui.SystemWorkbenchService;
13  import org.argeo.jcr.JcrUtils;
14  import org.eclipse.e4.core.di.annotations.Execute;
15  
16  /**
17   * Creates a new entity under draft path of the current repository and opens the
18   * corresponding editor. The Node type of the relevant entity must be passed as
19   * parameter.
20   */
21  public class OpenEntity {
22  	public final static String PARAM_TARGET_NODE_TYPE = "targetNodeType";
23  
24  	@Inject
25  	private Repository repository;
26  	@Inject
27  	private SystemWorkbenchService systemWorkbenchService;
28  
29  	@Execute
30  	public void execute(@Named(ConnectEditor.PARAM_JCR_ID) String jcrId,
31  			@Named(ConnectEditor.PARAM_OPEN_FOR_EDIT) String openForEdit) {
32  		Session mainSession = null;
33  
34  		try {
35  			mainSession = repository.login();
36  			Node entity = mainSession.getNodeByIdentifier(jcrId);
37  			systemWorkbenchService.openEntityEditor(entity);
38  		} catch (RepositoryException e) {
39  			throw new ConnectException("Cannot get entity #" + jcrId, e);
40  		} finally {
41  			JcrUtils.logoutQuietly(mainSession);
42  		}
43  
44  	}
45  
46  }