26 |
26 |
import java.awt.event.ActionListener;
|
27 |
27 |
import javax.swing.DefaultListModel;
|
28 |
28 |
import javax.swing.JComponent;
|
|
29 |
import org.apache.commons.lang3.ArrayUtils;
|
29 |
30 |
import org.apache.commons.lang3.StringUtils;
|
30 |
31 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCOptions;
|
31 |
32 |
|
32 |
33 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
|
33 |
34 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
|
34 |
|
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
|
35 |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
36 |
36 |
import org.gvsig.fmap.dal.feature.FeatureType;
|
37 |
37 |
import org.gvsig.tools.ToolsLocator;
|
... | ... | |
46 |
46 |
|
47 |
47 |
private static final long serialVersionUID = 2652404227373508779L;
|
48 |
48 |
|
49 |
|
private ExporttoJDBCOptions provider;
|
|
49 |
private final ExporttoJDBCOptions provider;
|
50 |
50 |
|
51 |
51 |
public SelectPkPanel(ExporttoJDBCOptions provider) {
|
52 |
52 |
this.provider = provider;
|
... | ... | |
55 |
55 |
|
56 |
56 |
protected void initComponents() {
|
57 |
57 |
this.rdoCreatePrimaryNewKey.addActionListener(new ActionListener() {
|
|
58 |
@Override
|
58 |
59 |
public void actionPerformed(ActionEvent e) {
|
59 |
60 |
onSelect();
|
60 |
61 |
}
|
61 |
62 |
});
|
62 |
63 |
this.rdoUseExistingFieldAsPrimariKey.addActionListener(new ActionListener() {
|
|
64 |
@Override
|
63 |
65 |
public void actionPerformed(ActionEvent e) {
|
64 |
66 |
onSelect();
|
65 |
67 |
}
|
66 |
68 |
});
|
67 |
69 |
this.rdoDoNotCreatePrimaryKey.addActionListener(new ActionListener() {
|
|
70 |
@Override
|
68 |
71 |
public void actionPerformed(ActionEvent e) {
|
69 |
72 |
onSelect();
|
70 |
73 |
}
|
71 |
74 |
});
|
72 |
|
this.rdoCreatePrimaryNewKey.setSelected(true);
|
|
75 |
if( this.hasSourcePrimaryKey() ) {
|
|
76 |
this.rdoDoNotCreatePrimaryKey.setSelected(true);
|
|
77 |
} else {
|
|
78 |
this.rdoCreatePrimaryNewKey.setSelected(true);
|
|
79 |
}
|
73 |
80 |
this.translate();
|
74 |
81 |
}
|
75 |
82 |
|
... | ... | |
113 |
120 |
return pkname.trim();
|
114 |
121 |
}
|
115 |
122 |
|
|
123 |
@Override
|
116 |
124 |
public String getPanelTitle() {
|
117 |
125 |
I18nManager i18nManager = ToolsLocator.getI18nManager();
|
118 |
126 |
return i18nManager.getTranslation("_Primary_key");
|
119 |
127 |
}
|
120 |
128 |
|
|
129 |
@Override
|
121 |
130 |
public boolean isValidPanel() throws ExporttoPanelValidationException {
|
122 |
131 |
return true;
|
123 |
132 |
}
|
|
133 |
|
|
134 |
private boolean hasSourcePrimaryKey() {
|
|
135 |
try {
|
|
136 |
FeatureType featureType = this.provider.getSource().getDefaultFeatureType();
|
|
137 |
return ! ArrayUtils.isEmpty(featureType.getPrimaryKey());
|
|
138 |
} catch (Exception ex) {
|
|
139 |
return false;
|
|
140 |
}
|
|
141 |
}
|
124 |
142 |
|
|
143 |
@Override
|
125 |
144 |
public void enterPanel() {
|
126 |
145 |
this.fillListOfFields();
|
127 |
146 |
if( !this.provider.canCreatetable() ) {
|
... | ... | |
140 |
159 |
if (! this.rdoCreatePrimaryNewKey.isSelected()
|
141 |
160 |
&& ! this.rdoUseExistingFieldAsPrimariKey.isSelected()
|
142 |
161 |
&& ! this.rdoDoNotCreatePrimaryKey.isSelected()) {
|
143 |
|
this.rdoCreatePrimaryNewKey.setSelected(true);
|
|
162 |
if( this.hasSourcePrimaryKey() ) {
|
|
163 |
this.rdoDoNotCreatePrimaryKey.setSelected(true);
|
|
164 |
} else {
|
|
165 |
this.rdoCreatePrimaryNewKey.setSelected(true);
|
|
166 |
}
|
144 |
167 |
}
|
145 |
168 |
}
|
146 |
169 |
}
|
147 |
170 |
|
|
171 |
@Override
|
148 |
172 |
public JComponent asJComponent() {
|
149 |
173 |
return this;
|
150 |
174 |
}
|