DialogFormField.java

  1. /*
  2.  * Copyright (C) 2003-2008 eXo Platform SAS.
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Affero General Public License
  6.  * as published by the Free Software Foundation; either version 3
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, see<http://www.gnu.org/licenses/>.
  16.  */
  17. package org.exoplatform.ecm.webui.form;

  18. import java.util.HashMap;

  19. import org.exoplatform.services.cms.JcrInputProperty;
  20. import org.exoplatform.webui.form.UIFormInputBase;

  21. /**
  22.  * Created by The eXo Platform SAS
  23.  * @author : Hoa.Pham
  24.  *          hoa.pham@exoplatform.com
  25.  * Jun 23, 2008
  26.  */
  27. public abstract class DialogFormField {

  28.   protected final String SEPARATOR = "=";
  29.   protected final String JCR_PATH = "jcrPath" + SEPARATOR;
  30.   protected final String EDITABLE = "editable" + SEPARATOR;
  31.   protected final String ONCHANGE = "onchange" + SEPARATOR;
  32.   protected final String OPTIONS = "options" + SEPARATOR;
  33.   protected final String TYPE = "type" + SEPARATOR ;
  34.   protected final String VISIBLE = "visible" + SEPARATOR;
  35.   protected final String NODETYPE = "nodetype" + SEPARATOR;
  36.   protected final String MIXINTYPE = "mixintype" + SEPARATOR;
  37.   protected final String MIMETYPE = "mimetype" + SEPARATOR;
  38.   protected final String VALIDATE = "validate" + SEPARATOR;
  39.   protected final String SELECTOR_ACTION = "selectorAction" + SEPARATOR;
  40.   protected final String SELECTOR_CLASS = "selectorClass" + SEPARATOR;
  41.   protected final String SELECTOR_ICON = "selectorIcon" + SEPARATOR;
  42.   protected final String SELECTOR_PARAMS = "selectorParams" + SEPARATOR;
  43.   protected final String WORKSPACE_FIELD = "workspaceField" + SEPARATOR;
  44.   protected final String SCRIPT = "script" + SEPARATOR;
  45.   protected final String SCRIPT_PARAMS = "scriptParams" + SEPARATOR;
  46.   protected final String MULTI_VALUES = "multiValues" + SEPARATOR;
  47.   protected final String REFERENCE = "reference" + SEPARATOR;
  48.   protected final String REPOSITORY = "repository";
  49.   protected final String DEFAULT_VALUES = "defaultValues" + SEPARATOR ;
  50.   protected final String ROW_SIZE = "rows" + SEPARATOR ;
  51.   protected final String COL_SIZE = "columns" + SEPARATOR ;
  52.   protected final String SIZE = "size" + SEPARATOR ;
  53.   protected final String CHANGE_IN_JCR_PATH_PARAM = "changeInJcrPathParam" + SEPARATOR;
  54.   protected final String FILL_JCR_DATA_OF_FILE = "fillJcrDataOfFile" + SEPARATOR;

  55.   protected String editable;
  56.   protected String defaultValue;
  57.   protected String rowSize;
  58.   protected String colSize;
  59.   protected String jcrPath;
  60.   protected String selectorAction;
  61.   protected String selectorClass;
  62.   protected String workspaceField;
  63.   protected String selectorIcon;
  64.   protected String multiValues;
  65.   protected String reference;
  66.   protected String validateType;
  67.   protected String selectorParams;
  68.   protected String name;
  69.   protected String label;
  70.   protected String options;
  71.   protected String visible;
  72.   protected String nodeType;
  73.   protected String mixinTypes;
  74.   protected String mimeTypes;
  75.   protected String onchange;
  76.   protected String groovyScript;
  77.   protected String[] scriptParams;
  78.   protected String type;
  79.   protected String size;
  80.   protected String changeInJcrPathParam;
  81.   protected String fillJcrDataOfFile = "true";

  82.   public DialogFormField(String name, String label, String[] arguments) {
  83.     HashMap<String,String> parsedArguments = parseArguments(arguments) ;
  84.     this.editable = parsedArguments.get(EDITABLE);
  85.     this.defaultValue = parsedArguments.get(DEFAULT_VALUES);
  86.     this.rowSize = parsedArguments.get(ROW_SIZE);
  87.     this.colSize = parsedArguments.get(COL_SIZE);
  88.     this.jcrPath = parsedArguments.get(JCR_PATH);
  89.     this.selectorAction = parsedArguments.get(SELECTOR_ACTION);
  90.     this.selectorClass = parsedArguments.get(SELECTOR_CLASS);
  91.     this.workspaceField = parsedArguments.get(WORKSPACE_FIELD);
  92.     this.selectorIcon = parsedArguments.get(SELECTOR_ICON);
  93.     this.multiValues = parsedArguments.get(MULTI_VALUES);
  94.     this.reference = parsedArguments.get(REFERENCE);
  95.     this.validateType = parsedArguments.get(VALIDATE);
  96.     this.selectorParams = parsedArguments.get(SELECTOR_PARAMS) ;
  97.     this.options = parsedArguments.get(OPTIONS);
  98.     this.visible = parsedArguments.get(VISIBLE);
  99.     this.nodeType = parsedArguments.get(NODETYPE);
  100.     this.mixinTypes = parsedArguments.get(MIXINTYPE);
  101.     this.mimeTypes = parsedArguments.get(MIMETYPE);
  102.     this.onchange = parsedArguments.get(ONCHANGE);
  103.     this.groovyScript = parsedArguments.get(SCRIPT);
  104.     this.type = parsedArguments.get(TYPE);
  105.     this.size = parsedArguments.get(SIZE);
  106.     this.changeInJcrPathParam = parsedArguments.get(CHANGE_IN_JCR_PATH_PARAM);
  107.     this.fillJcrDataOfFile = parsedArguments.get(FILL_JCR_DATA_OF_FILE);
  108.     String scriptParam = parsedArguments.get(SCRIPT_PARAMS);
  109.     if(scriptParam != null) {
  110.       scriptParams = scriptParam.split(",");
  111.     }
  112.     this.name = name;
  113.     this.label = label;
  114.   }

  115.   @SuppressWarnings("unchecked")
  116.   public abstract <T extends UIFormInputBase> T createUIFormInput() throws Exception;

  117.   public JcrInputProperty createJcrInputProperty (){
  118.     JcrInputProperty inputProperty = new JcrInputProperty();
  119.     inputProperty.setJcrPath(jcrPath);
  120.     return inputProperty;
  121.   }

  122.   public String getEditable() { return editable; }
  123.   public void setEditable(String editable) { this.editable = editable; }

  124.   public String getDefaultValue() { return defaultValue; }
  125.   public void setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; }

  126.   public String getRowSize() { return rowSize; }
  127.   public void setRowSize(String rowSize) { this.rowSize = rowSize; }

  128.   public String getColSize() { return colSize; }
  129.   public void setColSize(String colSize) { this.colSize = colSize; }

  130.   public String getJcrPath() { return jcrPath; }
  131.   public void setJcrPath(String jcrPath) { this.jcrPath = jcrPath; }

  132.   public String getSelectorAction() { return selectorAction; }
  133.   public void setSelectorAction(String selectorAction) {
  134.     this.selectorAction = selectorAction;
  135.   }

  136.   public String getSelectorClass() { return selectorClass; }
  137.   public void setSelectorClass(String selectorClass) {
  138.     this.selectorClass = selectorClass;
  139.   }

  140.   public String getWorkspaceField() { return workspaceField; }
  141.   public void setWorkspaceField(String workspaceField) {
  142.     this.workspaceField = workspaceField;
  143.   }

  144.   public String getSelectorIcon() {  return selectorIcon; }
  145.   public void setSelectorIcon(String selectorIcon) {
  146.     this.selectorIcon = selectorIcon;
  147.   }

  148.   public String getMultiValues() { return multiValues; }
  149.   public void setMultiValues(String multiValues) {
  150.     this.multiValues = multiValues;
  151.   }

  152.   public String getReference() { return reference; }
  153.   public void setReferenceType(String reference) {
  154.     this.reference = reference;
  155.   }

  156.   public String getValidateType() { return validateType; }
  157.   public void setValidateType(String validateType) {
  158.     this.validateType = validateType;
  159.   }

  160.   public String[] getSelectorParams() {
  161.     if(selectorParams != null) {
  162.       return selectorParams.split(",");
  163.     }
  164.     return null;
  165.   }

  166.   public String getSelectorParam() { return selectorParams; }
  167.   public void setSelectorParam(String param) { this.selectorParams = param; }

  168.   public String getName() { return name; }
  169.   public void setName(String name) { this.name = name; }

  170.   public String getLabel() { return label; }
  171.   public void setLabel(String label) {this.label = label;}

  172.   public String getOptions() { return options; }
  173.   public void setOptions(String options) { this.options = options; }

  174.   public String getVisible() { return visible;}
  175.   public void setVisible(String visible) {this.visible = visible; }

  176.   public String getNodeType() { return nodeType; }
  177.   public void setNodeType(String nodeType) { this.nodeType = nodeType; }

  178.   public String getMixinTypes() { return mixinTypes; }
  179.   public void setMixinTypes(String mixinTypes) { this.mixinTypes = mixinTypes; }
  180.  
  181.   public String getMimeTypes() { return mimeTypes; }
  182.   public void setMimeTypes(String mimeTypes) { this.mimeTypes = mimeTypes; }

  183.   public String getOnchange() { return onchange; }
  184.   public void setOnchange(String onchange) { this.onchange = onchange; }

  185.   public String getGroovyScript() { return groovyScript; }
  186.   public void setGroovyScript(String groovyScript) { this.groovyScript = groovyScript; }

  187.   public String[] getScriptParams() { return scriptParams; }
  188.   public void setScriptParams(String[] scriptParams) { this.scriptParams = scriptParams; }

  189.   public String getType() { return type; }
  190.   public void setType(String type) { this.type = type;}

  191.   public String getSize() { return size; }
  192.   public void setSize(String size) { this.size = size;}
  193.  
  194.   public String getChangeInJcrPathParam() { return changeInJcrPathParam; }
  195.   public void setChangeInJcrPathParam(String value) { this.changeInJcrPathParam = value; }
  196.  
  197.   public String getFillJcrDataFile() { return fillJcrDataOfFile; }
  198.   public void setFillJcrDataFile(String value) { fillJcrDataOfFile = value; }

  199.   public boolean isMultiValues() { return "true".equalsIgnoreCase(multiValues); }
  200.   public boolean isReference() { return "true".equalsIgnoreCase(reference); }
  201.   public boolean isEditable() { return !"false".equalsIgnoreCase(editable); }
  202.   public boolean isEditableIfNull() { return "if-null".equalsIgnoreCase(editable); }
  203.   public boolean isVisibleIfNotNull() { return "if-not-null".equals(visible); }
  204.   public boolean isFillJcrDataFile() {
  205.     return "true".equals(fillJcrDataOfFile) || fillJcrDataOfFile == null;
  206.   }

  207.   private HashMap<String,String> parseArguments(String[] arguments) {
  208.     HashMap<String,String> map = new HashMap<String,String>() ;
  209.     for(String argument:arguments) {
  210.       String value = null;
  211.       if(argument.indexOf(SEPARATOR)>0) {
  212.         value = argument.substring(argument.indexOf(SEPARATOR)+1) ;
  213.       }else {
  214.         value = argument;
  215.         map.put(DEFAULT_VALUES,value) ; continue;
  216.       }
  217.       if (argument.startsWith(JCR_PATH)) {
  218.         map.put(JCR_PATH,value); continue;
  219.       } else if (argument.startsWith(EDITABLE)) {
  220.         map.put(EDITABLE,value); continue;
  221.       } else if (argument.startsWith(SELECTOR_ACTION)) {
  222.         map.put(SELECTOR_ACTION,value) ; continue;
  223.       } else if (argument.startsWith(SELECTOR_CLASS)) {
  224.         map.put(SELECTOR_CLASS,value); continue;
  225.       } else if (argument.startsWith(MULTI_VALUES)) {
  226.         map.put(MULTI_VALUES,value); continue;
  227.       } else if (argument.startsWith(SELECTOR_ICON)) {
  228.         map.put(SELECTOR_ICON,value); continue;
  229.       } else if (argument.startsWith(SELECTOR_PARAMS)) {
  230.         map.put(SELECTOR_PARAMS,value); continue;
  231.       }else if (argument.startsWith(WORKSPACE_FIELD)) {
  232.         map.put(WORKSPACE_FIELD,value); continue;
  233.       } else if (argument.startsWith(VALIDATE)) {
  234.         map.put(VALIDATE,value); continue;
  235.       } else if (argument.startsWith(REFERENCE)) {
  236.         map.put(REFERENCE, value); continue;
  237.       } else if(argument.startsWith(DEFAULT_VALUES)) {
  238.         map.put(DEFAULT_VALUES,value); continue;
  239.       } else if(argument.startsWith(ROW_SIZE)) {
  240.         map.put(ROW_SIZE,value); continue;
  241.       } else if(argument.startsWith(COL_SIZE)) {
  242.         map.put(COL_SIZE,value); continue;
  243.       } else if(argument.startsWith(OPTIONS)){
  244.         map.put(OPTIONS,value);  continue;
  245.       } else if(argument.startsWith(SCRIPT)) {
  246.         map.put(SCRIPT,value); continue;
  247.       } else if(argument.startsWith(SCRIPT_PARAMS)){
  248.         map.put(SCRIPT_PARAMS,value); continue;
  249.       } else if(argument.startsWith(VISIBLE)){
  250.         map.put(VISIBLE,value); continue;
  251.       } else if(argument.startsWith(TYPE)){
  252.         map.put(TYPE,value) ; continue;
  253.       } else if(argument.startsWith(ONCHANGE)){
  254.         map.put(ONCHANGE,value); continue;
  255.       } else if (argument.startsWith(MIXINTYPE)) {
  256.         map.put(MIXINTYPE, value); continue;
  257.       } else if (argument.startsWith(MIMETYPE)) {
  258.         map.put(MIMETYPE, value); continue;
  259.       } else if(argument.startsWith(NODETYPE)) {
  260.         map.put(NODETYPE, value) ;
  261.         continue ;
  262.       } else if(argument.startsWith(SIZE)) {
  263.         map.put(SIZE, value) ;
  264.         continue ;
  265.       } else if (argument.startsWith(CHANGE_IN_JCR_PATH_PARAM)) {
  266.         map.put(CHANGE_IN_JCR_PATH_PARAM, value);
  267.         continue;
  268.       } else if (argument.startsWith(FILL_JCR_DATA_OF_FILE)) {
  269.         map.put(FILL_JCR_DATA_OF_FILE, value);
  270.         continue;
  271.       } else {
  272.         map.put(DEFAULT_VALUES,argument);
  273.       }
  274.     }
  275.     return map;
  276.   }
  277. }