1 18 package org.visualcontent.ui.namespacelist; 19 20 21 22 import javax.jcr.NamespaceRegistry; 23 import javax.jcr.Node; 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 NamespaceList 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 NamespaceList() { 60 } 61 62 NamespaceRegistry getNamespaceRegistry(){ 63 Node contentNode = (Node) viewer.getInput(); 64 NamespaceRegistry namespaceReg = null; 65 try { 66 namespaceReg = contentNode.getSession().getWorkspace().getNamespaceRegistry(); 67 } catch (RepositoryException e) { 68 UiPlugin.getDefault().showError("Could not retrieve the Namespace Registry.",e); 69 } 70 return namespaceReg; 71 } 72 73 77 public void createPartControl(Composite parent) { 78 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 79 viewer.setContentProvider(new ViewContentProvider(this)); 80 viewer.setLabelProvider(new ViewLabelProvider(this)); 81 getSite().getPage().addSelectionListener( 82 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 83 configTable(viewer); 84 } 85 86 private void configTable(TableViewer viewer) { 87 String [] columnNames = new String [] { 88 "Prefix", 89 "URI" 90 }; 91 TableColumn propertyNameColumn = new TableColumn(viewer.getTable(), 92 SWT.LEFT,0); 93 propertyNameColumn.setText(columnNames[0]); 94 propertyNameColumn.setWidth(200); 95 viewer.getTable().setHeaderVisible(true); 96 TableColumn propertyValueColumn = new TableColumn(viewer.getTable(), 97 SWT.LEFT,1); 98 propertyValueColumn.setText(columnNames[1]); 99 propertyValueColumn.setWidth(200); 100 101 viewer.setColumnProperties(columnNames); 102 103 } 104 107 public void setFocus() { 108 viewer.getControl().setFocus(); 109 } 110 111 public void dispose() { 112 super.dispose(); 113 getSite().getPage().removeSelectionListener( 114 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this); 115 } 116 } | Popular Tags |