1 18 package org.visualcontent.ui.nodetree; 19 20 import javax.jcr.Node; 21 import javax.jcr.RepositoryException; 22 import javax.jcr.Session; 23 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IConfigurationElement; 26 import org.eclipse.core.runtime.IExtensionRegistry; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.jface.action.IAction; 29 import org.eclipse.jface.viewers.ISelection; 30 import org.eclipse.ui.IViewActionDelegate; 31 import org.eclipse.ui.IViewPart; 32 import org.visualcontent.extensionpoints.RepositoryThrowable; 33 import org.visualcontent.extensionpoints.SessionThrowable; 34 import org.visualcontent.extensionpoints.VCRepository; 35 import org.visualcontent.ui.UiPlugin; 36 import org.visualcontent.ui.preferences.PreferenceConstants; 37 38 public class SessionLoginAction implements IViewActionDelegate { 39 40 NodeTreeViewPart nodeTreeView=null; 41 42 public void run(IAction action) { 43 SessionLogoutAction.logout(nodeTreeView); 44 this.initRepositoryAndSession(); 45 if (nodeTreeView.getVcSession()!=null) { 46 Session session = null; 47 try { 48 session = nodeTreeView.getVcSession().login(nodeTreeView.getVcRepository()); 49 } catch (SessionThrowable e1) { 50 UiPlugin.getDefault().showError("Could not login to the repository.",e1); 51 } catch (RepositoryThrowable e) { 52 UiPlugin.getDefault().showError("Could not login to the repository.",e); 53 } 54 if (session!=null){ 55 try { 56 Node rootNode = session.getRootNode(); 57 if (rootNode !=null){ 58 nodeTreeView.setInput(rootNode); 59 nodeTreeView.setJcrSession(session); 60 } 61 } catch (RepositoryException e) { 62 UiPlugin.getDefault().showError("Could not get the root node.",e); 63 } 64 } 65 } 66 } 67 68 public void selectionChanged(IAction action, ISelection selection) { 69 } 70 71 72 private void initRepositoryAndSession(){ 73 String repositoryId= org.visualcontent.ui.UiPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_REPOSITORY_CHOICE); 74 IExtensionRegistry registry = Platform.getExtensionRegistry (); 75 IConfigurationElement[] repositoryConfigElements = registry.getConfigurationElementsFor("org.visualcontent.extensionpoints.VCRepository"); 76 VCRepository repository = null; 77 for (int i = 0; i < repositoryConfigElements.length && repository==null; i++) { 78 try { 79 boolean isChoosenRepository = repositoryId.equals(repositoryConfigElements[i].getAttribute("id")); 80 boolean thereIsOnlyOneRepositoryPlugin = repositoryConfigElements.length == 1; 81 if (isChoosenRepository || thereIsOnlyOneRepositoryPlugin){ 82 repository = (VCRepository) repositoryConfigElements[i].createExecutableExtension("class"); 83 } 84 } catch (CoreException e) { 85 UiPlugin.getDefault().showError("Could not create the VCSession instance.",e); 86 } catch (Throwable t){ 87 UiPlugin.getDefault().showError("Could not create the VCSession instance.",t); 88 } 89 } 90 nodeTreeView.setVcRepository(repository); 91 nodeTreeView.setVcSession(repository.getCurrentVCSession()); 92 } 93 94 public void init(IViewPart view) { 95 nodeTreeView = (NodeTreeViewPart) view; 96 } 97 98 } 99 | Popular Tags |