diff --git a/db.dataview/nbproject/project.xml b/db.dataview/nbproject/project.xml --- a/db.dataview/nbproject/project.xml +++ b/db.dataview/nbproject/project.xml @@ -6,6 +6,15 @@ org.netbeans.modules.db.dataview + org.jdesktop.beansbinding + + + + 1 + 1.24 + + + org.netbeans.api.progress @@ -33,6 +42,15 @@ + org.netbeans.modules.options.api + + + + 1 + 1.41 + + + org.openide.awt diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/options/Bundle.properties b/db.dataview/src/org/netbeans/modules/db/dataview/options/Bundle.properties new file mode 100644 --- /dev/null +++ b/db.dataview/src/org/netbeans/modules/db/dataview/options/Bundle.properties @@ -0,0 +1,8 @@ +DataViewSettingsPanel.chkPackColumns.text=Pack columns +DataViewSettingsPanel.chkShowAbsoluteRowNumbers.text=Show absolute row numbers +DataViewSettingsPanel.rbRememberPageSize.text=Remember and use previous +DataViewSettingsPanel.lblPageSize.text=Default page size: +DataViewSettingsPanel.rbShowAllRows.text=Show all rows +DataViewSettingsPanel.rbFixedPageSize.text= +DataViewSettingsPanel.chkShowTruncateTableButton.text=Show truncate table button +DataViewSettingsPanel.chkCopyRowValuesWithHeaders.text=Copy row values with headers (keyboard) diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettings.java b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettings.java new file mode 100644 --- /dev/null +++ b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettings.java @@ -0,0 +1,109 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.db.dataview.options; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +/** + * + * @author Markus Opitz + */ +public final class DataViewSettings { + + public static final int PAGE_SIZE_REMEMBER = -1; + public static final int PAGE_SIZE_SHOW_ALL = 0; + + private static final String PROP_DEFAULT_PAGE_SIZE = "defaultPageSize"; + private static final String PROP_PACK_COLUMNS = "packColumns"; + private static final String PROP_SHOW_TRUNCATE_TABLE_BUTTON = "showTruncateTableButton"; + private static final String PROP_SHOW_ABSOLUTE_ROW_NUMBERS = "showAbsoluteRowNumbers"; + private static final String PROP_COPY_ROW_VALUES_WITH_HEADERS = "copyRowValuesWithHeaders"; + + private DataViewSettings() { + } + + public static int getDefaultPageSize() { + return getPreferences().getInt(PROP_DEFAULT_PAGE_SIZE, PAGE_SIZE_REMEMBER); + } + + public static void setDefautPageSize(int defaultPageSize) { + getPreferences().putInt(PROP_DEFAULT_PAGE_SIZE, defaultPageSize); + } + + public static boolean getPackColumns() { + return getPreferences().getBoolean(PROP_PACK_COLUMNS, false); + } + + public static void setPackColumns(boolean alwaysPackColumns) { + getPreferences().putBoolean(PROP_PACK_COLUMNS, alwaysPackColumns); + } + + public static boolean getShowTruncateTableButton() { + return getPreferences().getBoolean(PROP_SHOW_TRUNCATE_TABLE_BUTTON, true); + } + + public static void setShowTruncateTableButton(boolean showTruncateTableButton) { + getPreferences().putBoolean(PROP_SHOW_TRUNCATE_TABLE_BUTTON, showTruncateTableButton); + } + + public static boolean getShowAbsoluteRowNumbers() { + return getPreferences().getBoolean(PROP_SHOW_ABSOLUTE_ROW_NUMBERS, false); + } + + public static void setShowAbsoluteRowNumbers(boolean showAbsoluteRowNumbers) { + getPreferences().putBoolean(PROP_SHOW_ABSOLUTE_ROW_NUMBERS, showAbsoluteRowNumbers); + } + + public static boolean getCopyRowValuesWithHeaders() { + return getPreferences().getBoolean(PROP_COPY_ROW_VALUES_WITH_HEADERS, false); + } + + public static void setCopyRowValuesWithHeaders(boolean copyRowsWithHeaders) { + getPreferences().putBoolean(PROP_COPY_ROW_VALUES_WITH_HEADERS, copyRowsWithHeaders); + } + + private static Preferences getPreferences() { + return NbPreferences.forModule(DataViewSettings.class); + } +} diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsOptionsPanelController.java b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsOptionsPanelController.java new file mode 100644 --- /dev/null +++ b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsOptionsPanelController.java @@ -0,0 +1,122 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.dataview.options; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import javax.swing.SwingUtilities; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +@OptionsPanelController.SubRegistration( + displayName = "#AdvancedOption_DisplayName_DataViewSettings", + keywords = "#AdvancedOption_Keywords_DataViewSettings", + keywordsCategory = "Advanced/DataViewSettings" +) +@org.openide.util.NbBundle.Messages({"AdvancedOption_DisplayName_DataViewSettings=SQL Data View", "AdvancedOption_Keywords_DataViewSettings=SQL"}) +public final class DataViewSettingsOptionsPanelController extends OptionsPanelController { + + private DataViewSettingsPanel panel; + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + public void update() { + getPanel().load(); + changed = false; + } + + public void applyChanges() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + getPanel().store(); + changed = false; + } + }); + } + + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + public boolean isValid() { + return getPanel().valid(); + } + + public boolean isChanged() { + return changed; + } + + public HelpCtx getHelpCtx() { + return null; // new HelpCtx("...ID") if you have a help set + } + + public JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + private DataViewSettingsPanel getPanel() { + if (panel == null) { + panel = new DataViewSettingsPanel(this); + } + return panel; + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.form b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.form new file mode 100644 --- /dev/null +++ b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.form @@ -0,0 +1,137 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.java b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.java new file mode 100644 --- /dev/null +++ b/db.dataview/src/org/netbeans/modules/db/dataview/options/DataViewSettingsPanel.java @@ -0,0 +1,195 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.dataview.options; + +import org.netbeans.modules.db.dataview.api.DataViewPageContext; + +final class DataViewSettingsPanel extends javax.swing.JPanel { + + private final DataViewSettingsOptionsPanelController controller; + + DataViewSettingsPanel(DataViewSettingsOptionsPanelController controller) { + this.controller = controller; + initComponents(); + pageSizeButtonGroup.add(rbRememberPageSize); + pageSizeButtonGroup.add(rbShowAllRows); + pageSizeButtonGroup.add(rbFixedPageSize); + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT + * modify this code. The content of this method is always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); + + pageSizeButtonGroup = new javax.swing.ButtonGroup(); + chkShowTruncateTableButton = new javax.swing.JCheckBox(); + chkShowAbsoluteRowNumbers = new javax.swing.JCheckBox(); + chkPackColumns = new javax.swing.JCheckBox(); + chkCopyRowValuesWithHeaders = new javax.swing.JCheckBox(); + rbRememberPageSize = new javax.swing.JRadioButton(); + rbFixedPageSize = new javax.swing.JRadioButton(); + spnFixedPageSize = new javax.swing.JSpinner(); + lblPageSize = new javax.swing.JLabel(); + rbShowAllRows = new javax.swing.JRadioButton(); + + chkShowTruncateTableButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(chkShowTruncateTableButton, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.chkShowTruncateTableButton.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(chkShowAbsoluteRowNumbers, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.chkShowAbsoluteRowNumbers.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(chkPackColumns, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.chkPackColumns.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(chkCopyRowValuesWithHeaders, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.chkCopyRowValuesWithHeaders.text")); // NOI18N + + rbRememberPageSize.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(rbRememberPageSize, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.rbRememberPageSize.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(rbFixedPageSize, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.rbFixedPageSize.text")); // NOI18N + + org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rbFixedPageSize, org.jdesktop.beansbinding.ELProperty.create("${selected}"), spnFixedPageSize, org.jdesktop.beansbinding.BeanProperty.create("enabled")); + bindingGroup.addBinding(binding); + + org.openide.awt.Mnemonics.setLocalizedText(lblPageSize, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.lblPageSize.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(rbShowAllRows, org.openide.util.NbBundle.getMessage(DataViewSettingsPanel.class, "DataViewSettingsPanel.rbShowAllRows.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(chkShowAbsoluteRowNumbers) + .addComponent(chkShowTruncateTableButton) + .addComponent(chkCopyRowValuesWithHeaders) + .addComponent(chkPackColumns) + .addComponent(lblPageSize) + .addComponent(rbRememberPageSize) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(rbFixedPageSize) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(spnFixedPageSize, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(rbShowAllRows, javax.swing.GroupLayout.Alignment.LEADING))) + .addContainerGap(251, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(lblPageSize) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(rbRememberPageSize) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(rbShowAllRows) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(rbFixedPageSize) + .addComponent(spnFixedPageSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(chkPackColumns) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkShowTruncateTableButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkShowAbsoluteRowNumbers) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkCopyRowValuesWithHeaders) + .addContainerGap(129, Short.MAX_VALUE)) + ); + + bindingGroup.bind(); + }// //GEN-END:initComponents + + void load() { + int defaultPageSize = DataViewSettings.getDefaultPageSize(); + if (defaultPageSize == DataViewSettings.PAGE_SIZE_REMEMBER) { + rbRememberPageSize.setSelected(true); + spnFixedPageSize.setValue(DataViewPageContext.DEFAULT_PAGE_SIZE); + } else if (defaultPageSize == DataViewSettings.PAGE_SIZE_SHOW_ALL) { + rbShowAllRows.setSelected(true); + spnFixedPageSize.setValue(DataViewPageContext.DEFAULT_PAGE_SIZE); + } else { + rbFixedPageSize.setSelected(true); + spnFixedPageSize.setValue(defaultPageSize); + } + chkPackColumns.setSelected(DataViewSettings.getPackColumns()); + chkShowTruncateTableButton.setSelected(DataViewSettings.getShowTruncateTableButton()); + chkShowAbsoluteRowNumbers.setSelected(DataViewSettings.getShowAbsoluteRowNumbers()); + chkCopyRowValuesWithHeaders.setSelected(DataViewSettings.getCopyRowValuesWithHeaders()); + } + + void store() { + if (rbRememberPageSize.isSelected()) { + DataViewSettings.setDefautPageSize(DataViewSettings.PAGE_SIZE_REMEMBER); + } else if (rbShowAllRows.isSelected()) { + DataViewSettings.setDefautPageSize(DataViewSettings.PAGE_SIZE_SHOW_ALL); + } else { + DataViewSettings.setDefautPageSize((int) spnFixedPageSize.getValue()); + } + DataViewSettings.setPackColumns(chkPackColumns.isSelected()); + DataViewSettings.setShowTruncateTableButton(chkShowTruncateTableButton.isSelected()); + DataViewSettings.setShowAbsoluteRowNumbers(chkShowAbsoluteRowNumbers.isSelected()); + DataViewSettings.setCopyRowValuesWithHeaders(chkCopyRowValuesWithHeaders.isSelected()); + } + + boolean valid() { + return true; + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox chkCopyRowValuesWithHeaders; + private javax.swing.JCheckBox chkPackColumns; + private javax.swing.JCheckBox chkShowAbsoluteRowNumbers; + private javax.swing.JCheckBox chkShowTruncateTableButton; + private javax.swing.JLabel lblPageSize; + private javax.swing.ButtonGroup pageSizeButtonGroup; + private javax.swing.JRadioButton rbFixedPageSize; + private javax.swing.JRadioButton rbRememberPageSize; + private javax.swing.JRadioButton rbShowAllRows; + private javax.swing.JSpinner spnFixedPageSize; + private org.jdesktop.beansbinding.BindingGroup bindingGroup; + // End of variables declaration//GEN-END:variables +}