Revision: 4869
          http://sourceforge.net/p/jump-pilot/code/4869
Author:   michaudm
Date:     2016-03-27 15:37:31 +0000 (Sun, 27 Mar 2016)
Log Message:
-----------
Cleaning, formatting rewriting jump.util

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/util/Blackboard.java
    core/trunk/src/com/vividsolutions/jump/util/CollectionMap.java
    core/trunk/src/com/vividsolutions/jump/util/CollectionUtil.java
    
core/trunk/src/com/vividsolutions/jump/workbench/datasource/AbstractLoadDatasetPlugIn.java
    
core/trunk/src/com/vividsolutions/jump/workbench/datasource/LoadDatasetPlugIn.java
    core/trunk/src/com/vividsolutions/jump/workbench/plugin/AbstractPlugIn.java
    
core/trunk/src/org/openjump/core/ui/plugin/file/DataSourceQueryChooserOpenWizard.java
    core/trunk/src/org/openjump/core/ui/util/ExceptionUtil.java

Modified: core/trunk/src/com/vividsolutions/jump/util/Blackboard.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/Blackboard.java 2016-03-26 
14:57:15 UTC (rev 4868)
+++ core/trunk/src/com/vividsolutions/jump/util/Blackboard.java 2016-03-27 
15:37:31 UTC (rev 4869)
@@ -41,20 +41,22 @@
 * it's stored on the Workbench Blackboard.
 */
 public class Blackboard implements Cloneable, Serializable {
+
     private static final long serialVersionUID = 6504993615735124204L;
-    private HashMap properties = new HashMap();
 
+    private HashMap<String,Object> properties = new HashMap<>();
+
     /**
      * Used by Java2XML
      */
-    public HashMap getProperties() {
+    public HashMap<String,Object> getProperties() {
         return properties;
     }
 
     /**
      * Used by Java2XML
      */
-    public void setProperties(HashMap properties) {
+    public void setProperties(HashMap<String,Object> properties) {
         this.properties = properties;
     }
 
@@ -68,24 +70,37 @@
     }
 
     public Blackboard put(String key, boolean value) {
-        put(key, new Boolean(value));
+        properties.put(key, value);
         return this;
     }
-    public Blackboard putAll(Map properties) {
+
+    public Blackboard putAll(Map<String,Object> properties) {
         this.properties.putAll(properties);
         return this;
     }
 
+    /**
+     * If no value is yet defined for this key, map default value to the key
+     * in the blackboard and return it.
+     * @param key key of the value to retrieve
+     * @param defaultValue default boolean value for this key
+     * @return the value associated to the key or defaultValue if no value
+     * is yet defined for the key
+     */
     public boolean get(String key, boolean defaultValue) {
         if (get(key) == null) {
             put(key, defaultValue);
         }
-
         return getBoolean(key);
     }
 
+    /**
+     * Use getBoolean if you know that the value stored for key is an integer.
+     * @param key key of the value to retrieve
+     * @return the boolean value associated with this key
+     */
     public boolean getBoolean(String key) {
-        return ((Boolean) get(key)).booleanValue();
+        return (Boolean)get(key);
     }
 
     public Blackboard put(String key, int value) {
@@ -102,39 +117,67 @@
       return properties.remove(key);
     }
 
+    /**
+     * If no value is yet defined for this key, map default value to the key
+     * in the blackboard and return it.
+     * @param key key of the value to retrieve
+     * @param defaultValue default double value for this key
+     * @return the value associated to the key or defaultValue if no value
+     * is yet defined for the key
+     */
     public double get(String key, double defaultValue) {
         if (get(key) == null) {
             put(key, defaultValue);
         }
-
         return getDouble(key);
     }
 
+    /**
+     * If no value is yet defined for this key, map default value to the key
+     * in the blackboard and return it.
+     * @param key key of the value to retrieve
+     * @param defaultValue default integer value for this key
+     * @return the value associated to the key or defaultValue if no value
+     * is yet defined for the key
+     */
     public int get(String key, int defaultValue) {
         if (get(key) == null) {
             put(key, defaultValue);
         }
-
         return getInt(key);
     }
 
+    /**
+     * Use getInt if you know that the value stored for key is an integer.
+     * @param key key of the value to retrieve
+     * @return the integer value associated with this key
+     */
     public int getInt(String key) {
-        return ((Integer) get(key)).intValue();
+        return (Integer)get(key);
     }
 
+    /**
+     * Use getDouble if you know that the value stored for key is a double.
+     * @param key key of the value to retrieve
+     * @return the double value associated with this key
+     */
     public double getDouble(String key) {
-        return ((Double) get(key)).doubleValue();
+        return (Double)get(key);
     }
 
     public Object get(String key, Object defaultValue) {
         if (get(key) == null) {
             put(key, defaultValue);
         }
-
         return get(key);
     }
-    
-    public Object clone() {
+
+    /**
+     * Warning : does not follow the clone contract (does not call 
super.clone())
+     * but uses a copy consructor instead.
+     * @return a new Blackboard containing the same properties
+     */
+    public Blackboard clone() {
         return new Blackboard().putAll(properties);
     }
 }

Modified: core/trunk/src/com/vividsolutions/jump/util/CollectionMap.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/CollectionMap.java      
2016-03-26 14:57:15 UTC (rev 4868)
+++ core/trunk/src/com/vividsolutions/jump/util/CollectionMap.java      
2016-03-27 15:37:31 UTC (rev 4869)
@@ -41,8 +41,9 @@
 /**
  *  A Map whose values are Collections.
  */
-public class CollectionMap implements Map {
-    private Map map;
+public class CollectionMap<U,V> implements Map<U,Collection<V>> {
+
+    private Map<U,Collection<V>> map;
     private Class collectionClass = ArrayList.class;
 
     /**
@@ -51,22 +52,18 @@
      */
     public CollectionMap(Class mapClass) {
         try {
-            map = (Map) mapClass.newInstance();
-        } catch (InstantiationException e) {
+            map = (Map<U,Collection<V>>)mapClass.newInstance();
+        } catch (InstantiationException|IllegalAccessException e) {
             Assert.shouldNeverReachHere();
-        } catch (IllegalAccessException e) {
-            Assert.shouldNeverReachHere();
         }
     }
     
     public CollectionMap(Class mapClass, Class collectionClass) {
         this.collectionClass = collectionClass;
         try {
-            map = (Map) mapClass.newInstance();
-        } catch (InstantiationException e) {
+            map = (Map<U,Collection<V>>) mapClass.newInstance();
+        } catch (InstantiationException|IllegalAccessException e) {
             Assert.shouldNeverReachHere();
-        } catch (IllegalAccessException e) {
-            Assert.shouldNeverReachHere();
         }
     }    
 
@@ -77,15 +74,13 @@
         this(HashMap.class);
     }
     
-    private Collection getItemsInternal(Object key) {
-        Collection collection = (Collection) map.get(key);
+    private Collection<V> getItemsInternal(U key) {
+        Collection<V> collection = map.get(key);
         if (collection == null) {
             try {
-                collection = (Collection) collectionClass.newInstance();
-            } catch (InstantiationException e) {
+                collection = (Collection<V>) collectionClass.newInstance();
+            } catch (InstantiationException|IllegalAccessException e) {
                 Assert.shouldNeverReachHere();
-            } catch (IllegalAccessException e) {
-                Assert.shouldNeverReachHere();
             }
             map.put(key, collection);
         }
@@ -98,11 +93,11 @@
      * @param key the key to the Collection to which the item should be added
      * @param item the item to add
      */
-    public void addItem(Object key, Object item) {
+    public void addItem(U key, V item) {
         getItemsInternal(key).add(item);
     }
     
-    public void removeItem(Object key, Object item) {
+    public void removeItem(U key, V item) {
         getItemsInternal(key).remove(item);
     }
 
@@ -116,15 +111,14 @@
      * @param key the key to the Collection to which the items should be added
      * @param items the items to add
      */
-    public void addItems(Object key, Collection items) {
-        for (Iterator i = items.iterator(); i.hasNext();) {
-            addItem(key, i.next());
+    public void addItems(U key, Collection<V> items) {
+        for (V item : items) {
+            addItem(key, item);
         }
     }
     
-    public void addItems(CollectionMap other) {
-        for (Iterator i = other.keySet().iterator(); i.hasNext(); ) {
-            Object key = i.next();
+    public void addItems(CollectionMap<U,V> other) {
+        for (U key : other.keySet()) {
             addItems(key, other.getItems(key));
         }
     }
@@ -133,7 +127,7 @@
      * Returns the values.
      * @return a view of the values, backed by this CollectionMap
      */
-    public Collection values() {
+    public Collection<Collection<V>> values() {
         return map.values();
     }
 
@@ -141,7 +135,7 @@
      * Returns the keys.
      * @return a view of the keys, backed by this CollectionMap
      */
-    public Set keySet() {
+    public Set<U> keySet() {
         return map.keySet();
     }
 
@@ -153,15 +147,19 @@
         return map.size();
     }
 
-    public Object get(Object key) {
-        return getItems(key);
+    public Collection<V> get(Object key) {
+        try {
+            return getItems((U)key);
+        } catch(ClassCastException e) {
+            return null;
+        }
     }
 
-    public Collection getItems(Object key) {
+    public Collection<V> getItems(U key) {
         return Collections.unmodifiableCollection(getItemsInternal(key));
     }
 
-    public Object remove(Object key) {
+    public Collection<V> remove(Object key) {
         return map.remove(key);
     }
 
@@ -173,7 +171,7 @@
         return map.containsValue(value);
     }
 
-    public Set entrySet() {
+    public Set<Map.Entry<U,Collection<V>>> entrySet() {
         return map.entrySet();
     }
 
@@ -181,20 +179,19 @@
         return map.isEmpty();
     }
 
-    public Object put(Object key, Object value) {
-        Assert.isTrue(value instanceof Collection);
-
+    public Collection<V> put(U key, Collection<V> value) {
+        //Assert.isTrue(value instanceof Collection);
         return map.put(key, value);
     }
 
-    public void putAll(Map map) {
-        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
-            Object key = i.next();
+    public void putAll(Map<? extends U, ? extends Collection<V>> map) {
+        for (U key : map.keySet()) {
             //Delegate to #put so that the assertion is made. [Jon Aquino]
             put(key, map.get(key));
         }
     }
-    public void removeItems(Object key, Collection items) {
+
+    public void removeItems(U key, Collection<V> items) {
         getItemsInternal(key).removeAll(items);
     }
 

Modified: core/trunk/src/com/vividsolutions/jump/util/CollectionUtil.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/CollectionUtil.java     
2016-03-26 14:57:15 UTC (rev 4868)
+++ core/trunk/src/com/vividsolutions/jump/util/CollectionUtil.java     
2016-03-27 15:37:31 UTC (rev 4869)
@@ -45,16 +45,19 @@
 
 
 public class CollectionUtil {
+
     public CollectionUtil() {
     }
-    public static Collection concatenate(Collection a, Collection b) {
-        ArrayList result = new ArrayList();
+
+    public static <T> Collection<T> concatenate(Collection<T> a, Collection<T> 
b) {
+        List<T> result = new ArrayList<>();
         result.addAll(a);
         result.addAll(b);
         return result;
     }
-    public static List list(Object a, Object b) {
-        ArrayList list = new ArrayList();
+
+    public static <T> List<T> list(T a, T b) {
+        List<T> list = new ArrayList<>();
         list.add(a);
         list.add(b);
         return list;
@@ -68,25 +71,17 @@
         return combinations(original, maxCombinationSize, null);
     }
 
-    public static Map inverse(Map map) {
-        Map inverse;
+    public static <U,V> Map<V,U> inverse(Map<U,V> map) {
+        Map<V,U> inverse;
         try {
-            inverse = (Map) map.getClass().newInstance();
-        } catch (InstantiationException e) {
+            inverse = map.getClass().newInstance();
+        } catch (InstantiationException|IllegalAccessException e) {
             Assert.shouldNeverReachHere(e.toString());
-
             return null;
-        } catch (IllegalAccessException e) {
-            Assert.shouldNeverReachHere(e.toString());
-
-            return null;
         }
-        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
-            Object key = i.next();
-            Object value = map.get(key);
-            inverse.put(value, key);
+        for (Map.Entry<U,V> entry : map.entrySet()) {
+            inverse.put(entry.getValue(), entry.getKey());
         }
-
         return inverse;
     }
 
@@ -96,13 +91,14 @@
      * @param mandatoryItem an item that all returned combinations must 
contain,
      * or null to leave unspecified
      */
-    public static List combinations(List original, int maxCombinationSize,
-        Object mandatoryItem) {
-        ArrayList combinations = new ArrayList();
+    public static <T> List<List<T>> combinations(List<T> original,
+                int maxCombinationSize, T mandatoryItem) {
 
+        List<List<T>> combinations = new ArrayList<>();
+
         //Combinations are given by the bits of each binary number from 1 to 
2^N
         for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) {
-            ArrayList combination = new ArrayList();
+            List<T> combination = new ArrayList<>();
             for (int j = 0; j < original.size(); j++) {
                 if ((i & (int) Math.pow(2, j)) > 0) {
                     combination.add(original.get(j));
@@ -111,8 +107,7 @@
             if (combination.size() > maxCombinationSize) {
                 continue;
             }
-            if ((mandatoryItem != null) &&
-                    !combination.contains(mandatoryItem)) {
+            if ((mandatoryItem != null) && 
!combination.contains(mandatoryItem)) {
                 continue;
             }
             combinations.add(combination);
@@ -124,13 +119,12 @@
     /**
      * Returns a List of Lists: all combinations of the elements of the given 
List.
      */
-    public static List combinations(List original) {
+    public static <T> List<List<T>> combinations(List<T> original) {
         return combinations(original, original.size(), null);
     }
 
-    public static void removeKeys(Collection keys, Map map) {
-        for (Iterator i = keys.iterator(); i.hasNext();) {
-            Object key = (Object) i.next();
+    public static <U,V> void removeKeys(Collection<U> keys, Map<U,V> map) {
+        for (U key : keys) {
             map.remove(key);
         }
     }
@@ -139,23 +133,20 @@
      * The nth key corresponds to the nth value
      */
     public static List[] keysAndCorrespondingValues(Map map) {
-        ArrayList keys = new ArrayList(map.keySet());
-        ArrayList values = new ArrayList();
-        for (Iterator i = keys.iterator(); i.hasNext();) {
-            Object key = i.next();
+        List keys = new ArrayList(map.keySet());
+        List values = new ArrayList();
+        for (Object key : keys) {
             values.add(map.get(key));
         }
 
         return new List[] { keys, values };
     }
 
-    public static Collection concatenate(Collection collections) {
-        ArrayList concatenation = new ArrayList();
-        for (Iterator i = collections.iterator(); i.hasNext();) {
-            Collection collection = (Collection) i.next();
+    public static <T> Collection<T> concatenate(Collection<Collection<T>> 
collections) {
+        List<T> concatenation = new ArrayList<>();
+        for (Collection<T> collection : collections) {
             concatenation.addAll(collection);
         }
-
         return concatenation;
     }
 
@@ -163,10 +154,10 @@
         return list.get((int) Math.floor(Math.random() * list.size()));
     }
 
-    public static SortedSet reverseSortedSet(int[] ints) {
-        TreeSet sortedSet = new TreeSet(Collections.reverseOrder());
-        for (int i = 0; i < ints.length; i++) {
-            sortedSet.add(new Integer(ints[i]));
+    public static SortedSet<Integer> reverseSortedSet(int[] ints) {
+        TreeSet<Integer> sortedSet = new TreeSet<>(Collections.reverseOrder());
+        for (int i : ints) {
+            sortedSet.add(i);
         }
 
         return sortedSet;
@@ -181,12 +172,12 @@
     /**
      * Data is evenly discarded or duplicated to attain the new size
      */
-    public static Collection stretch(Collection source, Collection destination,
-        int destinationSize) {
+    public static <T> Collection stretch(Collection<T> source,
+                Collection<T> destination, int destinationSize) {
         Assert.isTrue(destination.isEmpty());
 
-        List originalList = source instanceof List ? (List) source
-                                                   : new ArrayList(source);
+        List<T> originalList = source instanceof List ?
+                (List<T>) source : new ArrayList<T>(source);
         for (int i = 0; i < destinationSize; i++) {
             destination.add(originalList.get(
                     (int) Math.round(
@@ -200,7 +191,7 @@
         return c.contains(o) ? o : alternative;
     }
 
-    public static void setIfNull(int i, List list, String value) {
+    public static void setIfNull(int i, List<String> list, String value) {
         if (i >= list.size()) {
             resize(list, i + 1);
         }
@@ -236,15 +227,13 @@
      * Brute force, for when HashSet and TreeSet won't work (e.g. #hashCode
      * implementation isn't appropriate). The original Collection is not 
modified.
      */
-    public static Collection removeDuplicates(Collection original) {
-        ArrayList result = new ArrayList();
-        for (Iterator i = original.iterator(); i.hasNext();) {
-            Object item = i.next();
+    public static <T> Collection<T> removeDuplicates(Collection<T> original) {
+        List<T> result = new ArrayList<>();
+        for (T item : original) {
             if (!result.contains(item)) {
                 result.add(item);
             }
         }
-
         return result;
     }
 
@@ -272,19 +261,17 @@
         return createMap(HashMap.class, alternatingKeysAndValues);
     }
 
-    public static Map createMap(Class mapClass,
+    public static Map<Object,Object> createMap(Class mapClass,
         Object[] alternatingKeysAndValues) {
-        Map map = null;
+        Map<Object,Object> map = null;
         try {
-            map = (Map) mapClass.newInstance();
+            map = (Map<Object,Object>) mapClass.newInstance();
+            for (int i = 0; i < alternatingKeysAndValues.length; i += 2) {
+                map.put(alternatingKeysAndValues[i], 
alternatingKeysAndValues[i + 1]);
+            }
         } catch (Exception e) {
             Assert.shouldNeverReachHere(e.toString());
         }
-        for (int i = 0; i < alternatingKeysAndValues.length; i += 2) {
-            map.put(alternatingKeysAndValues[i], alternatingKeysAndValues[i +
-                1]);
-        }
-
         return map;
     }
 
@@ -304,26 +291,22 @@
      * The Smalltalk #select method.
      */
     public static Collection select(Collection collection, Block block) {
-        ArrayList result = new ArrayList();
-        for (Iterator i = collection.iterator(); i.hasNext();) {
-            Object item = i.next();
+        List<Object> result = new ArrayList<>();
+        for (Object item : collection) {
             if (Boolean.TRUE.equals(block.yield(item))) {
                 result.add(item);
             }
-            ;
         }
-
         return result;
     }
 
-    public static Object get(Class c, Map map) {
+    public static Object get(Class c, Map<Class,Object> map) {
         if (map.keySet().contains(c)) {
             return map.get(c);
         }
-        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
-            Class candidateClass = (Class) i.next();
-            if (candidateClass.isAssignableFrom(c)) {
-                return map.get(candidateClass);
+        for (Class<?> clazz : map.keySet()) {
+            if (clazz.isAssignableFrom(c)) {
+                return map.get(clazz);
             }
         }
 

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/AbstractLoadDatasetPlugIn.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/AbstractLoadDatasetPlugIn.java
  2016-03-26 14:57:15 UTC (rev 4868)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/AbstractLoadDatasetPlugIn.java
  2016-03-27 15:37:31 UTC (rev 4869)
@@ -25,6 +25,7 @@
 import com.vividsolutions.jump.workbench.plugin.PlugInContext;
 import com.vividsolutions.jump.workbench.ui.GUIUtil;
 import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
+import org.openjump.core.ui.util.ExceptionUtil;
 
 public abstract class AbstractLoadDatasetPlugIn extends 
AbstractLoadSaveDatasetPlugIn { 
     public void run(TaskMonitor monitor, PlugInContext context)
@@ -70,31 +71,15 @@
         }
     }
 
-    private void reportExceptions(ArrayList exceptions,
+    private void reportExceptions(ArrayList<Throwable> exceptions,
         DataSourceQuery dataSourceQuery, PlugInContext context) {
         context.getOutputFrame().addHeader(1,
             exceptions.size() + " 
"+I18N.get("datasource.LoadDatasetPlugIn.problem") + 
StringUtil.s(exceptions.size()) +
             " "+ I18N.get("datasource.LoadDatasetPlugIn.loading")  + " " + 
dataSourceQuery.toString() + "." +
             ((exceptions.size() > 10) ? " 
"+I18N.get("datasource.LoadDatasetPlugIn.first-and-last-five") : ""));
         
context.getOutputFrame().addText(I18N.get("datasource.LoadDatasetPlugIn.see-view-log"));
-        context.getOutputFrame().append("<ul>");
 
-        Collection exceptionsToReport = exceptions.size() <= 10 ? exceptions
-                                                                : 
CollectionUtil.concatenate(Arrays.asList(
-                    new Collection[] {
-                        exceptions.subList(0, 5),
-                        exceptions.subList(exceptions.size() - 5,
-                            exceptions.size())
-                    }));
-        for (Iterator j = exceptionsToReport.iterator(); j.hasNext();) {
-            Exception exception = (Exception) j.next();
-            context.getWorkbenchFrame().log(StringUtil.stackTrace(exception));
-            context.getOutputFrame().append("<li>");
-            context.getOutputFrame().append(GUIUtil.escapeHTML(
-                    WorkbenchFrame.toMessage(exception), true, true));
-            context.getOutputFrame().append("</li>");
-        }
-        context.getOutputFrame().append("</ul>");
+        ExceptionUtil.reportExceptions(context, exceptions);
     }
 
     private String chooseCategory(PlugInContext context) {

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/LoadDatasetPlugIn.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/LoadDatasetPlugIn.java
  2016-03-26 14:57:15 UTC (rev 4868)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/datasource/LoadDatasetPlugIn.java
  2016-03-27 15:37:31 UTC (rev 4869)
@@ -53,14 +53,12 @@
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
 import com.vividsolutions.jump.util.Blackboard;
+import org.openjump.core.ui.util.ExceptionUtil;
 
 import java.awt.event.ComponentAdapter;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.*;
 
 import javax.swing.ImageIcon;
 import javax.swing.JFileChooser;
@@ -214,31 +212,15 @@
         }
     }
 
-    private void reportExceptions(ArrayList exceptions,
+    private void reportExceptions(List<Throwable> exceptions,
         DataSourceQuery dataSourceQuery, PlugInContext context) {
         context.getOutputFrame().addHeader(1,
             exceptions.size() + " " + 
I18N.get("datasource.LoadDatasetPlugIn.problem") + 
StringUtil.s(exceptions.size()) +
             " "+ I18N.get("datasource.LoadDatasetPlugIn.loading") +" "+ 
dataSourceQuery.toString() + "." +
             ((exceptions.size() > 10) ? 
I18N.get("datasource.LoadDatasetPlugIn.first-and-last-five") : ""));
         
context.getOutputFrame().addText(I18N.get("datasource.LoadDatasetPlugIn.see-view-log"));
-        context.getOutputFrame().append("<ul>");
 
-        Collection exceptionsToReport = exceptions.size() <= 10 ? exceptions
-                                                                : 
CollectionUtil.concatenate(Arrays.asList(
-                    new Collection[] {
-                        exceptions.subList(0, 5),
-                        exceptions.subList(exceptions.size() - 5,
-                            exceptions.size())
-                    }));
-        for (Iterator j = exceptionsToReport.iterator(); j.hasNext();) {
-            Exception exception = (Exception) j.next();
-            context.getWorkbenchFrame().log(StringUtil.stackTrace(exception));
-            context.getOutputFrame().append("<li>");
-            context.getOutputFrame().append(GUIUtil.escapeHTML(
-                    WorkbenchFrame.toMessage(exception), true, true));
-            context.getOutputFrame().append("</li>");
-        }
-        context.getOutputFrame().append("</ul>");
+        ExceptionUtil.reportExceptions(context, exceptions);
     }
 
     private String chooseCategory(PlugInContext context) {

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/plugin/AbstractPlugIn.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/plugin/AbstractPlugIn.java 
2016-03-26 14:57:15 UTC (rev 4868)
+++ core/trunk/src/com/vividsolutions/jump/workbench/plugin/AbstractPlugIn.java 
2016-03-27 15:37:31 UTC (rev 4869)
@@ -38,10 +38,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
+import java.util.*;
 
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
@@ -50,6 +47,7 @@
 
 import com.vividsolutions.jts.util.Assert;
 import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.util.CollectionUtil;
 import com.vividsolutions.jump.util.StringUtil;
 import com.vividsolutions.jump.workbench.JUMPWorkbench;
 import com.vividsolutions.jump.workbench.Logger;
@@ -65,6 +63,7 @@
 import com.vividsolutions.jump.workbench.model.UndoableEditReceiver;
 import com.vividsolutions.jump.workbench.ui.EditTransaction;
 import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
 import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
 
 /**

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/file/DataSourceQueryChooserOpenWizard.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/file/DataSourceQueryChooserOpenWizard.java
       2016-03-26 14:57:15 UTC (rev 4868)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/file/DataSourceQueryChooserOpenWizard.java
       2016-03-27 15:37:31 UTC (rev 4869)
@@ -1,9 +1,6 @@
 package org.openjump.core.ui.plugin.file;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.*;
 
 import org.openjump.core.ui.plugin.file.open.ChooseProjectPanel;
 import org.openjump.core.ui.swing.wizard.AbstractWizardGroup;
@@ -24,6 +21,7 @@
 import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 import com.vividsolutions.jump.workbench.ui.wizard.WizardDialog;
+import org.openjump.core.ui.util.ExceptionUtil;
 
 public class DataSourceQueryChooserOpenWizard extends AbstractWizardGroup {
 
@@ -74,7 +72,7 @@
         boolean exceptionsEncountered = false;
         for (Iterator i = dataSourceQueries.iterator(); i.hasNext();) {
           DataSourceQuery dataSourceQuery = (DataSourceQuery)i.next();
-          ArrayList exceptions = new ArrayList();
+          List<Throwable> exceptions = new ArrayList<>();
           if (dataSourceQuery.getDataSource().isReadable()) {
             monitor.report("Loading " + dataSourceQuery.toString() + "...");
 
@@ -126,7 +124,7 @@
         .toString();
   }
 
-  private void reportExceptions(ArrayList exceptions,
+  private void reportExceptions(List<Throwable> exceptions,
     DataSourceQuery dataSourceQuery, PlugInContext context) {
     context.getOutputFrame()
       .addHeader(
@@ -144,21 +142,7 @@
             : ""));
     context.getOutputFrame().addText(
       I18N.get("datasource.LoadDatasetPlugIn.see-view-log"));
-    context.getOutputFrame().append("<ul>");
 
-    Collection exceptionsToReport = exceptions.size() <= 10 ? exceptions
-      : CollectionUtil.concatenate(Arrays.asList(new Collection[] {
-        exceptions.subList(0, 5),
-        exceptions.subList(exceptions.size() - 5, exceptions.size())
-      }));
-    for (Iterator j = exceptionsToReport.iterator(); j.hasNext();) {
-      Exception exception = (Exception)j.next();
-      context.getWorkbenchFrame().log(StringUtil.stackTrace(exception));
-      context.getOutputFrame().append("<li>");
-      context.getOutputFrame().append(
-        GUIUtil.escapeHTML(WorkbenchFrame.toMessage(exception), true, true));
-      context.getOutputFrame().append("</li>");
-    }
-    context.getOutputFrame().append("</ul>");
+    ExceptionUtil.reportExceptions(context, exceptions);
   }
 }

Modified: core/trunk/src/org/openjump/core/ui/util/ExceptionUtil.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/util/ExceptionUtil.java 2016-03-26 
14:57:15 UTC (rev 4868)
+++ core/trunk/src/org/openjump/core/ui/util/ExceptionUtil.java 2016-03-27 
15:37:31 UTC (rev 4869)
@@ -1,21 +1,19 @@
 package org.openjump.core.ui.util;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.*;
 
 import com.vividsolutions.jump.I18N;
 import com.vividsolutions.jump.io.datasource.DataSourceQuery;
 import com.vividsolutions.jump.util.CollectionUtil;
 import com.vividsolutions.jump.util.StringUtil;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
 import com.vividsolutions.jump.workbench.ui.GUIUtil;
 import com.vividsolutions.jump.workbench.ui.HTMLFrame;
 import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
 
 public class ExceptionUtil {
 
-  public static void reportExceptions(ArrayList exceptions,
+  public static void reportExceptions(List<Throwable> exceptions,
     DataSourceQuery dataSourceQuery, WorkbenchFrame workbenchFrame,
     HTMLFrame outputFrame) {
     outputFrame.addHeader(
@@ -34,13 +32,12 @@
     outputFrame.addText(I18N.get("datasource.LoadDatasetPlugIn.see-view-log"));
     outputFrame.append("<ul>");
 
-    Collection exceptionsToReport = exceptions.size() <= 10 ? exceptions
-      : CollectionUtil.concatenate(Arrays.asList(new Collection[] {
-        exceptions.subList(0, 5),
-        exceptions.subList(exceptions.size() - 5, exceptions.size())
-      }));
-    for (Iterator j = exceptionsToReport.iterator(); j.hasNext();) {
-      Exception exception = (Exception)j.next();
+    Collection<Throwable> exceptionsToReport = exceptions.size() <= 10 ?
+            exceptions :
+            CollectionUtil.concatenate(
+                exceptions.subList(0, 5),
+                exceptions.subList(exceptions.size() - 5, exceptions.size()));
+    for (Throwable exception : exceptionsToReport) {
       workbenchFrame.log(StringUtil.stackTrace(exception));
       outputFrame.append("<li>");
       outputFrame.append(GUIUtil.escapeHTML(
@@ -51,4 +48,22 @@
     outputFrame.append("</ul>");
   }
 
+  public static void reportExceptions(PlugInContext context, List<Throwable> 
exceptions) {
+    context.getOutputFrame().append("<ul>");
+    int size = exceptions.size();
+    Collection<Throwable> exceptionsToReport = size <= 10 ?
+            exceptions :
+            CollectionUtil.concatenate(
+                    exceptions.subList(0, 5),
+                    exceptions.subList(size - 5, size));
+    for (Throwable exception : exceptionsToReport) {
+      context.getWorkbenchFrame().log(StringUtil.stackTrace(exception));
+      context.getOutputFrame().append("<li>");
+      context.getOutputFrame().append(GUIUtil.escapeHTML(
+              WorkbenchFrame.toMessage(exception), true, true));
+      context.getOutputFrame().append("</li>");
+    }
+    context.getOutputFrame().append("</ul>");
+  }
+
 }


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to