Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 1ec2d15b9f1db5a96fdec7e9ce93abe300725289 (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
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation 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:
 *     IBM Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.server.ui.internal.viewers;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Widget;
/**
 *
 */
public class LockedTableViewer extends TableViewer {
	protected Color color;

	public LockedTableViewer(Composite parent) {
		super(parent);
		createColor(parent);
	}
	
	public LockedTableViewer(Composite parent, int style) {
		super(parent, style);
		createColor(parent);
	}

	public LockedTableViewer(Table table) {
		super(table);
		createColor(table);
	}

	protected void createColor(Control c) {
		color = new Color(c.getDisplay(), 255, 255, 225);
		c.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				color.dispose();
			}
		});
	}

	public void doUpdateItem(Widget widget, Object element, boolean fullMap) {
		if (color == null)
			return;
		if (widget instanceof TableItem) {
			TableItem item = (TableItem) widget;
			if (getLabelProvider() instanceof ILockedLabelProvider) {
				ILockedLabelProvider provider = (ILockedLabelProvider) getLabelProvider();
				if (provider.isLocked(element)) {
					item.setBackground(color);
					item.setImage(0, null);
				} else
					item.setBackground(null);
			}
		}
		super.doUpdateItem(widget, element, fullMap);
	}
}

Back to the top