cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r895574 [2/2] - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: dialog/ dialog/objentity/ dialog/validator/ editor/ editor/dbentity/ pref/ util/
Date Mon, 04 Jan 2010 08:04:59 GMT
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TableHeaderSortingListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TableHeaderSortingListener.java?rev=895574&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TableHeaderSortingListener.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TableHeaderSortingListener.java
Mon Jan  4 08:04:52 2010
@@ -0,0 +1,87 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.util;
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JTable;
+import javax.swing.table.JTableHeader;
+
+import org.apache.cayenne.modeler.pref.TableColumnPreferences;
+
+public class TableHeaderSortingListener extends MouseAdapter {
+
+    private JTableHeader header;
+    private SortButtonRenderer renderer;
+    private JTable table;
+    private TableColumnPreferences tableColumnPreferences;
+
+    public TableHeaderSortingListener(JTableHeader header, SortButtonRenderer renderer) {
+        this.header = header;
+        this.renderer = renderer;
+        table = header.getTable();
+
+    }
+
+    public void mousePressed(MouseEvent e) {
+
+        int col = header.columnAtPoint(e.getPoint());
+        int sortCol = table.convertColumnIndexToModel(col);
+        if (((CayenneTableModel) table.getModel()).isColumnSortable(sortCol)) {
+            boolean isAscent;
+            if (SortButtonRenderer.DOWN == renderer.getState(col)) {
+                isAscent = false;
+            }
+            else {
+                isAscent = true;
+            }
+            sortByDefinedColumn(col, sortCol, isAscent);
+            tableColumnPreferences.setSortOrder(isAscent);
+            tableColumnPreferences.setSortColumn(sortCol);
+        }
+    }
+
+    public void mouseReleased(MouseEvent e) {
+        renderer.setPressedColumn(-1); // clear
+        header.repaint();
+    }
+
+    public void sortByDefinedColumn(int col, int sortCol, boolean order) {
+        CayenneTableModel model = (CayenneTableModel) table.getModel();
+        if (model.isColumnSortable(sortCol)) {
+            renderer.setPressedColumn(col);
+            renderer.setSelectedColumn(col, order);
+            header.repaint();
+
+            if (table.isEditing()) {
+                table.getCellEditor().stopCellEditing();
+            }
+
+            model.sortByColumn(sortCol, order);
+        }
+    }
+
+    public void setPreferences(TableColumnPreferences tableColumnPreferences) {
+        if (this.tableColumnPreferences == null) {
+            this.tableColumnPreferences = tableColumnPreferences;
+        }
+    }
+
+}



Mime
View raw message