1 18 package org.visualcontent.ui.nodepropertylist; 19 20 21 22 import javax.jcr.Node; 23 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.StructuredSelection; 26 import org.eclipse.jface.viewers.TableViewer; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.TableColumn; 30 import org.eclipse.ui.ISelectionListener; 31 import org.eclipse.ui.IWorkbenchPart; 32 import org.eclipse.ui.part.ViewPart; 33 import org.visualcontent.ui.UiPlugin; 34 35 36 39 40 public class NodePropertyList extends ViewPart implements ISelectionListener{ 41 private TableViewer viewer; 42 43 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 46 try { 47 Node node = (Node) ((StructuredSelection) selection).getFirstElement(); 48 viewer.setInput(node); 49 } catch (RuntimeException e) { 50 UiPlugin.getDefault().log("The session has probably been closed extenally.",e); 51 } 52 } 53 54 57 public NodePropertyList() { 58 } 59 60 64 public void createPartControl(Composite parent) { 65 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 66 viewer.setContentProvider(new ViewContentProvider(this)); 67 viewer.setLabelProvider(new ViewLabelProvider(this)); 68 getSite().getPage().addSelectionListener( 69 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 70 configTable(viewer); 71 } 72 73 private void configTable(TableViewer viewer) { 74 String [] columnNames = new String [] { 75 "Property Name", 76 "Property Value" 77 }; 78 TableColumn propertyNameColumn = new TableColumn(viewer.getTable(), 79 SWT.LEFT,0); 80 propertyNameColumn.setText(columnNames[0]); 81 propertyNameColumn.setWidth(200); 82 viewer.getTable().setHeaderVisible(true); 83 TableColumn propertyValueColumn = new TableColumn(viewer.getTable(), 84 SWT.LEFT,1); 85 propertyValueColumn.setText(columnNames[1]); 86 propertyValueColumn.setWidth(200); 87 88 viewer.setColumnProperties(columnNames); 89 90 } 91 94 public void setFocus() { 95 viewer.getControl().setFocus(); 96 } 97 98 public void dispose() { 99 super.dispose(); 100 getSite().getPage().removeSelectionListener( 101 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 102 } 103 } | Popular Tags |