r2437 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui: sensitivity simulator widget
Author: chatellier Date: 2009-06-25 15:52:01 +0000 (Thu, 25 Jun 2009) New Revision: 2437 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/ Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserUI.jaxx Log: Remove tooltip model & factory (now managed per ui models) Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserUI.jaxx 2009-06-25 15:46:01 UTC (rev 2436) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserUI.jaxx 2009-06-25 15:52:01 UTC (rev 2437) @@ -33,9 +33,6 @@ import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.export.SensitivityExport; import fr.ifremer.isisfish.IsisFishException; - import fr.ifremer.isisfish.ui.simulator.ToolTipListModelFactory; - import fr.ifremer.isisfish.ui.widget.renderer.SimpleToolTipComboBoxRenderer; - import fr.ifremer.isisfish.ui.widget.renderer.SimpleToolTipTableColumnRenderer; import fr.ifremer.isisfish.ui.models.export.ExportListModel; import fr.ifremer.isisfish.ui.models.export.ExportListRenderer; Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java 2009-06-25 15:46:01 UTC (rev 2436) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java 2009-06-25 15:52:01 UTC (rev 2437) @@ -1,556 +0,0 @@ -/* *##% - * Copyright (C) 2005 - 2009 - * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin - * - * 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; either version 2 - * of the License, or (at your option) any later version. - * - * 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; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.ui.simulator; - -import static org.codelutin.i18n.I18n._; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import javax.swing.JButton; -import javax.swing.JList; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import fr.ifremer.isisfish.datastore.AnalysePlanStorage; -import fr.ifremer.isisfish.datastore.ExportStorage; -import fr.ifremer.isisfish.datastore.RuleStorage; -import fr.ifremer.isisfish.datastore.ScriptStorage; -import fr.ifremer.isisfish.datastore.SensitivityStorage; -import fr.ifremer.isisfish.export.Export; -import fr.ifremer.isisfish.rule.Rule; -import fr.ifremer.isisfish.simulator.AnalysePlan; -import fr.ifremer.isisfish.ui.widget.renderer.ToolTipListModel; -import fr.ifremer.isisfish.util.Doc; - -/** - * This is a factory of {@link ToolTipListModel} used in simulator ui - * - * @author chemit - * @version $Revision$ - * - * Mise a jour: $Date$ - */ -public class ToolTipListModelFactory { - - /** Class logger. */ - private static Log log = LogFactory.getLog(ToolTipListModelFactory.class); - - /** - * Build a new {@link ToolTipListModel} for for @Doc'field of all given - * 'Result' script field value (we must find back the field name... : - * <ul> - * <li>text : the value of the field</li> - * <li>tooltip : the nicely printed version of the @Doc associated - * to field</li> - * </ul> - * - * @param names Result script field names - * @return the model builded - */ - public static ToolTipListModel createResultFieldsModel(List<String> names) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!names.isEmpty()) { - try { - ScriptStorage storage = ScriptStorage - .getScript("ResultName.java"); - Class resultNameClass = storage.getCodeClass(); - // TODO: if we can't find class, perhaps try to parser Java source ? - Field[] fields = resultNameClass.getFields(); - Map<String, String> map = new TreeMap<String, String>(); - for (Field f : fields) { - String fieldName = f.getName(); - String fieldValue = (String) f.get(null); - if (names.contains(fieldValue)) { - map.put(fieldValue, fieldName); - } - } - for (String name : names) { - String fieldName = map.get(name); - texts.add(name); - Doc fieldDoc = storage.getFieldDoc(fieldName); - toolTips.add(ToolTipListModelFactory.asString(fieldDoc)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.doc.resultName"), eee); - } - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for @Doc'class of all given Export: - * <ul> - * <li>text : the name fo the export</li> - * <li>tooltip : the nicely printed version of the @Doc associated to - * class of the Export</li> - * </ul> - * - * @param names Export names to use - * @return the model builded - */ - public static ToolTipListModel createExportClassDocsModel(List<String> names) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!names.isEmpty()) { - try { - for (String name : names) { - ExportStorage storage = ExportStorage.getExport(name); - Doc classDoc = storage.getClassDoc(); - String description = storage.getDescription(); - // suppress .java extension - texts.add(name.substring(0, name.length() - 5)); - toolTips.add(ToolTipListModelFactory.asString(classDoc, - description)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.doc.export"), eee); - } - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for descriptions of given Rule names : - * <ul> - * <li>text : the name of the Rule</li> - * <li>tooltip : the description of the Rule</li> - * </ul> - * - * @param names Rule names - * @return the model builded - */ - public static ToolTipListModel createRuleDescriptionsModel( - List<String> names) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!names.isEmpty()) { - try { - for (String name : names) { - RuleStorage storage = RuleStorage.getRule(name); - Doc classDoc = storage.getClassDoc(); - String description = storage.getDescription(); - // suppress .java extension ? - texts.add(name.substring(0, name.length() - 5)); - toolTips.add(ToolTipListModelFactory.asString(classDoc, - description)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.doc.rule"), eee); - } - } - } - // we are using this in Combo and due to bug (I think) with index - // that is not filled, when coming in getListCellRendererComponent - // we must also give to model the objects of the model... - // TODO Fix this - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for descriptions of given Rules : - * <ul> - * <li>text : the name of the Rule</li> - * <li>tooltip : the description of the Rule</li> - * </ul> - * - * @param rules rules to use - * @param clearButton the clear button linked with list - * @param list the list containing the renderer - * @return the model builded - */ - public static ToolTipListModel createRuleDescriptionsModel2( - List<Rule> rules, JButton clearButton, JList list) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!rules.isEmpty()) { - try { - for (Rule rule : rules) { - String name = RuleStorage.getName(rule); - RuleStorage storage = RuleStorage.getRule(name); - String description = storage.getDescription(); - // suppress .java extension ? - texts.add(name); - toolTips.add(description); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.doc.rule"), eee); - } - } - } - ToolTipListModel listModel = new ToolTipListModel(texts, toolTips); - // should check if there is an already listener ? - SimulatorListeners.initButtonClearIfListNotEmpty(clearButton, list - .getModel()); - return listModel; - } - - /** - * Build a new {@link ToolTipListModel} for params of a given Rule : - * <ul> - * <li>text : the name fo the param fo the Rule</li> - * <li>tooltip : the nicely printed version of the @Doc associated to - * the param in the Rule</li> - * </ul> - * - * @param ruleName the selected rule name (we only use the first one) - * @return the model builded - */ - public static ToolTipListModel createRuleParamsModel(String ruleName) { - - if (log.isDebugEnabled()) { - log.debug("createRuleParamsModel for rules : " + ruleName); - } - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (StringUtils.isEmpty(ruleName)) { - return new ToolTipListModel(texts, toolTips); - } - - try { - RuleStorage storage = RuleStorage.getRule(ruleName); - Map<String, Class<?>> mapParams = storage.getParameterNames(); - - if (!mapParams.isEmpty()) { - for (String paramName : mapParams.keySet()) { - Doc fieldDoc = storage.getParamDoc(paramName); - texts.add(paramName); - toolTips.add(ToolTipListModelFactory.asString(fieldDoc)); - } - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.field", ruleName), eee); - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for descriptions of given - * AnalysePlans names : - * <ul> - * <li>text : the name of the AnalysePlan</li> - * <li>tooltip : the description of the AnalysePlan</li> - * </ul> - * - * @param names AnalysePlan names to use - * @return the model builded - */ - public static ToolTipListModel createAnalysePlanDescriptionsModel( - List<String> names) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (names.isEmpty()) { - return new ToolTipListModel(texts, toolTips); - } - - try { - for (String name : names) { - AnalysePlanStorage storage = AnalysePlanStorage - .getAnalysePlan(name); - Doc classDoc = storage.getClassDoc(); - String description = storage.getDescription(); - // suppress .java extension ? - texts.add(name.substring(0, name.length() - 5)); - toolTips.add(ToolTipListModelFactory.asString(classDoc, description)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.analyseplan"), eee); - } - } - // we are using this in Combo and due to bug (I think) with index - // that is not filled, when coming in getListCellRendererComponent - // we must also give to model the objects of the model... - // TODO Fix this - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for descriptions of given - * AnalysePlans : - * <ul> - * <li>text : the name of the AnalysePlan</li> - * <li>tooltip : the description of the AnalysePlan</li> - * </ul> - * - * @param plans plans to use - * @param clearButton clear button linked to list - * @param list list containing the renderer - * @return the model builded - */ - public static ToolTipListModel createAnalysePlanDescriptionsModel2( - List<AnalysePlan> plans, JButton clearButton, JList list) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!plans.isEmpty()) { - try { - // we are dealing with AnalysePlan objects - for (AnalysePlan analysePlan : plans) { - String name = AnalysePlanStorage.getName(analysePlan); - AnalysePlanStorage storage = AnalysePlanStorage - .getAnalysePlan(name); - Doc classDoc = storage.getClassDoc(); - String description = storage.getDescription(); - // suppress .java extension ? - texts.add(name); - toolTips.add(ToolTipListModelFactory.asString(classDoc, description)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.analyseplan"), eee); - } - } - } - ToolTipListModel listModel = new ToolTipListModel(texts, toolTips); - // should check if there is an already listener ? - SimulatorListeners.initButtonClearIfListNotEmpty(clearButton, list - .getModel()); - return listModel; - } - - /** - * Build a new {@link ToolTipListModel} for params of a given AnalysePlan : - * <ul> - * <li>text : the name fo the param fo the AnalysePlan</li> - * <li>tooltip : the nicely printed version of the @Doc associated to - * the param in the AnalysePlan</li> - * </ul> - * - * @param name the selected analyze plan name - * @return the model builded - */ - public static ToolTipListModel createAnalysePlanParamsModel(String name) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - if (name != null && !name.equals("")) { - try { - AnalysePlanStorage storage = AnalysePlanStorage - .getAnalysePlan(name); - Map<String, Class<?>> mapParams = storage.getParameterNames(); - - if (!mapParams.isEmpty()) { - for (String paramName : mapParams.keySet()) { - Doc fieldDoc = storage.getParamDoc(paramName); - texts.add(paramName); - toolTips.add(ToolTipListModelFactory.asString(fieldDoc)); - } - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.field.analyseplan", name), - eee); - } - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for params of a given {link SensitivityCalculator} : - * <ul> - * <li>text : the name fo the param fo the AnalysePlan</li> - * <li>tooltip : the nicely printed version of the @Doc associated to - * the param in the {link SensitivityCalculator}</li> - * </ul> - * - * @param sensitivityName the sensitivity calculator name - * @return the model builded - */ - public static ToolTipListModel createSensitivityParamsModel( - String sensitivityName) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - if (!StringUtils.isEmpty(sensitivityName)) { - try { - SensitivityStorage storage = SensitivityStorage - .getSensitivity(sensitivityName); - Map<String, Class<?>> mapParams = storage.getParameterNames(); - - if (!mapParams.isEmpty()) { - for (String paramName : mapParams.keySet()) { - Doc fieldDoc = storage.getParamDoc(paramName); - texts.add(paramName); - toolTips.add(ToolTipListModelFactory.asString(fieldDoc)); - } - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.field.sensitivitycalculator", - sensitivityName), eee); - } - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for params of a given {@link Export} : - * <ul> - * <li>text : the name fo the param fo the AnalysePlan</li> - * <li>tooltip : the nicely printed version of the @Doc associated to - * the param in the AnalysePlan</li> - * </ul> - * - * @param exportName the selected export name - * @return the model builded - */ - public static ToolTipListModel createExportParamsModel(String exportName) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - if (!StringUtils.isEmpty(exportName)) { - try { - ExportStorage storage = ExportStorage.getExport(exportName); - Map<String, Class<?>> mapParams = storage.getParameterNames(); - - if (!mapParams.isEmpty()) { - for (String paramName : mapParams.keySet()) { - Doc fieldDoc = storage.getParamDoc(paramName); - texts.add(paramName); - toolTips.add(ToolTipListModelFactory.asString(fieldDoc)); - } - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.field.export", - exportName), eee); - } - } - } - return new ToolTipListModel(texts, toolTips); - } - - /** - * Build a new {@link ToolTipListModel} for descriptions of given - * {@link Export} : - * <ul> - * <li>text : the name of the AnalysePlan</li> - * <li>tooltip : the description of the AnalysePlan</li> - * </ul> - * - * @param exports export to use - * @param clearButton clear button linked to list - * @param list list containing the renderer - * @return the model builded - */ - public static ToolTipListModel createExportDescriptionsModel2( - List<? extends Export> exports, JButton clearButton, JList list) { - - List<String> texts = new ArrayList<String>(); - List<String> toolTips = new ArrayList<String>(); - - if (!exports.isEmpty()) { - try { - // we are dealing with Export objects - for (Export export : exports) { - String name = ExportStorage.getName(export); - ExportStorage storage = ExportStorage.getExport(name); - Doc classDoc = storage.getClassDoc(); - String description = storage.getDescription(); - texts.add(name); - toolTips.add(ToolTipListModelFactory.asString(classDoc, description)); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.analyseplan"), eee); - } - } - } - ToolTipListModel listModel = new ToolTipListModel(texts, toolTips); - // should check if there is an already listener ? - SimulatorListeners.initButtonClearIfListNotEmpty(clearButton, list - .getModel()); - return listModel; - } - - /** - * Return HTML formatted tooltip. - * - * Use optional documentation (if any) or use @Doc's class doc. - * - * @param doc the doc to use - * @param optionalDocumentations optional documentation - * @return a string nicely print version - */ - protected static String asString(Doc doc, String... optionalDocumentations) { - - String tooltip = null; - - if (doc != null) { - StringBuilder sb = new StringBuilder(); - sb.append("<html>"); - if (!ArrayUtils.isEmpty(optionalDocumentations)) { - for (String optionalDocumentation : optionalDocumentations) { - sb.append("<p>" + optionalDocumentation + "</p>"); - } - } else { - sb.append("<p>" + doc.value() + "</p>"); - } - if (!StringUtils.isEmpty(doc.author())) { - sb.append("<p><b>author: </b>" + doc.author() + "</p>"); - } - if (!StringUtils.isEmpty(doc.date())) { - sb.append("<p><b>date: </b>" + doc.date() + "</p>"); - } - if (!StringUtils.isEmpty(doc.version())) { - sb.append("<p><b>version: </b>" + doc.version() + "</p>"); - } - sb.append("</html>"); - tooltip = sb.toString(); - - // replace all \n by <br/> - tooltip = tooltip.replace("\n", "<br/>"); - } - return tooltip; - } -}
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org