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: AbstractTableView.java
13   * Created: 2005-11-30
14   * Author: apohllo
15   * $Id: AbstractTableView.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.TableViewer;
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 TableViewer} as visual
26   * model.
27   *
28   * @author AGH CAST Team
29   */
30  public abstract class AbstractTableView extends AbstractConfigurableView {
31  
32  	/**
33  	 * Tree viewer which is used by this view.
34  	 */
35  	protected TableViewer viewer;
36  
37  	/**
38  	 * This method initializes the part control, i.e. the TableViewer.
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  
48  		// actions and menus oriented methods
49  		makeActions();
50  		hookContextMenu();
51  		hookDoubleClickAction();
52  		contributeToActionBars();
53  		activate();
54  	}
55  
56  	/**
57  	 * This method creates the tree control, it is intended to be changed in subclasses which need some more
58  	 * sophisticated control.
59  	 *
60  	 * @param parent
61  	 *            parent control
62  	 */
63  	protected void createControl(Composite parent) {
64  		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
65  	}
66  
67  	/**
68  	 * Sets the input for the viewer. This default implementation sends the object to the viewer without checking its
69  	 * type, etc. This should be done in the content provider associated with the viewer.
70  	 *
71  	 * @param object
72  	 *            input object
73  	 */
74  	public void setInput(Object object) {
75  		viewer.setInput(object);
76  	}
77  
78  	/**
79  	 * Returns the input of the view.
80  	 *
81  	 * @return the input of the view
82  	 */
83  	public Object getInput() {
84  		return viewer.getInput();
85  	}
86  
87  	/**
88  	 * This method sets the focus on the tree viewer.
89  	 *
90  	 * {@inheritDoc}
91  	 *
92  	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
93  	 */
94  	@Override
95  	public void setFocus() {
96  		viewer.getControl().setFocus();
97  	}
98  
99  	/**
100 	 * {@inheritDoc}
101 	 *
102 	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
103 	 */
104 	@Override
105 	public void dispose() {
106 		if (viewer != null) {
107 			viewer.getControl().dispose();
108 		}
109 		super.dispose();
110 	}
111 
112 	protected TableViewer getViewer() {
113 		return viewer;
114 	}
115 
116 }