Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0add02f077b54ac2315d72b3d8c4e9a96947426c (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
/*******************************************************************************
 * Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf.
 * 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:
 *     Michael Jastram - initial API and implementation
 ******************************************************************************/
package org.eclipse.rmf.reqif10.agilegrid;

import java.math.BigInteger;

import org.agilemore.agilegrid.AgileGrid;
import org.agilemore.agilegrid.ICellEditorValidator;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.rmf.reqif10.util.ProrUtil;

public class ProrStringCellEditor extends ProrCellEditor {

	private BigInteger maxLength;
	
	public ProrStringCellEditor(AgileGrid agileGrid,
			EditingDomain editingDomain) {
		super(agileGrid, editingDomain);
		this.setValidator(new ICellEditorValidator() {

			@Override
			public String isValid(Object value) {
				if (!(value instanceof String)) {
					return null;
				}
				// TODO conversion from BigInteger to int is dangerous!
				if (((String) value).length() > maxLength.intValue()) {
					return "Maximum length of " + maxLength + " exceeded";
				}
				return null;
			}
		});
	}

	@Override
	protected Object doGetValue() {
		ProrUtil.setTheValue(attributeValue, text.getText(), editingDomain);
		return attributeValue;
	}

	public void setMaxLength(BigInteger maxLength) {
		this.maxLength = maxLength;
	}

}

Back to the top