Revision: 5076
          http://sourceforge.net/p/jump-pilot/code/5076
Author:   michaudm
Date:     2016-10-15 10:35:42 +0000 (Sat, 15 Oct 2016)
Log Message:
-----------
FR #237 : add an option in ViewOptionsPlugIn to synchronize/desynchronize 
selection in LayerView AttributePanel (synchronized by default)

Modified Paths:
--------------
    core/trunk/ChangeLog
    core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributePanel.java
    core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTab.java
    core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
    core/trunk/src/org/openjump/core/ui/plugin/view/ViewOptionsPlugIn.java

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2016-10-13 19:53:51 UTC (rev 5075)
+++ core/trunk/ChangeLog        2016-10-15 10:35:42 UTC (rev 5076)
@@ -3,6 +3,10 @@
 # 2. make sure that lines break at 80 chars for constricted display situations
 #<-------------------------------- 80 chars 
---------------------------------->#
 
+2016-10-15 mmichaud <m.michael.mich...@orange.fr>
+  * FR #237 : add an option in ViewOptionsPlugIn to synchronize/desynchronize
+    selection in LayerView AttributePanel (synchronized by default)
+
 2016-10-13 mmichaud <m.michael.mich...@orange.fr>
   * EditOptions are now persistent except rolling back invalid edits which is
     activated by default (in OpenJumpConfiguration)

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributePanel.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributePanel.java     
2016-10-13 19:53:51 UTC (rev 5075)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributePanel.java     
2016-10-15 10:35:42 UTC (rev 5076)
@@ -267,7 +267,7 @@
         for (Iterator i = layerToTablePanelMap.values().iterator(); 
i.hasNext();) {
             AttributeTablePanel tablePanel = (AttributeTablePanel) i.next();
             if (tablePanel.getModel().getRowCount() == 0) {
-               return selectedFeatures;
+                continue;
             }
             int[] selectedRows = tablePanel.getTable().getSelectedRows();
             for (int j = 0; j < selectedRows.length; j++) {
@@ -278,7 +278,7 @@
     }
 
     // [mmichaud 2015-06-13] moved to AttributeTablePanel
-    /*
+    //
     public void selectInLayerViewPanel() {
         taskFrame.getLayerViewPanel().getSelectionManager().clear();
         for (Iterator i = layerToTablePanelMap.values().iterator(); 
i.hasNext();) {
@@ -297,8 +297,8 @@
                 selectedFeatures);
         }
     }
-    */
 
+
     public Row topSelectedRow() {
         for (Iterator i = layerToTablePanelMap.values().iterator(); 
i.hasNext();) {
             AttributeTablePanel panel = (AttributeTablePanel) i.next();

Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTab.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTab.java       
2016-10-13 19:53:51 UTC (rev 5075)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTab.java       
2016-10-15 10:35:42 UTC (rev 5076)
@@ -32,6 +32,7 @@
 package com.vividsolutions.jump.workbench.ui;
 
 import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.util.Blackboard;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
 import com.vividsolutions.jump.workbench.model.*;
 import com.vividsolutions.jump.workbench.plugin.EnableCheck;
@@ -41,6 +42,8 @@
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 import com.vividsolutions.jump.workbench.ui.plugin.FeatureInfoPlugIn;
 import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
+import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
+import org.openjump.core.ui.plugin.view.ViewOptionsPlugIn;
 
 import javax.swing.*;
 import javax.swing.event.ListSelectionEvent;
@@ -386,7 +389,7 @@
                 new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 try {
-                    //panel.selectInLayerViewPanel();
+                    panel.selectInLayerViewPanel();
                 } catch (Throwable t) {
                     errorHandler.handleThrowable(t);
                 }

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java    
    2016-10-13 19:53:51 UTC (rev 5075)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java    
    2016-10-15 10:35:42 UTC (rev 5076)
@@ -48,7 +48,6 @@
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jump.I18N;
 import com.vividsolutions.jump.feature.Feature;
-import com.vividsolutions.jump.io.datasource.DataSourceQuery;
 import com.vividsolutions.jump.util.Blackboard;
 import com.vividsolutions.jump.util.FlexibleDateParser;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
@@ -73,17 +72,18 @@
        /**
         * The property name of the columns width map in the project file 
(resides in the data-source subtree).
         */
-       public static final String ATTRIBUTE_COLUMNS_WIDTH_MAP = 
"AttributeColumnsWidthMap";
-    public static final String DATE_FORMAT_KEY = 
ViewOptionsPlugIn.DATE_FORMAT_KEY;
+       private static final String ATTRIBUTE_COLUMNS_WIDTH_MAP = 
"AttributeColumnsWidthMap";
+    private static final String DATE_FORMAT_KEY = 
ViewOptionsPlugIn.DATE_FORMAT_KEY;
+    private static final String SELECTION_SYNC_KEY = 
ViewOptionsPlugIn.SELECTION_SYNCHRONIZATION_KEY;
 
     private static SimpleDateFormat DEFAULT_DATE_FORMAT = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");
 
     private Blackboard blackboard;
 
-    ImageIcon nullObject = IconLoader.icon("null1.png");
-    ImageIcon nullString = IconLoader.icon("null1.png");
+    private ImageIcon nullObject = IconLoader.icon("null1.png");
+    private ImageIcon nullString = IconLoader.icon("null1.png");
 
-    public interface FeatureEditor {
+    interface FeatureEditor {
 
         void edit(PlugInContext context, Feature feature, Layer layer)
                 throws Exception;
@@ -113,7 +113,7 @@
 
     private class MyTable extends JTable {
 
-        public MyTable() {
+        MyTable() {
             //We want table-size changes to be absorbed by the last column.
             //By default, AUTO_RESIZE_LAST_COLUMN will not achieve this
             //(it works for column-size changes only). But I am overriding
@@ -279,14 +279,13 @@
         }
     }
 
-    class NullableCheckBox extends JCheckBox implements TableCellRenderer {
-        public NullableCheckBox() {
+    private class NullableCheckBox extends JCheckBox implements 
TableCellRenderer {
+        NullableCheckBox() {
             super();
             setHorizontalAlignment(SwingConstants.CENTER);
         }
         public Component getTableCellRendererComponent(JTable table, Object 
value, boolean isSelected, boolean hasFocus, int row, int column) {
             if (value == null) {
-                //this.setBackground(Color.LIGHT_GRAY);
                 this.setIcon(nullObject);
             } else {
                 super.setSelected((Boolean)value);
@@ -296,9 +295,9 @@
     }
 
     // A popup menu item to set a value to null
-    class PopUpNullifyCell extends JPopupMenu {
+    private class PopUpNullifyCell extends JPopupMenu {
         JMenuItem anItem;
-        public PopUpNullifyCell(){
+        PopUpNullifyCell(){
             anItem = new JMenuItem(nullString);
             add(anItem);
         }
@@ -307,7 +306,7 @@
     // A mouse listener to display a PopUpNullifyCell
     // The popup is display after a left mouse pressed and disappear after the 
mouse release
     // To nullify a value, click the PopUpNullifyCell between mouse press and 
mouse release
-    class NullifyMouseAdapter extends MouseAdapter {
+    private class NullifyMouseAdapter extends MouseAdapter {
         JTable table;
         PopUpNullifyCell menu;
 
@@ -496,17 +495,17 @@
     private Layer layer;
     private HashMap<Object,Integer> columnsWidthMap;
 
-    private boolean selectionSynchronized = true;
+    //private boolean selectionSynchronized = true;
 
-    private void setSelectionSynchronized(boolean selectionSynchronized) {
-        this.selectionSynchronized = selectionSynchronized;
-    }
+    //private void setSelectionSynchronized(boolean selectionSynchronized) {
+    //    this.selectionSynchronized = selectionSynchronized;
+    //}
 
-    private boolean isSelectionSynchronized() {
-        return selectionSynchronized;
-    }
+    //private boolean isSelectionSynchronized() {
+    //    return selectionSynchronized;
+    //}
 
-    AttributeTableLayerViewPanelListener layerViewPanelListener = null;
+    private AttributeTableLayerViewPanelListener layerViewPanelListener = null;
 
     public AttributeTablePanel(final LayerTableModel model, boolean 
addScrollPane,
             final WorkbenchContext workbenchContext) {
@@ -517,9 +516,10 @@
         final DefaultListSelectionModel defaultSelectionModel = new 
DefaultListSelectionModel();
         table.setSelectionModel(selectionModel);
         
selectionModel.setSelectionMode(SelectionModelWrapper.MULTIPLE_INTERVAL_SELECTION);
-        selectionModel.setFireSelectionReplaced(true);
+        //selectionModel.setFireSelectionReplaced(true);
 
         // A LayerViewPanel listener to reflect layerView selection into the 
AttributeTablePanel
+        // (if selection synchronization is on)
         layerViewPanelListener = new AttributeTableLayerViewPanelListener(
                 workbenchContext, this, selectionModel, defaultSelectionModel);
 
@@ -821,16 +821,16 @@
      * columns will be stored in the datasource properties. Later this can be
      * saved within the projectfile.
      * 
-     * @param columnModel
-     * @param override
-     *          ignore datasource defaults, e.g. if user manually resizes col 
in
-     *          gui
+     * @param columnModel the table column model
+     * @param override ignore datasource defaults, e.g. if user manually 
resizes
+     *                 col in gui
      */
     private void changeColumnWidths(TableColumnModel columnModel, boolean 
override) {
   
       // init col widths memory map
-      if (!(columnsWidthMap instanceof HashMap))
-        columnsWidthMap = new HashMap<>(columnModel.getColumnCount());
+      if (columnsWidthMap == null) {
+          columnsWidthMap = new HashMap<>(columnModel.getColumnCount());
+      }
       // loop over table cols and restore if entry found
       for (int i = 0; i < columnModel.getColumnCount(); i++) {
         Integer savedWidth = (Integer) 
columnsWidthMap.get(columnModel.getColumn(
@@ -874,19 +874,25 @@
         }
     }
 
-    private static class SelectionModelWrapper implements ListSelectionModel {
+    private class SelectionModelWrapper implements ListSelectionModel {
 
         private AttributeTablePanel panel;
 
         private ListSelectionModel selectionModel;
 
-        private boolean fireSelectionReplaced = true;
+        //private boolean fireSelectionReplaced = true;
 
-        public void setFireSelectionReplaced(boolean b) {
-            this.fireSelectionReplaced = b;
+        private boolean isSynchronized() {
+            Object sync = blackboard
+                    .get(SELECTION_SYNC_KEY);
+            return sync != null && Boolean.parseBoolean(sync.toString());
         }
 
-        public SelectionModelWrapper(AttributeTablePanel panel) {
+        //public void setFireSelectionReplaced(boolean b) {
+        //    this.fireSelectionReplaced = b;
+        //}
+
+        SelectionModelWrapper(AttributeTablePanel panel) {
             this.panel = panel;
             selectionModel = panel.table.getSelectionModel();
         }
@@ -901,7 +907,7 @@
 
         public void setSelectionInterval(int index0, int index1) {
             selectionModel.setSelectionInterval(index0, index1);
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
 
         public void setSelectionMode(int selectionMode) {
@@ -950,22 +956,22 @@
 
         public void addSelectionInterval(int index0, int index1) {
             selectionModel.addSelectionInterval(index0, index1);
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
 
         public void clearSelection() {
             selectionModel.clearSelection();
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
 
         public void insertIndexInterval(int index, int length, boolean before) 
{
             selectionModel.insertIndexInterval(index, length, before);
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
 
         public void removeIndexInterval(int index0, int index1) {
             selectionModel.removeIndexInterval(index0, index1);
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
 
         public void removeListSelectionListener(ListSelectionListener x) {
@@ -974,7 +980,7 @@
 
         public void removeSelectionInterval(int index0, int index1) {
             selectionModel.removeSelectionInterval(index0, index1);
-            if (fireSelectionReplaced) panel.fireSelectionReplaced();
+            if (isSynchronized()) panel.fireSelectionReplaced();
         }
     }
 
@@ -990,7 +996,7 @@
         return selectedFeatures;
     }
 
-    public LayerNameRenderer getLayerNameRenderer() {
+    LayerNameRenderer getLayerNameRenderer() {
         return layerListCellRenderer;
     }
 
@@ -1004,10 +1010,18 @@
      */
     public void selectionReplaced() {
 
+        Object syncObject = PersistentBlackboardPlugIn.get(workbenchContext)
+                .get(SELECTION_SYNC_KEY);
+        boolean sync = syncObject != null && 
Boolean.parseBoolean(syncObject.toString());
+        if (!sync) return;
+
         int[] selectedRows = table.getSelectedRows();
         // After selectedRows have been memorized, clear the layer selection,
         // other wise OpenJUMP will add the selectedRows to the already 
selected features
+        
//PersistentBlackboardPlugIn.get(workbenchContext).put(SELECTION_SYNC_KEY, 
false);
         
workbenchContext.getLayerViewPanel().getSelectionManager().unselectItems(getModel().getLayer());
+        
//PersistentBlackboardPlugIn.get(workbenchContext).put(SELECTION_SYNC_KEY, 
sync);
+
         Map<Feature,List<Geometry>> map = new HashMap<>();
         for (int j = 0; j < selectedRows.length; j++) {
             Feature feature = getModel().getFeature(selectedRows[j]);
@@ -1022,7 +1036,7 @@
 
     // A LayerViewListener to synchronized selection in AttributeTablePanel 
every time
     // the selection change in LayerViewPanel
-    static class AttributeTableLayerViewPanelListener implements 
LayerViewPanelListener {
+    private static class AttributeTableLayerViewPanelListener implements 
LayerViewPanelListener {
 
         final WorkbenchContext workbenchContext;
         final AttributeTablePanel attributeTablePanel;
@@ -1041,6 +1055,11 @@
 
         @Override
         public void selectionChanged() {
+
+            Object syncObject = 
PersistentBlackboardPlugIn.get(workbenchContext)
+                    .get(SELECTION_SYNC_KEY);
+            boolean sync = syncObject != null && 
Boolean.parseBoolean(syncObject.toString());
+
             try {
 
                 if 
(workbenchContext.getWorkbench().getFrame().getActiveInternalFrame()
@@ -1048,6 +1067,8 @@
                 if 
(workbenchContext.getWorkbench().getFrame().getActiveInternalFrame()
                         .isAncestorOf(attributeTablePanel)) return;
 
+                if (!sync) return;
+
                 // Get selected features :
                 // For AttributeTable, selected features are highlighted
                 // For InfoModel, selected features may be added to the model
@@ -1056,17 +1077,19 @@
                         .getLayerViewPanel().getSelectionManager()
                         
.getFeaturesWithSelectedItems(attributeTablePanel.layer);
 
-                // From now on (2015-06-13), LayerViewSelection is propagated 
to
-                // AttributeTablePanel and the other way.
+                // From now on (2015-06-13), the LayerViewSelection can be 
propagated
+                // to AttributeTablePanel and the other way.
                 // This assertion will avoid recursive updates between 
LayerView and
                 // AttributeTable
-                selectionModel.setFireSelectionReplaced(false);
+                //selectionModel.setFireSelectionReplaced(false);
 
+                PersistentBlackboardPlugIn.get(workbenchContext)
+                        .put(ViewOptionsPlugIn.SELECTION_SYNCHRONIZATION_KEY, 
false);
                 attributeTablePanel.table.clearSelection();
-                if (selection.size() == 0) {
-                    selectionModel.setFireSelectionReplaced(true);
-                    return;
-                }
+                //if (selection.size() == 0) {
+                //    selectionModel.setFireSelectionReplaced(sync);
+                //    return;
+                //}
 
                 // Map feature ids to row ids
                 Map<Integer, Integer> mapIdRow = new HashMap<>();
@@ -1119,7 +1142,9 @@
                 attributeTablePanel.table.setSelectionModel(selectionModel);
 
             } finally {
-                selectionModel.setFireSelectionReplaced(true);
+                //selectionModel.setFireSelectionReplaced(sync);
+                PersistentBlackboardPlugIn.get(workbenchContext)
+                        .put(ViewOptionsPlugIn.SELECTION_SYNCHRONIZATION_KEY, 
sync);
             }
         }
 

Modified: core/trunk/src/org/openjump/core/ui/plugin/view/ViewOptionsPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/view/ViewOptionsPlugIn.java      
2016-10-13 19:53:51 UTC (rev 5075)
+++ core/trunk/src/org/openjump/core/ui/plugin/view/ViewOptionsPlugIn.java      
2016-10-15 10:35:42 UTC (rev 5076)
@@ -9,8 +9,10 @@
 import com.vividsolutions.jump.workbench.ui.OptionsPanel;
 import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
 import com.vividsolutions.jump.workbench.ui.plugin.ViewAttributesPlugIn;
+import org.apache.batik.ext.swing.GridBagConstants;
 
 import javax.swing.*;
+import java.awt.*;
 import java.text.SimpleDateFormat;
 
 /**
@@ -22,12 +24,22 @@
 
     public static final String DATE_FORMAT_KEY = 
ViewOptionsPlugIn.class.getName() + " - DATE_FORMAT_KEY";
 
+    public static final String SELECTION_SYNCHRONIZATION_KEY = 
ViewOptionsPlugIn.class.getName() + " - SELECTION_SYNCHRONIZATION";
+
     private static final String DATE_FORMAT = 
I18N.get("org.openjump.core.ui.plugin.view.ViewOptionsPlugIn.Date-format");
     private JComboBox dateFormatChooser;
+    private static final String SELECTION_SYNC = 
I18N.get("org.openjump.core.ui.plugin.view.ViewOptionsPlugIn.Selection-syncronization");
+    private JCheckBox synchronizationCheckBox;
 
+    private Blackboard blackBoard;
+
     public void initialize(final PlugInContext context) throws Exception {
 
+        blackBoard = 
PersistentBlackboardPlugIn.get(context.getWorkbenchContext());
+
         ViewOptionsPanel viewOptionsPanel = new ViewOptionsPanel(context);
+        viewOptionsPanel.setLayout(new GridBagLayout());
+        GridBagConstraints c = new GridBagConstraints();
 
         // Most useful formats for english and european speakers
         dateFormatChooser = new JComboBox(new String[]{
@@ -41,9 +53,33 @@
         dateFormatChooser.setEnabled(true);
         dateFormatChooser.setEditable(true);
 
-        viewOptionsPanel.add(new JLabel(DATE_FORMAT));
-        viewOptionsPanel.add(dateFormatChooser);
+        synchronizationCheckBox = new JCheckBox();
 
+        c.gridx = 0;
+        c.gridy = 0;
+        c.ipadx = 10;
+        c.weighty = 0;
+
+        c.anchor = GridBagConstants.EAST;
+
+        viewOptionsPanel.add(new JLabel(DATE_FORMAT), c);
+        c.gridx = 1;
+        c.anchor = GridBagConstants.WEST;
+        viewOptionsPanel.add(dateFormatChooser, c);
+
+        c.gridx = 0;
+        c.gridy = 1;
+        c.anchor = GridBagConstants.EAST;
+        viewOptionsPanel.add(new JLabel(SELECTION_SYNC), c);
+        c.gridx = 1;
+        c.anchor = GridBagConstants.WEST;
+        viewOptionsPanel.add(synchronizationCheckBox, c);
+
+        c.gridy = 2;
+        c.weighty = 1;
+        c.fill = GridBagConstants.VERTICAL;
+        viewOptionsPanel.add(new JPanel(), c);
+
         OptionsDialog.instance(context.getWorkbenchContext().getWorkbench())
                 .addTab(VIEW_OPTIONS, viewOptionsPanel);
     }
@@ -67,7 +103,7 @@
 
         public void okPressed() {
             // If ok pressed,save the format in Workbench.xml configuration 
file
-            Blackboard blackBoard = 
PersistentBlackboardPlugIn.get(context.getWorkbenchContext());
+            //Blackboard blackBoard = 
PersistentBlackboardPlugIn.get(context.getWorkbenchContext());
             blackBoard.put(DATE_FORMAT_KEY, 
dateFormatChooser.getSelectedItem().toString());
             JInternalFrame[] frames = 
context.getWorkbenchFrame().getInternalFrames();
             for (JInternalFrame frame : frames) {
@@ -75,13 +111,12 @@
                     frame.repaint();
                 }
             }
+            blackBoard.put(SELECTION_SYNCHRONIZATION_KEY, 
synchronizationCheckBox.isSelected());
         }
 
         public void init() {
             // Init formatter from the Workbench.xml configuration file
-            Object persistedFormat = PersistentBlackboardPlugIn
-                    .get(context.getWorkbenchContext())
-                    .get(DATE_FORMAT_KEY);
+            Object persistedFormat = blackBoard.get(DATE_FORMAT_KEY);
             if (persistedFormat != null) {
                 dateFormatChooser.setSelectedItem(
                         PersistentBlackboardPlugIn
@@ -90,6 +125,13 @@
             } else {
                 dateFormatChooser.setSelectedIndex(0);
             }
+            Object sync = blackBoard.get(SELECTION_SYNCHRONIZATION_KEY);
+            if (sync != null) {
+                synchronizationCheckBox.setSelected(
+                        Boolean.parseBoolean(sync.toString()));
+            } else {
+                synchronizationCheckBox.setSelected(true);
+            }
         }
     }
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to