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 / SessionEditor.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.3 KB  |  119 lines

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