Changeset 6035


Ignore:
Timestamp:
2003-11-28T17:44:21+13:00 (20 years ago)
Author:
jmt12
Message:

Extends to implement TableModel, plus a couple of new method to allow for new FileAssociationDialog to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java

    r5894 r6035  
    2828
    2929import java.io.*;
     30import javax.swing.table.*;
     31import org.greenstone.gatherer.Dictionary;
    3032import org.greenstone.gatherer.Gatherer;
    3133import org.greenstone.gatherer.gui.FileAssociationDialog;
     
    3537import org.w3c.dom.*;
    3638
    37 public class FileAssociationManager {
     39public class FileAssociationManager
     40    extends AbstractTableModel {
    3841    static final public String FILENAME_ARG = "%1";
    3942    static final private String DATA_FILENAME = "associations.xml";
     
    134137    return command;
    135138    }
     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    }
    136155   
    137156    public String getCommand(File file) {
     
    218237    }
    219238
     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
    220254    public void save() {
    221255    Utility.export(document, data_file);
     
    227261    Element entry = getCommand(extension);
    228262    // If no previous entry existed create one.
    229     if(entry == null) {
     263    if(entry == null && command != null) {
    230264        entry = document.createElement(ENTRY_ELEMENT);
    231265        entry.setAttribute(EXTENSION_ATTRIBUTE, extension);
    232266        document.getDocumentElement().appendChild(entry);
    233267    }
    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    }
    236277    entry = null;
     278    fireTableDataChanged(); // Can't be anymore efficient as DOM does not gareuntee ordering of new child nodes is consistant
    237279    }
    238280
Note: See TracChangeset for help on using the changeset viewer.