source: josm/trunk/src/org/openstreetmap/josm/gui/oauth/AbstractAuthorizationUI.java@ 6883

Last change on this file since 6883 was 6883, checked in by Don-vip, 10 years ago

fix some Sonar issues

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.oauth;
3
4import org.openstreetmap.josm.data.Preferences;
5import org.openstreetmap.josm.data.oauth.OAuthParameters;
6import org.openstreetmap.josm.data.oauth.OAuthToken;
7import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
8import org.openstreetmap.josm.tools.CheckParameterUtil;
9
10/**
11 * This is the abstract base class for the three authorisation UIs.
12 *
13 * @since 2746
14 */
15public abstract class AbstractAuthorizationUI extends VerticallyScrollablePanel {
16 /**
17 * The property name for the Access Token property
18 */
19 public static final String ACCESS_TOKEN_PROP = AbstractAuthorizationUI.class.getName() + ".accessToken";
20
21 private String apiUrl;
22 private final AdvancedOAuthPropertiesPanel pnlAdvancedProperties;
23 private OAuthToken accessToken;
24
25 protected void fireAccessTokenChanged(OAuthToken oldValue, OAuthToken newValue) {
26 firePropertyChange(ACCESS_TOKEN_PROP, oldValue, newValue);
27 }
28
29 /**
30 * Constructs a new {@code AbstractAuthorizationUI} for the given API URL.
31 * @param apiUrl The OSM API URL
32 * @since 5422
33 */
34 public AbstractAuthorizationUI(String apiUrl) {
35 pnlAdvancedProperties = new AdvancedOAuthPropertiesPanel();
36 setApiUrl(apiUrl);
37 }
38
39 /**
40 * Replies the URL of the OSM API for which this UI is currently trying to retrieve an OAuth
41 * Access Token
42 *
43 * @return the API URL
44 */
45 public String getApiUrl() {
46 return apiUrl;
47 }
48
49 /**
50 * Sets the URL of the OSM API for which this UI is currently trying to retrieve an OAuth
51 * Access Token
52 *
53 * @param apiUrl the api URL
54 */
55 public void setApiUrl(String apiUrl) {
56 this.apiUrl = apiUrl;
57 this.pnlAdvancedProperties.setApiUrl(apiUrl);
58 }
59
60 /**
61 * Replies the panel for entering advanced OAuth parameters (see {@link OAuthParameters})
62 *
63 * @return the panel for entering advanced OAuth parameters
64 * @see #getOAuthParameters()
65 */
66 protected AdvancedOAuthPropertiesPanel getAdvancedPropertiesPanel() {
67 return pnlAdvancedProperties;
68 }
69
70 /**
71 * Replies the current set of advanced OAuth parameters in this UI
72 *
73 * @return the current set of advanced OAuth parameters in this UI
74 */
75 public OAuthParameters getOAuthParameters() {
76 return pnlAdvancedProperties.getAdvancedParameters();
77 }
78
79 /**
80 * Replies the retrieved Access Token. null, if no Access Token was retrieved.
81 *
82 * @return the retrieved Access Token
83 */
84 public OAuthToken getAccessToken() {
85 return accessToken;
86 }
87
88 /**
89 * Sets the current Access Token. This will fire a property change event for {@link #ACCESS_TOKEN_PROP}
90 * if the access token has changed
91 *
92 * @param accessToken the new access token. null, to clear the current access token
93 */
94 protected void setAccessToken(OAuthToken accessToken) {
95 OAuthToken oldValue = this.accessToken;
96 this.accessToken = accessToken;
97 if (oldValue == null ^ this.accessToken == null) {
98 fireAccessTokenChanged(oldValue, this.accessToken);
99 } else if (oldValue == null && this.accessToken == null) {
100 // no change - don't fire an event
101 } else if (! oldValue.equals(this.accessToken)) {
102 fireAccessTokenChanged(oldValue, this.accessToken);
103 }
104 }
105
106 /**
107 * Replies true if this UI currently has an Access Token
108 *
109 * @return true if this UI currently has an Access Token
110 */
111 public boolean hasAccessToken() {
112 return accessToken != null;
113 }
114
115 /**
116 * Replies whether the user has chosen to save the Access Token in the JOSM
117 * preferences or not.
118 *
119 * @return true if the user has chosen to save the Access Token
120 */
121 public abstract boolean isSaveAccessTokenToPreferences();
122
123 /**
124 * Initializes the authorisation UI with preference values in <code>pref</code>.
125 *
126 * @param pref the preferences. Must not be null.
127 * @throws IllegalArgumentException thrown if pref is null
128 */
129 public void initFromPreferences(Preferences pref) throws IllegalArgumentException{
130 CheckParameterUtil.ensureParameterNotNull(pref, "pref");
131 pnlAdvancedProperties.initFromPreferences(pref);
132 }
133}
Note: See TracBrowser for help on using the repository browser.