diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AddQueryStateObject.java')
-rw-r--r-- | jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AddQueryStateObject.java | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AddQueryStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AddQueryStateObject.java new file mode 100644 index 0000000000..9dd862cff1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AddQueryStateObject.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2009 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.ui.internal.details; + +import java.util.List; +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>AddQueryDialog</code>, which stores + * the current name and validates it when it is modified. + * + * @see AddQueryDialog + * + * @version 2.1 + * @since 2.1 + */ +final class AddQueryStateObject extends AbstractNode +{ + /** + * The initial name or <code>null</code> + */ + private String name; + + /** + * The initial queryType or <code>null</code> + */ + private String queryType; + + /** + * The <code>Validator</code> used to validate this state object. + */ + private Validator validator; + + /** + * Notifies a change in the data value property. + */ + static final String NAME_PROPERTY = "nameProperty"; //$NON-NLS-1$ + + /** + * Notifies a change in the query type property. + */ + static final String QUERY_TYPE_PROPERTY = "queryTypeProperty"; //$NON-NLS-1$ + + /** + * 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 + */ + AddQueryStateObject() { + super(null); + + } + + private void addNameProblemsTo(List<Problem> currentProblems) { + if (StringTools.stringIsEmpty(this.name)) { + currentProblems.add(buildProblem(JptUiDetailsMessages.QueryStateObject_nameMustBeSpecified)); + } + } + + private void addQueryTypeProblemsTo(List<Problem> currentProblems) { + if (StringTools.stringIsEmpty(this.queryType)) { + currentProblems.add(buildProblem(JptUiDetailsMessages.QueryStateObject_typeMustBeSpecified)); + } + } + + @Override + protected void addProblemsTo(List<Problem> currentProblems) { + super.addProblemsTo(currentProblems); + addNameProblemsTo(currentProblems); + addQueryTypeProblemsTo(currentProblems); + } + + @Override + protected void checkParent(Node parentNode) { + //no parent + } + + public String displayString() { + return null; + } + + String getName() { + return this.name; + } + + String getQueryType() { + return this.queryType; + } + + public void setName(String newName) { + String oldName = this.name; + this.name = newName; + firePropertyChanged(NAME_PROPERTY, oldName, newName); + } + + public void setQueryType(String newQueryType) { + String old = this.queryType; + this.queryType = newQueryType; + firePropertyChanged(QUERY_TYPE_PROPERTY, old, newQueryType); + } + + @Override + public void setValidator(Validator validator) { + this.validator = validator; + } + + @Override + public Validator getValidator() { + return this.validator; + } +} |