001: package net.sourceforge.squirrel_sql.plugins.hibernate.configuration;
002:
003: import net.sourceforge.squirrel_sql.fw.util.StringManager;
004: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
005:
006: import javax.swing.*;
007: import javax.swing.border.TitledBorder;
008: import java.awt.*;
009:
010: public class HibernateConfigPanel extends JPanel {
011: private static final StringManager s_stringMgr = StringManagerFactory
012: .getStringManager(HibernateConfigPanel.class);
013:
014: JComboBox cboConfigs;
015: JButton btnNewConfig;
016: JButton btnRemoveConfig;
017: JTextField txtFactoryProvider;
018: JButton btnEditFactoryProviderInfo;
019: JList lstClassPath;
020: JButton btnClassPathAdd;
021: JButton btnClassPathRemove;
022: JTextField txtConfigName;
023: JButton btnApplyConfigChanges;
024: JRadioButton radConfiguration;
025: JRadioButton radUserDefProvider;
026: JRadioButton radJPA;
027: JTextField txtPersistenceUnitName;
028:
029: public HibernateConfigPanel() {
030: setLayout(new GridBagLayout());
031:
032: GridBagConstraints gbc;
033:
034: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
035: GridBagConstraints.WEST, GridBagConstraints.NONE,
036: new Insets(5, 5, 5, 5), 0, 0);
037: // i18n[HibernateConfigPanel.config=Configuration]
038: JLabel lblConfig = new JLabel(s_stringMgr
039: .getString("HibernatePanel.config"));
040: add(lblConfig, gbc);
041:
042: gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
043: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
044: new Insets(5, 5, 5, 5), 0, 0);
045: cboConfigs = new JComboBox();
046: add(cboConfigs, gbc);
047:
048: gbc = new GridBagConstraints(2, 0, 1, 1, 0, 0,
049: GridBagConstraints.WEST, GridBagConstraints.NONE,
050: new Insets(5, 5, 5, 5), 0, 0);
051: // i18n[HibernateConfigPanel.newConfig=New]
052: btnNewConfig = new JButton(s_stringMgr
053: .getString("HibernatePanel.newConfig"));
054: add(btnNewConfig, gbc);
055:
056: gbc = new GridBagConstraints(3, 0, 1, 1, 0, 0,
057: GridBagConstraints.WEST, GridBagConstraints.NONE,
058: new Insets(5, 5, 5, 5), 0, 0);
059: // i18n[HibernateConfigPanel.removeConfig=Remove]
060: btnRemoveConfig = new JButton(s_stringMgr
061: .getString("HibernatePanel.removeConfig"));
062: add(btnRemoveConfig, gbc);
063:
064: gbc = new GridBagConstraints(0, 1, 4, 1, 1, 1,
065: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
066: new Insets(15, 10, 10, 10), 0, 0);
067: add(createConfigDefPanel(), gbc);
068: }
069:
070: private JPanel createConfigDefPanel() {
071: JPanel ret = new JPanel(new GridBagLayout());
072: // i18n[HibernateConfigPanel.ConfiguirationDef=Configuration definition]
073: ret.setBorder(BorderFactory.createTitledBorder(s_stringMgr
074: .getString("HibernatePanel.ConfiguirationDef")));
075:
076: GridBagConstraints gbc;
077:
078: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
079: GridBagConstraints.NORTHWEST,
080: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
081: 0, 0);
082: ret.add(createConfigNamePanel(), gbc);
083:
084: gbc = new GridBagConstraints(0, 1, 1, 1, 1, 1,
085: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
086: new Insets(0, 5, 5, 5), 0, 0);
087: ret.add(createClasspathPanel(), gbc);
088:
089: gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
090: GridBagConstraints.NORTHWEST,
091: GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5),
092: 0, 0);
093: ret.add(createHowToCreateSessionFactoryPanel(), gbc);
094:
095: gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
096: GridBagConstraints.CENTER, GridBagConstraints.NONE,
097: new Insets(10, 5, 5, 5), 0, 0);
098: // i18n[HibernateConfigPanel.applyConfigChanges=Apply changes to this configuration]
099: btnApplyConfigChanges = new JButton(s_stringMgr
100: .getString("HibernatePanel.applyConfigChanges"));
101: ret.add(btnApplyConfigChanges, gbc);
102:
103: return ret;
104: }
105:
106: private JPanel createConfigNamePanel() {
107: JPanel ret = new JPanel(new GridBagLayout());
108:
109: GridBagConstraints gbc;
110:
111: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
112: GridBagConstraints.WEST, GridBagConstraints.NONE,
113: new Insets(5, 5, 5, 5), 0, 0);
114: // i18n[HibernateConfigPanel.configName=Configuration name]
115: ret.add(new JLabel(s_stringMgr
116: .getString("HibernatePanel.configName")), gbc);
117:
118: gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
119: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
120: new Insets(5, 5, 5, 5), 0, 0);
121: txtConfigName = new JTextField();
122: ret.add(txtConfigName, gbc);
123:
124: return ret;
125: }
126:
127: private JPanel createClasspathPanel() {
128: // i18n[HibernateConfigPanel.newFactoryClasspathBorder=Additional classpath entries to create a SessionFactoryImpl]
129: TitledBorder brd = BorderFactory.createTitledBorder(s_stringMgr
130: .getString("HibernatePanel.newFactoryClasspathBorder"));
131: JPanel ret = new JPanel(new GridBagLayout());
132: ret.setBorder(brd);
133:
134: GridBagConstraints gbc;
135:
136: gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1,
137: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
138: new Insets(0, 5, 5, 5), 0, 0);
139: lstClassPath = new JList();
140: ret.add(new JScrollPane(lstClassPath), gbc);
141:
142: gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
143: GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
144: new Insets(0, 5, 5, 5), 0, 0);
145: ret.add(createButtonClasspathPanel(), gbc);
146:
147: return ret;
148:
149: }
150:
151: private JPanel createButtonClasspathPanel() {
152: JPanel ret = new JPanel(new GridBagLayout());
153:
154: GridBagConstraints gbc;
155:
156: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
157: GridBagConstraints.WEST, GridBagConstraints.NONE,
158: new Insets(5, 5, 5, 5), 0, 0);
159: // i18n[HibernateConfigPanel.classPathAdd=Add classpath entry]
160: btnClassPathAdd = new JButton(s_stringMgr
161: .getString("HibernatePanel.classPathAdd"));
162: ret.add(btnClassPathAdd, gbc);
163:
164: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
165: GridBagConstraints.WEST, GridBagConstraints.NONE,
166: new Insets(5, 5, 5, 5), 0, 0);
167: // i18n[HibernateConfigPanel.classPathRemove=Remove selected entries]
168: btnClassPathRemove = new JButton(s_stringMgr
169: .getString("HibernatePanel.classPathRemove"));
170: ret.add(btnClassPathRemove, gbc);
171:
172: return ret;
173: }
174:
175: private JPanel createHowToCreateSessionFactoryPanel() {
176: JPanel ret = new JPanel();
177:
178: ret.setBorder(BorderFactory.createEtchedBorder());
179: ret.setLayout(new GridBagLayout());
180:
181: GridBagConstraints gbc;
182:
183: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
184: GridBagConstraints.WEST, GridBagConstraints.NONE,
185: new Insets(5, 5, 5, 5), 0, 0);
186: // i18n[HibernateConfigPanel.toObtainSessionFact=To obtain a Hibernate SessionFactoryImpl instance SQuirreL should:]
187: ret.add(new JLabel(s_stringMgr
188: .getString("HibernatePanel.toObtainSessionFact")), gbc);
189:
190: gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
191: GridBagConstraints.WEST, GridBagConstraints.NONE,
192: new Insets(5, 5, 5, 5), 0, 0);
193: // i18n[HibernateConfigPanel.toObtainSessionFactConfiguration=Call "new org.hibernate.cfg.Configuration().configure().buildSessionFactory();"]
194: radConfiguration = new JRadioButton(
195: s_stringMgr
196: .getString("HibernatePanel.toObtainSessionFactConfiguration"));
197: ret.add(radConfiguration, gbc);
198:
199: gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
200: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
201: new Insets(5, 5, 5, 5), 0, 0);
202: ret.add(createJPAPanel(), gbc);
203:
204: gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
205: GridBagConstraints.WEST, GridBagConstraints.NONE,
206: new Insets(5, 5, 0, 5), 0, 0);
207: // i18n[HibernateConfigPanel.toObtainSessionFactFactoryProvider=Invoke the user defined provider method below:]
208: radUserDefProvider = new JRadioButton(
209: s_stringMgr
210: .getString("HibernatePanel.toObtainSessionFactFactoryProvider"));
211: ret.add(radUserDefProvider, gbc);
212:
213: ButtonGroup btnGr = new ButtonGroup();
214: btnGr.add(radConfiguration);
215: btnGr.add(radUserDefProvider);
216: btnGr.add(radJPA);
217: radConfiguration.setSelected(true);
218:
219: gbc = new GridBagConstraints(0, 4, 1, 1, 1, 0,
220: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
221: new Insets(0, 5, 5, 5), 0, 0);
222: ret.add(createUserDefinedSessionFactoryPanel(), gbc);
223:
224: return ret;
225:
226: }
227:
228: private JPanel createJPAPanel() {
229: JPanel ret = new JPanel(new GridBagLayout());
230:
231: GridBagConstraints gbc;
232:
233: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
234: GridBagConstraints.WEST, GridBagConstraints.NONE,
235: new Insets(5, 0, 5, 5), 0, 0);
236: // i18n[HibernateConfigPanel.toObtainSessionFactJPA=Call "javax.persistence.Persistence.createEntityManagerFactory("<persitence-unit name>");"]
237: radJPA = new JRadioButton(s_stringMgr
238: .getString("HibernatePanel.toObtainSessionFactJPA"));
239: ret.add(radJPA, gbc);
240:
241: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
242: GridBagConstraints.WEST, GridBagConstraints.NONE,
243: new Insets(5, 5, 5, 5), 0, 0);
244: // i18n[HibernateConfigPanel.toObtainSessionFactPersUnit=persitence-unit name:]
245: ret
246: .add(
247: new JLabel(
248: s_stringMgr
249: .getString("HibernatePanel.toObtainSessionFactPersUnit")),
250: gbc);
251:
252: gbc = new GridBagConstraints(2, 0, 1, 1, 1, 0,
253: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
254: new Insets(5, 0, 5, 5), 0, 0);
255: txtPersistenceUnitName = new JTextField();
256: ret.add(txtPersistenceUnitName, gbc);
257:
258: return ret;
259: }
260:
261: private JPanel createUserDefinedSessionFactoryPanel() {
262: JPanel ret = new JPanel(new GridBagLayout());
263:
264: GridBagConstraints gbc;
265: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
266: GridBagConstraints.WEST, GridBagConstraints.NONE,
267: new Insets(5, 5, 5, 5), 0, 0);
268: // i18n[HibernateConfigPanel.FactoryProvider=SessionFactoryImpl provider]
269: JLabel lblConfig = new JLabel(s_stringMgr
270: .getString("HibernatePanel.FactoryProvider"));
271: ret.add(lblConfig, gbc);
272:
273: gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
274: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
275: new Insets(5, 5, 5, 5), 0, 0);
276: txtFactoryProvider = new JTextField();
277: txtFactoryProvider.setEditable(false);
278: txtFactoryProvider.setBackground(Color.lightGray);
279:
280: ret.add(txtFactoryProvider, gbc);
281:
282: gbc = new GridBagConstraints(2, 0, 1, 1, 0, 0,
283: GridBagConstraints.WEST, GridBagConstraints.NONE,
284: new Insets(5, 5, 5, 5), 0, 0);
285: // i18n[HibernateConfigPanel.editFactoryProvider=Edit]
286: btnEditFactoryProviderInfo = new JButton(s_stringMgr
287: .getString("HibernatePanel.editFactoryProvider"));
288: ret.add(btnEditFactoryProviderInfo, gbc);
289:
290: return ret;
291: }
292: }
|