001 /* 002 * $Id: AddeEntry.java,v 1.16 2012/04/12 15:36:31 jbeavers Exp $ 003 * 004 * This file is part of McIDAS-V 005 * 006 * Copyright 2007-2012 007 * Space Science and Engineering Center (SSEC) 008 * University of Wisconsin - Madison 009 * 1225 W. Dayton Street, Madison, WI 53706, USA 010 * https://www.ssec.wisc.edu/mcidas 011 * 012 * All Rights Reserved 013 * 014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 015 * some McIDAS-V source code is based on IDV and VisAD source code. 016 * 017 * McIDAS-V is free software; you can redistribute it and/or modify 018 * it under the terms of the GNU Lesser Public License as published by 019 * the Free Software Foundation; either version 3 of the License, or 020 * (at your option) any later version. 021 * 022 * McIDAS-V is distributed in the hope that it will be useful, 023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 025 * GNU Lesser Public License for more details. 026 * 027 * You should have received a copy of the GNU Lesser Public License 028 * along with this program. If not, see http://www.gnu.org/licenses. 029 */ 030 031 package edu.wisc.ssec.mcidasv.servermanager; 032 033 034 /** 035 * Represents a source of ADDE data. An ADDE entry may describe a dataset on 036 * remote servers or the user's own machine. 037 */ 038 public interface AddeEntry { 039 040 /** Represents the possible actions that an ADDE editor can perform. */ 041 // @PersistableEnum 042 public enum EditorAction { 043 /** Created a new entry; hasn't been verified. */ 044 ADDED, 045 046 /** Canceled out of creating or editing an entry. */ 047 CANCELLED, 048 049 /** Verified the contents of the editor GUI. */ 050 VERIFIED, 051 052 /** Created a new, verified entry. */ 053 ADDED_VERIFIED, 054 055 /** Updated an existing entry without verifying changes. */ 056 EDITED, 057 058 /** Updated an entry and verified the changes. */ 059 EDITED_VERIFIED, 060 061 /** Editor GUI performed some {@literal "invalid"} action. */ 062 INVALID; 063 }; 064 065 /** Type of chooser this should appear under. */ 066 067 public enum EntryType { 068 /** {@link edu.wisc.ssec.mcidasv.chooser.adde.AddeImageChooser} */ 069 IMAGE, 070 071 /** {@link edu.wisc.ssec.mcidasv.chooser.adde.AddePointDataChooser} */ 072 POINT, 073 074 /** */ 075 GRID, 076 077 /** {@link edu.wisc.ssec.mcidasv.chooser.adde.AddeFrontChooser} */ 078 TEXT, 079 080 /** */ 081 NAV, 082 083 /** {@link edu.wisc.ssec.mcidasv.chooser.adde.AddeRadarChooser} */ 084 RADAR, 085 086 /** */ 087 UNKNOWN, 088 089 /** */ 090 INVALID; 091 092 /** 093 * Attempts to convert a given {@code String} value into a valid 094 * {@code EntryType}. 095 * 096 * @param str {@code String} to convert. Should not be {@code null}. 097 * 098 * @return {@code EntryType} of the value specified in {@code str}. 099 */ 100 public static EntryType fromStr(final String str) { 101 return EntryType.valueOf(str); 102 } 103 104 /** 105 * Attempts to convert a given {@code EntryType} into its 106 * {@code String} representation. 107 * 108 * @param type {@code EntryType} constant; should not be {@code null}. 109 * 110 * @return {@code String} representation of {@code type}. 111 */ 112 public static String toStr(final EntryType type) { 113 return type.name(); 114 } 115 }; 116 117 /** Sort of a {@literal "misc"} status field... */ 118 public enum EntryValidity { 119 /** Entry has been verified by connecting to the server. */ 120 VERIFIED, 121 122 /** Unknown whether or not this entry actually works. */ 123 UNVERIFIED, 124 125 /** Entry is being checked for validity. */ 126 VALIDATING, 127 128 /** 129 * User has elected to remove this entry. This is an unfortunate 130 * {@literal "special case"}, as we can't simply remove these entries 131 * from a list! Say the user import entries from a remote MCTABLE file 132 * and later deleted some of the imported entries. Fine, good! But 133 * what should happen if the user hears that new servers have been 134 * added to that same MCTABLE file? The entries that the user has 135 * deleted <i>locally</i> should not reappear, right? 136 */ 137 DELETED, 138 139 /** Entry is invalid in some way. */ 140 INVALID; 141 142 public static EntryValidity fromStr(final String str) { 143 return EntryValidity.valueOf(str); 144 } 145 public static String toStr(final EntryValidity validity) { 146 return validity.name(); 147 } 148 }; 149 150 /** Where did this entry come from? */ 151 public enum EntrySource { 152 /** Entry originated from McIDAS-V. */ 153 SYSTEM, 154 155 /** Entry was imported from a MCTABLE file. */ 156 MCTABLE, 157 158 /** Entry was added by the user.*/ 159 USER, 160 161 /** 162 * Represents an {@literal "invalid"} {@code EntrySource}. Useful for 163 * invalid entry objects ({@link RemoteAddeEntry#INVALID_ENTRY} and 164 * {@link LocalAddeEntry#INVALID_ENTRY}). 165 */ 166 INVALID; 167 168 public static EntrySource fromStr(final String str) { 169 return EntrySource.valueOf(str); 170 } 171 public static String toStr(final EntrySource source) { 172 return source.name(); 173 } 174 }; 175 176 /** 177 * Has the user elected to disable this entry from appearing in its 178 * relevant chooser? 179 */ 180 public enum EntryStatus { 181 /** Entry is valid and toggled on. */ 182 ENABLED, 183 184 /** Entry is valid and toggled off. */ 185 DISABLED, 186 187 /** Something is wrong with this entry. */ 188 INVALID; 189 190 public static EntryStatus fromStr(final String str) { 191 return EntryStatus.valueOf(str); 192 } 193 194 public static String toStr(final EntryType type) { 195 return type.name(); 196 } 197 }; 198 199 /** Represents the {@literal "no accounting"} entries. */ 200 public static final AddeAccount DEFAULT_ACCOUNT = 201 new AddeAccount("idv", "0"); 202 203 /** 204 * Address of the server associated with the current entry. 205 * {@link LocalAddeEntry}s will return {@code localhost}. 206 */ 207 public String getAddress(); 208 209 /** 210 * Dataset/group located on the server. 211 */ 212 public String getGroup(); 213 214 // TODO(jon): what part of a resolv.srv does this represent? 215 /** 216 * Name associated with this entry. 217 * 218 * @return Name associated with this entry. 219 */ 220 public String getName(); 221 222 /** 223 * Accounting information associated with the current entry. If the server 224 * does not require accounting information, this method returns 225 * {@link #DEFAULT_ACCOUNT}. 226 * 227 * @return ADDE account object. 228 */ 229 public AddeAccount getAccount(); 230 231 /** 232 * Type of chooser this entry should appear under. 233 * 234 * @return The {@literal "type"} of data associated with this entry. 235 */ 236 public EntryType getEntryType(); 237 238 /** 239 * Does this entry represent a {@literal "valid"} ADDE server. 240 * 241 * @return Whether or not this entry has been validated. 242 */ 243 public EntryValidity getEntryValidity(); 244 245 /** 246 * Source that specified this entry. For example; allows you to 247 * distinguish {@literal "system"} entries (which cannot be removed, only 248 * disabled) from entries created by the user (full control). 249 */ 250 public EntrySource getEntrySource(); 251 252 /** 253 * GUI status of the entry. Differs from {@link EntryValidity} in that 254 * {@code EntryStatus} controls this entry showing up in a chooser and has 255 * nothing to do with whether or not the entry is a valid ADDE server. 256 */ 257 public EntryStatus getEntryStatus(); 258 259 /** 260 * Handy {@code String} representation of this ADDE entry. Currently looks 261 * like {@code ADDRESS/GROUP}, but this is subject to change. 262 */ 263 public String getEntryText(); 264 265 // TODO(jon): should this be removed? this makes the entries mutable! 266 public void setEntryStatus(final EntryStatus newStatus); 267 268 // TODO(jon): integrate with parameter sets one fine day? 269 public String getEntryAlias(); 270 271 // TODO(jon): should this be removed? this makes the entries mutable! 272 public void setEntryAlias(final String newAlias); 273 274 /** 275 * Currently used as a identifier for convenient storage by the server 276 * manager. 277 */ 278 public String asStringId(); 279 280 /** 281 * String representation of this entry. 282 */ 283 public String toString(); 284 }