Ticket #12462: ExtendedSaveLayersDialog.patch

File ExtendedSaveLayersDialog.patch, 19.7 KB (added by holgermappt, 10 years ago)
  • src/org/openstreetmap/josm/Main.java

     
    10451045                continue;
    10461046            }
    10471047            AbstractModifiableLayer odl = (AbstractModifiableLayer) l;
    1048             if ((odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged())) && odl.isModified()) {
     1048            if (odl.isModified() &&
     1049                    ((!odl.isSavable() && !odl.isUploadable()) ||
     1050                     odl.requiresSaveToFile() ||
     1051                     (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {
    10491052                layersWithUnmodifiedChanges.add(odl);
    10501053            }
    10511054        }
  • src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java

     
    5656
    5757        ActionMap am = getActionMap();
    5858        for (final JCheckBox b : checkBoxes) {
    59             add(b, GBC.eol().fill(GBC.HORIZONTAL));
    6059            b.setPreferredSize(new Dimension(b.getPreferredSize().width, 19));
    6160            b.addActionListener(al);
    6261            am.put(b.getText(), new AbstractAction() {
     
    6766                }
    6867            });
    6968        }
    70 
    71         setToolTipText(tr("<html>"+
    72             "Select which actions to perform for this layer, if you click the leftmost button.<br/>"+
    73             "Check \"upload\" to upload the changes to the OSM server.<br/>"+
    74             "Check \"Save\" to save the layer to the file specified on the left."+
    75             "</html>"));
    7669    }
    7770
    7871    protected void updateCheckboxes(Object v) {
     
    9083        }
    9184    }
    9285
     86    private void updatePanel(SaveLayerInfo info) {
     87        StringBuilder sb = new StringBuilder();
     88        sb.append("<html>");
     89        sb.append(tr("Select which actions to perform for this layer, if you click the leftmost button."));
     90        removeAll();
     91        if (info != null) {
     92            if (info.isUploadable()) {
     93                sb.append("<br/>");
     94                sb.append(tr("Check \"Upload\" to upload the changes to the OSM server."));
     95                add(checkBoxes[0], GBC.eol().fill(GBC.HORIZONTAL));
     96            }
     97            if (info.isSavable()) {
     98                sb.append("<br/>");
     99                sb.append(tr("Check \"Save\" to save the layer to the file specified on the left."));
     100                add(checkBoxes[1], GBC.eol().fill(GBC.HORIZONTAL));
     101            }
     102        }
     103        sb.append("</html>");
     104        setToolTipText(sb.toString());
     105    }
     106
    93107    @Override
    94108    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     109        updatePanel((SaveLayerInfo) value);
    95110        updateCheckboxes(value);
    96111        return this;
    97112    }
     
    137152
    138153    @Override
    139154    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
     155        updatePanel((SaveLayerInfo) value);
    140156        updateCheckboxes(value);
    141157        return this;
    142158    }
  • src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java

     
    8080        SaveLayerInfo info = (SaveLayerInfo) value;
    8181        StringBuilder sb = new StringBuilder();
    8282        sb.append("<html>")
    83           .append(addLblLayerName(info))
    84           .append("<br>");
    85         add(btnFileChooser, GBC.std());
    86         sb.append(addLblFilename(info))
    87           .append("</html>");
     83          .append(addLblLayerName(info));
     84        if (info.isSavable()) {
     85            add(btnFileChooser, GBC.std());
     86            sb.append("<br>")
     87              .append(addLblFilename(info));
     88        }
     89        sb.append("</html>");
    8890        setToolTipText(sb.toString());
    8991        return this;
    9092    }
     
    98100
    99101        StringBuilder sb = new StringBuilder();
    100102        sb.append("<html>")
    101           .append(addLblLayerName(info))
    102           .append("<br/>");
     103          .append(addLblLayerName(info));
    103104
    104         add(btnFileChooser, GBC.std());
    105         add(tfFilename, GBC.eol().fill(GBC.HORIZONTAL).insets(1, 0, 0, 0));
    106         tfFilename.selectAll();
     105        if (info.isSavable()) {
     106            add(btnFileChooser, GBC.std());
     107            add(tfFilename, GBC.eol().fill(GBC.HORIZONTAL).insets(1, 0, 0, 0));
     108            tfFilename.selectAll();
    107109
    108         sb.append(tfFilename.getToolTipText())
    109           .append("</html>");
     110            sb.append("<br>")
     111              .append(tfFilename.getToolTipText());
     112        }
     113        sb.append("</html>");
    110114        setToolTipText(sb.toString());
    111115        return this;
    112116    }
  • src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java

     
    4646    }
    4747
    4848    /**
     49     * Replies true if the layer can be saved to a file
     50     *
     51     * @return {@code true} if the layer can be saved to a file; {@code false} otherwise
     52     */
     53    public boolean isSavable() {
     54        return layer.isSavable();
     55    }
     56
     57    /**
     58     * Replies true if the layer can be uploaded to a server
     59     *
     60     * @return {@code true} if the layer can be uploaded to a server; {@code false} otherwise
     61     */
     62    public boolean isUploadable() {
     63        return layer.isUploadable();
     64    }
     65
     66    /**
    4967     * Replies true if preconditions should be checked before saving; false, otherwise
    5068     *
    5169     * @return true if preconditions should be checked before saving; false, otherwise
     
    8098     * @param doSaveToFile true to save; false, to skip saving
    8199     */
    82100    public void setDoSaveToFile(boolean doSaveToFile) {
    83         this.doSaveToFile = doSaveToFile;
     101        this.doSaveToFile = isSavable() ? doSaveToFile : false;
    84102    }
    85103
    86104    /**
     
    93111    }
    94112
    95113    /**
    96      * Sets whether this layer should be uploaded to a file
     114     * Sets whether this layer should be uploaded to a server
    97115     *
    98116     * @param doUploadToServer {@code true} to upload; {@code false}, to skip uploading
    99117     */
    100 
    101118    public void setDoUploadToServer(boolean doUploadToServer) {
    102         this.doUploadToServer = doUploadToServer;
     119        this.doUploadToServer = isUploadable() ? doUploadToServer : false;
    103120    }
    104121
    105122    /**
  • src/org/openstreetmap/josm/gui/io/SaveLayersModel.java

     
    102102
    103103    @Override
    104104    public void setValueAt(Object value, int row, int column) {
     105        final SaveLayerInfo info = this.layerInfo.get(row);
    105106        switch(column) {
    106107        case columnFilename:
    107             this.layerInfo.get(row).setFile((File) value);
    108             this.layerInfo.get(row).setDoSaveToFile(true);
     108            info.setFile((File) value);
     109            if (info.isSavable()) {
     110                info.setDoSaveToFile(true);
     111            }
    109112            break;
    110113        case columnActions:
    111114            boolean[] values = (boolean[]) value;
    112             this.layerInfo.get(row).setDoUploadToServer(values[0]);
    113             this.layerInfo.get(row).setDoSaveToFile(values[1]);
     115            info.setDoUploadToServer(values[0]);
     116            info.setDoSaveToFile(values[1]);
    114117            break;
    115118        }
    116119        fireTableDataChanged();
  • src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java

     
    4646                    sb.append(tr("Layer ''{0}'' has modifications which should be uploaded to the server.", info.getName()));
    4747
    4848                } else {
    49                     panel.add(pnlEmpty, defaultCellStyle);
     49                    if (info.isUploadable()) {
     50                        panel.add(pnlEmpty, defaultCellStyle);
     51                    }
    5052                    if (info.getLayer().requiresUploadToServer()) {
    5153                        sb.append(tr("Layer ''{0}'' has modifications which are discouraged to be uploaded.", info.getName()));
    5254                    } else {
     
    5355                        sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName()));
    5456                    }
    5557                }
     58
    5659                sb.append("<br/>");
    57 
    5860                if (info.getLayer().requiresSaveToFile()) {
    5961                    panel.add(needsSave, defaultCellStyle);
    6062                    sb.append(tr("Layer ''{0}'' has modifications which should be saved to its associated file ''{1}''.",
    6163                            info.getName(), info.getFile().toString()));
    6264                } else {
    63                     panel.add(pnlEmpty, defaultCellStyle);
     65                    if (info.isSavable()) {
     66                        panel.add(pnlEmpty, defaultCellStyle);
     67                    }
    6468                    sb.append(tr("Layer ''{0}'' has no modifications to be saved.", info.getName()));
    6569                }
    6670            }
  • src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java

     
    99 * A modifiable layer.
    1010 * @since 7358
    1111 */
    12 public abstract class AbstractModifiableLayer extends Layer {
     12public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile {
    1313
    1414    /**
    1515     * Constructs a new {@code ModifiableLayer}.
     
    2020    }
    2121
    2222    /**
     23     * Determines if the layer is able to upload data and implements the
     24     * {@code UploadToServer} interface.
     25     *
     26     * @return true if the layer is able to upload data; false, otherwise
     27     */
     28    @Override
     29    public boolean isUploadable() {
     30        // Override if needed
     31        return false;
     32    }
     33
     34    /**
    2335     * Determines if the data managed by this layer needs to be uploaded to
    2436     * the server because it contains modified data.
    2537     *
     
    2638     * @return true if the data managed by this layer needs to be uploaded to
    2739     * the server because it contains modified data; false, otherwise
    2840     */
     41    @Override
    2942    public boolean requiresUploadToServer() {
    3043        // Override if needed
    3144        return false;
     
    3952     *
    4053     * @return true if the data managed by this layer needs to be saved to a file
    4154     */
     55    @Override
    4256    public boolean requiresSaveToFile() {
    4357        // Override if needed
    4458        return false;
     
    5064     *
    5165     * @return true if upload is discouraged for this layer; false, otherwise
    5266     */
     67    @Override
    5368    public boolean isUploadDiscouraged() {
    5469        // Override if needed
    5570        return false;
     
    6479    /**
    6580     * Initializes the layer after a successful save of data to a file.
    6681     */
     82    @Override
    6783    public void onPostSaveToFile() {
    6884        // Override if needed
    6985    }
     
    7187    /**
    7288     * Initializes the layer after a successful upload to the server.
    7389     */
     90    @Override
    7491    public void onPostUploadToServer() {
    7592        // Override if needed
    7693    }
     
    8097     * @param monitor The progress monitor
    8198     * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable
    8299     */
     100    @Override
    83101    public AbstractIOTask createUploadTask(ProgressMonitor monitor) {
    84102        // Override if needed
    85103        return null;
     
    89107     * Returns the upload dialog for this layer.
    90108     * @return the upload dialog for this layer, or {@code null} if not applicable
    91109     */
     110    @Override
    92111    public AbstractUploadDialog getUploadDialog() {
    93112        // Override if needed
    94113        return null;
  • src/org/openstreetmap/josm/gui/layer/NoteLayer.java

     
    4747 * A layer to hold Note objects.
    4848 * @since 7522
    4949 */
    50 public class NoteLayer extends AbstractModifiableLayer implements MouseListener {
     50public class NoteLayer extends AbstractModifiableLayer implements MouseListener, UploadToServer, SaveToFile {
    5151
    5252    private final NoteData noteData;
    5353
     
    8585    }
    8686
    8787    @Override
     88    public boolean isUploadable() {
     89        return true;
     90    }
     91
     92    @Override
    8893    public boolean requiresUploadToServer() {
    8994        return isModified();
    9095    }
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

     
    107107 * @author imi
    108108 * @since 17
    109109 */
    110 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {
     110public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener, UploadToServer, SaveToFile {
    111111    /** Property used to know if this layer has to be saved on disk */
    112112    public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk";
    113113    /** Property used to know if this layer has to be uploaded */
     
    832832    }
    833833
    834834    @Override
     835    public boolean isUploadable() {
     836        return true;
     837    }
     838
     839    @Override
    835840    public boolean requiresUploadToServer() {
    836841        return requiresUploadToServer;
    837842    }
  • src/org/openstreetmap/josm/gui/layer/SaveToFile.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.layer;
     3
     4/**
     5 * Interface for layers that can save data to a file.
     6 */
     7public interface SaveToFile {
     8
     9    /**
     10     * Replies the savable state of the layer (i.e. if it can be saved through
     11     * a "File-&gt;Save" dialog).  A layer that implements the
     12     * {@code SaveToFile} interface must return {@code true}.
     13     *
     14     * @return {@code true} if the layer can be saved to a file; {@code false}, otherwise
     15     */
     16    public boolean isSavable();
     17
     18    /**
     19     * Determines if the data managed by this layer needs to be saved to
     20     * a file. Only replies true if a file is assigned to this layer and
     21     * if the data managed by this layer has been modified since the last
     22     * save operation to the file.
     23     *
     24     * @return {@code true} if the data managed by this layer needs to be saved to a file; {@code false}, otherwise
     25     */
     26    public boolean requiresSaveToFile();
     27
     28    /**
     29     * Initializes the layer after a successful save of data to a file.
     30     */
     31    public void onPostSaveToFile();
     32}
  • src/org/openstreetmap/josm/gui/layer/UploadToServer.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.layer;
     3
     4import org.openstreetmap.josm.gui.io.AbstractIOTask;
     5import org.openstreetmap.josm.gui.io.AbstractUploadDialog;
     6import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     7
     8/**
     9 * Interface for layers that can upload data.
     10 */
     11public interface UploadToServer {
     12
     13    /**
     14     * Determines if the layer is able to upload data and implements the
     15     * {@code UploadToServer} interface.  A layer that implements the
     16     * {@code UploadToServer} interface must return {@code true}.
     17     *
     18     * @return {@code true} if the layer is able to upload data; {@code false}, otherwise
     19     */
     20    public boolean isUploadable();
     21
     22    /**
     23     * Determines if the data managed by this layer needs to be uploaded to
     24     * the server because it contains modified data.
     25     *
     26     * @return {@code true} if the data managed by this layer needs to be
     27     *         uploaded to the server because it contains modified data;
     28     *         {@code false}, otherwise
     29     */
     30    public boolean requiresUploadToServer();
     31
     32    /**
     33     * Determines if upload of data managed by this layer is discouraged.
     34     * This feature allows to use "private" data layers.
     35     *
     36     * @return {@code true} if upload is discouraged for this layer; {@code false}, otherwise
     37     */
     38    public boolean isUploadDiscouraged();
     39
     40    /**
     41     * Initializes the layer after a successful upload to the server.
     42     */
     43    public void onPostUploadToServer();
     44
     45    /**
     46     * Creates a new {@code AbstractIOTask} for uploading data.
     47     * @param monitor The progress monitor
     48     * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable
     49     */
     50    public AbstractIOTask createUploadTask(ProgressMonitor monitor);
     51
     52    /**
     53     * Returns the upload dialog for this layer.
     54     * @return the upload dialog for this layer, or {@code null} if not applicable
     55     */
     56    public AbstractUploadDialog getUploadDialog();
     57}
  • src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

     
    5959import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer;
    6060import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker;
    6161import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
     62import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    6263import org.openstreetmap.josm.gui.layer.Layer;
    6364import org.openstreetmap.josm.gui.util.GuiHelper;
    6465import org.openstreetmap.josm.io.JpgImporter;
     
    6869/**
    6970 * Layer displaying geottaged pictures.
    7071 */
    71 public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {
     72public class GeoImageLayer extends AbstractModifiableLayer implements PropertyChangeListener, JumpToMarkerLayer {
    7273
    7374    private static List<Action> menuAdditions = new LinkedList<>();
    7475
     
    370371        return infoText();
    371372    }
    372373
     374    /**
     375     * Determines if data managed by this layer has been modified.  That is
     376     * the case if one image has modified GPS data.
     377     * @return {@code true} if data has been modified; {@code false}, otherwise
     378     */
    373379    @Override
     380    public boolean isModified() {
     381        if (data != null) {
     382            for (ImageEntry e : data) {
     383                if (e.hasNewGpsData()) {
     384                    return true;
     385                }
     386            }
     387        }
     388        return false;
     389    }
     390
     391    @Override
    374392    public boolean isMergable(Layer other) {
    375393        return other instanceof GeoImageLayer;
    376394    }