001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.layer; 003 004import org.openstreetmap.josm.gui.io.AbstractIOTask; 005import org.openstreetmap.josm.gui.io.AbstractUploadDialog; 006import org.openstreetmap.josm.gui.progress.ProgressMonitor; 007 008/** 009 * A modifiable layer. 010 * @since 7358 011 */ 012public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile { 013 014 /** 015 * Constructs a new {@code ModifiableLayer}. 016 * @param name Layer name 017 */ 018 public AbstractModifiableLayer(String name) { 019 super(name); 020 } 021 022 /** 023 * Determines if the layer is able to upload data and implements the 024 * {@code UploadToServer} interface. 025 * 026 * @return true if the layer is able to upload data; false, otherwise 027 */ 028 @Override 029 public boolean isUploadable() { 030 // Override if needed 031 return false; 032 } 033 034 /** 035 * Determines if the data managed by this layer needs to be uploaded to 036 * the server because it contains modified data. 037 * 038 * @return true if the data managed by this layer needs to be uploaded to 039 * the server because it contains modified data; false, otherwise 040 */ 041 @Override 042 public boolean requiresUploadToServer() { 043 // Override if needed 044 return false; 045 } 046 047 /** 048 * Determines if the data managed by this layer needs to be saved to 049 * a file. Only replies true if a file is assigned to this layer and 050 * if the data managed by this layer has been modified since the last 051 * save operation to the file. 052 * 053 * @return true if the data managed by this layer needs to be saved to a file 054 */ 055 @Override 056 public boolean requiresSaveToFile() { 057 // Override if needed 058 return false; 059 } 060 061 /** 062 * Determines if upload of data managed by this layer is discouraged. 063 * This feature allows to use "private" data layers. 064 * 065 * @return true if upload is discouraged for this layer; false, otherwise 066 */ 067 @Override 068 public boolean isUploadDiscouraged() { 069 // Override if needed 070 return false; 071 } 072 073 /** 074 * Determines if data managed by this layer has been modified. 075 * @return true if data has been modified; false, otherwise 076 */ 077 public abstract boolean isModified(); 078 079 /** 080 * Initializes the layer after a successful save of data to a file. 081 */ 082 @Override 083 public void onPostSaveToFile() { 084 // Override if needed 085 } 086 087 /** 088 * Initializes the layer after a successful upload to the server. 089 */ 090 @Override 091 public void onPostUploadToServer() { 092 // Override if needed 093 } 094 095 /** 096 * Creates a new {@code AbstractIOTask} for uploading data. 097 * @param monitor The progress monitor 098 * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable 099 */ 100 @Override 101 public AbstractIOTask createUploadTask(ProgressMonitor monitor) { 102 // Override if needed 103 return null; 104 } 105 106 /** 107 * Returns the upload dialog for this layer. 108 * @return the upload dialog for this layer, or {@code null} if not applicable 109 */ 110 @Override 111 public AbstractUploadDialog getUploadDialog() { 112 // Override if needed 113 return null; 114 } 115}