KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > PullPushCheckboxTableViewer


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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.refactoring;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.swt.widgets.Table;
16 import org.eclipse.swt.widgets.TableItem;
17 import org.eclipse.swt.widgets.Widget;
18
19 import org.eclipse.jface.viewers.CheckboxTableViewer;
20
21 import org.eclipse.jdt.internal.corext.refactoring.structure.IMemberActionInfo;
22
23 class PullPushCheckboxTableViewer extends CheckboxTableViewer{
24     public PullPushCheckboxTableViewer(Table table) {
25         super(table);
26     }
27
28     /*
29      * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean)
30      */

31     protected void doUpdateItem(Widget widget, Object JavaDoc element, boolean fullMap) {
32         super.doUpdateItem(widget, element, fullMap);
33         if (! (widget instanceof TableItem))
34             return;
35         TableItem item= (TableItem)widget;
36         IMemberActionInfo info= (IMemberActionInfo)element;
37         item.setChecked(PullPushCheckboxTableViewer.getCheckState(info));
38         Assert.isTrue(item.getChecked() == PullPushCheckboxTableViewer.getCheckState(info));
39     }
40
41     /*
42      * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object)
43      */

44     protected void inputChanged(Object JavaDoc input, Object JavaDoc oldInput) {
45         super.inputChanged(input, oldInput);
46         // XXX workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=9390
47
setCheckState((IMemberActionInfo[])input);
48     }
49
50     private void setCheckState(IMemberActionInfo[] infos) {
51         if (infos == null)
52             return;
53         for (int i= 0; i < infos.length; i++) {
54             IMemberActionInfo info= infos[i];
55             setChecked(info, PullPushCheckboxTableViewer.getCheckState(info));
56         }
57     }
58
59     private static boolean getCheckState(IMemberActionInfo info) {
60         return info.isActive();
61     }
62     
63     /*
64      * @see org.eclipse.jface.viewers.Viewer#refresh()
65      */

66     public void refresh() {
67         int topIndex = getTable().getTopIndex();
68         super.refresh();
69         // XXX workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=9390
70
setCheckState((IMemberActionInfo[])getInput());
71         if (topIndex < getTable().getItemCount())
72             getTable().setTopIndex(topIndex); //see bug 31645
73
}
74 }
75
Popular Tags