This commit is contained in:
serso 2012-10-15 14:37:14 +04:00
parent f31d033caf
commit 3fbce93445
3 changed files with 163 additions and 147 deletions

View File

@ -444,7 +444,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
varBuilder.setValue(result);
varBuilder.setDescription(CalculatorMessages.getBundle().getString("ans_description"));
varsRegistry.add(varBuilder);
CalculatorVarsRegistry.saveVariable(varsRegistry, varBuilder, ansVar, this, false);
}
}
}

View File

@ -8,9 +8,12 @@ package org.solovyev.android.calculator;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.model.MathEntityBuilder;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.calculator.model.Vars;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
@ -41,7 +44,24 @@ public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<ICons
super(mathRegistry, "c_var_description_", mathEntityDao);
}
@NotNull
public static <T extends MathEntity> void saveVariable(@NotNull CalculatorMathRegistry<T> registry,
@NotNull MathEntityBuilder<? extends T> builder,
@Nullable T editedInstance,
@NotNull Object source, boolean save) {
final T addedVar = registry.add(builder);
if (save) {
registry.save();
}
if (editedInstance == null) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
} else {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
}
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;

View File

@ -14,7 +14,10 @@ import jscl.text.ParseException;
import jscl.text.Parser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.CalculatorVarsRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.MathEntityBuilder;
import org.solovyev.common.math.MathEntity;
@ -116,18 +119,11 @@ class VarEditorSaver<T extends MathEntity> implements View.OnClickListener {
if (error != null) {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(error, MessageType.error);
} else {
final T addedVar = mathRegistry.add(varBuilder);
mathRegistry.save();
if (editedInstance == null) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
} else {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
}
CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
}
}
boolean isValidName(@Nullable String name) {
boolean isValidName(@Nullable String name) {
boolean result = false;
if (!StringUtils.isEmpty(name)) {