- Timestamp:
- 2003-11-28T17:44:21+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java
r5894 r6035 28 28 29 29 import java.io.*; 30 import javax.swing.table.*; 31 import org.greenstone.gatherer.Dictionary; 30 32 import org.greenstone.gatherer.Gatherer; 31 33 import org.greenstone.gatherer.gui.FileAssociationDialog; … … 35 37 import org.w3c.dom.*; 36 38 37 public class FileAssociationManager { 39 public class FileAssociationManager 40 extends AbstractTableModel { 38 41 static final public String FILENAME_ARG = "%1"; 39 42 static final private String DATA_FILENAME = "associations.xml"; … … 134 137 return command; 135 138 } 139 140 public int getColumnCount() { 141 return 2; 142 } 143 144 public String getColumnName(int column) { 145 String name; 146 switch(column) { 147 case 0: 148 name = Dictionary.get("FileAssociationDialog.Table.Extension"); 149 break; 150 default: 151 name = Dictionary.get("FileAssociationDialog.Table.Command"); 152 } 153 return name; 154 } 136 155 137 156 public String getCommand(File file) { … … 218 237 } 219 238 239 public int getRowCount() { 240 NodeList entries = document.getDocumentElement().getElementsByTagName(ENTRY_ELEMENT); 241 return entries.getLength(); 242 } 243 244 public Object getValueAt(int row, int column) { 245 String extension = getExtension(row); 246 switch(column) { 247 case 0: 248 return extension; 249 default: 250 return getCommandString(extension); 251 } 252 } 253 220 254 public void save() { 221 255 Utility.export(document, data_file); … … 227 261 Element entry = getCommand(extension); 228 262 // If no previous entry existed create one. 229 if(entry == null ) {263 if(entry == null && command != null) { 230 264 entry = document.createElement(ENTRY_ELEMENT); 231 265 entry.setAttribute(EXTENSION_ATTRIBUTE, extension); 232 266 document.getDocumentElement().appendChild(entry); 233 267 } 234 // Replace the text in this node. If the user has used filename instead of %1 then too bad. 235 MSMUtils.setValue(entry, command); 268 269 if(command != null) { 270 // Replace the text in this node. If the user has used filename instead of %1 then too bad. 271 MSMUtils.setValue(entry, command); 272 } 273 else { 274 // Remove the entry 275 document.getDocumentElement().removeChild(entry); 276 } 236 277 entry = null; 278 fireTableDataChanged(); // Can't be anymore efficient as DOM does not gareuntee ordering of new child nodes is consistant 237 279 } 238 280
Note:
See TracChangeset
for help on using the changeset viewer.