KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > namespacelist > NamespaceList


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 /**
39  *
40  */

41
42 public class NamespaceList extends ViewPart implements ISelectionListener{
43     private TableViewer viewer;
44     
45     // Implement the method defined in ISelectionListener, to consume UI
46
// selections
47
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
48         try {
49             Node node = (Node) ((StructuredSelection) selection).getFirstElement();
50             viewer.setInput(node);
51         } catch (RuntimeException JavaDoc e) {
52             UiPlugin.getDefault().log("The session has probably been closed extenally.",e);
53         }
54     }
55      
56     /**
57      * The constructor.
58      */

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     /**
74      * This is a callback that will allow us
75      * to create the viewer and initialize it.
76      */

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 JavaDoc[] columnNames = new String JavaDoc[] {
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     /**
105      * Passing the focus request to the viewer's control.
106      */

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