}
@Override
public void setValue(Object valueObject) throws Exception {
String valueString = valueObject instanceof String ? (String) valueObject : null;
final AstEditor editor = m_this.getEditor();
final MethodInvocation invocation = getInvocation();
final String signaturePrefix = "setColumnWidth(com.google.gwt.user.cellview.client.Column,";
// remove value
if (StringUtils.isEmpty(valueString)) {
if (invocation != null) {
ExecutionUtils.run(m_this, new RunnableEx() {
public void run() throws Exception {
editor.removeEnclosingStatement(invocation);
}
});
}
return;
}
// new value
if (invocation == null) {
final String valueSource = StringConverter.INSTANCE.toJavaSource(m_this, valueString);
ExecutionUtils.run(m_this, new RunnableEx() {
public void run() throws Exception {
StatementTarget target = new StatementTarget(getAssociation().getStatement(), false);
String signature = signaturePrefix + "java.lang.String)";
String argumentsSource = TemplateUtils.format("{0}, {1}", m_this, valueSource);
MethodInvocation newInvocation =
getParentJava().addMethodInvocation(target, signature, argumentsSource);
addRelatedNodes(newInvocation);
}
});
return;
}
// update value
final List<Expression> arguments = DomGenerics.arguments(invocation);
// setColumnWidth(Column,String)
{
String signature = signaturePrefix + "java.lang.String)";
if (AstNodeUtils.isMethodInvocation(invocation, signature)) {
final String valueSource = StringConverter.INSTANCE.toJavaSource(m_this, valueString);
ExecutionUtils.run(m_this, new RunnableEx() {
public void run() throws Exception {
editor.replaceExpression(arguments.get(1), valueSource);
}
});
}
}
// setColumnWidth(Column,double,Unit)
{
String typeNameUnit = "com.google.gwt.dom.client.Style.Unit";
String signature = signaturePrefix + "double," + typeNameUnit + ")";
if (AstNodeUtils.isMethodInvocation(invocation, signature)) {
// prepare "value" and "unit"
double sizeValue;
Object sizeUnit;
try {
sizeValue = getValueFromSizeString(valueString);
sizeUnit = getUnitFromSizeString(valueString);
} catch (Throwable e) {
return;
}
// no unit
if (sizeUnit == null) {
return;
}
// apply "value" and "unit"
final String valueSource = DoubleConverter.INSTANCE.toJavaSource(m_this, sizeValue);
final String unitSource = typeNameUnit + "." + sizeUnit.toString();
ExecutionUtils.run(m_this, new RunnableEx() {
public void run() throws Exception {
editor.replaceExpression(arguments.get(1), valueSource);
editor.replaceExpression(arguments.get(2), unitSource);
}
});
}
}
}