Changeset 3908


Ignore:
Timestamp:
Oct 21, 2010, 11:47:37 AM (13 years ago)
Author:
Gregory Vincic
Message:

Refs #711. Added feature to use nested fieldsets within forms. These fieldsets may however not be shown or hidden.

Location:
trunk/client/servlet
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/gui/web/GUIConverter.java

    r3905 r3908  
    11/*
    22    $Id$
    3    
     3       
    44    Copyright (C) 2006 Gregory Vincic
    55    Copyright (C) 2007 Gregory Vincic, Olle Mansson
    6    
     6       
    77    Files are copyright by their respective authors. The contributions to
    88    files where copyright is not explicitly stated can be traced with the
    99    source code revision system.
    10    
     10       
    1111    This file is part of Proteios.
    1212    Available at http://www.proteios.org/
    13    
     13       
    1414    Proteios-2.x is free software; you can redistribute it and/or
    1515    modify it under the terms of the GNU General Public License
    1616    as published by the Free Software Foundation; either version 2
    1717    of the License, or (at your option) any later version.
    18    
     18       
    1919    Proteios is distributed in the hope that it will be useful,
    2020    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2121    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2222    GNU General Public License for more details.
    23    
     23       
    2424    You should have received a copy of the GNU General Public License
    2525    along with this program; if not, write to the Free Software
     
    132132    private String currentFormId = null;
    133133    private TypeUtil typeUtil = new TypeUtil();
    134    
     134       
    135135    public HttpServletRequest getRequest()
    136136    {
    137137        return request;
    138138    }
    139    
     139       
    140140    public void setRequest(HttpServletRequest request)
    141141    {
     
    143143        hf.setRequest(request);
    144144    }
    145    
     145       
    146146    public GUIConverter(String contextPath)
    147147    {
     
    151151        this.hf = new HtmlFactory(contextPath);
    152152    }
    153    
     153       
    154154    private Random r = new Random();
    155    
     155       
    156156    public Tag convert(Image img)
    157157    {
     
    238238        return div;
    239239    }
    240    
     240       
    241241    public Tag convert(IFrame obj)
    242242    {
     
    250250        return tag;
    251251    }
    252    
     252       
    253253    public Tag convert(Listing list)
    254254    {
     
    285285        return layout;
    286286    }
    287    
     287       
    288288    /**
    289289        * @param action
     
    302302        return sb.toString();
    303303    }
    304    
     304       
    305305    public Tag convert(org.proteios.gui.TreeMenu menu)
    306306    {
     
    314314        return layout.getRoot();
    315315    }
    316    
     316       
    317317    public Tag convert(org.proteios.gui.MainMenu menu)
    318318    {
    319319        Tag div, ul;
    320        
     320               
    321321        div = hf.newLayoutDiv();
    322322        ul = convert((org.proteios.gui.TreeMenu) menu);
    323        
     323               
    324324        div.add(ul);
    325325        return div;
    326326    }
    327    
     327       
    328328    public String convert(ClosePopup button)
    329329    {
    330330        return "closeAllVisiblePopups()";
    331331    }
    332    
     332       
    333333    public Tag<?> convert(ActionLink pageLink, String formId, boolean localize)
    334334    {
     
    347347        return tag;
    348348    }
    349    
     349       
    350350    /**
    351351        * Converts an ActionLink such that each parameter of the ActionLink is a
     
    383383        return js.toString();
    384384    }
    385    
     385       
    386386    public Tag convert(Scroller scroller, String formId)
    387387    {
     
    446446        return scrollBar.getRoot();
    447447    }
    448    
     448       
    449449    /**
    450450        * @param table to convert
     
    486486                    }
    487487                }
    488                
     488                               
    489489            }
    490490            scroller = table.getScroller();
     
    580580                        // Column display order select box
    581581                        Integer colDisplayOrder = col.getDisplayOrder();
    582                        
     582                                               
    583583                        if (ad.getKey().equals("Id"))
    584584                        {
     
    608608                            tr.newTd().add(displayOrderSelectBox);
    609609                        }
    610                                    
     610                                                           
    611611                        // Order by
    612612                        if (col.getDisplayFilter())
     
    893893        return layout.getRoot();
    894894    }
    895    
     895       
    896896    public Tag convert(org.proteios.gui.table.FolderTable table)
    897897    {
     
    943943        return layout.getRoot();
    944944    }
    945    
     945       
    946946    public Tr convert(Row row)
    947947    {
     
    962962        return tr;
    963963    }
    964    
     964       
    965965    public Tr convert(TreeRow row)
    966966    {
     
    989989        return tr;
    990990    }
    991    
     991       
    992992    public Tag convert(Separator sep)
    993993    {
    994994        return new Hr();
    995995    }
    996    
     996       
    997997    public <D extends Object> Tag convert(Cell<D> cell)
    998998    {
     
    10691069        return td;
    10701070    }
    1071    
     1071       
    10721072    public Tag convert(Column col)
    10731073    {
     
    10781078        return th;
    10791079    }
    1080    
     1080       
    10811081    public Tag convert(Column col, org.proteios.gui.table.Table table)
    10821082    {
     
    10991099        return th;
    11001100    }
    1101    
     1101       
    11021102    public Tag convert(Text txt)
    11031103    {
     
    11071107        return layout;
    11081108    }
    1109    
     1109       
    11101110    public Tag convert(TitledWindow win)
    11111111    {
     
    11501150        return window.getRoot();
    11511151    }
    1152    
     1152       
    11531153    @SuppressWarnings("unused")
    11541154    public Tag convert(Space space)
     
    11561156        return new Div().setClass("space");
    11571157    }
    1158    
     1158       
    11591159    public Tag convert(Message msg)
    11601160    {
     
    11631163        return layout.getRoot();
    11641164    }
    1165    
     1165       
    11661166    int idCounter = 0;
    11671167    String lastId = "";
    1168    
     1168       
    11691169    public String nextId()
    11701170    {
     
    11731173        return lastId;
    11741174    }
    1175    
     1175       
    11761176    public String getLastId()
    11771177    {
    11781178        return lastId;
    11791179    }
    1180    
     1180       
    11811181    public Tag convert(org.proteios.gui.Error err)
    11821182    {
     
    11851185        return layout.getRoot();
    11861186    }
    1187    
     1187       
    11881188    public Tag convert(org.proteios.gui.form.Form w)
    11891189    {
     
    11941194        Input field;
    11951195        AbstractLink defaultAction;
    1196        
     1196               
    11971197        layout = hf.newLayoutDiv();
    11981198        clearForm = false;
     
    12391239        return layout.getRoot();
    12401240    }
    1241    
     1241       
    12421242    public Tag convert(org.proteios.gui.form.Fieldset fs)
    12431243    {
    12441244        return convertFieldset(fs, null, false);
    12451245    }
    1246    
     1246       
    12471247    private int fieldsetId = 0;
    12481248    private int nextFieldsetId() { fieldsetId++; return fieldsetId; }
    1249 
     1249   
    12501250    private Tag convertFieldset(org.proteios.gui.form.Fieldset fs, Form form, Boolean useToggle)
    12511251    {
    12521252        Fieldset fieldset;
    12531253        Tag legend, title, fields, table, row, helpC, input;
    1254     Img btn;
     1254        Img btn;
    12551255        String subtitle;
    12561256        org.proteios.gui.form.Field field;
    12571257        String id = "fs" + nextFieldsetId();
    1258       String btnId = "btn" + id;
     1258        String btnId = "btn" + id;
    12591259        fieldset = new Fieldset();
    12601260        // Fieldset legend
    12611261        legend = fieldset.newDiv().setClass("legend");
    12621262        title = new Div().addClass("title");
    1263       if(useToggle)
    1264     {
    1265         legend.setOnClick("toggleFieldset('" + id + "')");   
    1266       btn = new Img();
    1267           btn.addClass("toggle");
    1268       btn.setId(btnId);
    1269       legend.add(btn);
    1270       btn.setSrc(fs.isOpen() ? "static/img/minus.gif" : "static/img/plus.gif");
    1271     }
    1272 
     1263        if(useToggle)
     1264        {
     1265            legend.setOnClick("toggleFieldset('" + id + "')");   
     1266            btn = new Img();
     1267            btn.addClass("toggle");
     1268            btn.setId(btnId);
     1269            legend.add(btn);
     1270            btn.setSrc(fs.isOpen() ? "static/img/minus.gif" : "static/img/plus.gif");
     1271        }
     1272       
    12731273        if (fs.getTitle()!= null)
    12741274        {
     
    12831283        }
    12841284        legend.add(title.getRoot());
    1285        
     1285               
    12861286        fields = fieldset.newDiv().setClass("fields");
    1287     fields.setId(id);
    1288     fields.setStyle("display: " + (fs.isOpen() ? "block" : "none"));
     1287        fields.setId(id);
     1288        fields.setStyle("display: " + (fs.isOpen() ? "block" : "none"));
    12891289        table = fields.newTable();
    12901290        for (org.proteios.gui.GUIElement f : fs.getFields())
    12911291        {
    1292             row = table.newTr();
    1293             // Label cell
    1294             if(f instanceof org.proteios.gui.form.Field)
    1295             {
    1296                 field = (org.proteios.gui.form.Field) f;
    1297                 row.newTd().addClass("label").newCData(locale.get(field.getLabel()));
    1298                 input = null;
    1299                 // Field cell
    1300                 if (f instanceof TextField)
    1301                 {
    1302                     input = convert((TextField<?>) f);
    1303                     if(((TextField<?>)field).isHidden())
    1304                     {
    1305                         row.addClass("hidden");
    1306                     }
    1307                 }
    1308                 else if (f instanceof PasswordField)
    1309                 {
    1310                     input = convert((PasswordField) f);
    1311                 }
    1312                 else if (f instanceof FileField)
    1313                 {
    1314                     if (form != null)
    1315                     {
    1316                         form.setMultipart();
    1317                     }
    1318                     input = convert((FileField) f);
    1319                 }
    1320                 else if (f instanceof TextArea)
    1321                 {
    1322                     input = convert((TextArea) f);
    1323                 }
    1324                 else if (f instanceof org.proteios.gui.form.Select)
    1325                 {
    1326                     input = convert((org.proteios.gui.form.Select) f);
    1327                     if (((org.proteios.gui.form.Select)f).isHidden() != null && ((org.proteios.gui.form.Select)f).isHidden())
    1328                     {
    1329                       row.addClass("hidden");
    1330                     }
    1331                 }
    1332                 else if (f instanceof org.proteios.gui.form.Checkbox)
    1333                 {
    1334                     input = convert((org.proteios.gui.form.Checkbox) f, false);
    1335                 }
    1336                    
    1337                 if (field.getParam().isRequired() ||
    1338                 (field.getParam() instanceof VString && ((VString) field.getParam()).getMinCharacterLength() > 0))
    1339                 {
    1340                     input.addClass("required");
    1341                 }
    1342                 if(input != null)
    1343                 {
    1344                     row.newTd().add(input);
    1345                 }
    1346                
    1347                 // Help and error field
    1348                 helpC = row.newTd();
    1349                 helpC.newDiv().addClass("error").add(hf.getFieldError(field));
    1350                 helpC.newDiv().addClass("help").newCData(field.getHelp());
    1351             }
    1352             if (f instanceof org.proteios.gui.table.Table)
    1353             {
    1354                 row.newTd().add(convert((org.proteios.gui.table.Table) f));
    1355             }
    1356                
     1292            addFieldAsRow(table, f, form);
    13571293        }
    13581294        return fieldset;
    13591295    }
    13601296   
     1297    private Tag addFieldAsRow(Tag table, org.proteios.gui.GUIElement f, Form form)
     1298    {
     1299        Tag legend, title, fields, row, helpC, input;
     1300        org.proteios.gui.form.Field field;
     1301        row = table.newTr();
     1302        // Label cell
     1303        if(f instanceof org.proteios.gui.form.Field)
     1304        {
     1305            field = (org.proteios.gui.form.Field) f;
     1306            row.newTd().addClass("label").newCData(locale.get(field.getLabel()));
     1307            input = null;
     1308            // Field cell
     1309            if (f instanceof TextField)
     1310            {
     1311                input = convert((TextField<?>) f);
     1312                if(((TextField<?>)field).isHidden())
     1313                {
     1314                    row.addClass("hidden");
     1315                }
     1316            }
     1317            else if (f instanceof PasswordField)
     1318            {
     1319                input = convert((PasswordField) f);
     1320            }
     1321            else if (f instanceof FileField)
     1322            {
     1323                if (form != null)
     1324                {
     1325                    form.setMultipart();
     1326                }
     1327                input = convert((FileField) f);
     1328            }
     1329            else if (f instanceof TextArea)
     1330            {
     1331                input = convert((TextArea) f);
     1332            }
     1333            else if (f instanceof org.proteios.gui.form.Select)
     1334            {
     1335                input = convert((org.proteios.gui.form.Select) f);
     1336                if (((org.proteios.gui.form.Select)f).isHidden() != null && ((org.proteios.gui.form.Select)f).isHidden())
     1337                {
     1338                    row.addClass("hidden");
     1339                }
     1340            }
     1341            else if (f instanceof org.proteios.gui.form.Checkbox)
     1342            {
     1343                input = convert((org.proteios.gui.form.Checkbox) f, false);
     1344            }
     1345                               
     1346            if (field.getParam().isRequired() ||
     1347            (field.getParam() instanceof VString && ((VString) field.getParam()).getMinCharacterLength() > 0))
     1348            {
     1349                input.addClass("required");
     1350            }
     1351            if(input != null)
     1352            {
     1353                row.newTd().add(input);
     1354            }
     1355                           
     1356            // Help and error field
     1357            helpC = row.newTd();
     1358            helpC.newDiv().addClass("error").add(hf.getFieldError(field));
     1359            helpC.newDiv().addClass("help").newCData(field.getHelp());
     1360        }
     1361        else if (f instanceof org.proteios.gui.table.Table)
     1362        {
     1363            row.newTd().add(convert((org.proteios.gui.table.Table) f));
     1364        }
     1365        else if (f instanceof org.proteios.gui.form.Fieldset)
     1366        {
     1367            org.proteios.gui.form.Fieldset subfs = (org.proteios.gui.form.Fieldset) f;
     1368            // Sub fieldsets are not allowed to have toggling feature
     1369            row.newTd().setAttribute(new Attribute("colspan", "2")).setClass("sublegend").newCData(subfs.getTitle().getTitle());
     1370            for (org.proteios.gui.GUIElement subf : subfs.getFields())
     1371            {
     1372                Tag subRow = addFieldAsRow(table, subf, form);
     1373          Tag labeltd = (Tag) subRow.getElements().get(0); // the td tag
     1374        labeltd.addClass("subfield");
     1375            }
     1376            table.newTr().newTd().setAttribute(new Attribute("colspan", "2")).setClass("subend").newBr();
     1377        }
     1378        return row;
     1379    }
     1380       
    13611381    private Tag convert(FileField f)
    13621382    {
     
    13691389        return in;
    13701390    }
    1371    
     1391       
    13721392    public Tag convert(org.proteios.gui.form.Select<?> select)
    13731393    {
     
    14041424        if (select.isHidden() != null && select.isHidden())
    14051425        {
    1406           selectTag.setAttribute(new Attribute("style", "display:none;"));
     1426            selectTag.setAttribute(new Attribute("style", "display:none;"));
    14071427        }
    14081428        selectTag.setOnChange("setNameField(this)");
     
    14311451        return field;
    14321452    }
    1433    
     1453       
    14341454    public Tag convert(ColumnContainer container)
    14351455    {
     
    14561476        return layout;
    14571477    }
    1458    
     1478       
    14591479    public Tag convert(org.proteios.gui.Empty empty)
    14601480    {
    14611481        return new Span().newCData("&nbsp;");
    14621482    }
    1463    
     1483       
    14641484    public Tag convert(RowContainer container)
    14651485    {
     
    14841504        return span;
    14851505    }
    1486    
     1506       
    14871507    private int treeLevel = 0;
    1488    
     1508       
    14891509    public Tag convert(Node node)
    14901510    {
     
    15571577                    childHref.addClass("last");
    15581578                }
    1559                
     1579                               
    15601580                if (first)
    15611581                first = false;
     
    15661586        return li;
    15671587    }
    1568    
     1588       
    15691589    /**
    15701590        * Convenience method for getting path to a bullet/spacer image file marking
     
    15951615        return iconPath;
    15961616    }
    1597    
     1617       
    15981618    /**
    15991619        * Converts a toolbar so that button clicks post the form referenced by
     
    16641684        return new CData("");
    16651685    }
    1666    
     1686       
    16671687    public Tag convert(org.proteios.gui.TabSet set)
    16681688    {
     
    16911711        return layout;
    16921712    }
    1693    
     1713       
    16941714    private Tag convert(org.proteios.gui.Tab tab, boolean convertTabContent)
    16951715    {
     
    17101730        return li;
    17111731    }
    1712    
     1732       
    17131733    private Tag convert(org.proteios.gui.form.TextArea f)
    17141734    {
     
    17271747        return in;
    17281748    }
    1729    
     1749       
    17301750    private String formatedValue(TextField<?> f)
    17311751    {
     
    17411761        return value;
    17421762    }
    1743    
     1763       
    17441764    private <D extends Object> Tag<?> convert(
    17451765    org.proteios.gui.form.TextField<D> f)
     
    17491769        Input in;
    17501770        Tag<?> field;
    1751        
     1771               
    17521772        // Format the value
    17531773        value = formatedValue(f);
    17541774        container = new CData("");
    1755        
     1775               
    17561776        in = null;
    17571777        type = "text";
     
    17801800        return container;
    17811801    }
    1782    
     1802       
    17831803    private Tag<?> convert(org.proteios.gui.form.PasswordField f)
    17841804    {
     
    17911811        return in;
    17921812    }
    1793    
     1813       
    17941814    public Tag<?> convert(org.proteios.gui.form.Checkbox<?> checkbox)
    17951815    {
    17961816        return convert(checkbox, false);
    17971817    }
    1798    
     1818       
    17991819    private Tag<?> convert(org.proteios.gui.form.Checkbox<?> checkbox,
    18001820    boolean inForm)
     
    18171837        return cbF;
    18181838    }
    1819    
     1839       
    18201840    public Tag<?> convert(org.proteios.gui.Toolbar toolbar)
    18211841    {
     
    18831903        return layout.getRoot();
    18841904    }
    1885    
     1905       
    18861906    public Tag<?> convert(org.proteios.gui.Button button)
    18871907    {
     
    19501970        return layout.getRoot();
    19511971    }
    1952    
     1972       
    19531973    public Tag<?> convert(org.proteios.gui.ButtonSet toolbar)
    19541974    {
     
    19571977        return layout;
    19581978    }
    1959    
     1979       
    19601980    public Tag<?> convert(org.proteios.gui.Title title)
    19611981    {
     
    19771997        return hx.getRoot();
    19781998    }
    1979    
     1999       
    19802000    @Override
    19812001    public Tag missingConverter(ConvertableElement obj)
     
    19872007        return div;
    19882008    }
    1989    
     2009       
    19902010    public void setLocale(Localizer locale)
    19912011    {
     
    19972017        }
    19982018    }
    1999    
     2019       
    20002020    public void setIconSet(Properties iconSet)
    20012021    {
  • trunk/client/servlet/www/static/css/layout2.jsp

    r3905 r3908  
    222222
    223223
     224.sublegend
     225{
     226  text-align: right;
     227  font-size: 0.8em;
     228  text-transform: uppercase;
     229    padding-top: 10px;
     230}
     231
     232
    224233div.form form div.legend
    225234{
Note: See TracChangeset for help on using the changeset viewer.