KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodetree > NodeTreeViewPart


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.nodetree;
19
20
21 import javax.jcr.Session;
22
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.action.IMenuCreator;
25 import org.eclipse.jface.action.IMenuListener;
26 import org.eclipse.jface.action.IMenuManager;
27 import org.eclipse.jface.action.IToolBarManager;
28 import org.eclipse.jface.action.MenuManager;
29 import org.eclipse.jface.action.Separator;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.util.IPropertyChangeListener;
32 import org.eclipse.jface.viewers.TreeViewer;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.dnd.Clipboard;
35 import org.eclipse.swt.events.HelpListener;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Event;
38 import org.eclipse.swt.widgets.Menu;
39 import org.eclipse.swt.widgets.Text;
40 import org.eclipse.ui.IActionBars;
41 import org.eclipse.ui.IWorkbenchActionConstants;
42 import org.eclipse.ui.actions.ActionFactory;
43 import org.eclipse.ui.part.DrillDownAdapter;
44 import org.eclipse.ui.part.ViewPart;
45 import org.visualcontent.extensionpoints.RepositoryThrowable;
46 import org.visualcontent.extensionpoints.VCRepository;
47 import org.visualcontent.extensionpoints.VCSession;
48 import org.visualcontent.ui.UiPlugin;
49
50
51 /**
52  *
53  */

54
55 public class NodeTreeViewPart extends ViewPart {
56     private TreeViewer viewer;
57     private DrillDownAdapter drillDownAdapter;
58     private VCSession vcSession = null;
59     private VCRepository vcRepository = null;
60     private Clipboard clipboard;
61     private CopyXPathAction copyXPathAction;
62     private Session jcrSession=null;
63     /**
64      * This is a callback that will allow us
65      * to create the viewer and initialize it.
66      */

67     public void createPartControl(Composite parent) {
68         viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
69         drillDownAdapter = new DrillDownAdapter(viewer);
70         viewer.setContentProvider(new NodeTreeContentProvider());
71         viewer.setLabelProvider(new NodeTreeLabelProvider(this));
72         getSite().setSelectionProvider(viewer);
73         hookContextMenu();
74         contributeToActionBars();
75 // parent.add
76
// manager.add(new Text(this.getSite().getShell(),SWT.SINGLE));
77
}
78     
79     private void hookContextMenu() {
80         copyXPathAction = new CopyXPathAction(this, "Copy XPath");
81         getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(),copyXPathAction);
82
83         MenuManager menuMgr = new MenuManager("#PopupMenu");
84         menuMgr.setRemoveAllWhenShown(true);
85         menuMgr.addMenuListener(new IMenuListener() {
86             public void menuAboutToShow(IMenuManager manager) {
87                 NodeTreeViewPart.this.fillContextMenu(manager);
88             }
89         });
90         Menu menu = menuMgr.createContextMenu(viewer.getControl());
91         viewer.getControl().setMenu(menu);
92         getSite().registerContextMenu(menuMgr, viewer);
93     }
94
95     void setInput(Object JavaDoc anObject){
96         this.viewer.setInput(anObject);
97     }
98     private void contributeToActionBars() {
99         IActionBars bars = getViewSite().getActionBars();
100         fillLocalToolBar(bars.getToolBarManager());
101     }
102
103     private void fillContextMenu(IMenuManager manager) {
104         drillDownAdapter.addNavigationActions(manager);
105         // Other plug-ins can contribute there actions here
106
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
107         manager.add(copyXPathAction);
108     }
109     
110     private void fillLocalToolBar(IToolBarManager manager) {
111         drillDownAdapter.addNavigationActions(manager);
112     }
113
114     /**
115      * Passing the focus request to the viewer's control.
116      */

117     public void setFocus() {
118         viewer.getControl().setFocus();
119     }
120
121     public void dispose() {
122         super.dispose();
123         clipboard.dispose();
124         try {
125             this.vcRepository.releaseRepository();
126         } catch (RepositoryThrowable e) {
127             UiPlugin.getDefault().showError("Could not release the repository.",e);
128         }
129     }
130
131     public Clipboard getClipboard(){
132         if (clipboard == null){
133             clipboard= new Clipboard(this.getSite().getShell().getDisplay());
134         }
135         return clipboard;
136     }
137     public VCSession getVcSession() {
138         return vcSession;
139     }
140
141     public void setVcSession(VCSession vcSession) {
142         this.vcSession = vcSession;
143     }
144
145     public VCRepository getVcRepository() {
146         return vcRepository;
147     }
148
149     public void setVcRepository(VCRepository vcRepository) {
150         this.vcRepository = vcRepository;
151     }
152
153     public Session getJcrSession() {
154         return jcrSession;
155     }
156
157     public void setJcrSession(Session jcrSession) {
158         this.jcrSession = jcrSession;
159     }
160 }
Popular Tags