Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5b1018cd38da5bf854bbfa0d045d5940ed384956 (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
/*******************************************************************************
 * Copyright (c) 2009, 2014 Angelo Zerr 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:
 *     Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.e4.ui.css.swt.dom;

import org.eclipse.e4.ui.css.core.dom.CSSStylableElement;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTFontHelper;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;


/**
 * {@link CSSStylableElement} implementation which wrap SWT {@link TableItem}.
 *
 */
public class TableItemElement extends ItemElement {

	public TableItemElement(TableItem tableItem, CSSEngine engine) {
		super(tableItem, engine);
	}

	@Override
	public boolean isPseudoInstanceOf(String s) {
		if ("odd".equals(s)) {
			TableItem tableItem = getTableItem();
			int index = tableItem.getParent().indexOf(tableItem);
			return ((index & 1) == 1);

		}
		if ("even".equals(s)) {
			TableItem tableItem = getTableItem();
			int index = tableItem.getParent().indexOf(tableItem);
			return ((index & 1) == 0);
		}
		return super.isPseudoInstanceOf(s);
	}

	protected TableItem getTableItem() {
		return (TableItem) getNativeWidget();
	}

	@Override
	public void reset() {
		super.reset();
		TableItem tableItem = getTableItem();
		tableItem.setForeground(null);
		tableItem.setBackground(null);
		CSSSWTImageHelper.restoreDefaultImage(tableItem);
		tableItem.setFont(null); // in such case the parent's font will be taken

		Table parent = tableItem.getParent();
		parent.setForeground(null);
		parent.setBackground(null);
		CSSSWTFontHelper.restoreDefaultFont(parent);
	}
}

Back to the top