| 1 |
|
| 2 |
package org.openstreetmap.josm.gui.oauth; |
| 3 |
|
| 4 |
import java.util.Objects; |
| 5 |
|
| 6 |
import org.openstreetmap.josm.data.oauth.IOAuthParameters; |
| 7 |
import org.openstreetmap.josm.data.oauth.IOAuthToken; |
| 8 |
import org.openstreetmap.josm.data.oauth.OAuthParameters; |
| 9 |
import org.openstreetmap.josm.data.oauth.OAuthVersion; |
| 10 |
import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; |
| 11 |
import org.openstreetmap.josm.tools.CheckParameterUtil; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public abstract class AbstractAuthorizationUI extends VerticallyScrollablePanel { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public static final String ACCESS_TOKEN_PROP = AbstractAuthorizationUI.class.getName() + ".accessToken"; |
| 23 |
|
| 24 |
private String apiUrl; |
| 25 |
private final AdvancedOAuthPropertiesPanel pnlAdvancedProperties; |
| 26 |
private transient IOAuthToken accessToken; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
protected AbstractAuthorizationUI(String apiUrl, OAuthVersion oAuthVersion) { |
| 35 |
this.pnlAdvancedProperties = new AdvancedOAuthPropertiesPanel(oAuthVersion); |
| 36 |
if (apiUrl != null) { |
| 37 |
setApiUrl(apiUrl); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
protected void fireAccessTokenChanged(IOAuthToken oldValue, IOAuthToken newValue) { |
| 42 |
firePropertyChange(ACCESS_TOKEN_PROP, oldValue, newValue); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public String getApiUrl() { |
| 52 |
return apiUrl; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public void setApiUrl(String apiUrl) { |
| 62 |
this.apiUrl = apiUrl; |
| 63 |
this.pnlAdvancedProperties.setApiUrl(apiUrl); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
protected AdvancedOAuthPropertiesPanel getAdvancedPropertiesPanel() { |
| 73 |
return pnlAdvancedProperties; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public IOAuthParameters getOAuthParameters() { |
| 82 |
return pnlAdvancedProperties.getAdvancedParameters(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public IOAuthToken getAccessToken() { |
| 91 |
return accessToken; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
protected void setAccessToken(IOAuthToken accessToken) { |
| 101 |
IOAuthToken oldValue = this.accessToken; |
| 102 |
this.accessToken = accessToken; |
| 103 |
if (oldValue == null ^ this.accessToken == null) { |
| 104 |
fireAccessTokenChanged(oldValue, this.accessToken); |
| 105 |
} else if (oldValue == null && this.accessToken == null) { |
| 106 |
|
| 107 |
} else if (!Objects.equals(oldValue, this.accessToken)) { |
| 108 |
fireAccessTokenChanged(oldValue, this.accessToken); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public OAuthVersion getOAuthVersion() { |
| 118 |
return this.pnlAdvancedProperties.getAdvancedParameters().getOAuthVersion(); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public boolean hasAccessToken() { |
| 127 |
return accessToken != null; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public abstract boolean isSaveAccessTokenToPreferences(); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public void initialize(String paramApiUrl) { |
| 145 |
CheckParameterUtil.ensureParameterNotNull(paramApiUrl, "paramApiUrl"); |
| 146 |
pnlAdvancedProperties.initialize(paramApiUrl); |
| 147 |
} |
| 148 |
} |