1 18 package org.visualcontent.ui.nodetree; 19 20 21 import javax.jcr.Session; 22 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.action.IMenuCreator; 25 import org.eclipse.jface.action.IMenuListener; 26 import org.eclipse.jface.action.IMenuManager; 27 import org.eclipse.jface.action.IToolBarManager; 28 import org.eclipse.jface.action.MenuManager; 29 import org.eclipse.jface.action.Separator; 30 import org.eclipse.jface.resource.ImageDescriptor; 31 import org.eclipse.jface.util.IPropertyChangeListener; 32 import org.eclipse.jface.viewers.TreeViewer; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.dnd.Clipboard; 35 import org.eclipse.swt.events.HelpListener; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Event; 38 import org.eclipse.swt.widgets.Menu; 39 import org.eclipse.swt.widgets.Text; 40 import org.eclipse.ui.IActionBars; 41 import org.eclipse.ui.IWorkbenchActionConstants; 42 import org.eclipse.ui.actions.ActionFactory; 43 import org.eclipse.ui.part.DrillDownAdapter; 44 import org.eclipse.ui.part.ViewPart; 45 import org.visualcontent.extensionpoints.RepositoryThrowable; 46 import org.visualcontent.extensionpoints.VCRepository; 47 import org.visualcontent.extensionpoints.VCSession; 48 import org.visualcontent.ui.UiPlugin; 49 50 51 54 55 public class NodeTreeViewPart extends ViewPart { 56 private TreeViewer viewer; 57 private DrillDownAdapter drillDownAdapter; 58 private VCSession vcSession = null; 59 private VCRepository vcRepository = null; 60 private Clipboard clipboard; 61 private CopyXPathAction copyXPathAction; 62 private Session jcrSession=null; 63 67 public void createPartControl(Composite parent) { 68 viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 69 drillDownAdapter = new DrillDownAdapter(viewer); 70 viewer.setContentProvider(new NodeTreeContentProvider()); 71 viewer.setLabelProvider(new NodeTreeLabelProvider(this)); 72 getSite().setSelectionProvider(viewer); 73 hookContextMenu(); 74 contributeToActionBars(); 75 } 78 79 private void hookContextMenu() { 80 copyXPathAction = new CopyXPathAction(this, "Copy XPath"); 81 getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(),copyXPathAction); 82 83 MenuManager menuMgr = new MenuManager("#PopupMenu"); 84 menuMgr.setRemoveAllWhenShown(true); 85 menuMgr.addMenuListener(new IMenuListener() { 86 public void menuAboutToShow(IMenuManager manager) { 87 NodeTreeViewPart.this.fillContextMenu(manager); 88 } 89 }); 90 Menu menu = menuMgr.createContextMenu(viewer.getControl()); 91 viewer.getControl().setMenu(menu); 92 getSite().registerContextMenu(menuMgr, viewer); 93 } 94 95 void setInput(Object anObject){ 96 this.viewer.setInput(anObject); 97 } 98 private void contributeToActionBars() { 99 IActionBars bars = getViewSite().getActionBars(); 100 fillLocalToolBar(bars.getToolBarManager()); 101 } 102 103 private void fillContextMenu(IMenuManager manager) { 104 drillDownAdapter.addNavigationActions(manager); 105 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 107 manager.add(copyXPathAction); 108 } 109 110 private void fillLocalToolBar(IToolBarManager manager) { 111 drillDownAdapter.addNavigationActions(manager); 112 } 113 114 117 public void setFocus() { 118 viewer.getControl().setFocus(); 119 } 120 121 public void dispose() { 122 super.dispose(); 123 clipboard.dispose(); 124 try { 125 this.vcRepository.releaseRepository(); 126 } catch (RepositoryThrowable e) { 127 UiPlugin.getDefault().showError("Could not release the repository.",e); 128 } 129 } 130 131 public Clipboard getClipboard(){ 132 if (clipboard == null){ 133 clipboard= new Clipboard(this.getSite().getShell().getDisplay()); 134 } 135 return clipboard; 136 } 137 public VCSession getVcSession() { 138 return vcSession; 139 } 140 141 public void setVcSession(VCSession vcSession) { 142 this.vcSession = vcSession; 143 } 144 145 public VCRepository getVcRepository() { 146 return vcRepository; 147 } 148 149 public void setVcRepository(VCRepository vcRepository) { 150 this.vcRepository = vcRepository; 151 } 152 153 public Session getJcrSession() { 154 return jcrSession; 155 } 156 157 public void setJcrSession(Session jcrSession) { 158 this.jcrSession = jcrSession; 159 } 160 } | Popular Tags |