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 / RelationViewEditor.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.7 KB  |  121 lines

  1. /*
  2.  * @(#RelationViewEditor.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.  
  15. /**
  16.  * Supports editing the RelationView property.
  17.  */
  18. public class RelationViewEditor extends PropertyEditorSupport {
  19.  
  20.     /**
  21.      * Constructs a default RelationViewEditor.
  22.      */
  23.     public RelationViewEditor() {
  24.     }
  25.  
  26.     /**
  27.      * Set (or change) the object that is to be edited.
  28.      * @param value The new target object to be edited.  Note that this
  29.      *     object should not be modified by the PropertyEditor, rather
  30.      *     the PropertyEditor should create a new object to hold any
  31.      *     modified value.
  32.      */
  33.     public void setValue(Object value) {
  34.         name = "null";
  35.         try {
  36.             if (value != null) {
  37.                 if (value instanceof RelationView) {
  38.                     name = ((RelationView)value).getName();
  39.                 }
  40.                 else {
  41.                     System.out.println("RelationViewEditor.setValue (value is not a RelationView)");
  42.                     System.out.println("Class: [" + value.getClass().getName() + "]");
  43.                     System.out.println("Value: [" + value.toString() + "]");
  44.                     Thread.dumpStack();
  45.                     if (value instanceof String) {
  46.                         name = (String)value;
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.         catch (Exception ex) {
  52.             System.out.print("RelationViewEditor: 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.         RelationView rv = null;
  66.         try {
  67.             Session sess = new Session("");
  68.             ConnectionInfo conn = new ConnectionInfo("");
  69.             Request rvRequest = new Request(sess, conn);
  70.             rv = new RelationView(rvRequest);
  71.             rv.setName(name);
  72.         } catch (Exception ex) {
  73.             System.out.print("RelationViewEditor: getValue: exception " + ex.getMessage());
  74.         }
  75.         return rv;
  76.     }
  77.  
  78.     //----------------------------------------------------------------------
  79.  
  80.     /**
  81.      * This method is intended for use when generating Java code to set
  82.      * the value of the property.  It should return a fragment of Java code
  83.      * that can be used to initialize a variable with the current property
  84.      * value.
  85.      * <p>
  86.      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
  87.      *
  88.      * @return A fragment of Java code representing an initializer for the
  89.      *       current value.
  90.      */
  91.     public String getJavaInitializationString() {
  92.         return name;
  93.     }
  94.  
  95.     //----------------------------------------------------------------------
  96.  
  97.     /**
  98.      * @return The property value as a string suitable for presentation
  99.      *       to a human to edit.
  100.      * <p>   Returns "null" is the value can't be expressed as a string.
  101.      * <p>   If a non-null value is returned, then the PropertyEditor should
  102.      *         be prepared to parse that string back in setAsText().
  103.      */
  104.     public String getAsText() {
  105.         return name;
  106.     }
  107.  
  108.     /**
  109.      * Set the property value by parsing a given String.  May raise
  110.      * java.lang.IllegalArgumentException if either the String is
  111.      * badly formatted or if this kind of property can't be expressed
  112.      * as text.
  113.      * @param text  The string to be parsed.
  114.      */
  115.     public void setAsText(String text) throws java.lang.IllegalArgumentException {
  116.         name = text;
  117.     }
  118.  
  119.     private String name = "null";
  120. }
  121.