01: /*
02: * KeyColumnSelectorPanel.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.GridBagConstraints;
15: import java.awt.GridBagLayout;
16: import java.awt.Insets;
17: import javax.swing.JCheckBox;
18:
19: import javax.swing.JLabel;
20:
21: import workbench.db.ColumnIdentifier;
22: import workbench.db.TableIdentifier;
23: import workbench.resource.ResourceMgr;
24:
25: /**
26: *
27: * @author support@sql-workbench.net
28: */
29: public class KeyColumnSelectorPanel extends ColumnSelectorPanel {
30: private ColumnIdentifier[] columns;
31: private String tableName;
32: private JCheckBox saveCheckBox;
33:
34: public KeyColumnSelectorPanel(ColumnIdentifier[] cols,
35: TableIdentifier table) {
36: super (cols);
37: this .tableName = (table == null ? "" : table.getTableName());
38: this .setSelectionLabel(ResourceMgr
39: .getString("LblHeaderKeyColumnPKFlag"));
40: configureInfoPanel();
41: this .doLayout();
42: this .columns = new ColumnIdentifier[cols.length];
43: for (int i = 0; i < this .columns.length; i++) {
44: this .columns[i] = cols[i].createCopy();
45: this .setColumnSelected(i, cols[i].isPkColumn());
46: }
47: }
48:
49: protected void configureInfoPanel() {
50: if (this .tableName == null) {
51: return;
52: }
53:
54: String msg = ResourceMgr.getString("MsgSelectKeyColumns")
55: .replaceAll("%tablename%", tableName);
56: JLabel infoLabel = new JLabel(msg);
57: this .infoPanel.setLayout(new GridBagLayout());
58: GridBagConstraints c = new GridBagConstraints();
59: c.gridx = 0;
60: c.gridy = 0;
61: c.fill = GridBagConstraints.BOTH;
62: c.anchor = GridBagConstraints.NORTHWEST;
63: c.weightx = 1.0;
64:
65: this .infoPanel.add(infoLabel, c);
66:
67: this .saveCheckBox = new JCheckBox(ResourceMgr
68: .getString("LblRememberPKMapping"));
69: this .saveCheckBox.setToolTipText(ResourceMgr
70: .getDescription("LblRememberPKMapping"));
71: c.gridx = 0;
72: c.gridy = 1;
73: c.fill = GridBagConstraints.NONE;
74: c.anchor = GridBagConstraints.NORTHWEST;
75: c.weighty = 1.0;
76: c.weightx = 0.0;
77: c.insets = new Insets(5, 0, 5, 0);
78: this .infoPanel.add(saveCheckBox, c);
79: }
80:
81: public boolean getSaveToGlobalPKMap() {
82: return this .saveCheckBox.isSelected();
83: }
84:
85: public ColumnIdentifier[] getColumns() {
86: for (int i = 0; i < this.columns.length; i++) {
87: columns[i].setIsPkColumn(this.isColumnSelected(i));
88: }
89: return this.columns;
90: }
91: }
|