From: Hirzel P. <ph...@us...> - 2008-06-18 15:27:38
|
Update of /cvsroot/tcotool/TCO-Tool/plugins/ch.softenvironment.tcotool.tco/source/ch/softenvironment/tcotool/tco In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16375/plugins/ch.softenvironment.tcotool.tco/source/ch/softenvironment/tcotool/tco Added Files: ReportTcoDirect.java SEPlugin.java ReportTcoEstimated.java Log Message: New reports --- NEW FILE: ReportTcoEstimated.java --- package ch.softenvironment.tcotool.tco; /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.IOException; import java.util.*; import org.tcotool.model.*; import org.tcotool.standard.report.ReportTco; import org.tcotool.standard.report.ReportTool; import org.tcotool.tools.Calculator; import org.tcotool.tools.CalculatorTco; import org.tcotool.tools.ModelUtility; import org.tcotool.application.*; import ch.softenvironment.client.ResourceManager; import ch.softenvironment.jomm.DbObjectServer; import ch.softenvironment.jomm.serialize.AttributeList; import ch.softenvironment.util.NlsUtils; /** * Utility to report estimated TCO costs * based Cost#estimated * . * Calculations as Plugin for TCO-Tool. * Design Pattern: Visitor * * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2008/06/18 15:27:44 $ */ class ReportTcoEstimated extends ReportTco { private ClassLoader loader = null; private String labelEstimated = ResourceManager.getResourceAsNonLabeled(FactCostDetailView.class, "ChxEstimated_text"); private String labelKnown = ResourceManager.getResourceAsNonLabeled(FactCostDetailView.class, "ChxKnown_text"); protected ReportTcoEstimated(String title) { super(title); } /** * Summarize all other TCO-Costs within given object and sub-packages. */ public static ReportTool createBlock(TcoObject root, long maxUsage, ClassLoader loader) throws java.lang.Throwable { ReportTcoEstimated tool = new ReportTcoEstimated(ResourceManager.getResource(SEPlugin.class, "MniReportTcoEstimated_text", loader)); tool.loader = loader; tool.calculator = new CalculatorTco(LauncherView.getInstance().getUtility(), root, maxUsage); tool.totalCost(root); return tool; } /** * Overwrites. */ public void startBody(AttributeList list) throws IOException { super.startBody(list); java.net.URL url = loader.getResource(SEPlugin.REPORT_HEADER); image(url, "", 0); } /** * Overwrites. */ protected void encodeCodes(DbObjectServer server, TcoObject root) throws Throwable { //List codes = server.retrieveCodes(CostCause.class); // Cost->CostCause (contains DIRECT/INDIRECT info) //if (codes.size() > 0) { startParagraph(); encodeCostBlock(root, null, null, ModelUtility.getTypeString(Cost.class)); endParagraph(); //} } /** * Estimated or known costs are defined on Cost#estimated only. * Overwrites. */ protected void encodeCostBlock(TcoObject root, List codes, final String codeUndefined, String title) throws IOException { bold(getRsc("CIBy") + " <" + title + ">:"); String tmp = getRsc("CIEstimatedRatio") + " = "; double knownValue = Calculator.getValue(calculator.getCodeTotal(root, Calculator.KNOWN), Calculator.INDEX_TOTAL); double estimatedValue = Calculator.getValue(calculator.getCodeTotal(root, Calculator.ESTIMATED), Calculator.INDEX_TOTAL); paragraph(tmp + amount(estimatedValue) + " : " + amount(knownValue)); /* getCsvWriter().cell(tmp); getCsvWriter().cell(new Double(estimatedValue)); getCsvWriter().cell(" : "); getCsvWriter().cell(new Double(knownValue)); getCsvWriter().newline(); */ startTable(1); startTableRow(); // print header tableHeader(""); //evtl. colspan with next column tableHeader(title); for (int year=0; year<calculator.getDurationYears(); year++) { String partialYear = ""; if ((calculator.getMaxDurationMonths() - year * 12) < 12) { partialYear = NlsUtils.formatMessage("<br>" + getRsc("CIPartialYear"), (int)calculator.getMaxDurationMonths() % 12); } String header = getRsc("CITCO") + partialYear; tmp = (year + 1) + ". " + getRsc("CIYear"); nativeContent("<th>" + header + "<br>" + tmp + "</th>"); getCsvWriter().cell(header + tmp); } tableHeader(getRsc("CITCOOverAll")); endTableRow(); List estimated = encodeCostBlockColumns(root, PersonalCost.class, labelEstimated, Calculator./*PERSONAL_*/ESTIMATED); List known = encodeCostBlockColumns(root, PersonalCost.class, labelKnown, Calculator./*PERSONAL_*/KNOWN); Calculator.accumulateLists(estimated, encodeCostBlockColumns(root, FactCost.class, labelEstimated, Calculator./*FACT_*/ESTIMATED)); Calculator.accumulateLists(known, encodeCostBlockColumns(root, FactCost.class, labelKnown, Calculator./*FACT_*/KNOWN)); // print total bottom line List totalCosts = calculator.getCostBlock(root); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text")); double sumTcoOverUsage = 0.0; for (int i=2; i<totalCosts.size(); i++) { double amount = Calculator.getValue(totalCosts, i); tableDataAmount(amount, true); if (i>=2) { sumTcoOverUsage += amount; } } tableDataAmount(sumTcoOverUsage, true); endTableRow(); startTableRow(); // sum up direct & indirect nativeContent("<td colspan='6'>" + SPACE + "</td>"); getCsvWriter().newline(); endTableRow(); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text") + " " + labelEstimated); for (int i=0; i < estimated.size(); i++) { tableDataAmount(((Double)estimated.get(i)).doubleValue(), true); } endTableRow(); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text") + " " + labelKnown); for (int i=0; i < known.size(); i++) { tableDataAmount(((Double)known.get(i)).doubleValue(), true); } endTableRow(); endTable(); encodeCostUnit(""); } /** * Print Columns for TCO in HTML: * [Personal/Fact Direct/Indirect] [TCO_Y1] [TCO_Y2]... [TCO_Total] * @param root print to data of given service (null for all services) */ protected List encodeCostBlockColumns(TcoObject root, Class cost, final String rowTitle, String code) throws IOException { String kind = cost == FactCost.class ? Calculator.KIND_FC : Calculator.KIND_PC; List figures = new ArrayList(); startTableRow(); nativeContent("<td>" + getTcoObjectImage(cost) + "</td>"); getCsvWriter().cell(cost == PersonalCost.class ? ResourceManager.getResource(PersonalCostDetailView.class, "FrmWindow_text") : ResourceManager.getResource(FactCostDetailView.class, "FrmWindow_text")); if (rowTitle == null) { tableDataCode(Calculator.COST_CAUSE_UNDEFINED); } else { tableData(rowTitle); } int year = 0; double sumTcoOverUsage = 0.0; for (; year < calculator.getMaxDurationMonths()/12; year++) { double amount = Calculator.getValue(calculator.getCodeTotal(root, code, kind), year + Calculator.INDEX_TOTAL + 1); figures.add(new Double(amount)); tableDataAmount(amount, false); sumTcoOverUsage += amount; } if (calculator.getMaxDurationMonths() % 12 > 0) { // partial year double amount = Calculator.getValue(calculator.getCodeTotal(root, code, kind), year + Calculator.INDEX_TOTAL + 1); figures.add(new Double(amount)); tableDataAmount(amount, false); sumTcoOverUsage += amount; } figures.add(new Double(sumTcoOverUsage)); tableDataAmount(sumTcoOverUsage, true); endTableRow(); return figures; } } --- NEW FILE: SEPlugin.java --- package ch.softenvironment.tcotool.tco; /* * Copyright (C) 2006 Peter Hirzel softEnvironment (http://www.softenvironment.ch). * All rights reserved. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import javax.swing.JComponent; import javax.swing.JMenuItem; import org.java.plugin.Plugin; import org.tcotool.application.LauncherView; import org.tcotool.core.runtime.ApplicationPlugin; import org.tcotool.model.TcoObject; import org.tcotool.model.TcoPackage; import org.tcotool.pluginsupport.PluginUtility; import org.tcotool.standard.report.ReportTool; import org.tcotool.tools.ModelUtility; /** * Free <i>soft</i>Environment Plugins (might serve as sample). * PLUGIN_ID = "ch.softenvironment.tcotool.finance"; * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2008/06/18 15:27:44 $ */ public final class SEPlugin extends Plugin implements org.tcotool.pluginsupport.Menu { protected static final String REPORT_HEADER = "ReportHeader.png"; /** * Constructor. */ public SEPlugin() { super(); } /** * @see org.java.plugin.Plugin#doStart() */ protected void doStart() throws Exception { } /** * @see org.java.plugin.Plugin#doStop() */ protected void doStop() throws Exception { } /** * Menu was clicked -> generate the report. * @see org.tcotool.pluginsupport.Menu#init(javax.swing.JComponent) */ public void actionPerform(final JComponent item, final Object object) { ApplicationPlugin.showBusy(new Runnable() { public void run() { try { String actionCommand = ((JMenuItem)item).getActionCommand(); if (actionCommand.equals("tcoDirect" /*@see plugin.xml=>extension-id*/)) { reportTcoDirect(ModelUtility.getTcoPackageOrRoot(object)); } else if (actionCommand.equals("tcoEstimated" /*@see plugin.xml=>extension-id*/)) { reportTcoEstimated(ModelUtility.getTcoPackageOrRoot(object)); } } catch(Throwable e) { LauncherView.getInstance().handleException(e); } } }); } /** * Menu callback. */ private void reportTcoDirect(TcoObject root) throws Throwable { LauncherView.getInstance().addReport(ReportTcoDirect.createBlock(root, ReportTool.getUsageDuration(), PluginUtility.getClassLoader(this))); } /** * Menu callback. */ private void reportTcoEstimated(TcoObject root) throws Throwable { LauncherView.getInstance().addReport(ReportTcoEstimated.createBlock(root, ReportTool.getUsageDuration(), PluginUtility.getClassLoader(this))); } } --- NEW FILE: ReportTcoDirect.java --- package ch.softenvironment.tcotool.tco; /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.IOException; import java.util.*; import org.tcotool.model.*; import org.tcotool.standard.report.ReportTco; import org.tcotool.standard.report.ReportTool; import org.tcotool.tools.Calculator; import org.tcotool.tools.CalculatorTco; import org.tcotool.tools.ModelUtility; import org.tcotool.application.*; import ch.softenvironment.client.ResourceManager; import ch.softenvironment.jomm.DbObjectServer; import ch.softenvironment.jomm.serialize.AttributeList; import ch.softenvironment.util.NlsUtils; /** * Utility to report direct/indirect TCO costs * based on CostCause#direct assignment to Personal/Fact-Cost. * * Calculations as Plugin for TCO-Tool. * Design Pattern: Visitor * * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2008/06/18 15:27:44 $ */ class ReportTcoDirect extends ReportTco { private ClassLoader loader = null; private String labelDirect = ResourceManager.getResourceAsNonLabeled(CostCauseDetailView.class, "LblDirect_text"); private String labelIndirect = ResourceManager.getResourceAsNonLabeled(CostCauseDetailView.class, "LblIndirect_text"); protected ReportTcoDirect(String title) { super(title); } /** * Summarize all other TCO-Costs within given object and sub-packages. */ public static ReportTool createBlock(TcoObject root, long maxUsage, ClassLoader loader) throws java.lang.Throwable { ReportTcoDirect tool = new ReportTcoDirect(ResourceManager.getResource(SEPlugin.class, "MniReportTcoDirectIndirect_text", loader)); tool.loader = loader; tool.calculator = new CalculatorTco(LauncherView.getInstance().getUtility(), root, maxUsage); tool.totalCost(root); return tool; } /** * Overwrites. */ public void startBody(AttributeList list) throws IOException { super.startBody(list); java.net.URL url = loader.getResource(SEPlugin.REPORT_HEADER); image(url, "", 0); } /** * Overwrites. */ protected void encodeCodes(DbObjectServer server, TcoObject root) throws Throwable { //List codes = server.retrieveCodes(CostCause.class); // Cost->CostCause (contains DIRECT/INDIRECT info) //if (codes.size() > 0) { startParagraph(); encodeCostBlock(root, null /*codes*/, null /*Calculator.COST_CAUSE_UNDEFINED*/, ModelUtility.getTypeString(CostCause.class)); endParagraph(); //} } /** * Direct or Indirect costs are defined on Cost#CostCause only. * Overwrites. */ protected void encodeCostBlock(TcoObject root, List codes, final String codeUndefined, String title) throws IOException { bold(getRsc("CIBy") + " <" + title + " *>:"); startTable(1); startTableRow(); // print header tableHeader(""); //evtl. colspan with next column tableHeader(title); for (int year=0; year<calculator.getDurationYears(); year++) { String partialYear = ""; if ((calculator.getMaxDurationMonths() - year * 12) < 12) { partialYear = NlsUtils.formatMessage("<br>" + getRsc("CIPartialYear"), (int)calculator.getMaxDurationMonths() % 12); } String header = getRsc("CITCO") + partialYear; String tmp = (year + 1) + ". " + getRsc("CIYear"); nativeContent("<th>" + header + "<br>" + tmp + "</th>"); getCsvWriter().cell(header + tmp); } tableHeader(getRsc("CITCOOverAll")); endTableRow(); List direct = encodeCostBlockColumns(root, PersonalCost.class, labelDirect, Calculator./*PERSONAL_*/DIRECT); List indirect = encodeCostBlockColumns(root, PersonalCost.class, labelIndirect, Calculator./*PERSONAL_*/INDIRECT); //TODO only show undefined PC if link is pressed List undefined = encodeCostBlockColumns(root, PersonalCost.class, null /*Undefined*/, Calculator./*PERSONAL_*/DIRECT_UNDEFINED); Calculator.accumulateLists(direct, encodeCostBlockColumns(root, FactCost.class, labelDirect, Calculator./*FACT_*/DIRECT)); Calculator.accumulateLists(indirect, encodeCostBlockColumns(root, FactCost.class, labelIndirect, Calculator./*FACT_*/INDIRECT)); //TODO only show undefined FC if link is pressed Calculator.accumulateLists(undefined, encodeCostBlockColumns(root, FactCost.class, null /*Undefined*/, Calculator./*FACT_*/DIRECT_UNDEFINED)); // print total bottom line List totalCosts = calculator.getCostBlock(root); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text")); double sumTcoOverUsage = 0.0; for (int i=2; i<totalCosts.size(); i++) { double amount = Calculator.getValue(totalCosts, i); tableDataAmount(amount, true); if (i>=2) { sumTcoOverUsage += amount; } } tableDataAmount(sumTcoOverUsage, true); endTableRow(); startTableRow(); // sum up direct & indirect nativeContent("<td colspan='6'>" + SPACE + "</td>"); getCsvWriter().newline(); endTableRow(); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text") + " " + labelDirect); for (int i=0; i < direct.size(); i++) { tableDataAmount(((Double)direct.get(i)).doubleValue(), true); } endTableRow(); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text") + " " + labelIndirect); for (int i=0; i < indirect.size(); i++) { tableDataAmount(((Double)indirect.get(i)).doubleValue(), true); } endTableRow(); startTableRow(); tableData("*"); tableDataBold(ResourceManager.getResource(ServiceDetailView.class, "TbcTotal_text") + " " + getCodeName(Calculator.COST_CAUSE_UNDEFINED)); for (int i=0; i < undefined.size(); i++) { tableDataAmount(((Double)undefined.get(i)).doubleValue(), true); } endTableRow(); endTable(); encodeCostUnit(""); } /** * Print Columns for TCO in HTML: * [Personal/Fact Direct/Indirect] [TCO_Y1] [TCO_Y2]... [TCO_Total] * @param root print to data of given service (null for all services) */ protected List encodeCostBlockColumns(TcoObject root, Class cost, final String rowTitle, final String code) throws IOException { String kind = cost == FactCost.class ? Calculator.KIND_FC : Calculator.KIND_PC; List figures = new ArrayList(); startTableRow(); nativeContent("<td>" + getTcoObjectImage(cost) + "</td>"); getCsvWriter().cell(cost == PersonalCost.class ? ResourceManager.getResource(PersonalCostDetailView.class, "FrmWindow_text") : ResourceManager.getResource(FactCostDetailView.class, "FrmWindow_text")); if (rowTitle == null) { tableDataCode(Calculator.COST_CAUSE_UNDEFINED); } else { tableData(rowTitle); } int year = 0; double sumTcoOverUsage = 0.0; for (; year < calculator.getMaxDurationMonths()/12; year++) { double amount = Calculator.getValue(calculator.getCodeTotal(root, code, kind), year + Calculator.INDEX_TOTAL + 1); figures.add(new Double(amount)); tableDataAmount(amount, false); sumTcoOverUsage += amount; } if (calculator.getMaxDurationMonths() % 12 > 0) { // partial year double amount = Calculator.getValue(calculator.getCodeTotal(root, code, kind), year + Calculator.INDEX_TOTAL + 1); figures.add(new Double(amount)); tableDataAmount(amount, false); sumTcoOverUsage += amount; } figures.add(new Double(sumTcoOverUsage)); tableDataAmount(sumTcoOverUsage, true); endTableRow(); return figures; } } |