protected void executeSelectedAlgorithmIteratively(final int iParameterToIterateOver) { try { if (m_Alg != null) { final GeoAlgorithm alg = m_Alg.getNewInstance(); final int iRet = SextanteGUI.getGUIFactory().showAlgorithmDialog(alg, m_ParentDialog.getDialog(), null); if (iRet == IGUIFactory.OK) { final ParametersSet params = m_Alg.getParameters(); final int iParamCount = params.getNumberOfParameters(); int iVectorLayers = 0; for (int i = 0; i < iParamCount; i++) { final Parameter param = m_Alg.getParameters().getParameter(i); if (param instanceof ParameterVectorLayer) { if (iVectorLayers == iParameterToIterateOver) { GeoAlgorithmExecutors.executeIterative( alg, m_ParentDialog.getDialog(), param.getParameterName()); break; } iVectorLayers++; } } } } } catch (final Exception e) { Sextante.addErrorToLog(e); } }
/** * Returns the help associated with a given geoalgorithm as a html-formatted string * * @param alg the geoalgorithm * @param sFilename the filename where help for the passed algorithm is stored * @return a html-formatted string with help for the given algorithm */ public static String getHelpAsHTMLCode(final GeoAlgorithm alg, final String sFilename) { HelpElement element; final ArrayList list = open(sFilename); HashMap elements; final String sPath = "file:///" + sFilename.substring(0, sFilename.lastIndexOf(File.separator)) + File.separator; if (list != null) { elements = createMap(list); } else { elements = new HashMap(); } final HTMLDoc doc = new HTMLDoc(); doc.open(alg.getName()); doc.addHeader(Sextante.getText(alg.getName()), 1); doc.addHeader(Sextante.getText("Description"), 2); element = (HelpElement) elements.get("DESCRIPTION"); if (element != null) { doc.addParagraph(element.getTextAsFormattedHTML()); for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } doc.addHeader(Sextante.getText("Parameters"), 2); final ParametersSet params = alg.getParameters(); doc.startUnorderedList(); for (int i = 0; i < params.getNumberOfParameters(); i++) { final Parameter param = params.getParameter(i); String sParam = param.getParameterDescription(); sParam = "<b>" + sParam + "[" + getParameterTypeName(param) + "]: </b>"; element = (HelpElement) elements.get(param.getParameterName()); if (element != null) { sParam = sParam + element.getTextAsFormattedHTML(); } doc.addListElement(sParam); if (element != null) { for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } } doc.closeUnorderedList(); doc.addHeader(Sextante.getText("Outputs"), 2); element = (HelpElement) elements.get("OUTPUT_DESCRIPTION"); if (element != null) { doc.addParagraph(element.getTextAsFormattedHTML()); for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } doc.startUnorderedList(); final OutputObjectsSet oo = alg.getOutputObjects(); String sOutputType = ""; for (int i = 0; i < oo.getOutputObjectsCount(); i++) { final Output out = oo.getOutput(i); String sOutput = out.getDescription(); if (out instanceof OutputRasterLayer) { sOutputType = Sextante.getText("Raster_Layer"); } else if (out instanceof Output3DRasterLayer) { sOutputType = Sextante.getText("3D_Raster_layer"); } else if (out instanceof OutputVectorLayer) { sOutputType = Sextante.getText("Vector_Layer"); final OutputVectorLayer ovl = (OutputVectorLayer) out; switch (ovl.getShapeType()) { case OutputVectorLayer.SHAPE_TYPE_UNDEFINED: default: sOutputType = sOutputType + " - " + Sextante.getText("Any_type"); break; case OutputVectorLayer.SHAPE_TYPE_LINE: sOutputType = sOutputType + " - " + Sextante.getText("Line"); break; case OutputVectorLayer.SHAPE_TYPE_POLYGON: sOutputType = sOutputType + " - " + Sextante.getText("Polygon"); break; case OutputVectorLayer.SHAPE_TYPE_POINT: sOutputType = sOutputType + " - " + Sextante.getText("Point"); break; } } else if (out instanceof OutputTable) { sOutputType = Sextante.getText("Table"); } else if (out instanceof OutputChart) { sOutputType = Sextante.getText("graph-chart"); } else if (out instanceof OutputText) { sOutputType = Sextante.getText("Text"); } else if (out instanceof OutputNumericalValue) { sOutputType = Sextante.getText("Numerical_value"); } sOutput = "<b>" + sOutput + "[" + sOutputType + "]: </b>"; element = (HelpElement) elements.get(out.getName()); if (element != null) { sOutput = sOutput + element.getTextAsFormattedHTML(); } doc.addListElement(sOutput); if (element != null) { for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } } doc.closeUnorderedList(); doc.addHeader(Sextante.getText("Additional_information"), 2); element = (HelpElement) elements.get("ADDITIONAL_INFO"); if (element != null) { doc.addParagraph(element.getTextAsFormattedHTML()); for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } doc.addHeader(Sextante.getText("Command_line"), 2); String sText = alg.getCommandLineHelp(); sText = sText.replaceAll("\n", "<br>"); sText = sText.replace(" ", "   "); doc.addCourierText(sText); doc.addParagraph(""); element = (HelpElement) elements.get("EXTENSION_AUTHOR"); if (element != null) { doc.addParagraph( "<i>" + Sextante.getText("Algorithm_created_by") + " " + element.getText() + "</i>"); for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } element = (HelpElement) elements.get("HELP_AUTHOR"); if (element != null) { doc.addParagraph( "<i>" + Sextante.getText("Help_file_created_by") + " " + element.getText() + "</i>"); for (int j = 0; j < element.getImages().size(); j++) { final ImageAndDescription iad = (ImageAndDescription) element.getImages().get(j); doc.addImageAndDescription(sPath + iad.getFilename(), iad.getDescription()); } } doc.close(); return doc.getHTMLCode(); }