KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodepropertylist > NodePropertyList


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.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 /**
37  *
38  */

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

57     public NodePropertyList() {
58     }
59
60     /**
61      * This is a callback that will allow us
62      * to create the viewer and initialize it.
63      */

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

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