Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3bbcf481745a1c9ac31c63f141a0fd3ad1fa6547 (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
/*******************************************************************************
 * Copyright (c) 2008 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.eclipselink.ui.internal.mappings.details;

import java.util.Collection;
import java.util.List;
import org.eclipse.jpt.eclipselink.ui.internal.mappings.EclipseLinkUiMappingsMessages;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.node.AbstractNode;
import org.eclipse.jpt.utility.internal.node.Node;
import org.eclipse.jpt.utility.internal.node.Problem;

/**
 * This is the state object used by the <code>NewNameDialog</code>, which stores
 * the current name and validates it when it is modified.
 *
 * @see NewNameDialog
 *
 * @version 2.1
 * @since 2.1
 */
@SuppressWarnings("nls")
final class ConversionValueStateObject extends AbstractNode
{
	/**
	 * The initial dataValue or <code>null</code>
	 */
	private String dataValue;
	
	/**
	 * The collection of data values that can't be used or an empty collection
	 */
	private Collection<String> dataValues;

	/**
	 * The initial objectValue or <code>null</code>
	 */
	private String objectValue;

	/**
	 * The <code>Validator</code> used to validate this state object.
	 */
	private Validator validator;

	/**
	 * Notifies a change in the data value property.
	 */
	static final String DATA_VALUE_PROPERTY = "dataValue";
	
	/**
	 * Notifies a change in the object value property.
	 */
	static final String OBJECT_VALUE_PROPERTY = "objectValue";

	/**
	 * Creates a new <code>NewNameStateObject</code>.
	 *
	 * @param name The initial input or <code>null</code> if no initial value can
	 * be specified
	 * @param names The collection of names that can't be used or an empty
	 * collection if none are available
	 */
	ConversionValueStateObject(String dataValue, String objectValue, Collection<String> dataValues) {
		super(null);

		this.dataValue  = dataValue;
		this.objectValue = objectValue;
		this.dataValues = dataValues;
	}

	private void addDataValueProblemsTo(List<Problem> currentProblems) {
		if (StringTools.stringIsEmpty(this.dataValue)) {
			currentProblems.add(buildProblem(EclipseLinkUiMappingsMessages.ConversionValueStateObject_dataValueMustBeSpecified));
		}
		else if (this.dataValues.contains(this.dataValue)) {
			currentProblems.add(buildProblem(EclipseLinkUiMappingsMessages.ConversionValueStateObject_dataValueAlreadyExists));
		}
	}

	private void addObjectValueProblemsTo(List<Problem> currentProblems) {
		if (StringTools.stringIsEmpty(this.objectValue)) {
			currentProblems.add(buildProblem(EclipseLinkUiMappingsMessages.ConversionValueStateObject_objectValueMustBeSpecified));
		}
	}

	@Override
	protected void addProblemsTo(List<Problem> currentProblems) {
		super.addProblemsTo(currentProblems);
		addDataValueProblemsTo(currentProblems);
		addObjectValueProblemsTo(currentProblems);
	}

	@Override
	protected void checkParent(Node parentNode) {
		//not parent
	}

	public String displayString() {
		return null;
	}

	String getDataValue() {
		return this.dataValue;
	}

	String getObjectValue() {
		return this.objectValue;
	}

	public void setDataValue(String dataValue) {
		String oldDataValue = this.dataValue;
		this.dataValue = dataValue;
		firePropertyChanged(DATA_VALUE_PROPERTY, oldDataValue, dataValue);
	}

	public void setObjectValue(String objectValue) {
		String oldObjectValue = this.objectValue;
		this.objectValue = objectValue;
		firePropertyChanged(OBJECT_VALUE_PROPERTY, oldObjectValue, objectValue);
	}

	@Override
	public void setValidator(Validator validator) {
		this.validator = validator;
	}

	@Override
	public Validator getValidator() {
		return this.validator;
	}
}

Back to the top