KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > EditorsView


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * CSC - Intial implementation
10  * IBM Corporation - ongoing maintenance
11  *******************************************************************************/

12 package org.eclipse.team.internal.ccvs.ui;
13
14 import org.eclipse.jface.viewers.*;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.*;
19 import org.eclipse.team.internal.ccvs.core.EditorsInfo;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.part.ViewPart;
22
23 /**
24  *
25  * The <code>EditorsView</code> shows the result of cvs editors command
26  *
27  * @author <a HREF="mailto:gregor.kohlwes@csc.com,kohlwes@gmx.net">Gregor Kohlwes</a>
28  * @see org.eclipse.team.internal.ccvs.ui.actions.ShowEditorsAction
29  */

30 public class EditorsView extends ViewPart {
31     public static final String JavaDoc VIEW_ID = "org.eclipse.team.ccvs.ui.EditorsView"; //$NON-NLS-1$
32

33     private Table table;
34     private TableViewer tableViewer;
35
36     class EditorsContentProvider implements IStructuredContentProvider {
37
38         /**
39          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
40          */

41         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
42             return (EditorsInfo[]) inputElement;
43         }
44
45         /**
46          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
47          */

48         public void dispose() {
49         }
50
51         /**
52          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
53          */

54         public void inputChanged(
55             Viewer viewer,
56             Object JavaDoc oldInput,
57             Object JavaDoc newInput) {
58         }
59
60     }
61
62     class EditorsLabelProvider implements ITableLabelProvider {
63         /**
64          * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
65          */

66         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
67             return null;
68         }
69
70         /**
71          * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
72          */

73         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
74             if (element == null)
75                 return ""; //$NON-NLS-1$
76
EditorsInfo info = (EditorsInfo) element;
77
78             String JavaDoc result = null;
79             switch (columnIndex) {
80                 case 0 :
81                     result = info.getFileName();
82                     break;
83                 case 1 :
84                     result = info.getUserName();
85                     break;
86                 case 2 :
87                     result = info.getDateString();
88                     break;
89                 case 3 :
90                     result = info.getComputerName();
91                     break;
92             }
93             // This method must not return null
94
if (result == null) result = ""; //$NON-NLS-1$
95
return result;
96
97         }
98
99         /**
100          * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
101          */

102         public void addListener(ILabelProviderListener listener) {
103         }
104
105         /**
106          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
107          */

108         public void dispose() {
109         }
110
111         /**
112          * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
113          */

114         public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
115             return false;
116         }
117
118         /**
119          * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
120          */

121         public void removeListener(ILabelProviderListener listener) {
122         }
123
124     }
125
126     /**
127      * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
128      */

129     public void createPartControl(Composite parent) {
130         table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
131         table.setHeaderVisible(true);
132         table.setLinesVisible(true);
133
134         GridData gridData = new GridData(GridData.FILL_BOTH);
135         gridData.widthHint=500;
136         gridData.heightHint=100;
137         table.setLayoutData(gridData);
138
139         TableLayout layout = new TableLayout();
140         table.setLayout(layout);
141
142         tableViewer = new TableViewer(table);
143         createColumns(table, layout);
144
145         tableViewer.setContentProvider(new EditorsContentProvider());
146         tableViewer.setLabelProvider(new EditorsLabelProvider());
147         // set F1 help
148
PlatformUI.getWorkbench().getHelpSystem().setHelp(tableViewer.getControl(), IHelpContextIds.CVS_EDITORS_VIEW);
149     }
150     public void setInput(EditorsInfo[] infos) {
151         tableViewer.setInput(infos);
152     }
153     /**
154      * Method createColumns.
155      * @param table
156      * @param layout
157      * @param viewer
158      */

159     private void createColumns(Table table, TableLayout layout) {
160
161         TableColumn col;
162         // file name
163
col = new TableColumn(table, SWT.NONE);
164         col.setResizable(true);
165         col.setText(CVSUIMessages.EditorsView_file);
166         layout.addColumnData(new ColumnWeightData(30, true));
167
168         // user name
169
col = new TableColumn(table, SWT.NONE);
170         col.setResizable(true);
171         col.setText(CVSUIMessages.EditorsView_user);
172         layout.addColumnData(new ColumnWeightData(20, true));
173
174         // creation date
175
col = new TableColumn(table, SWT.NONE);
176         col.setResizable(true);
177         col.setText(CVSUIMessages.EditorsView_date);
178         layout.addColumnData(new ColumnWeightData(30, true));
179
180         // computer name
181
col = new TableColumn(table, SWT.NONE);
182         col.setResizable(true);
183         col.setText(CVSUIMessages.EditorsView_computer);
184         layout.addColumnData(new ColumnWeightData(20, true));
185
186     }
187
188     /**
189      * @see org.eclipse.ui.IWorkbenchPart#setFocus()
190      */

191     public void setFocus() {
192         if (table != null)
193             table.setFocus();
194     }
195     
196     /**
197      * Method getTable.
198      */

199     public Table getTable() {
200         return table;
201     }
202
203 }
204
Popular Tags