001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.swing;
024:
025: // Toolbox
026: import org.enhydra.tool.common.InnerPanel;
027: import org.enhydra.tool.common.DataValidationException;
028:
029: // AddinCore
030: import org.enhydra.kelp.common.node.OtterNode;
031: import org.enhydra.kelp.common.node.OtterProject;
032:
033: // JDK
034: import java.awt.*;
035: import java.awt.event.FocusAdapter;
036: import java.awt.event.FocusEvent;
037: import java.awt.event.WindowEvent;
038: import java.awt.event.WindowAdapter;
039: import java.beans.*;
040: import java.lang.ref.WeakReference;
041: import javax.swing.*;
042:
043: public class AddinInnerPanel extends InnerPanel {
044:
045: private WeakReference nodeRef = null;
046:
047: public AddinInnerPanel() {
048: super ();
049: }
050:
051: // override InnerPanel
052: public void clearAll() {
053: super .clearAll();
054: if (nodeRef != null) {
055: nodeRef.clear();
056: }
057: nodeRef = null;
058: }
059:
060: // override InnerPanel
061: public void save() {
062: try {
063: write(getNode());
064: } catch (DataValidationException e) {
065: System.err.println(e.getValidationMessage());
066: }
067: }
068:
069: public void read(OtterNode node) {
070: nodeRef = new WeakReference(node);
071: }
072:
073: public void write(OtterNode node) throws DataValidationException {
074: nodeRef = new WeakReference(node);
075: }
076:
077: protected OtterNode getNode() {
078: OtterNode node = null;
079:
080: if (nodeRef != null) {
081: node = (OtterNode) nodeRef.get();
082: }
083: return node;
084: }
085:
086: protected OtterProject getProject() {
087: OtterNode node = null;
088: OtterProject project = null;
089:
090: node = getNode();
091: if (node == null) {
092: project = null;
093: } else if (node instanceof OtterProject) {
094: project = (OtterProject) node;
095: } else {
096: project = node.getProject();
097: }
098: return project;
099: }
100:
101: }
|