home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / ConnectionInfoEditor.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.0 KB  |  107 lines

  1. /*
  2.  * @(#ConnectionInfoEditor.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8.  
  9. package symantec.itools.db.awt;
  10.  
  11. import java.awt.*;
  12. import java.beans.*;
  13. import symantec.itools.db.pro.*;
  14. import java.util.*;
  15.  
  16. /**
  17.  * Supports editing the ConnectionInfo property.
  18.  */
  19. public class ConnectionInfoEditor extends PropertyEditorSupport
  20. {
  21.  
  22.     /**
  23.      * Constructs a ConnectionInfoEditor object.
  24.      */
  25.     public ConnectionInfoEditor() {
  26.     }
  27.  
  28.     /**
  29.      * Set (or change) the object that is to be edited.
  30.      * @param value The new target object to be edited.  Note that this
  31.      *     object should not be modified by the PropertyEditor, rather
  32.      *     the PropertyEditor should create a new object to hold any
  33.      *     modified value.
  34.      */
  35.     public void setValue(Object value) {
  36.         name = "null";
  37.         if (value instanceof String) {
  38.             name = (String)value;
  39.         }
  40.         else if (value instanceof ConnectionInfo) {
  41.             try {
  42.                 name = ((ConnectionInfo)value).getName();
  43.             }
  44.             catch (Exception ex) {
  45.             }
  46.         }
  47.         firePropertyChange();
  48.     }
  49.  
  50.     /**
  51.      * @return The value of the property.
  52.      */
  53.  
  54.     public Object getValue() {
  55.         if (name.equals("null")) {
  56.             return null;
  57.         }
  58.         ConnectionInfo conn = new ConnectionInfo("");
  59.         conn.setName(name);
  60.         return conn;
  61.     }
  62.  
  63.     //----------------------------------------------------------------------
  64.  
  65.     /**
  66.      * This method is intended for use when generating Java code to set
  67.      * the value of the property.  It should return a fragment of Java code
  68.      * that can be used to initialize a variable with the current property
  69.      * value.
  70.      * <p>
  71.      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
  72.      *
  73.      * @return A fragment of Java code representing an initializer for the
  74.      *       current value.
  75.      */
  76.     public String getJavaInitializationString() {
  77.         return name;
  78.     }
  79.  
  80.     //----------------------------------------------------------------------
  81.  
  82.     /**
  83.      * @return The property value as a string suitable for presentation
  84.      *       to a human to edit.
  85.      * <p>   Returns "null" is the value can't be expressed as a string.
  86.      * <p>   If a non-null value is returned, then the PropertyEditor should
  87.      *         be prepared to parse that string back in setAsText().
  88.      */
  89.     public String getAsText() {
  90.         return name;
  91.     }
  92.  
  93.     /**
  94.      * Set the property value by parsing a given String.  May raise
  95.      * java.lang.IllegalArgumentException if either the String is
  96.      * badly formatted or if this kind of property can't be expressed
  97.      * as text.
  98.      * @param text  The string to be parsed.
  99.      */
  100.     public void setAsText(String text) throws java.lang.IllegalArgumentException {
  101.         name = text;
  102.     }
  103.  
  104.     private String name = "null";
  105.  
  106. }
  107.