1 18 package org.visualcontent.ui.repositorypropertylist; 19 20 21 22 import javax.jcr.Node; 23 import javax.jcr.Repository; 24 import javax.jcr.RepositoryException; 25 26 import org.eclipse.jface.viewers.ISelection; 27 import org.eclipse.jface.viewers.StructuredSelection; 28 import org.eclipse.jface.viewers.TableViewer; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.TableColumn; 32 import org.eclipse.ui.ISelectionListener; 33 import org.eclipse.ui.IWorkbenchPart; 34 import org.eclipse.ui.part.ViewPart; 35 import org.visualcontent.ui.UiPlugin; 36 37 38 41 42 public class RepositoryPropertyList extends ViewPart implements ISelectionListener{ 43 private TableViewer viewer; 44 45 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 48 try { 49 Node node = (Node) ((StructuredSelection) selection).getFirstElement(); 50 viewer.setInput(node); 51 } catch (RuntimeException e) { 52 UiPlugin.getDefault().log("The session has probably been closed extenally.",e); 53 } 54 } 55 56 59 public RepositoryPropertyList() { 60 } 61 62 66 public void createPartControl(Composite parent) { 67 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 68 viewer.setContentProvider(new ViewContentProvider(this)); 69 viewer.setLabelProvider(new ViewLabelProvider(this)); 70 getSite().getPage().addSelectionListener( 71 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 72 configTable(viewer); 73 } 74 75 Repository getRepository(){ 76 Object inputObj = this.viewer.getInput(); 77 Node contentNode = (Node) inputObj; 78 Repository repository = null; 79 try { 80 repository = contentNode.getSession().getRepository(); 81 } catch (RepositoryException e) { 82 UiPlugin.getDefault().showError("Could not get the repository.",e); 83 } 84 return repository; 85 } 86 87 private void configTable(TableViewer viewer) { 88 String [] columnNames = new String [] { 89 "Property Name", 90 "Property Value" 91 }; 92 TableColumn propertyNameColumn = new TableColumn(viewer.getTable(), 93 SWT.LEFT,0); 94 propertyNameColumn.setText(columnNames[0]); 95 propertyNameColumn.setWidth(200); 96 viewer.getTable().setHeaderVisible(true); 97 TableColumn propertyValueColumn = new TableColumn(viewer.getTable(), 98 SWT.LEFT,1); 99 propertyValueColumn.setText(columnNames[1]); 100 propertyValueColumn.setWidth(200); 101 102 viewer.setColumnProperties(columnNames); 103 104 } 105 106 109 public void setFocus() { 110 viewer.getControl().setFocus(); 111 } 112 public void dispose() { 113 super.dispose(); 114 getSite().getPage().removeSelectionListener( 115 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 116 } 117 } | Popular Tags |