Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ddaf3ce6bc5043cbedb4c187a9f50fabf0dce956 (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
/**
 * AbstractDecorationCellPaintListener.java
 * Created on Aug 21, 2011
 *
 * Copyright (c) 2011 Wind River Systems, Inc.
 *
 * The right to copy, distribute, modify, or otherwise make use
 * of this software may be licensed only pursuant to the terms
 * of an applicable Wind River license agreement.
 */
package org.eclipse.tcf.te.ui.swt.listener;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Widget;

/**
 * Abstract decoration cell paint listener implementation
 */
public abstract class AbstractDecorationCellPaintListener extends AbstractCellPaintListener {

	public static final int STATE_NONE = IMessageProvider.NONE;
	public static final int STATE_INFO = IMessageProvider.INFORMATION;
	public static final int STATE_WARNING = IMessageProvider.WARNING;
	public static final int STATE_ERROR = IMessageProvider.ERROR;

	/**
	 * Constructor.
	 * @param colums The valid columns.
	 * @param widget The widget.
	 */
	public AbstractDecorationCellPaintListener(Widget widget, int... columns) {
		super(widget, columns);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.swt.listener.AbstractCellPaintListener#getPaintOrigin(org.eclipse.swt.widgets.Event, org.eclipse.swt.graphics.Image)
	 */
	@Override
	protected Point getPaintOrigin(Event event, Image image) {
		return new Point(event.x, event.y);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.swt.listener.AbstractCellPaintListener#getImageToDraw(org.eclipse.swt.widgets.Item, int)
	 */
	@Override
	protected Image getImageToDraw(Item item, int columnIndex) {
		Assert.isNotNull(item);

		// If the image shall be painted to the current column
		if (isPaintImageInColumn(columnIndex)) {
			// Check which image to paint
			int state = getDecorationState(item.getData(), columnIndex);
			if (state >= 0) {
				String decorationId = null;
				switch (state) {
					case STATE_INFO:
						decorationId = FieldDecorationRegistry.DEC_INFORMATION;
						break;
					case STATE_WARNING:
						decorationId = FieldDecorationRegistry.DEC_WARNING;
						break;
					case STATE_ERROR:
						decorationId = FieldDecorationRegistry.DEC_ERROR;
						break;
				}
				if (decorationId != null) {
					// Get the field decoration
					FieldDecoration fieldDeco = FieldDecorationRegistry.getDefault().getFieldDecoration(decorationId);
					if (fieldDeco != null) {
						return fieldDeco.getImage();
					}
				}
			}
		}

		return null;
	}

	/**
	 * Returns the state for the decoration.
	 *
	 * @param data The associated event data or <code>null</code>:
	 * @param columnIndex The column index of the current column.
	 *
	 * @return The state for the decoration.
	 */
	protected abstract int getDecorationState(Object data, int columnIndex);

}

Back to the top