KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > IndentedTableViewer


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

11 package org.eclipse.ui.internal.dialogs;
12
13 import org.eclipse.jface.viewers.ITableLabelProvider;
14 import org.eclipse.jface.viewers.TableViewer;
15 import org.eclipse.swt.widgets.*;
16
17 /**
18  * A concrete viewer based on a SWT <code>Table</code> control. The viewer supports indentation
19  * of the table elements.
20  * <p>
21  * Label providers for this viewer must implement <code>IIndentedTableLabelProvider</code>
22  * in order to get indentation.</p>
23  */

24 public class IndentedTableViewer extends TableViewer {
25     /**
26      * Extends <code>ITableLabelProvider</code> with the methods
27      * to provide the indentation.
28      *
29      * @see TableViewer
30      */

31     public interface IIndentedTableLabelProvider extends ITableLabelProvider {
32         /**
33          * Returns the indent level for the element. This number will be used
34          * as the parameter to the <code>TableItem.setImageIndent(int)<code> method.
35          *
36          * @param element the object representing the entire row, or
37          * <code>null</code> indicating that no input object is set
38          * in the viewer
39          */

40         public int getIndent(Object JavaDoc element);
41     }
42     public IndentedTableViewer(Composite parent) {
43         super(parent);
44     }
45     public IndentedTableViewer(Composite parent, int style) {
46         super(parent, style);
47     }
48     public IndentedTableViewer(Table table) {
49         super(table);
50     }
51     public void doUpdateItem(Widget widget, Object JavaDoc element, boolean fullMap) {
52         if (widget instanceof TableItem) {
53             TableItem item = (TableItem) widget;
54             if (getLabelProvider() instanceof IIndentedTableLabelProvider) {
55                 IIndentedTableLabelProvider provider = (IIndentedTableLabelProvider)getLabelProvider();
56                 item.setImageIndent(provider.getIndent(element));
57             }
58         }
59         super.doUpdateItem(widget, element, fullMap);
60     }
61 }
62
Popular Tags