001: package net.sourceforge.squirrel_sql.client.session.properties;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.Component;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025:
026: import javax.swing.*;
027:
028: import net.sourceforge.squirrel_sql.client.IApplication;
029: import net.sourceforge.squirrel_sql.client.preferences.INewSessionPropertiesPanel;
030: import net.sourceforge.squirrel_sql.client.session.ISession;
031: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetViewerEditableTablePanel;
032: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetViewerTablePanel;
033: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetViewerTextPanel;
034: import net.sourceforge.squirrel_sql.fw.util.StringManager;
035: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
036:
037: public class GeneralSessionPropertiesPanel implements
038: INewSessionPropertiesPanel, ISessionPropertiesPanel {
039:
040: private static final StringManager s_stringMgr = StringManagerFactory
041: .getStringManager(GeneralSessionPropertiesPanel.class);
042:
043: /**
044: * This interface defines locale specific strings. This should be
045: * replaced with a property file.
046: */
047: interface GeneralSessionPropertiesPanelI18n {
048: // i18n[generalSessionPropertiesPanel.generalSettings=General settings for the current session]
049: String HINT = s_stringMgr
050: .getString("generalSessionPropertiesPanel.generalSettings");
051: // i18n[generalSessionPropertiesPanel.mainTabs=Main Tabs:]
052: String MAIN_TAB_PLACEMENT = s_stringMgr
053: .getString("generalSessionPropertiesPanel.mainTabs");
054: // i18n[generalSessionPropertiesPanel.metaData=Meta Data:]
055: String META_DATA = s_stringMgr
056: .getString("generalSessionPropertiesPanel.metaData");
057: // i18n[generalSessionPropertiesPanel.showToolbar=Show toolbar]
058: String SHOW_TOOLBAR = s_stringMgr
059: .getString("generalSessionPropertiesPanel.showToolbar");
060: // i18n[generalSessionPropertiesPanel.objectTabs=Object Tabs:]
061: String OBJECT_TAB_PLACEMENT = s_stringMgr
062: .getString("generalSessionPropertiesPanel.objectTabs");
063: // i18n[generalSessionPropertiesPanel.sqlExecTabs=SQL Execution Tabs:]
064: String SQL_EXECUTION_TAB_PLACEMENT = s_stringMgr
065: .getString("generalSessionPropertiesPanel.sqlExecTabs");
066: // i18n[generalSessionPropertiesPanel.sqlResults=SQL Results:]
067: String SQL_RESULTS = s_stringMgr
068: .getString("generalSessionPropertiesPanel.sqlResults");
069: // i18n[generalSessionPropertiesPanel.sqlResultTabs=SQL Results Tabs:]
070: String SQL_RESULTS_TAB_PLACEMENT = s_stringMgr
071: .getString("generalSessionPropertiesPanel.sqlResultTabs");
072: // i18n[generalSessionPropertiesPanel.general=General]
073: String TITLE = s_stringMgr
074: .getString("generalSessionPropertiesPanel.general");
075: // i18n[generalSessionPropertiesPanel.tableContents=Table Contents:]
076: String TABLE_CONTENTS = s_stringMgr
077: .getString("generalSessionPropertiesPanel.tableContents");
078:
079: // i18n[generalSessionPropertiesPanel.table=Table]
080: String TABLE = s_stringMgr
081: .getString("generalSessionPropertiesPanel.table");
082: // i18n[generalSessionPropertiesPanel.editableTable=Editable Table]
083: String EDITABLE_TABLE = s_stringMgr
084: .getString("generalSessionPropertiesPanel.editableTable");
085: // i18n[generalSessionPropertiesPanel.text=Text]
086: String TEXT = s_stringMgr
087: .getString("generalSessionPropertiesPanel.text");
088:
089: // i18n[generalSessionPropertiesPanel.dataTYpe1=Properties for the individual Data Types may be set in the]
090: String DATA_TYPE1 = s_stringMgr
091: .getString("generalSessionPropertiesPanel.dataTYpe1");
092: // i18n[generalSessionPropertiesPanel.dataTYpe2='General Preferences' window under the 'Data Type Controls' tab.]
093: String DATA_TYPE2 = s_stringMgr
094: .getString("generalSessionPropertiesPanel.dataTYpe2");
095: }
096:
097: private SessionProperties _props;
098:
099: private MyPanel _myPanel = new MyPanel();
100: private JScrollPane _scrolledMyPanel = new JScrollPane(_myPanel);
101:
102: public GeneralSessionPropertiesPanel() {
103: super ();
104: }
105:
106: public void initialize(IApplication app)
107: throws IllegalArgumentException {
108: if (app == null) {
109: throw new IllegalArgumentException(
110: "Null IApplication passed");
111: }
112: _props = app.getSquirrelPreferences().getSessionProperties();
113:
114: _myPanel.loadData(_props);
115: }
116:
117: public void initialize(IApplication app, ISession session)
118: throws IllegalArgumentException {
119: if (app == null) {
120: throw new IllegalArgumentException(
121: "Null IApplication passed");
122: }
123: if (session == null) {
124: throw new IllegalArgumentException("Null ISession passed");
125: }
126:
127: _props = session.getProperties();
128:
129: _myPanel.loadData(_props);
130: }
131:
132: public Component getPanelComponent() {
133: return _scrolledMyPanel;
134: }
135:
136: public String getTitle() {
137: return GeneralSessionPropertiesPanelI18n.TITLE;
138: }
139:
140: public String getHint() {
141: return GeneralSessionPropertiesPanelI18n.HINT;
142: }
143:
144: public void applyChanges() {
145: _myPanel.applyChanges(_props);
146: }
147:
148: private static final class MyPanel extends JPanel {
149: private JCheckBox _showToolBar = new JCheckBox(
150: GeneralSessionPropertiesPanelI18n.SHOW_TOOLBAR);
151: private TabPlacementCombo _mainTabPlacementCmb = new TabPlacementCombo();
152: private TabPlacementCombo _objectTabPlacementCmb = new TabPlacementCombo();
153: private TabPlacementCombo _sqlExecutionTabPlacementCmb = new TabPlacementCombo();
154: private TabPlacementCombo _sqlResultsTabPlacementCmb = new TabPlacementCombo();
155: private OutputTypeCombo _metaDataCmb = new OutputTypeCombo(
156: false);
157: private OutputTypeCombo _sqlResultsCmb = new OutputTypeCombo(
158: true);
159: private OutputTypeCombo _tableContentsCmb = new OutputTypeCombo(
160: true);
161:
162: MyPanel() {
163: super (new GridBagLayout());
164: createGUI();
165: }
166:
167: void loadData(SessionProperties props) {
168: _showToolBar.setSelected(props.getShowToolBar());
169:
170: int mainTabPlacement = props.getMainTabPlacement();
171: for (int i = 0, limit = _mainTabPlacementCmb.getModel()
172: .getSize(); i < limit; ++i) {
173: TabPlacement tp = (TabPlacement) _mainTabPlacementCmb
174: .getItemAt(i);
175: if (tp.getValue() == mainTabPlacement) {
176: _mainTabPlacementCmb.setSelectedIndex(i);
177: break;
178: }
179: }
180: if (_mainTabPlacementCmb.getSelectedIndex() == -1) {
181: _mainTabPlacementCmb.setSelectedIndex(0);
182: }
183:
184: int objectTabPlacement = props.getObjectTabPlacement();
185: for (int i = 0, limit = _objectTabPlacementCmb.getModel()
186: .getSize(); i < limit; ++i) {
187: TabPlacement tp = (TabPlacement) _objectTabPlacementCmb
188: .getItemAt(i);
189: if (tp.getValue() == objectTabPlacement) {
190: _objectTabPlacementCmb.setSelectedIndex(i);
191: break;
192: }
193: }
194: if (_objectTabPlacementCmb.getSelectedIndex() == -1) {
195: _objectTabPlacementCmb.setSelectedIndex(0);
196: }
197:
198: int sqlExecutionTabPlacement = props
199: .getSQLExecutionTabPlacement();
200: for (int i = 0, limit = _sqlExecutionTabPlacementCmb
201: .getModel().getSize(); i < limit; ++i) {
202: TabPlacement tp = (TabPlacement) _sqlExecutionTabPlacementCmb
203: .getItemAt(i);
204: if (tp.getValue() == sqlExecutionTabPlacement) {
205: _sqlExecutionTabPlacementCmb.setSelectedIndex(i);
206: break;
207: }
208: }
209: if (_sqlExecutionTabPlacementCmb.getSelectedIndex() == -1) {
210: _sqlExecutionTabPlacementCmb.setSelectedIndex(0);
211: }
212:
213: int sqlResultsTabPlacement = props
214: .getSQLResultsTabPlacement();
215: for (int i = 0, limit = _sqlResultsTabPlacementCmb
216: .getModel().getSize(); i < limit; ++i) {
217: TabPlacement tp = (TabPlacement) _sqlResultsTabPlacementCmb
218: .getItemAt(i);
219: if (tp.getValue() == sqlResultsTabPlacement) {
220: _sqlResultsTabPlacementCmb.setSelectedIndex(i);
221: break;
222: }
223: }
224: if (_sqlResultsTabPlacementCmb.getSelectedIndex() == -1) {
225: _sqlResultsTabPlacementCmb.setSelectedIndex(0);
226: }
227:
228: _metaDataCmb.selectClassName(props
229: .getMetaDataOutputClassName());
230: _sqlResultsCmb.selectClassName(props
231: .getSQLResultsOutputClassName());
232: _tableContentsCmb.selectClassName(props
233: .getTableContentsOutputClassName());
234: }
235:
236: void applyChanges(SessionProperties props) {
237: props.setShowToolBar(_showToolBar.isSelected());
238: props.setMetaDataOutputClassName(_metaDataCmb
239: .getSelectedClassName());
240: props.setSQLResultsOutputClassName(_sqlResultsCmb
241: .getSelectedClassName());
242: props.setTableContentsOutputClassName(_tableContentsCmb
243: .getSelectedClassName());
244:
245: TabPlacement tp = (TabPlacement) _mainTabPlacementCmb
246: .getSelectedItem();
247: props.setMainTabPlacement(tp.getValue());
248:
249: tp = (TabPlacement) _objectTabPlacementCmb
250: .getSelectedItem();
251: props.setObjectTabPlacement(tp.getValue());
252:
253: tp = (TabPlacement) _sqlExecutionTabPlacementCmb
254: .getSelectedItem();
255: props.setSQLExecutionTabPlacement(tp.getValue());
256:
257: tp = (TabPlacement) _sqlResultsTabPlacementCmb
258: .getSelectedItem();
259: props.setSQLResultsTabPlacement(tp.getValue());
260: }
261:
262: private void createGUI() {
263: final GridBagConstraints gbc = new GridBagConstraints();
264: gbc.anchor = GridBagConstraints.WEST;
265: gbc.fill = GridBagConstraints.HORIZONTAL;
266: gbc.insets = new Insets(4, 4, 4, 4);
267:
268: gbc.gridx = 0;
269: gbc.gridy = 0;
270: add(createAppearancePanel(), gbc);
271:
272: ++gbc.gridy;
273: add(createOutputPanel(), gbc);
274:
275: ++gbc.gridy;
276: add(new JLabel(""), gbc);
277: ++gbc.gridy;
278: add(
279: new JLabel(
280: GeneralSessionPropertiesPanelI18n.DATA_TYPE1),
281: gbc);
282: ++gbc.gridy;
283: add(
284: new JLabel(
285: GeneralSessionPropertiesPanelI18n.DATA_TYPE2),
286: gbc);
287: }
288:
289: private JPanel createAppearancePanel() {
290: JPanel pnl = new JPanel(new GridBagLayout());
291: // i18n[generalSessionPropertiesPanel.appearance=Appearance]
292: pnl
293: .setBorder(BorderFactory
294: .createTitledBorder(s_stringMgr
295: .getString("generalSessionPropertiesPanel.appearance")));
296:
297: final GridBagConstraints gbc = new GridBagConstraints();
298: gbc.fill = GridBagConstraints.HORIZONTAL;
299: gbc.anchor = GridBagConstraints.WEST;
300: gbc.insets = new Insets(4, 4, 4, 4);
301:
302: gbc.gridx = 0;
303: gbc.gridy = 0;
304: pnl.add(_showToolBar, gbc);
305:
306: ++gbc.gridy;
307: pnl
308: .add(
309: new JLabel(
310: GeneralSessionPropertiesPanelI18n.MAIN_TAB_PLACEMENT,
311: SwingConstants.RIGHT), gbc);
312:
313: ++gbc.gridx;
314: gbc.weightx = 0.5;
315: pnl.add(_mainTabPlacementCmb, gbc);
316:
317: ++gbc.gridx;
318: gbc.weightx = 0.0;
319: pnl
320: .add(
321: new JLabel(
322: GeneralSessionPropertiesPanelI18n.OBJECT_TAB_PLACEMENT,
323: SwingConstants.RIGHT), gbc);
324:
325: ++gbc.gridx;
326: gbc.weightx = 0.5;
327: pnl.add(_objectTabPlacementCmb, gbc);
328:
329: gbc.gridx = 0;
330: ++gbc.gridy;
331: pnl
332: .add(
333: new JLabel(
334: GeneralSessionPropertiesPanelI18n.SQL_EXECUTION_TAB_PLACEMENT,
335: SwingConstants.RIGHT), gbc);
336:
337: ++gbc.gridx;
338: gbc.weightx = 0.5;
339: pnl.add(_sqlExecutionTabPlacementCmb, gbc);
340:
341: ++gbc.gridx;
342: gbc.weightx = 0.0;
343: pnl
344: .add(
345: new JLabel(
346: GeneralSessionPropertiesPanelI18n.SQL_RESULTS_TAB_PLACEMENT,
347: SwingConstants.RIGHT), gbc);
348:
349: ++gbc.gridx;
350: gbc.weightx = 0.5;
351: pnl.add(_sqlResultsTabPlacementCmb, gbc);
352:
353: return pnl;
354: }
355:
356: private JPanel createOutputPanel() {
357: JPanel pnl = new JPanel(new GridBagLayout());
358: // i18n[editWherColsSheet.output=Output]
359: pnl.setBorder(BorderFactory.createTitledBorder(s_stringMgr
360: .getString("editWherColsSheet.output")));
361:
362: final GridBagConstraints gbc = new GridBagConstraints();
363: gbc.fill = GridBagConstraints.HORIZONTAL;
364: gbc.insets = new Insets(4, 4, 4, 4);
365:
366: gbc.gridx = 0;
367: gbc.gridy = 0;
368: pnl.add(new JLabel(
369: GeneralSessionPropertiesPanelI18n.META_DATA,
370: SwingConstants.RIGHT), gbc);
371:
372: ++gbc.gridx;
373: pnl.add(_metaDataCmb, gbc);
374:
375: ++gbc.gridy;
376: gbc.gridx = 0;
377: pnl.add(new JLabel(
378: GeneralSessionPropertiesPanelI18n.TABLE_CONTENTS,
379: SwingConstants.RIGHT), gbc);
380:
381: ++gbc.gridx;
382: pnl.add(_tableContentsCmb, gbc);
383:
384: ++gbc.gridy;
385: gbc.gridx = 0;
386: pnl.add(new JLabel(
387: GeneralSessionPropertiesPanelI18n.SQL_RESULTS,
388: SwingConstants.RIGHT), gbc);
389:
390: ++gbc.gridx;
391: pnl.add(_sqlResultsCmb, gbc);
392:
393: return pnl;
394: }
395: }
396:
397: private final static class OutputType {
398: static final OutputType TEXT = new OutputType(
399: GeneralSessionPropertiesPanelI18n.TEXT,
400: DataSetViewerTextPanel.class.getName());
401: static final OutputType TABLE = new OutputType(
402: GeneralSessionPropertiesPanelI18n.TABLE,
403: DataSetViewerTablePanel.class.getName());
404: static final OutputType EDITABLE_TABLE = new OutputType(
405: GeneralSessionPropertiesPanelI18n.EDITABLE_TABLE,
406: DataSetViewerEditableTablePanel.class.getName());
407: private final String _name;
408: private final String _className;
409:
410: OutputType(String name, String className) {
411: super ();
412: _name = name;
413: _className = className;
414: }
415:
416: public String toString() {
417: return _name;
418: }
419:
420: String getPanelClassName() {
421: return _className;
422: }
423: }
424:
425: private static final class OutputTypeCombo extends JComboBox {
426: OutputTypeCombo(boolean possiblyEditable) {
427: super ();
428: addItem(OutputType.TABLE);
429: addItem(OutputType.TEXT);
430: if (possiblyEditable) {
431: addItem(OutputType.EDITABLE_TABLE);
432: }
433: }
434:
435: void selectClassName(String className) {
436: if (className.equals(DataSetViewerTablePanel.class
437: .getName())) {
438: setSelectedItem(OutputType.TABLE);
439: } else if (className.equals(DataSetViewerTextPanel.class
440: .getName())) {
441: setSelectedItem(OutputType.TEXT);
442: } else if (className
443: .equals(DataSetViewerEditableTablePanel.class
444: .getName())) {
445: setSelectedItem(OutputType.EDITABLE_TABLE);
446: }
447: }
448:
449: String getSelectedClassName() {
450: return ((OutputType) getSelectedItem()).getPanelClassName();
451: }
452: }
453:
454: private static final class TabPlacement {
455: // i18n[generalPropertiesPanel.top=Top]
456: static final TabPlacement TOP = new TabPlacement(s_stringMgr
457: .getString("generalPropertiesPanel.top"),
458: SwingConstants.TOP);
459: // i18n[generalPropertiesPanel.left=Left]
460: static final TabPlacement LEFT = new TabPlacement(s_stringMgr
461: .getString("generalPropertiesPanel.left"),
462: SwingConstants.LEFT);
463: // i18n[generalPropertiesPanel.bottom=Bottom]
464: static final TabPlacement BOTTOM = new TabPlacement(s_stringMgr
465: .getString("generalPropertiesPanel.bottom"),
466: SwingConstants.BOTTOM);
467: // i18n[generalPropertiesPanel.right=Right]
468: static final TabPlacement RIGHT = new TabPlacement(s_stringMgr
469: .getString("generalPropertiesPanel.right"),
470: SwingConstants.RIGHT);
471:
472: private final String _name;
473: private final int _value;
474:
475: TabPlacement(String name, int value) {
476: super ();
477: _name = name;
478: _value = value;
479: }
480:
481: public String toString() {
482: return _name;
483: }
484:
485: int getValue() {
486: return _value;
487: }
488: }
489:
490: private static final class TabPlacementCombo extends JComboBox {
491: TabPlacementCombo() {
492: super ();
493: addItem(TabPlacement.TOP);
494: addItem(TabPlacement.LEFT);
495: addItem(TabPlacement.BOTTOM);
496: addItem(TabPlacement.RIGHT);
497: }
498:
499: void selectClassName(String className) {
500: if (className.equals(DataSetViewerTablePanel.class
501: .getName())) {
502: setSelectedItem(OutputType.TABLE);
503: } else if (className.equals(DataSetViewerTextPanel.class
504: .getName())) {
505: setSelectedItem(OutputType.TEXT);
506: } else if (className
507: .equals(DataSetViewerEditableTablePanel.class
508: .getName())) {
509: setSelectedItem(OutputType.EDITABLE_TABLE);
510: }
511: }
512:
513: String getSelectedClassName() {
514: return ((OutputType) getSelectedItem()).getPanelClassName();
515: }
516: }
517: }
|