View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.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    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: AbstractTreeView.java
13   * Created: 2005-11-30
14   * Author: apohllo
15   * $Id: AbstractTreeView.java 2312 2009-01-12 22:53:55Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.ui;
19  
20  import org.eclipse.jface.viewers.TreeViewer;
21  import org.eclipse.swt.SWT;
22  import org.eclipse.swt.widgets.Composite;
23  
24  /**
25   * This class is base class for all views which implement the IConfigurableView and have {@link TreeViewer} as visual
26   * model.
27   *
28   * @author AGH CAST Team
29   */
30  public abstract class AbstractTreeView extends AbstractConfigurableView {
31  
32  	/**
33  	 * Tree viewer which is used by this view.
34  	 */
35  	private TreeViewer viewer;
36  
37  	/**
38  	 * This method initializes the part control, i.e. the {@link TreeViewer}.
39  	 *
40  	 * {@inheritDoc}
41  	 *
42  	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
43  	 */
44  	@Override
45  	public void createPartControl(Composite parent) {
46  		createControl(parent);
47  		// actions and menus oriented methods
48  		makeActions();
49  		hookContextMenu();
50  		hookDoubleClickAction();
51  		contributeToActionBars();
52  		activate();
53  	}
54  
55  	/**
56  	 * This method creats the tree control, it is intendet to be changed in subclasses which need some more
57  	 * sophisticated control.
58  	 *
59  	 * @param parent
60  	 *            parent control
61  	 */
62  	protected void createControl(Composite parent) {
63  		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
64  	}
65  
66  	/**
67  	 * Sets the input for the viewer. This default implementation sends the object to the viewer without checking its
68  	 * type, etc. This should be done in the content provider associated with the viewer.
69  	 *
70  	 * @param object
71  	 *            input object
72  	 */
73  	public void setInput(Object object) {
74  		viewer.setInput(object);
75  	}
76  
77  	/**
78  	 * This method sets the focus on the tree viewer.
79  	 *
80  	 * {@inheritDoc}
81  	 *
82  	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
83  	 */
84  	@Override
85  	public void setFocus() {
86  		viewer.getControl().setFocus();
87  	}
88  
89  	/**
90  	 * {@inheritDoc}
91  	 *
92  	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
93  	 */
94  	@Override
95  	public void dispose() {
96  		if (viewer != null) {
97  			viewer.getControl().dispose();
98  		}
99  		super.dispose();
100 	}
101 
102 	protected TreeViewer getViewer() {
103 		return viewer;
104 	}
105 
106 }