KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > swing > AddinInnerPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.swing;
24
25 // Toolbox
26
import org.enhydra.tool.common.InnerPanel;
27 import org.enhydra.tool.common.DataValidationException;
28
29 // AddinCore
30
import org.enhydra.kelp.common.node.OtterNode;
31 import org.enhydra.kelp.common.node.OtterProject;
32
33 // JDK
34
import java.awt.*;
35 import java.awt.event.FocusAdapter JavaDoc;
36 import java.awt.event.FocusEvent JavaDoc;
37 import java.awt.event.WindowEvent JavaDoc;
38 import java.awt.event.WindowAdapter JavaDoc;
39 import java.beans.*;
40 import java.lang.ref.WeakReference JavaDoc;
41 import javax.swing.*;
42
43 public class AddinInnerPanel extends InnerPanel {
44
45     private WeakReference JavaDoc nodeRef = null;
46
47     public AddinInnerPanel() {
48         super();
49     }
50
51     // override InnerPanel
52
public void clearAll() {
53         super.clearAll();
54         if (nodeRef != null) {
55             nodeRef.clear();
56         }
57         nodeRef = null;
58     }
59
60     // override InnerPanel
61
public void save() {
62         try {
63             write(getNode());
64         } catch (DataValidationException e) {
65             System.err.println(e.getValidationMessage());
66         }
67     }
68
69     public void read(OtterNode node) {
70         nodeRef = new WeakReference JavaDoc(node);
71     }
72
73     public void write(OtterNode node) throws DataValidationException {
74         nodeRef = new WeakReference JavaDoc(node);
75     }
76
77     protected OtterNode getNode() {
78         OtterNode node = null;
79
80         if (nodeRef != null) {
81             node = (OtterNode) nodeRef.get();
82         }
83         return node;
84     }
85
86     protected OtterProject getProject() {
87         OtterNode node = null;
88         OtterProject project = null;
89
90         node = getNode();
91         if (node == null) {
92             project = null;
93         } else if (node instanceof OtterProject) {
94             project = (OtterProject) node;
95         } else {
96             project = node.getProject();
97         }
98         return project;
99     }
100
101 }
102
Popular Tags