| 195 | | // re-writes fedora-admin.properties with latest values for servers |
|---|
| 196 | | // and usernames |
|---|
| 197 | | |
|---|
| | 189 | |
|---|
| | 190 | public void saveProperties(JComboBox control, String affectedProperty, String editedValue) { |
|---|
| | 191 | //String editedValue = (String)control.getSelectedItem(); |
|---|
| | 192 | // Edited value is the value in the combobox editfield, it has not yet been added to the combobox |
|---|
| | 193 | control.insertItemAt(editedValue, 0); |
|---|
| | 194 | |
|---|
| | 195 | if(editedValue == null) { |
|---|
| | 196 | editedValue = (String)control.getItemAt(0); // else reuse the first default |
|---|
| | 197 | } |
|---|
| | 198 | Configuration.setString(affectedProperty, true, editedValue); |
|---|
| | 199 | |
|---|
| | 200 | // Add the values in the combobox as well. |
|---|
| | 201 | int value_count = 1; |
|---|
| | 202 | for(int i = 0; value_count < MAX_ITEMS && i < control.getItemCount(); i++, value_count++) { |
|---|
| | 203 | String value = (String)control.getItemAt(i); |
|---|
| | 204 | if(value == null || value.equals(editedValue) || value.equals("")) { |
|---|
| | 205 | // skip duplicates of just-edited comboBox value and empty values |
|---|
| | 206 | value_count--; |
|---|
| | 207 | } else { |
|---|
| | 208 | Configuration.setString(affectedProperty+value_count, true, value); |
|---|
| | 209 | } // else retain old value for this affectedProperty (e.g. general.gliserver_url) |
|---|
| | 210 | } |
|---|
| | 211 | } |
|---|
| | 212 | |
|---|
| | 213 | private void setComboBoxValues() { |
|---|
| | 214 | // All comboboxes are of the same size |
|---|
| | 215 | Dimension newSize=new Dimension(m_serverComboBox.getPreferredSize().width+20, m_serverComboBox.getPreferredSize().height); |
|---|
| | 216 | m_passwordField.setPreferredSize(newSize); |
|---|
| | 217 | |
|---|
| | 218 | setComboBoxValues(m_serverComboBox, "fedora.server", newSize); |
|---|
| | 219 | setComboBoxValues(m_protocolComboBox, "fedora.protocol", newSize); |
|---|
| | 220 | setComboBoxValues(m_usernameComboBox, "fedora.username", newSize); |
|---|
| | 221 | newSize = null; |
|---|
| | 222 | } |
|---|
| 199 | | public void saveProperties() { |
|---|
| 200 | | try { |
|---|
| 201 | | Properties props=new Properties(); |
|---|
| 202 | | props.setProperty("lastServer", m_lastServer); |
|---|
| 203 | | props.setProperty("lastProtocol", m_lastProtocol); |
|---|
| 204 | | props.setProperty("lastUsername", m_lastUsername); |
|---|
| 205 | | Iterator iter; |
|---|
| 206 | | int i; |
|---|
| 207 | | iter=m_servers.keySet().iterator(); |
|---|
| 208 | | i=0; |
|---|
| 209 | | while (iter.hasNext()) { |
|---|
| 210 | | String name=(String) iter.next(); |
|---|
| 211 | | props.setProperty("server" + i, name); |
|---|
| 212 | | i++; |
|---|
| 213 | | } |
|---|
| 214 | | iter=m_protocols.keySet().iterator(); |
|---|
| 215 | | i=0; |
|---|
| 216 | | while (iter.hasNext()) { |
|---|
| 217 | | String name=(String) iter.next(); |
|---|
| 218 | | props.setProperty("protocol" + i, name); |
|---|
| 219 | | i++; |
|---|
| 220 | | } |
|---|
| 221 | | iter=m_usernames.keySet().iterator(); |
|---|
| 222 | | i=0; |
|---|
| 223 | | while (iter.hasNext()) { |
|---|
| 224 | | String name=(String) iter.next(); |
|---|
| 225 | | props.setProperty("username" + i, name); |
|---|
| 226 | | i++; |
|---|
| 227 | | } |
|---|
| 228 | | props.store(new FileOutputStream(new File(Gatherer.getGLIUserDirectoryPath(), "fedora-admin.properties")), "Fedora Administrator saved settings"); |
|---|
| 229 | | } catch (Exception e) { |
|---|
| 230 | | System.err.println("Warning: Error writing properties: " |
|---|
| 231 | | + e.getClass().getName() + ": " + e.getMessage()); |
|---|
| 232 | | } |
|---|
| 233 | | } |
|---|
| 234 | | |
|---|
| 235 | | |
|---|
| 236 | | private void setComboBoxValues() { |
|---|
| 237 | | // get values from prop file, or use localhost:8080/fedoraAdmin if none |
|---|
| 238 | | try { |
|---|
| 239 | | Properties props=new Properties(); |
|---|
| 240 | | props.load(new FileInputStream(new File(Gatherer.getGLIUserDirectoryPath(), "fedora-admin.properties"))); |
|---|
| 241 | | Enumeration names=props.propertyNames(); |
|---|
| 242 | | while (names.hasMoreElements()) { |
|---|
| 243 | | String prop=(String) names.nextElement(); |
|---|
| 244 | | if (prop.equals("lastServer")) { |
|---|
| 245 | | m_lastServer=props.getProperty(prop); |
|---|
| 246 | | } else if (prop.equals("lastProtocol")) { |
|---|
| 247 | | m_lastProtocol=props.getProperty(prop); |
|---|
| 248 | | } else if (prop.equals("lastUsername")) { |
|---|
| 249 | | m_lastUsername=props.getProperty(prop); |
|---|
| 250 | | } else if (prop.startsWith("server")) { |
|---|
| 251 | | m_servers.put(props.getProperty(prop), ""); |
|---|
| 252 | | } else if (prop.startsWith("protocol")) { |
|---|
| 253 | | m_protocols.put(props.getProperty(prop), ""); |
|---|
| 254 | | } else if (prop.startsWith("username")) { |
|---|
| 255 | | m_usernames.put(props.getProperty(prop), ""); |
|---|
| 256 | | } |
|---|
| 257 | | } |
|---|
| 258 | | } catch (Exception e) { |
|---|
| 259 | | // no problem if props file doesn't exist...we have defaults |
|---|
| 260 | | } |
|---|
| 261 | | // finally, populate them |
|---|
| 262 | | m_serverComboBox.addItem(m_lastServer); |
|---|
| 263 | | Iterator sIter=m_servers.keySet().iterator(); |
|---|
| 264 | | while (sIter.hasNext()) { |
|---|
| 265 | | String a=(String) sIter.next(); |
|---|
| 266 | | if (!a.equals(m_lastServer)) { |
|---|
| 267 | | m_serverComboBox.addItem(a); |
|---|
| 268 | | } |
|---|
| 269 | | } |
|---|
| 270 | | m_servers.put(m_lastServer, ""); |
|---|
| 271 | | |
|---|
| 272 | | m_protocolComboBox.addItem(m_lastProtocol); |
|---|
| 273 | | Iterator protocolIter=m_protocols.keySet().iterator(); |
|---|
| 274 | | while (protocolIter.hasNext()) { |
|---|
| 275 | | String a=(String) protocolIter.next(); |
|---|
| 276 | | if (!a.equals(m_lastProtocol)) { |
|---|
| 277 | | m_protocolComboBox.addItem(a); |
|---|
| 278 | | } |
|---|
| 279 | | } |
|---|
| 280 | | m_protocols.put(m_lastProtocol, ""); |
|---|
| 281 | | |
|---|
| 282 | | m_usernameComboBox.addItem(m_lastUsername); |
|---|
| 283 | | Iterator uIter=m_usernames.keySet().iterator(); |
|---|
| 284 | | while (uIter.hasNext()) { |
|---|
| 285 | | String a=(String) uIter.next(); |
|---|
| 286 | | if (!a.equals(m_lastUsername)) { |
|---|
| 287 | | m_usernameComboBox.addItem(a); |
|---|
| 288 | | } |
|---|
| 289 | | } |
|---|
| 290 | | m_usernames.put(m_lastUsername, ""); |
|---|
| 291 | | |
|---|
| 292 | | // make all entry widgets same size |
|---|
| 293 | | Dimension newSize=new Dimension( |
|---|
| 294 | | m_serverComboBox.getPreferredSize().width+20, |
|---|
| 295 | | m_serverComboBox.getPreferredSize().height); |
|---|
| 296 | | m_serverComboBox.setPreferredSize(newSize); |
|---|
| 297 | | m_protocolComboBox.setPreferredSize(newSize); |
|---|
| 298 | | m_usernameComboBox.setPreferredSize(newSize); |
|---|
| 299 | | m_passwordField.setPreferredSize(newSize); |
|---|
| | 224 | private void setComboBoxValues(JComboBox control, String affectedProperty, Dimension newSize) { |
|---|
| | 225 | // get values from Configuration file, if none, it will go back to using defaultvalues |
|---|
| | 226 | // put them into the combobox |
|---|
| | 227 | |
|---|
| | 228 | String value = Configuration.getString(affectedProperty, true); |
|---|
| | 229 | boolean finished = value.equals(""); |
|---|
| | 230 | if(!finished) { |
|---|
| | 231 | control.removeAllItems(); // remove defaults, since config file now contains init values |
|---|
| | 232 | control.addItem(value); |
|---|
| | 233 | } // else value and combobox already contains the defaults |
|---|
| | 234 | |
|---|
| | 235 | |
|---|
| | 236 | for(int i = 1; !finished; i++) { |
|---|
| | 237 | value = Configuration.getString(affectedProperty+i, true); |
|---|
| | 238 | if(value.equals("")) { |
|---|
| | 239 | finished = true; |
|---|
| | 240 | } |
|---|
| | 241 | else { // value is not empty |
|---|
| | 242 | control.addItem(value); |
|---|
| | 243 | } |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | // setting the size of the dropdown control |
|---|
| | 247 | control.setPreferredSize(newSize); |
|---|