Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7c8a9a48885fe7cf6088c32e16886cad4b470d7b (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 *
 * 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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.nattable.celleditor;

import org.eclipse.jface.window.Window;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.edit.DialogEditHandler;
import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;

/**
 * This class allows to store required information to customize
 * a Button to open a dialog
 */
public abstract class AbstractOpenDialogCellEditorButtonAction {

	/** The text to use for the button. */
	private String text;

	/** The tooltip to use for the button. */
	private String tooltipText;

	/** the image to set on the button. */
	private Image image;

	/**
	 * the new cell value selected by the user opening a dialog
	 */
	protected Object newValue;

	/**
	 * the column index of the edited cell
	 */
	protected int columnIndex;

	/**
	 * the row index of the edited cell
	 */
	protected int rowIndex;

	/**
	 * Gets the image.
	 *
	 * @return the image
	 */
	public Image getImage() {
		return image;
	}


	/**
	 * Sets the image.
	 *
	 * @param image
	 *            the new image
	 */
	public void setImage(Image image) {
		this.image = image;
	}


	/**
	 * Gets the text.
	 *
	 * @return the text
	 */
	public String getText() {
		return text;
	}


	/**
	 * Sets the text.
	 *
	 * @param text
	 *            the new text
	 */
	public void setText(String text) {
		this.text = text;
	}


	/**
	 * Gets the tooltip text.
	 *
	 * @return the tooltip text
	 */
	public String getTooltipText() {
		return tooltipText;
	}


	/**
	 * Sets the tooltip text.
	 *
	 * @param tooltipText
	 *            the new tooltip text
	 */
	public void setTooltipText(String tooltipText) {
		this.tooltipText = tooltipText;
	}


	/**
	 * 
	 * @return
	 *         the created dialog
	 */
	public abstract AbstractDialogCellEditor createDialogCellEditor();


	/**
	 * Setter for the edited cell location
	 *
	 * @param columnIndex
	 *            the column index of the edited cell
	 * @param rowIndex
	 *            the row index of the edited cell
	 */
	public final void setCellLocation(int columnIndex, int rowIndex) {
		this.columnIndex = columnIndex;
		this.rowIndex = rowIndex;
	}

	/**
	 * 
	 * @return
	 *         the value selected by the user
	 */
	public Object getEditorValue() {
		return this.newValue;
	}

	/**
	 * 
	 * @param parent
	 *            the parent composite used to open a dialog
	 * @param originalCanonicalValue
	 *            the original value
	 * @param cell
	 *            the cell to edit
	 * @param configRegistry
	 *            the config registry used by the nattable widget
	 * @return
	 *         a IStatus to know if the user cancel the action or validate the action
	 */
	public int openDialog(Composite parent, Object originalCanonicalValue, ILayerCell cell, IConfigRegistry configRegistry) {
		AbstractDialogCellEditor editor = createDialogCellEditor();
		editor.activateCell(parent, originalCanonicalValue, EditModeEnum.DIALOG, new DialogEditHandler(), cell, configRegistry);
		int res = editor.open();
		if (Window.OK == res) {
			this.newValue = editor.getEditorValue();
		}
		return res;
	}
}

Back to the top