Changeset 29298 in osm for applications/editors


Ignore:
Timestamp:
2013-03-02T00:32:50+01:00 (12 years ago)
Author:
donvip
Message:

[josm_opendata] better handling of .ods files (management of repeated cells)

Location:
applications/editors/josm/plugins/opendata
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/includes/org/jopendocument/io/SaxContentUnmarshaller.java

    r28000 r29298  
    285285            final TableTableCell cell = new TableTableCell();
    286286            cell.setTableStyleName(attribs.getValue("table:style-name"));
    287             //cell.setTableNumberColumnsRepeated(attribs.getValue("table:number-columns-repeated"));
     287            cell.setTableNumberColumnsRepeated(attribs.getValue("table:number-columns-repeated"));
    288288            //cell.setTableNumberColumnsSpanned(attribs.getValue("table:number-columns-spanned"));
    289289            //cell.setTableNumberRowsSpanned(attribs.getValue("table:number-rows-spanned"));
  • applications/editors/josm/plugins/opendata/includes/org/jopendocument/model/table/TableTableCell.java

    r28000 r29298  
    2222    private TableTableColumn column;
    2323
     24    protected int tableNumberColumnsRepeated = 1;
     25   
    2426    protected String tableStyleName;
    2527
    2628    private TextP textP;
     29
     30    protected TableTableCell cloneCell() {
     31        final TableTableCell c = new TableTableCell();
     32
     33        c.tableNumberColumnsRepeated = this.tableNumberColumnsRepeated;
     34        c.tableStyleName = this.tableStyleName;
     35        c.textP = this.textP;
     36        return c;
     37    }
    2738
    2839    private void computeStyle() {
     
    4859    }
    4960
     61    /**
     62     * Gets the value of the tableNumberColumnsRepeated property.
     63     *
     64     */
     65    public int getTableNumberColumnsRepeated() {
     66        return this.tableNumberColumnsRepeated;
     67    }
     68   
    5069    public TextP getTextP() {
    5170        return this.textP;
     71    }
     72
     73    /**
     74     * Sets the value of the tableNumberColumnsRepeated property.
     75     *
     76     * @param value allowed object is {@link String }
     77     *
     78     */
     79    public void setTableNumberColumnsRepeated(final String value) {
     80        if (value != null) {
     81            this.tableNumberColumnsRepeated = Integer.valueOf(value);
     82        }
    5283    }
    5384
     
    6495
    6596    }
    66 
    6797
    6898    public void setTextP(final TextP p) {
  • applications/editors/josm/plugins/opendata/includes/org/jopendocument/model/table/TableTableRow.java

    r28000 r29298  
    1616package org.jopendocument.model.table;
    1717
     18import java.util.ArrayList;
     19import java.util.Collection;
    1820import java.util.Vector;
    1921
     
    2325public class TableTableRow {
    2426    static int count = 0;
    25 
     27    ArrayList<TableTableCell> allCells;
    2628
    2729    Vector<TableTableCell> cells = new Vector<TableTableCell>();
    2830
    2931    int id = 0;
    30 
     32   
    3133    protected int tableNumberRowsRepeated = 1;
    3234
     
    3941        this.cells.add(c);
    4042
     43    }
     44   
     45    /**
     46     * Compute AllCell except the last one
     47     */
     48    void computeAllCells() {
     49        this.allCells = new ArrayList<TableTableCell>();
     50        for (int index = 0; index < this.cells.size(); index++) {
     51            final TableTableCell c = this.cells.get(index);
     52            // for (TableTableCell c : cells) {
     53            //final int colPosition = this.allCells.size();
     54            int repeated = c.getTableNumberColumnsRepeated();
     55            // la derniere colonne n'est repétée que dans la limite de la zone d'impression
     56            // sinon, on s'en coltine des milliers
     57            if (index == this.cells.size() - 1) {
     58                //repeated = this.getTable().getPrintStopCol() - this.allCells.size() + 1;
     59                // Patch JOSM open data : do not care about last cell
     60                repeated = 0;
     61            }
     62            for (int i = 0; i < repeated; i++) {
     63             // Patch JOSM open data : do not care about column
     64                //final TableTableColumn col = this.table.getColumnAtPosition(colPosition + i);
     65                final TableTableCell cc = c.cloneCell();
     66                //cc.setRowAndColumn(this, col);
     67                this.allCells.add(cc);
     68            }
     69        }
     70        // }}
     71        // System.err.println("Computed:" + allCells.size() + " :" + allCells);
     72    }
     73   
     74    public Collection<TableTableCell> getAllCells() {
     75
     76        if (this.allCells == null) {
     77            this.computeAllCells();
     78        }
     79       
     80        return this.allCells;
    4181    }
    4282
     
    5696    // return cells;
    5797    // }
    58 
    5998
    6099    public String getText() {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsReader.java

    r28113 r29298  
    2424import org.jopendocument.model.office.OfficeSpreadsheet;
    2525import org.jopendocument.model.table.TableTable;
     26import org.jopendocument.model.table.TableTableCell;
    2627import org.jopendocument.model.table.TableTableRow;
     28import org.jopendocument.model.text.TextP;
    2729import org.openstreetmap.josm.data.osm.DataSet;
    2830import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    3638        private int rowIndex;
    3739       
    38         private static final String SEP = "TextP:\\[";
     40        private static final String SEP = "TextP:[";
    3941       
    4042        public OdsReader(SpreadSheetHandler handler) {
     
    7981                        List<String> result = new ArrayList<String>();
    8082                        boolean allFieldsBlank = true;
    81                         for (String text : row.getText().replaceFirst(SEP, "").replaceAll("\\]", "").replaceAll("null", SEP).split(SEP)) {
    82                                 result.add(text);
    83                                 if (allFieldsBlank && !text.isEmpty()) {
    84                                         allFieldsBlank = false;
    85                                 }
     83                        for (TableTableCell cell : row.getAllCells()) {
     84                            TextP textP = cell.getTextP();
     85                            String text = textP == null ? "" : textP.toString().replace(SEP, "").replace("]", "").replace("null", "").trim();
     86                result.add(text);
     87                if (allFieldsBlank && !text.isEmpty()) {
     88                    allFieldsBlank = false;
     89                }
    8690                        }
    8791                       
Note: See TracChangeset for help on using the changeset viewer.