Changeset 4425


Ignore:
Timestamp:
2003-05-30T13:50:22+12:00 (21 years ago)
Author:
mdewsnip
Message:

Some changes as a result of tidying up GValueTree. Now includes some code from there that is better here.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPane.java

    r4410 r4425  
    103103    /** The button, which when clicked, updates the selected metadata from the selected records. */
    104104    private JButton update;
     105    /** This button creates an editor dialog to allow for an expanded area to type in text. */
     106    private JButton expand;
    105107    /** The label at the top of the collection tree, which shows the collection name. */
    106108    private JLabel collection_label;
     
    182184    remove.setPreferredSize(BUTTON_SIZE);
    183185
    184     tree = new GValueTree(this, CONTROL_SIZE.width, CONTROL_SIZE.height, add, update, remove);
     186    expand = new JButton(get("General.Expand"));
     187    expand.addActionListener(this);
     188    expand.setEnabled(true);
     189    expand.setMnemonic(KeyEvent.VK_E);
     190    expand.setPreferredSize(MetaEditPane.BUTTON_SIZE);
     191
     192    tree = new GValueTree(this, CONTROL_SIZE.width, CONTROL_SIZE.height, add, update, remove, expand);
    185193    tree.setRootVisible(false);
    186194    }
     
    197205    Object esrc = event.getSource();
    198206    if(esrc == add) {
    199                 // Check the new metadata is valid
     207        // Check the new metadata is valid
    200208        ElementWrapper element = tree.getSelectedMetadataElement();
    201209        String value = tree.getSelectedValue();
     
    213221            Gatherer.c_man.getCollection().msm.addMetadata(System.currentTimeMillis(), records, element, value);
    214222        }
    215         }
    216                 // Slight hack. Used to do this automatically if a value was added to the GValueModel, however this caused a Garbage Collection loop with the latest incarnation of FileQueue, so I've removed it and I'll manually call the value tree update here.
    217         tree.valueChanged(new MSMEvent(this, 0, element, null, null));
    218                 // Else bad metadata.
     223        GValueNode value_node = ((GValueModel) tree.getModel()).addValue(value);
     224        model.setSelectedMetadata(new Metadata(element, value_node));
     225        }
    219226    }
    220227    else if(esrc == update) {
    221         System.err.println("MEP.Update!");
    222                 // You can only update if there is a selected_metadata and
    223                 // you have valid values in all fields.
     228        // You can only update if there is a selected_metadata and
     229        // you have valid values in all fields.
    224230        ElementWrapper element = tree.getSelectedMetadataElement();
    225231        String value = tree.getSelectedValue();
     
    227233        selected_metadata = Gatherer.c_man.getCollection().msm.updateMetadata(System.currentTimeMillis(), selected_metadata, records, value, MetaEditPrompt.OVERWRITE, selected_metadata.isFileLevel());
    228234        }
    229                 // Slight hack. Used to do this automatically if a value was added to the GValueModel, however this caused a Garbage Collection loop with the latest incarnation of FileQueue, so I've removed it and I'll manually call the value tree update here.
    230         tree.valueChanged(new MSMEvent(this, 0, element, null, null));
     235        GValueNode value_node = ((GValueModel) tree.getModel()).addValue(value);
     236        model.setSelectedMetadata(new Metadata(element, value_node));
    231237    }
    232238    else if(esrc == remove) {
    233239        if(selected_metadata != null && records != null) {
    234240        Gatherer.c_man.getCollection().msm.removeMetadata(System.currentTimeMillis(), selected_metadata, records);
     241        }
     242    }
     243    else if(esrc == expand) {
     244        EditorDialog ed = new EditorDialog();
     245        String temp = ed.display(tree.getSelectedValue());
     246        if(temp != null) {
     247        tree.setSelectedValue(temp);
    235248        }
    236249    }
     
    292305        Gatherer.c_man.getCollection().msm.removeMSMListener(this);
    293306        Gatherer.c_man.getCollection().msm.addMSMListener(this);
    294 
    295         tree.setElementModel(Gatherer.c_man.getCollection().msm.getElementModel());
    296        
    297307    }
    298308    else {
     
    590600    // Use this opportunity to update the table model etc.
    591601    valueChanged(new TreeSelectionEvent(this, null, false, null, null));
    592     tree.setElementModel(Gatherer.c_man.getCollection().msm.getElementModel());
     602    // tree.setElementModel(Gatherer.c_man.getCollection().msm.getElementModel());
    593603    }
    594604    /** Used to determine if this class contains a reference to an existing file record that matches the presumtively new record, and if one is found, returns it. Note that there is no need to search the metadata table model, as any file record that exists there must also exist in the records selection.
     
    701711    }
    702712    if(and_tree) {
    703         tree.validateControls();
     713        // Validate the buttons in the lower pane
     714        if (selected_metadata == null) {
     715        // Nothing selected
     716        return;
     717        }
     718
     719        ElementWrapper selected_element = selected_metadata.getElement();
     720        if (selected_element.getNamespace() == "") {
     721        // Extracted metadata
     722        add.setEnabled(false);
     723        update.setEnabled(false);
     724        remove.setEnabled(false);
     725        return;
     726        }
     727
     728        // Does the metadata element have no current value?
     729        GValueNode value_node = selected_metadata.getValueNode();
     730        if (value_node == null) {
     731        // Can only append if something has been entered
     732        add.setEnabled((tree.getSelectedValue().length() > 0));
     733        // Nothing to replace or remove
     734        update.setEnabled(false);
     735        remove.setEnabled(false);
     736        }
     737
     738        else {
     739        // Check if the text in the value field is the same as the metadata value
     740        if (tree.getSelectedValue().equals(value_node.getFullPath())) {
     741            // Can't append or replace
     742            add.setEnabled(false);
     743            update.setEnabled(false);
     744        }
     745        else {
     746            // Can append or replace
     747            add.setEnabled(true);
     748            update.setEnabled(true);
     749        }
     750
     751        // Can only remove if the metadata is file level
     752        remove.setEnabled(selected_metadata.isFileLevel());
     753        }
     754
     755        // tree.validateControls();
    704756    }
    705757    }
     
    717769
    718770    /** Another in a long list of listeners, this one is called whenever the
    719       * selection within the JTable changes. When it does we load the new data
    720       * and set the selected_metadata if applicable (ie the metadata is non-
    721       * empty).
    722       * @param event The <strong>ListSelectionEvent</strong> which contains all the information about the event that has been fired.
    723       * @see org.greenstone.gatherer.gui.table.GTableModel
    724       * @see org.greenstone.gatherer.valuetree.GValueTree
    725       */
     771     * selection within the JTable changes. When it does we load the new data
     772     * and set the selected_metadata if applicable (ie the metadata is non-
     773     * empty).
     774     * @param event The <strong>ListSelectionEvent</strong> which contains all the information about the event that has been fired.
     775     * @see org.greenstone.gatherer.gui.table.GTableModel
     776     * @see org.greenstone.gatherer.valuetree.GValueTree
     777     */
    726778    public void valueChanged(ListSelectionEvent event) {
    727     // We have a SINGLE_SELECTION model set so there is at most one
    728     // selection. Get the offending row.
    729     int selected = table.getSelectedRow();
    730     selected_metadata = model.getMetadataAtRow(selected);
    731     if(selected_metadata != null) { // Check something is selected.
    732         tree.setCommon(model.isCommon(selected));
    733         tree.setFileLevel(selected_metadata.isFileLevel());
    734         tree.setSelectedMetadataElement(selected_metadata.getElement());
    735         GValueNode value_node = selected_metadata.getValueNode();
    736         if(value_node != null) {
    737         tree.setSelectedValue(value_node.getFullPath());
    738         }
    739         else {
    740         tree.setSelectedValue("");
    741         }
    742     }
    743     else {
    744         card_layout2.show(control_pane, TOOLS_OFF);
     779    // We only want to handle one event per selection, so wait for the value to stabilise
     780    ListSelectionModel lsm = table.getSelectionModel();
     781    if (lsm.getValueIsAdjusting() == false) {
     782        // We have a SINGLE_SELECTION model set so there is at most one
     783        // selection. Get the offending row.
     784        int selected = table.getSelectedRow();
     785        selected_metadata = model.getMetadataAtRow(selected);
     786        if(selected_metadata != null) { // Check something is selected.
     787        tree.setSelectedMetadataElement(selected_metadata.getElement());
     788        GValueNode value_node = selected_metadata.getValueNode();
     789        if(value_node != null) {
     790            String fullPath = value_node.getFullPath();
     791            System.err.println("(LSE) fullPath: " + fullPath);
     792            tree.setSelectedValue(fullPath);
     793        }
     794        else {
     795            tree.setSelectedValue("");
     796        }
     797        }
     798        validateControls(true);
    745799    }
    746800    }
     
    752806
    753807    /** This method is called whenever the selection within the collection
    754       * tree changes. This causes the table to be rebuilt with a new model
    755       * @param event A <strong>TreeSelectionEvent</strong> containing information about the event.
    756       * @see org.greenstone.gatherer.Gatherer
    757       * @see org.greenstone.gatherer.collection.FileNode
    758       * @see org.greenstone.gatherer.gui.GUIManager
    759       * @see org.greenstone.gatherer.gui.MenuBar
    760       * @see org.greenstone.gatherer.gui.table.GTableModel
    761       * @see org.greenstone.gatherer.msm.MetadataSetManager
    762       * @see org.greenstone.gatherer.tree.GTree
    763       * @see org.greenstone.gatherer.util.ArrayTools
    764       */
     808     * tree changes. This causes the table to be rebuilt with a new model
     809     * @param event A <strong>TreeSelectionEvent</strong> containing information about the event.
     810     * @see org.greenstone.gatherer.Gatherer
     811     * @see org.greenstone.gatherer.collection.FileNode
     812     * @see org.greenstone.gatherer.gui.GUIManager
     813     * @see org.greenstone.gatherer.gui.MenuBar
     814     * @see org.greenstone.gatherer.gui.table.GTableModel
     815     * @see org.greenstone.gatherer.msm.MetadataSetManager
     816     * @see org.greenstone.gatherer.tree.GTree
     817     * @see org.greenstone.gatherer.util.ArrayTools
     818     */
    765819    public void valueChanged(TreeSelectionEvent event) {
    766     ///ystem.err.print("We just detected a value changed event.");
    767     if(Gatherer.g_man.getSelectedView() == this) {
    768         if(collection_tree.getSelectionCount() > 0) {
    769         records = null;
    770         TreePath paths[] = collection_tree.getSelectionPaths();
    771         int files = 0;
    772         int dirs = 0;
    773         ///ystem.err.println("Selected " + paths.length + " files.");
    774         for(int i = 0; i < paths.length; i++) {
    775             FileNode record = (FileNode) paths[i].getLastPathComponent();
    776             records = ArrayTools.add(records, record);
    777         }
    778 
    779         table_label.setText(collection_tree.getSelectionDetails());
    780                      
    781         // Remove old model from msm
     820    // System.err.println("(MEP) valueChanged(TreeSelectionEvent)...");
     821
     822    // Don't bother if this isn't the selected view
     823    if (Gatherer.g_man.getSelectedView() != this) {
     824        return;
     825    }
     826
     827    if(collection_tree.getSelectionCount() > 0) {
     828        records = null;
     829        TreePath paths[] = collection_tree.getSelectionPaths();
     830        for(int i = 0; i < paths.length; i++) {
     831        FileNode record = (FileNode) paths[i].getLastPathComponent();
     832        records = ArrayTools.add(records, record);
     833        }
     834
     835        table_label.setText(collection_tree.getSelectionDetails());
     836
     837        // Remove old model from msm
     838        Gatherer.c_man.getCollection().msm.removeMSMListener(model);
     839        // Create new model (which will add itself to msm).
     840        model = new GTableModel(table, records);
     841        table.setModel(model);
     842    }
     843    else {
     844        records = null;
     845        // Remove old model from msm
     846        if(Gatherer.c_man.ready()) {
    782847        Gatherer.c_man.getCollection().msm.removeMSMListener(model);
    783         // Create new model (which will add itself to msm).
    784         //model = new GTableModel(table, assigned_metadata_view, unassigned_metadata_view, activity_bar, records);
    785         model = new GTableModel(table, records);
    786         table.setModel(model);
    787         }
    788         else {
    789         ///ystem.err.println("No node selected!");
    790         records = null;
    791         // Remove old model from msm
    792         if(Gatherer.c_man.ready()) {
    793             Gatherer.c_man.getCollection().msm.removeMSMListener(model);
    794         }
    795         // Create new model (which will add itself to msm).
    796         //model = new GTableModel(table, assigned_metadata_view, unassigned_metadata_view, activity_bar);
    797         model = new GTableModel(table);
    798         table.setModel(model);
    799         }
    800         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    801         if(table != null) {
    802         Dimension table_size = table.getPreferredSize();
    803         TableColumnModel column_model = table.getColumnModel();
    804 
    805         TableColumn inherited_column = column_model.getColumn(0);
    806         inherited_column.setPreferredWidth(20);
    807         inherited_column.setCellRenderer(new TableCellRenderer(model));
    808                      
    809         TableColumn element_column = column_model.getColumn(1);
    810         element_column.setPreferredWidth(TABLE_SIZE.width / 4);
    811         element_column.setCellRenderer(new TableCellRenderer(model));
    812                      
    813         TableColumn value_column = column_model.getColumn(2);
    814         value_column.setPreferredWidth(((3 * TABLE_SIZE.width) / 4) - 15);
    815         value_column.setCellRenderer(new TableCellRenderer(model));
    816         }
    817         validateControls();
    818     }
    819     }
     848        }
     849        // Create new model (which will add itself to msm).
     850        model = new GTableModel(table);
     851        table.setModel(model);
     852    }
     853
     854    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     855    if(table != null) {
     856        Dimension table_size = table.getPreferredSize();
     857        TableColumnModel column_model = table.getColumnModel();
     858
     859        TableColumn inherited_column = column_model.getColumn(0);
     860        inherited_column.setPreferredWidth(20);
     861        inherited_column.setCellRenderer(new TableCellRenderer(model));
     862             
     863        TableColumn element_column = column_model.getColumn(1);
     864        element_column.setPreferredWidth(TABLE_SIZE.width / 4);
     865        element_column.setCellRenderer(new TableCellRenderer(model));
     866             
     867        TableColumn value_column = column_model.getColumn(2);
     868        value_column.setPreferredWidth(((3 * TABLE_SIZE.width) / 4) - 15);
     869        value_column.setCellRenderer(new TableCellRenderer(model));
     870    }
     871    validateControls();
     872    }
     873
     874
    820875    /** Retrieve a phrase from the Dictionary based on the given key.
    821876    * @param key The <strong>String</strong> which maps to the phrase to retrieve.
Note: See TracChangeset for help on using the changeset viewer.