Skip to main content
summaryrefslogtreecommitdiffstats
blob: a4b6e46a6efb5e702a513d64c28dbdee1e2a63cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2008 SAP AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Stefan Dimov, stefan.dimov@sap.com - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.internal.ui;

import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jst.j2ee.internal.SecondCheckBoxStateChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

public class DoubleCheckboxTableItem extends TableItem {
	
	protected int mSecondCheckboxColumnIndex;
	protected Button secondCheckBox;
	protected SelectionListener selLstnr;
	protected ICheckStateListener tblLstnr = null;
	protected DoubleCheckboxTableViewer tableViewer;
	
	public DoubleCheckboxTableItem (Table parent, int style, int secondCheckboxColumnIndex, DoubleCheckboxTableViewer tableViewer) {
		super(parent, style);
		mSecondCheckboxColumnIndex = secondCheckboxColumnIndex;
		this.tableViewer = tableViewer;
		createCheckBox(parent);
	}
	
	public DoubleCheckboxTableItem(Table parent, int style, int index, int secondCheckboxColumnIndex, DoubleCheckboxTableViewer tableViewer) {
		super(parent, style, index);
		mSecondCheckboxColumnIndex = secondCheckboxColumnIndex;
		this.tableViewer = tableViewer;		
		createCheckBox(parent);		
	}
	
	public void setSecondChecked (boolean checked) {
		secondCheckBox.setSelection(checked);
	}
	
	public boolean getSecondChecked() {
		return secondCheckBox.getSelection();
	}
	
	public void setSecondGrayed(boolean grayed) {
		secondCheckBox.setGrayed(grayed);
	}
	
	public boolean getSecondGrayed() {
		return secondCheckBox.getGrayed();
	}
	
	public void setSecondEnabled(boolean enabled) {
		secondCheckBox.setEnabled(enabled);
	}
	
	public boolean getSecondEnabled() {
		return secondCheckBox.getEnabled();
	}
	
	public boolean isSecondEnabled() {
		return secondCheckBox.isEnabled();
	}
	
	private void createCheckBox(Table parentTable) {
		secondCheckBox = new Button(parentTable, SWT.CHECK | SWT.FLAT);
		secondCheckBox.pack();
		final DoubleCheckboxTableItem th = this; 
		selLstnr = new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				SecondCheckBoxStateChangedEvent evt = new SecondCheckBoxStateChangedEvent(tableViewer, 
																			getData(),
																			getChecked());
				evt.setTableItem(th);
				tblLstnr.checkStateChanged(evt);
			}
			public void widgetDefaultSelected(SelectionEvent e) {}
		};
		secondCheckBox.addSelectionListener(selLstnr);
	}
	
	public Button getSecondCheckBox() {
		return secondCheckBox; 
	}
	
	@Override
	public void dispose() {
		disposeSecondCheckbox();
		super.dispose();
	}
	
	protected void disposeSecondCheckbox() {
		if (secondCheckBox != null) {
			secondCheckBox.removeSelectionListener(selLstnr);
			secondCheckBox.dispose();
			secondCheckBox = null;
		}
		selLstnr = null;
	}
	
	void setTableListener(ICheckStateListener tblLstnr) {
		this.tblLstnr = tblLstnr;
	}
	
	@Override
	protected void checkSubclass () {}

}

Back to the top