001: package net.sourceforge.squirrel_sql.plugins.hibernate;
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 java.awt.*;
008: import java.util.prefs.Preferences;
009:
010: public class HibernateTabPanel extends JPanel {
011: private static final StringManager s_stringMgr = StringManagerFactory
012: .getStringManager(HibernateTabPanel.class);
013:
014: private static final String PERF_KEY_HQL_TAB_DIVIDER_LOCATION = "Squirrel.hibernateplugin.hqlTabDivLoc";
015: private static final String PERF_KEY_LAST_SELECTED_TAB = "Squirrel.hibernateplugin.lastSelectedTab";
016:
017: JComboBox cboConfigurations;
018: JToggleButton btnConnected;
019: JButton btnOpenConfigs;
020:
021: private JSplitPane _splitHqlSql;
022: private JPanel _toolbar;
023: private int _curXOfToolbar;
024: private JTabbedPane _tabObjectsHql;
025: private HibernatePluginResources _resource;
026:
027: public HibernateTabPanel(JComponent mappedObjectComp,
028: JComponent hqlTextComp, JComponent sqlTextComp,
029: HibernatePluginResources resource) {
030: _resource = resource;
031: setLayout(new GridBagLayout());
032:
033: GridBagConstraints gbc;
034:
035: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
036: GridBagConstraints.NORTHWEST,
037: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
038: 0, 0);
039: _toolbar = createToolbar();
040: add(_toolbar, gbc);
041:
042: _splitHqlSql = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
043: hqlTextComp, sqlTextComp);
044:
045: _tabObjectsHql = new JTabbedPane();
046:
047: // i18n[HibernateTabPanel.mappedObjects=Mapped objects]
048: _tabObjectsHql.add(s_stringMgr
049: .getString("HQLTabPanel.mappedObjects"),
050: mappedObjectComp);
051:
052: // i18n[HibernateTabPanel.hql=HQL]
053: _tabObjectsHql.add(s_stringMgr.getString("HQLTabPanel.hql"),
054: _splitHqlSql);
055:
056: gbc = new GridBagConstraints(0, 1, 1, 1, 1, 1,
057: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
058: new Insets(0, 0, 0, 0), 0, 0);
059: add(_tabObjectsHql, gbc);
060:
061: _tabObjectsHql.setSelectedIndex(Preferences.userRoot().getInt(
062: PERF_KEY_LAST_SELECTED_TAB, 0));
063:
064: SwingUtilities.invokeLater(new Runnable() {
065: public void run() {
066: _splitHqlSql.setDividerLocation(Preferences.userRoot()
067: .getDouble(PERF_KEY_HQL_TAB_DIVIDER_LOCATION,
068: 0.5));
069: }
070: });
071:
072: }
073:
074: public void closing() {
075: Preferences.userRoot().putDouble(
076: PERF_KEY_HQL_TAB_DIVIDER_LOCATION,
077: ((double) _splitHqlSql.getDividerLocation())
078: / ((double) _splitHqlSql.getHeight()));
079: Preferences.userRoot().putInt(PERF_KEY_LAST_SELECTED_TAB,
080: _tabObjectsHql.getSelectedIndex());
081: }
082:
083: private JPanel createToolbar() {
084: JPanel ret = new JPanel();
085:
086: ret.setLayout(new GridBagLayout());
087:
088: GridBagConstraints gbc;
089:
090: _curXOfToolbar = 0;
091:
092: // i18n[HibernateTabPanel.configuration=Configuration]
093: JLabel lblCfg = new JLabel(s_stringMgr
094: .getString("HQLTabPanel.configuration"));
095: gbc = new GridBagConstraints(_curXOfToolbar++, 0, 1, 1, 0, 0,
096: GridBagConstraints.WEST, GridBagConstraints.NONE,
097: new Insets(5, 5, 5, 5), 0, 0);
098: ret.add(lblCfg, gbc);
099:
100: cboConfigurations = new JComboBox();
101: gbc = new GridBagConstraints(_curXOfToolbar++, 0, 1, 1, 1, 0,
102: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
103: new Insets(5, 0, 5, 5), 0, 0);
104: ret.add(cboConfigurations, gbc);
105:
106: gbc = new GridBagConstraints(_curXOfToolbar++, 0, 1, 1, 0, 0,
107: GridBagConstraints.WEST, GridBagConstraints.NONE,
108: new Insets(5, 5, 5, 5), 0, 0);
109: btnConnected = new JToggleButton();
110: //i18n[hibernate.HibernateTabPanel.connect=Connect/disconnect configuration selected configuration]
111: btnConnected.setToolTipText(s_stringMgr
112: .getString("hibernate.HQLTabPanel.connect"));
113: ret.add(btnConnected, gbc);
114:
115: gbc = new GridBagConstraints(_curXOfToolbar++, 0, 1, 1, 0, 0,
116: GridBagConstraints.WEST, GridBagConstraints.NONE,
117: new Insets(5, 5, 5, 5), 0, 0);
118: btnOpenConfigs = new JButton(
119: _resource
120: .getIcon(HibernatePluginResources.IKeys.HIBERNATE_IMAGE));
121: //i18n[hibernate.HibernateTabPanel.openConfigs=Open Hibernate configurations]
122: btnOpenConfigs.setToolTipText(s_stringMgr
123: .getString("hibernate.HibernateTabPanel.openConfigs"));
124: ret.add(btnOpenConfigs, gbc);
125:
126: return ret;
127: }
128:
129: public void addToToolbar(JComponent comp) {
130: GridBagConstraints gbc = new GridBagConstraints(
131: _curXOfToolbar++, 0, 1, 1, 0, 0,
132: GridBagConstraints.WEST, GridBagConstraints.NONE,
133: new Insets(5, 5, 5, 5), 0, 0);
134: _toolbar.add(comp, gbc);
135:
136: _toolbar.validate();
137: }
138: }
|