KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > editors > ModelViewEditor


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.administrator.editors;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.util.ArrayList JavaDoc;
35
36 import javax.swing.JButton JavaDoc;
37 import javax.swing.JLabel JavaDoc;
38 import javax.swing.JPanel JavaDoc;
39 import javax.swing.JTextField JavaDoc;
40
41 import com.genimen.djeneric.language.Messages;
42 import com.genimen.djeneric.repository.DjModelView;
43 import com.genimen.djeneric.repository.DjSession;
44 import com.genimen.djeneric.tools.administrator.helpers.AdminPanel;
45 import com.genimen.djeneric.tools.administrator.nodes.AdministratorTreeNode;
46 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
47 import com.genimen.djeneric.ui.Util;
48 import com.genimen.djeneric.util.DjLogger;
49
50 public class ModelViewEditor extends AdminEditor
51 {
52   private static final long serialVersionUID = 1L;
53
54   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
55   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
56   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
57   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
58   JButton JavaDoc _butOk = new JButton JavaDoc();
59   JButton JavaDoc _butCancel = new JButton JavaDoc();
60   AdministratorTreeNode _theNode;
61   DjModelView _view;
62   JPanel JavaDoc jPanel5 = new JPanel JavaDoc();
63   JTextField JavaDoc _edtCode = new JTextField JavaDoc();
64   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
65   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
66   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
67   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
68   JLabel JavaDoc jLabel2 = new JLabel JavaDoc();
69   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
70   AccessTableModel _model;
71   ArrayList JavaDoc _allAssocs = new ArrayList JavaDoc();
72
73   public ModelViewEditor(AdminPanel adminPanel, AdministratorTreeNode theNode, DjModelView view)
74   {
75     super(adminPanel);
76     _view = view;
77     _theNode = theNode;
78
79     try
80     {
81       jbInit();
82       _edtCode.setText(view.getCode());
83     }
84     catch (Exception JavaDoc ex)
85     {
86       DjLogger.log(ex);
87     }
88   }
89
90   void jbInit() throws Exception JavaDoc
91   {
92     this.setLayout(borderLayout1);
93     jPanel3.setLayout(borderLayout2);
94     _butOk.setText(Messages.getString("global.Ok"));
95     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
96     {
97       public void actionPerformed(ActionEvent JavaDoc e)
98       {
99         jButton1_actionPerformed(e);
100       }
101     });
102     _butCancel.setText(Messages.getString("global.Cancel"));
103     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
104     {
105       public void actionPerformed(ActionEvent JavaDoc e)
106       {
107         jButton2_actionPerformed(e);
108       }
109     });
110     jPanel2.setLayout(verticalFlowLayout2);
111     jPanel1.setLayout(verticalFlowLayout1);
112     jLabel2.setText(Messages.getString("global.Name"));
113     jPanel5.setLayout(borderLayout3);
114     this.add(jPanel3, BorderLayout.SOUTH);
115     jPanel3.add(jPanel4, BorderLayout.EAST);
116     jPanel4.add(_butCancel, null);
117     jPanel4.add(_butOk, null);
118     this.add(jPanel5, BorderLayout.NORTH);
119     jPanel2.add(_edtCode, null);
120     jPanel5.add(jPanel1, BorderLayout.WEST);
121     jPanel1.add(jLabel2, null);
122     jPanel5.add(jPanel2, BorderLayout.CENTER);
123
124     Util.sizeButtons(new JButton JavaDoc[]{_butOk, _butCancel});
125   }
126
127   void jButton2_actionPerformed(ActionEvent JavaDoc e)
128   {
129     _adminPanel.closeEditor(this);
130   }
131
132   public void setStatusMessage(String JavaDoc msg, boolean isInformative)
133   {
134     _adminPanel.setStatusMessage(msg, isInformative);
135   }
136
137   public void requestFocus()
138   {
139     _edtCode.requestFocus();
140   }
141
142   void jButton1_actionPerformed(ActionEvent JavaDoc e)
143   {
144     if (_edtCode.getText().trim().length() == 0)
145     {
146       setStatusMessage(Messages.getString("global.NameRequired"), false);
147       return;
148     }
149
150     _view.setCode(_edtCode.getText());
151
152     try
153     {
154       DjSession session = _adminPanel.getPersistenceManager().createSession();
155       try
156       {
157         _view.persist(session);
158         session.commit();
159       }
160       finally
161       {
162         session.close();
163       }
164       _adminPanel.closeEditor(this);
165       if (_theNode != null)
166       {
167         _theNode.reload();
168       }
169     }
170     catch (Exception JavaDoc x)
171     {
172       setStatusMessage(x);
173     }
174   }
175
176   public String JavaDoc getID()
177   {
178     if (_view.getId() == -1) return null;
179     return "V" + _view.getId();
180   }
181
182 }
Popular Tags