# HG changeset patch # User Jaroslav Tulach # Date 1364725567 -7200 # Node ID 52cb50cea1df210aa4272cd3675eeaa296343e25 # Parent e51a474fcf79873b111d2cf936e5c22e9a8201cb Introducing History model class with two defined properties and one derived diff -r e51a474fcf79 -r 52cb50cea1df javaquery/demo-calculator-dynamic/nbactions.xml --- a/javaquery/demo-calculator-dynamic/nbactions.xml Sun Mar 31 12:01:38 2013 +0200 +++ b/javaquery/demo-calculator-dynamic/nbactions.xml Sun Mar 31 12:26:07 2013 +0200 @@ -23,7 +23,7 @@ run process-classes - org.apidesign.bck2brwsr:mojo:0.5-SNAPSHOT:brwsr + org.apidesign.bck2brwsr:mojo:0.6-SNAPSHOT:brwsr diff -r e51a474fcf79 -r 52cb50cea1df javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Sun Mar 31 12:01:38 2013 +0200 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Sun Mar 31 12:26:07 2013 +0200 @@ -36,7 +36,7 @@ @Property(name = "display", type = double.class), @Property(name = "operation", type = String.class), @Property(name = "hover", type = boolean.class), - @Property(name = "history", type = double.class, array = true) + @Property(name = "history", type = HistoryImpl.class, array = true) }) public class Calc { static { @@ -74,19 +74,22 @@ c.getDisplay() ); c.setDisplay(newValue); - if (!c.getHistory().contains(newValue)) { - c.getHistory().add(newValue); + if (!containsValue(c.getHistory(), newValue)) { + History h = new History(); + h.setValue(newValue); + h.setOperation(c.getOperation()); + c.getHistory().add(h); } c.setMemory(0); } @OnFunction - static void recoverMemory(Calculator c, double data) { - c.setDisplay(data); + static void recoverMemory(Calculator c, History data) { + c.setDisplay(data.getValue()); } @OnFunction - static void removeMemory(Calculator c, double data) { + static void removeMemory(Calculator c, History data) { c.getHistory().remove(data); } @@ -131,4 +134,13 @@ static boolean emptyHistory(List history) { return history.isEmpty(); } + + private static boolean containsValue(List arr, final double newValue) { + for (History history : arr) { + if (history.getValue() == newValue) { + return true; + } + } + return false; + } } diff -r e51a474fcf79 -r 52cb50cea1df javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/HistoryImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/HistoryImpl.java Sun Mar 31 12:26:07 2013 +0200 @@ -0,0 +1,37 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.demo.calc; + +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty; +import org.apidesign.bck2brwsr.htmlpage.api.Model; +import org.apidesign.bck2brwsr.htmlpage.api.Property; + +/** + * + * @author Jaroslav Tulach + */ +@Model(className = "History", properties = { + @Property(name = "value", type = double.class), + @Property(name = "operation", type = String.class) +}) +public class HistoryImpl { + @ComputedProperty + static String resultOf(String operation) { + return "result of " + operation; + } +} diff -r e51a474fcf79 -r 52cb50cea1df javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml --- a/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Sun Mar 31 12:01:38 2013 +0200 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Sun Mar 31 12:26:07 2013 +0200 @@ -83,9 +83,10 @@
No results yet.