1
2
3
4
5
6
7
8
9
10 package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver.ui;
11
12 import java.util.prefs.Preferences;
13
14 import javax.swing.SpinnerNumberModel;
15
16 import org.netbeans.api.project.Project;
17
18 import de.funfried.netbeans.plugins.external.formatter.sql.dbeaver.DBeaverFormatterSettings;
19 import de.funfried.netbeans.plugins.external.formatter.ui.options.AbstractFormatterOptionsPanel;
20
21
22
23
24
25 public class DBeaverFormatterOptionsPanel extends AbstractFormatterOptionsPanel {
26 private static final long serialVersionUID = -7567475629479033730L;
27
28
29
30
31
32
33
34 public DBeaverFormatterOptionsPanel(Project project) {
35 super(project);
36
37 initComponents();
38 }
39
40
41
42
43
44
45
46 @SuppressWarnings("unchecked")
47
48 private void initComponents() {
49
50 spellingLbl = new javax.swing.JLabel();
51 keywordsLbl = new javax.swing.JLabel();
52 keywordsCmbBox = new javax.swing.JComboBox<>();
53 dialectLbl = new javax.swing.JLabel();
54 statementDelimiterLbl = new javax.swing.JLabel();
55 statementDelimiterTxtFld = new javax.swing.JTextField();
56 indentWidthLbl = new javax.swing.JLabel();
57 indentWidthSpnr = new javax.swing.JSpinner();
58 positioningLbl = new javax.swing.JLabel();
59 expandTabsToSpacesChkBox = new javax.swing.JCheckBox();
60
61 spellingLbl.setFont(new java.awt.Font("Helvetica Neue", 1, 13));
62 org.openide.awt.Mnemonics.setLocalizedText(spellingLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.spellingLbl.text"));
63
64 org.openide.awt.Mnemonics.setLocalizedText(keywordsLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.keywordsLbl.text"));
65
66 keywordsCmbBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "UPPER", "LOWER", "ORIGINAL" }));
67 keywordsCmbBox.setSelectedItem(DBeaverFormatterSettings.KEYWORD_CASE_DEFAULT);
68
69 dialectLbl.setFont(new java.awt.Font("Helvetica Neue", 1, 13));
70 org.openide.awt.Mnemonics.setLocalizedText(dialectLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.dialectLbl.text"));
71
72 org.openide.awt.Mnemonics.setLocalizedText(statementDelimiterLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.statementDelimiterLbl.text"));
73
74 statementDelimiterTxtFld.setText(DBeaverFormatterSettings.STATEMENT_DELIMITER_DEFAULT);
75
76 org.openide.awt.Mnemonics.setLocalizedText(indentWidthLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.indentWidthLbl.text"));
77
78 indentWidthSpnr.setModel(new SpinnerNumberModel(DBeaverFormatterSettings.INDENT_SIZE_DEFAULT, 1, 24, 1));
79
80 positioningLbl.setFont(new java.awt.Font("Helvetica Neue", 1, 13));
81 org.openide.awt.Mnemonics.setLocalizedText(positioningLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.positioningLbl.text"));
82
83 expandTabsToSpacesChkBox.setSelected(true);
84 org.openide.awt.Mnemonics.setLocalizedText(expandTabsToSpacesChkBox, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.expandTabsToSpacesChkBox.text"));
85
86 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
87 this.setLayout(layout);
88 layout.setHorizontalGroup(
89 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90 .addGroup(layout.createSequentialGroup()
91 .addContainerGap()
92 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93 .addGroup(layout.createSequentialGroup()
94 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95 .addComponent(spellingLbl)
96 .addComponent(positioningLbl))
97 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
98 .addGroup(layout.createSequentialGroup()
99 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
100 .addComponent(dialectLbl)
101 .addGroup(layout.createSequentialGroup()
102 .addGap(6, 6, 6)
103 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104 .addGroup(layout.createSequentialGroup()
105 .addComponent(statementDelimiterLbl)
106 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
107 .addComponent(statementDelimiterTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
108 .addGroup(layout.createSequentialGroup()
109 .addComponent(indentWidthLbl)
110 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
111 .addComponent(indentWidthSpnr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
112 .addGap(18, 18, 18)
113 .addComponent(expandTabsToSpacesChkBox))
114 .addGroup(layout.createSequentialGroup()
115 .addComponent(keywordsLbl)
116 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
117 .addComponent(keywordsCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
118 .addGap(0, 0, Short.MAX_VALUE))))
119 );
120 layout.setVerticalGroup(
121 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122 .addGroup(layout.createSequentialGroup()
123 .addContainerGap()
124 .addComponent(spellingLbl)
125 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
126 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
127 .addComponent(keywordsLbl)
128 .addComponent(keywordsCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
129 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
130 .addComponent(positioningLbl)
131 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
132 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
133 .addComponent(indentWidthLbl)
134 .addComponent(indentWidthSpnr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
135 .addComponent(expandTabsToSpacesChkBox))
136 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
137 .addComponent(dialectLbl)
138 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
139 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
140 .addComponent(statementDelimiterLbl)
141 .addComponent(statementDelimiterTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
142 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
143 );
144 }
145
146
147 private javax.swing.JLabel dialectLbl;
148 private javax.swing.JCheckBox expandTabsToSpacesChkBox;
149 private javax.swing.JLabel indentWidthLbl;
150 private javax.swing.JSpinner indentWidthSpnr;
151 private javax.swing.JComboBox<String> keywordsCmbBox;
152 private javax.swing.JLabel keywordsLbl;
153 private javax.swing.JLabel positioningLbl;
154 private javax.swing.JLabel spellingLbl;
155 private javax.swing.JLabel statementDelimiterLbl;
156 private javax.swing.JTextField statementDelimiterTxtFld;
157
158
159
160
161
162 @Override
163 public void load(Preferences preferences) {
164 keywordsCmbBox.setSelectedItem(preferences.get(DBeaverFormatterSettings.KEYWORD_CASE, DBeaverFormatterSettings.KEYWORD_CASE_DEFAULT));
165 indentWidthSpnr.setValue(preferences.getInt(DBeaverFormatterSettings.INDENT_SIZE, DBeaverFormatterSettings.INDENT_SIZE_DEFAULT));
166 expandTabsToSpacesChkBox.setSelected("space".equals(preferences.get(DBeaverFormatterSettings.INDENT_TYPE, DBeaverFormatterSettings.INDENT_TYPE_DEFAULT)));
167 statementDelimiterTxtFld.setText(preferences.get(DBeaverFormatterSettings.STATEMENT_DELIMITER, DBeaverFormatterSettings.STATEMENT_DELIMITER_DEFAULT));
168 }
169
170
171
172
173 @Override
174 public void store(Preferences preferences) {
175 preferences.put(DBeaverFormatterSettings.KEYWORD_CASE, String.valueOf(keywordsCmbBox.getSelectedItem()));
176 preferences.putInt(DBeaverFormatterSettings.INDENT_SIZE, Integer.parseInt(String.valueOf(indentWidthSpnr.getValue())));
177 preferences.put(DBeaverFormatterSettings.INDENT_TYPE, expandTabsToSpacesChkBox.isSelected() ? "space" : "tab");
178 preferences.put(DBeaverFormatterSettings.STATEMENT_DELIMITER, statementDelimiterTxtFld.getText());
179 }
180
181
182
183
184 @Override
185 public boolean valid() {
186 return true;
187 }
188 }