001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 Dennis Reil
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.installer;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: import com.izforge.izpack.rules.Condition;
028:
029: /**
030: *
031: * @author Dennis Reil, <Dennis.Reil@reddot.de>
032: * @version $Id: $
033: */
034: public class ConditionHistory {
035: private Condition condition;
036: private List<Object[]> values;
037:
038: private boolean newcondition;
039: private boolean changedcondition;
040:
041: public ConditionHistory(Condition condition) {
042: this .condition = condition;
043: values = new ArrayList<Object[]>();
044: newcondition = true;
045: changedcondition = true;
046: }
047:
048: public void addValue(boolean value, String comment) {
049: if ((values.size() == 0) || value != getLastValue()) {
050: Object[] valuecomment = new Object[2];
051: valuecomment[0] = value;
052: valuecomment[1] = comment;
053: this .values.add(valuecomment);
054: if (values.size() == 1) {
055: newcondition = true;
056: changedcondition = true;
057: } else {
058: changedcondition = true;
059: }
060: }
061: }
062:
063: public boolean getLastValue() {
064: if (values.size() > 0) {
065: return (Boolean) (values.get(values.size() - 1))[0];
066: } else {
067: return false;
068: }
069: }
070:
071: public int getValueCount() {
072: return values.size();
073: }
074:
075: public void clearState() {
076: newcondition = false;
077: changedcondition = false;
078: }
079:
080: /**
081: * @return the newcondition
082: */
083: public boolean isNewcondition() {
084: return this .newcondition;
085: }
086:
087: /**
088: * @return the changedcondition
089: */
090: public boolean isChangedcondition() {
091: return this .changedcondition;
092: }
093:
094: public String toString() {
095: return Boolean.toString(getLastValue());
096: }
097:
098: public String getConditionHistoryDetails() {
099: StringBuffer details = new StringBuffer();
100: details.append("<html><body>");
101: details.append("<h3>Details of <b>");
102: details.append(this .condition.getId());
103: details.append("</b></h3>");
104: for (int i = values.size() - 1; i >= 0; i--) {
105: Object[] condcomment = values.get(i);
106: details.append(i + 1);
107: details.append(". ");
108: details.append(((Boolean) condcomment[0]).toString());
109: details.append(" (");
110: details.append(condcomment[1]);
111: details.append(")<br>");
112: }
113: details.append("<h4>Dependencies</h4>");
114: details.append(this .condition.getDependenciesDetails());
115: details.append("</body></html>");
116: return details.toString();
117: }
118: }
|