[hg] main-silver: #156491: Remember page size settings

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #156491: Remember page size settings
  • Date: Tue, 29 Jan 2013 13:36:55 -0800

changeset 8890586a4d5a in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/8890586a4d5a
description:
        #156491: Remember page size settings

diffstat:

 db.core/nbproject/project.xml                                                
               |   2 +-
 db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java        
               |   5 +-
 db.core/src/org/netbeans/modules/db/sql/loader/SQLEditorSupport.java         
               |   2 +-
 db.dataview/manifest.mf                                                      
               |   2 +-
 
db.dataview/src/org/netbeans/modules/db/dataview/api/DataViewPageContext.java 
              |  52 +++++++
 
db.dataview/src/org/netbeans/modules/db/dataview/output/DataViewActionHandler.java
          |   2 +
 
db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewPageContextTest.java
 |  73 ++++++++++
 7 files changed, 132 insertions(+), 6 deletions(-)

diffs (226 lines):

diff --git a/db.core/nbproject/project.xml b/db.core/nbproject/project.xml
--- a/db.core/nbproject/project.xml
+++ b/db.core/nbproject/project.xml
@@ -81,7 +81,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.0</specification-version>
+                        <specification-version>1.20</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java 
b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
--- a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
+++ b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
@@ -52,6 +52,7 @@
 import java.util.logging.Logger;
 import org.netbeans.api.db.explorer.DatabaseConnection;
 import org.netbeans.modules.db.dataview.api.DataView;
+import org.netbeans.modules.db.dataview.api.DataViewPageContext;
 import org.netbeans.modules.db.sql.history.SQLHistoryEntry;
 import org.netbeans.modules.db.sql.history.SQLHistoryManager;
 
@@ -62,8 +63,6 @@
  */
 public final class SQLExecuteHelper {
 
-    public static final int DEFAULT_PAGE_SIZE = 20;
-
     private static final Logger LOGGER = 
Logger.getLogger(SQLExecuteHelper.class.getName());
     private static final boolean LOG = LOGGER.isLoggable(Level.FINE);
     
@@ -76,7 +75,7 @@
      */
     public static SQLExecutionResults execute(String sqlScript, int 
startOffset, int endOffset,
             DatabaseConnection conn, SQLExecutionLogger executionLogger) {
-        return execute(sqlScript, startOffset, endOffset, conn, 
executionLogger, DEFAULT_PAGE_SIZE);
+        return execute(sqlScript, startOffset, endOffset, conn, 
executionLogger, DataViewPageContext.DEFAULT_PAGE_SIZE);
     }
 
     /**
diff --git 
a/db.core/src/org/netbeans/modules/db/sql/loader/SQLEditorSupport.java 
b/db.core/src/org/netbeans/modules/db/sql/loader/SQLEditorSupport.java
--- a/db.core/src/org/netbeans/modules/db/sql/loader/SQLEditorSupport.java
+++ b/db.core/src/org/netbeans/modules/db/sql/loader/SQLEditorSupport.java
@@ -556,7 +556,7 @@
                         }
                     }
                     if (pageSize == -1) {
-                        pageSize = SQLExecuteHelper.DEFAULT_PAGE_SIZE;
+                        pageSize = DataViewPageContext.getStoredPageSize();
                     }
                     parent.closeExecutionResult();
 
diff --git a/db.dataview/manifest.mf b/db.dataview/manifest.mf
--- a/db.dataview/manifest.mf
+++ b/db.dataview/manifest.mf
@@ -1,5 +1,5 @@
 Manifest-Version: 1.0
 OpenIDE-Module: org.netbeans.modules.db.dataview
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/db/dataview/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.19
+OpenIDE-Module-Specification-Version: 1.20
 AutoUpdate-Show-In-Client: false
diff --git 
a/db.dataview/src/org/netbeans/modules/db/dataview/api/DataViewPageContext.java
 
b/db.dataview/src/org/netbeans/modules/db/dataview/api/DataViewPageContext.java
--- 
a/db.dataview/src/org/netbeans/modules/db/dataview/api/DataViewPageContext.java
+++ 
b/db.dataview/src/org/netbeans/modules/db/dataview/api/DataViewPageContext.java
@@ -42,12 +42,26 @@
 
 package org.netbeans.modules.db.dataview.api;
 
+import org.openide.util.NbPreferences;
+import org.openide.util.RequestProcessor;
+
 /** A helper which can return current page size for given data view.
  *
  * @author Jiri Rechtacek
  * @since 1.4
  */
 public final class DataViewPageContext {
+
+    /**
+     * Default page size (number of rows shown in query results table).
+     *
+     * @since 1.20
+     */
+    public static final int DEFAULT_PAGE_SIZE = 20;
+    private static final String PROP_STORED_PAGE_SIZE =
+            "storedPageSize"; //NOI18N
+    private static int defaultPageSize = -1;
+
     private DataViewPageContext() {}
 
     /** Returns current page size for given view
@@ -58,4 +72,42 @@
     public static int getPageSize(DataView view) {
         return view.delegate.getPageSize();
     }
+
+    /**
+     * Get stored or default page size.
+     *
+     * @return Page size, positive integer, not zero;
+     * @since 1.20
+     */
+    public static int getStoredPageSize() {
+        if (defaultPageSize <= 0) {
+            defaultPageSize = NbPreferences.forModule(
+                    DataViewPageContext.class).getInt(
+                    PROP_STORED_PAGE_SIZE, DEFAULT_PAGE_SIZE);
+            if (defaultPageSize <= 0) {
+                defaultPageSize = DEFAULT_PAGE_SIZE;
 }
+        }
+        return defaultPageSize;
+    }
+
+    /**
+     * Store page size.
+     *
+     * @param pageSize Page size, positive integer, not zero.
+     * @since 1.20
+     */
+    public static void setStoredPageSize(final int pageSize) {
+        if (pageSize <= 0) {
+            throw new IllegalArgumentException("Negative pageSize");    
//NOI18N
+        }
+        DataViewPageContext.defaultPageSize = pageSize;
+        RequestProcessor.getDefault().post(new Runnable() {
+            @Override
+            public void run() {
+                NbPreferences.forModule(DataViewPageContext.class).putInt(
+                        PROP_STORED_PAGE_SIZE, pageSize);
+            }
+        });
+    }
+}
diff --git 
a/db.dataview/src/org/netbeans/modules/db/dataview/output/DataViewActionHandler.java
 
b/db.dataview/src/org/netbeans/modules/db/dataview/output/DataViewActionHandler.java
--- 
a/db.dataview/src/org/netbeans/modules/db/dataview/output/DataViewActionHandler.java
+++ 
b/db.dataview/src/org/netbeans/modules/db/dataview/output/DataViewActionHandler.java
@@ -111,6 +111,8 @@
         if (rejectModifications()) {
             int pageSize = dataViewUI.getPageSize();
             dataPage.setPageSize(pageSize);
+            org.netbeans.modules.db.dataview.api.DataViewPageContext
+                    .setStoredPageSize(pageSize);
             dataPage.first();
             dataPage.setTotalRows(-1); // force total row refresh
             execHelper.executeQuery();
diff --git 
a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewPageContextTest.java
 
b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewPageContextTest.java
new file mode 100644
--- /dev/null
+++ 
b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewPageContextTest.java
@@ -0,0 +1,73 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 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 2013 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.dataview.api;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import org.netbeans.junit.NbTestCase;
+
+/**
+ *
+ * @author jhavlin
+ */
+public class DataViewPageContextTest extends NbTestCase {
+
+    public DataViewPageContextTest(String name) {
+        super(name);
+    }
+
+    public void testSetGetPageSize() {
+        int origSize = DataViewPageContext.getStoredPageSize();
+        assertTrue(origSize > 0);
+        int newSize = origSize + 1;
+        DataViewPageContext.setStoredPageSize(newSize);
+        assertEquals(newSize, DataViewPageContext.getStoredPageSize());
+
+        boolean exception = false;
+        try {
+            DataViewPageContext.setStoredPageSize(0);
+        } catch (IllegalArgumentException e) {
+            exception = true;
+        }
+        assertTrue(exception);
+    }
+}

[hg] main-silver: #156491: Remember page size settings

Jaroslav Havlin 01/29/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close