KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > repositorypropertylist > RepositoryPropertyList


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

41
42 public class RepositoryPropertyList 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 RepositoryPropertyList() {
60     }
61
62     /**
63      * This is a callback that will allow us
64      * to create the viewer and initialize it.
65      */

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

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