blob: 9ddf12aa12885a545f8bf3fdc33224e428477da6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006, 2007 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.core.internal.context.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.TextRange;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.java.JavaColumn;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.resource.java.ColumnAnnotation;
public class GenericJavaColumn extends AbstractJavaColumn<ColumnAnnotation> implements JavaColumn
{
protected Integer specifiedLength;
protected Integer specifiedPrecision;
protected Integer specifiedScale;
public GenericJavaColumn(JavaJpaContextNode parent, JavaColumn.Owner owner) {
super(parent, owner);
}
@Override
public void initializeFromResource(ColumnAnnotation column) {
super.initializeFromResource(column);
this.specifiedLength = this.specifiedLength(column);
this.specifiedPrecision = this.specifiedPrecision(column);
this.specifiedScale = this.specifiedScale(column);
}
@Override
public JavaColumn.Owner owner() {
return (JavaColumn.Owner) super.owner();
}
@Override
protected ColumnAnnotation columnResource() {
return this.owner().columnResource();
}
public Integer getLength() {
return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength();
}
public Integer getDefaultLength() {
return Column.DEFAULT_LENGTH;
}
public Integer getSpecifiedLength() {
return this.specifiedLength;
}
public void setSpecifiedLength(Integer newSpecifiedLength) {
Integer oldSpecifiedLength = this.specifiedLength;
this.specifiedLength = newSpecifiedLength;
columnResource().setLength(newSpecifiedLength);
firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength);
}
public Integer getPrecision() {
return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision();
}
public Integer getDefaultPrecision() {
return Column.DEFAULT_PRECISION;
}
public Integer getSpecifiedPrecision() {
return this.specifiedPrecision;
}
public void setSpecifiedPrecision(Integer newSpecifiedPrecision) {
Integer oldSpecifiedPrecision = this.specifiedPrecision;
this.specifiedPrecision = newSpecifiedPrecision;
columnResource().setPrecision(newSpecifiedPrecision);
firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision);
}
public Integer getScale() {
return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale();
}
public Integer getDefaultScale() {
return Column.DEFAULT_SCALE;
}
public Integer getSpecifiedScale() {
return this.specifiedScale;
}
public void setSpecifiedScale(Integer newSpecifiedScale) {
Integer oldSpecifiedScale = this.specifiedScale;
this.specifiedScale = newSpecifiedScale;
columnResource().setScale(newSpecifiedScale);
firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale);
}
@Override
public boolean tableIsAllowed() {
return true;
}
public TextRange validationTextRange(CompilationUnit astRoot) {
TextRange textRange = columnResource().textRange(astRoot);
return (textRange != null) ? textRange : this.owner().validationTextRange(astRoot);
}
@Override
public void update(ColumnAnnotation column) {
super.update(column);
this.setSpecifiedLength(this.specifiedLength(column));
this.setSpecifiedPrecision(this.specifiedPrecision(column));
this.setSpecifiedScale(this.specifiedScale(column));
}
protected Integer specifiedLength(ColumnAnnotation column) {
return column.getLength();
}
protected Integer specifiedPrecision(ColumnAnnotation column) {
return column.getPrecision();
}
protected Integer specifiedScale(ColumnAnnotation column) {
return column.getScale();
}
}