1 30 package com.genimen.djeneric.tools.administrator.editors; 31 32 import java.awt.BorderLayout ; 33 import java.awt.event.ActionEvent ; 34 import java.util.ArrayList ; 35 36 import javax.swing.JButton ; 37 import javax.swing.JLabel ; 38 import javax.swing.JPanel ; 39 import javax.swing.JTextField ; 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 borderLayout1 = new BorderLayout (); 55 JPanel jPanel3 = new JPanel (); 56 BorderLayout borderLayout2 = new BorderLayout (); 57 JPanel jPanel4 = new JPanel (); 58 JButton _butOk = new JButton (); 59 JButton _butCancel = new JButton (); 60 AdministratorTreeNode _theNode; 61 DjModelView _view; 62 JPanel jPanel5 = new JPanel (); 63 JTextField _edtCode = new JTextField (); 64 JPanel jPanel2 = new JPanel (); 65 JPanel jPanel1 = new JPanel (); 66 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 67 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 68 JLabel jLabel2 = new JLabel (); 69 BorderLayout borderLayout3 = new BorderLayout (); 70 AccessTableModel _model; 71 ArrayList _allAssocs = new ArrayList (); 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 ex) 85 { 86 DjLogger.log(ex); 87 } 88 } 89 90 void jbInit() throws Exception 91 { 92 this.setLayout(borderLayout1); 93 jPanel3.setLayout(borderLayout2); 94 _butOk.setText(Messages.getString("global.Ok")); 95 _butOk.addActionListener(new java.awt.event.ActionListener () 96 { 97 public void actionPerformed(ActionEvent e) 98 { 99 jButton1_actionPerformed(e); 100 } 101 }); 102 _butCancel.setText(Messages.getString("global.Cancel")); 103 _butCancel.addActionListener(new java.awt.event.ActionListener () 104 { 105 public void actionPerformed(ActionEvent 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 []{_butOk, _butCancel}); 125 } 126 127 void jButton2_actionPerformed(ActionEvent e) 128 { 129 _adminPanel.closeEditor(this); 130 } 131 132 public void setStatusMessage(String 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 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 x) 171 { 172 setStatusMessage(x); 173 } 174 } 175 176 public String getID() 177 { 178 if (_view.getId() == -1) return null; 179 return "V" + _view.getId(); 180 } 181 182 } | Popular Tags |