/** * Reset the List of external file types after user customization. * * @param types The new List of external file types. This is the complete list, not just new * entries. */ public void setExternalFileTypes(List<ExternalFileType> types) { // First find a list of the default types: List<ExternalFileType> defTypes = getDefaultExternalFileTypes(); // Make a list of types that are unchanged: List<ExternalFileType> unchanged = new ArrayList<ExternalFileType>(); externalFileTypes.clear(); for (Iterator<ExternalFileType> iterator = types.iterator(); iterator.hasNext(); ) { ExternalFileType type = iterator.next(); externalFileTypes.add(type); // See if we can find a type with matching name in the default type list: ExternalFileType found = null; for (ExternalFileType defType : defTypes) { if (defType.getName().equals(type.getName())) { found = defType; break; } } if (found != null) { // Found it! Check if it is an exact match, or if it has been customized: if (found.equals(type)) unchanged.add(type); else { // It was modified. Remove its entry from the defaults list, since // the type hasn't been removed: defTypes.remove(found); } } } // Go through unchanged types. Remove them from the ones that should be stored, // and from the list of defaults, since we don't need to mention these in prefs: for (ExternalFileType type : unchanged) { defTypes.remove(type); types.remove(type); } // Now set up the array to write to prefs, containing all new types, all modified // types, and a flag denoting each default type that has been removed: String[][] array = new String[types.size() + defTypes.size()][]; int i = 0; for (ExternalFileType type : types) { array[i] = type.getStringArrayRepresentation(); i++; } for (ExternalFileType type : defTypes) { array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG}; i++; } // System.out.println("Encoded: '"+Util.encodeStringArray(array)+"'"); put("externalFileTypes", Util.encodeStringArray(array)); }