- Timestamp:
- 2019-11-03T15:13:20+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/PermissionPrefWithDefault.java
r12846 r15500 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Arrays; 6 import java.util.ArrayList; 7 import java.util.Collections; 7 8 import java.util.List; 9 import java.util.stream.Collectors; 8 10 9 11 import org.openstreetmap.josm.spi.preferences.Config; … … 17 19 */ 18 20 public class PermissionPrefWithDefault { 21 private static final List<PermissionPrefWithDefault> PREFS = new ArrayList<>(); 19 22 20 23 public static final PermissionPrefWithDefault LOAD_DATA = … … 47 50 public final String preferenceText; 48 51 52 /** 53 * Create a new {@code PermissionPrefWithDefault} 54 * 55 * @param pref The preference key for the permission 56 * @param defaultVal The default value of the preference 57 * @param preferenceText The text to show in UI objects 58 */ 49 59 public PermissionPrefWithDefault(String pref, boolean defaultVal, String preferenceText) { 50 60 this.pref = pref; … … 53 63 } 54 64 65 /** 66 * Determines if the action is allowed. 67 * @return true if the action is allowed 68 */ 55 69 public boolean isAllowed() { 56 70 return Config.getPref().getBoolean(pref, defaultVal); 57 71 } 58 72 73 /** 74 * Returns a non-modifiable list of permission preferences for Remote Control. 75 * @return A non-modifiable list of permission preferences for Remote Control 76 */ 59 77 public static List<PermissionPrefWithDefault> getPermissionPrefs() { 60 return Arrays.asList( 61 LOAD_DATA, IMPORT_DATA, OPEN_FILES, LOAD_IMAGERY, 62 CHANGE_SELECTION, CHANGE_VIEWPORT, 63 CREATE_OBJECTS, READ_PROTOCOL_VERSION); 78 return Collections.unmodifiableList(PREFS); 79 } 80 81 /** 82 * Adds a permission preference. 83 * @param pref The preference to add to the list returned by 84 * {@link PermissionPrefWithDefault#getPermissionPrefs} 85 * @since 15500 86 */ 87 public static void addPermissionPref(PermissionPrefWithDefault pref) { 88 if (pref.pref != null && PREFS.parallelStream().noneMatch(tPref -> pref.pref.equals(tPref.pref))) 89 PREFS.add(pref); 90 } 91 92 /** 93 * Removes a permission preference. 94 * @param pref The preference to remove from the list returned by 95 * {@link PermissionPrefWithDefault#getPermissionPrefs} 96 * 97 * @return see {@link List#removeAll} 98 * @since 15500 99 */ 100 public static boolean removePermissionPref(PermissionPrefWithDefault pref) { 101 List<PermissionPrefWithDefault> toRemove = Collections.emptyList(); 102 if (pref.pref != null) 103 toRemove = PREFS.parallelStream().filter(tPref -> pref.pref.equals(tPref.pref)) 104 .collect(Collectors.toList()); 105 return PREFS.removeAll(toRemove); 64 106 } 65 107 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r12620 r15500 20 20 import java.util.Map; 21 21 import java.util.Map.Entry; 22 import java.util.Optional; 22 23 import java.util.StringTokenizer; 23 24 import java.util.TreeMap; … … 127 128 } 128 129 handlers.put(commandWithSlash, handler); 129 } 130 } 131 132 /** Add default request handlers */ 130 try { 131 Optional.ofNullable(handler.getConstructor().newInstance().getPermissionPref()) 132 .ifPresent(PermissionPrefWithDefault::addPermissionPref); 133 } catch (ReflectiveOperationException | RuntimeException e) { 134 Logging.debug(e); 135 } 136 } 137 } 138 139 /** 140 * Add default request handlers and permission preferences (order is important) 141 */ 133 142 static { 134 143 addRequestHandlerClass(LoadAndZoomHandler.command, LoadAndZoomHandler.class, true); 135 144 addRequestHandlerClass(LoadAndZoomHandler.command2, LoadAndZoomHandler.class, true); 145 addRequestHandlerClass(LoadObjectHandler.command, LoadObjectHandler.class, true); 136 146 addRequestHandlerClass(LoadDataHandler.command, LoadDataHandler.class, true); 147 addRequestHandlerClass(ImportHandler.command, ImportHandler.class, true); 148 addRequestHandlerClass(OpenFileHandler.command, OpenFileHandler.class, true); 137 149 addRequestHandlerClass(ImageryHandler.command, ImageryHandler.class, true); 150 PermissionPrefWithDefault.addPermissionPref(PermissionPrefWithDefault.CHANGE_SELECTION); 151 PermissionPrefWithDefault.addPermissionPref(PermissionPrefWithDefault.CHANGE_VIEWPORT); 138 152 addRequestHandlerClass(AddNodeHandler.command, AddNodeHandler.class, true); 139 153 addRequestHandlerClass(AddWayHandler.command, AddWayHandler.class, true); 140 addRequestHandlerClass(ImportHandler.command, ImportHandler.class, true);141 154 addRequestHandlerClass(VersionHandler.command, VersionHandler.class, true); 142 addRequestHandlerClass(LoadObjectHandler.command, LoadObjectHandler.class, true);143 addRequestHandlerClass(OpenFileHandler.command, OpenFileHandler.class, true);144 155 addRequestHandlerClass(FeaturesHandler.command, FeaturesHandler.class, true); 145 156 }
Note:
See TracChangeset
for help on using the changeset viewer.