001/*
002 * $Id: AddeEntry.java,v 1.13 2011/03/24 16:06:34 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
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
031package 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 */
038public 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        public static EntryType fromStr(final String str) {
093            return EntryType.valueOf(str);
094        }
095        public static String toStr(final EntryType type) {
096            return type.name();
097        }
098    };
099    
100    /** Sort of a {@literal "misc"} status field... */
101    public enum EntryValidity {
102        /** Entry has been verified by connecting to the server. */
103        VERIFIED,
104
105        /** Unknown whether or not this entry actually works. */
106        UNVERIFIED,
107
108        /** Entry is being checked for validity. */
109        VALIDATING,
110
111        /** 
112         * User has elected to remove this entry. This is an unfortunate 
113         * {@literal "special case"}, as we can't simply remove these entries
114         * from a list! Say the user import entries from a remote MCTABLE file
115         * and later deleted some of the imported entries. Fine, good! But 
116         * what should happen if the user hears that new servers have been
117         * added to that same MCTABLE file? The entries that the user has 
118         * deleted <i>locally</i> should not reappear, right? 
119         */
120        DELETED,
121
122        /** Entry is invalid in some way. */
123        INVALID;
124
125        public static EntryValidity fromStr(final String str) {
126            return EntryValidity.valueOf(str);
127        }
128        public static String toStr(final EntryValidity validity) {
129            return validity.name();
130        }
131    };
132
133    /** Where did this entry come from? */
134    public enum EntrySource {
135        /** Entry originated from McIDAS-V. */
136        SYSTEM, 
137
138        /** Entry was imported from a MCTABLE file. */
139        MCTABLE, 
140
141        /** Entry was added by the user.*/
142        USER,
143
144        /**
145         * Represents an {@literal "invalid"} {@code EntrySource}. Useful for
146         * invalid entry objects ({@link RemoteAddeEntry#INVALID_ENTRY} and 
147         * {@link LocalAddeEntry#INVALID_ENTRY}).
148         */
149        INVALID;
150        
151        public static EntrySource fromStr(final String str) {
152            return EntrySource.valueOf(str);
153        }
154        public static String toStr(final EntrySource source) {
155            return source.name();
156        }
157    };
158
159    /** 
160     * Has the user elected to disable this entry from appearing in its 
161     * relevant chooser? 
162     */
163    public enum EntryStatus {
164        /** Entry is valid and toggled on. */
165        ENABLED,
166
167        /** Entry is valid and toggled off. */
168        DISABLED,
169
170        /** Something is wrong with this entry. */
171        INVALID;
172
173        public static EntryStatus fromStr(final String str) {
174            return EntryStatus.valueOf(str);
175        }
176
177        public static String toStr(final EntryType type) {
178            return type.name();
179        }
180    };
181
182    /** Represents the {@literal "no accounting"} entries. */
183    public static final AddeAccount DEFAULT_ACCOUNT = 
184        new AddeAccount("idv", "0");
185
186    /**
187     * Address of the server associated with the current entry. 
188     * {@link LocalAddeEntry}s will return {@code localhost}.
189     */
190    public String getAddress();
191
192    /**
193     * Dataset/group located on the server.
194     */
195    public String getGroup();
196
197    // TODO(jon): what part of a resolv.srv does this represent?
198    public String getName();
199
200    /**
201     * Accounting information associated with the current entry. If the server
202     * does not require accounting information, this method returns 
203     * {@link #DEFAULT_ACCOUNT}.
204     */
205    public AddeAccount getAccount();
206
207    /**
208     * Type of chooser this entry should appear under.
209     */
210    public EntryType getEntryType();
211
212    /**
213     * Does this entry represent a {@literal "valid"} ADDE server.
214     */
215    public EntryValidity getEntryValidity();
216
217    /**
218     * Source that specified this entry. For example; allows you to 
219     * distinguish {@literal "system"} entries (which cannot be removed, only 
220     * disabled) from entries created by the user (full control).
221     */
222    public EntrySource getEntrySource();
223
224    /**
225     * GUI status of the entry. Differs from {@link EntryValidity} in that 
226     * {@code EntryStatus} controls this entry showing up in a chooser and has
227     * nothing to do with whether or not the entry is a valid ADDE server.
228     */
229    public EntryStatus getEntryStatus();
230
231    /**
232     * Handy {@code String} representation of this ADDE entry. Currently looks
233     * like {@code ADDRESS/GROUP}, but this is subject to change.
234     */
235    public String getEntryText();
236
237    // TODO(jon): should this be removed? this makes the entries mutable!
238    public void setEntryStatus(final EntryStatus newStatus);
239
240    // TODO(jon): integrate with parameter sets one fine day?
241    public String getEntryAlias();
242
243    // TODO(jon): should this be removed? this makes the entries mutable!
244    public void setEntryAlias(final String newAlias);
245
246    /**
247     * Currently used as a identifier for convenient storage by the server 
248     * manager.
249     */
250    public String asStringId();
251
252    /**
253     * String representation of this entry.
254     */
255    public String toString();
256}