View Javadoc
1   /*
2    * Copyright (c) 2021 bahlef.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v2.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v20.html
7    * Contributors:
8    * bahlef - initial API and implementation and/or initial documentation
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   * @author bahlef
24   */
25  public class DBeaverFormatterOptionsPanel extends AbstractFormatterOptionsPanel {
26  	private static final long serialVersionUID = -7567475629479033730L;
27  
28  	/**
29  	 * Creates new form {@link DBeaverFormatterOptionsPanel}.
30  	 *
31  	 * @param project the {@link Project} if the panel is used to modify project
32  	 *        specific settings, otherwise {@code null}
33  	 */
34  	public DBeaverFormatterOptionsPanel(Project project) {
35  		super(project);
36  
37  		initComponents();
38  	}
39  
40  	/**
41  	 * This method is called from within the constructor to
42  	 * initialize the form.
43  	 * WARNING: Do NOT modify this code. The content of this method is
44  	 * always regenerated by the Form Editor.
45  	 */
46  	@SuppressWarnings("unchecked")
47      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
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)); // NOI18N
62          org.openide.awt.Mnemonics.setLocalizedText(spellingLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.spellingLbl.text")); // NOI18N
63  
64          org.openide.awt.Mnemonics.setLocalizedText(keywordsLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.keywordsLbl.text")); // NOI18N
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)); // NOI18N
70          org.openide.awt.Mnemonics.setLocalizedText(dialectLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.dialectLbl.text")); // NOI18N
71  
72          org.openide.awt.Mnemonics.setLocalizedText(statementDelimiterLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.statementDelimiterLbl.text")); // NOI18N
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")); // NOI18N
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)); // NOI18N
81          org.openide.awt.Mnemonics.setLocalizedText(positioningLbl, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.positioningLbl.text")); // NOI18N
82  
83          expandTabsToSpacesChkBox.setSelected(true);
84          org.openide.awt.Mnemonics.setLocalizedText(expandTabsToSpacesChkBox, org.openide.util.NbBundle.getMessage(DBeaverFormatterOptionsPanel.class, "DBeaverFormatterOptionsPanel.expandTabsToSpacesChkBox.text")); // NOI18N
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     }// </editor-fold>//GEN-END:initComponents
145 
146     // Variables declaration - do not modify//GEN-BEGIN:variables
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     // End of variables declaration//GEN-END:variables
158 
159 	/**
160 	 * {@inheritDoc}
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 	 * {@inheritDoc}
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 	 * {@inheritDoc}
183 	 */
184 	@Override
185 	public boolean valid() {
186 		return true;
187 	}
188 }