Changeset 4403 for trunk/gli/src/org/greenstone/gatherer
- Timestamp:
- 2003-05-29T15:19:02+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java
r4365 r4403 101 101 private JScrollPane set_attributes_scroll = null; 102 102 private JPanel details_pane = null; 103 private KeepTreeRootExpandedListener keep_root_expanded_listener = null; 103 104 private MEMModel model = null; 104 105 private MEMNode current_node = null; … … 228 229 element_values.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); 229 230 element_values.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); 230 231 232 keep_root_expanded_listener = new KeepTreeRootExpandedListener(); 233 231 234 JPanel profile_details_pane = new JPanel(); 232 235 profile_details_pane.setOpaque(false); … … 1210 1213 this.setModal(true); 1211 1214 this.setSize(ADD_OR_EDIT_VALUE_SIZE); 1212 1215 // Create 1213 1216 JPanel content_pane = (JPanel) getContentPane(); 1214 1217 content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false)); … … 1249 1252 ok_button = new JButton(get("General.OK")); 1250 1253 ok_button.setEnabled(false); 1254 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button); 1251 1255 cancel_button = new JButton(get("General.Cancel")); 1252 1253 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);1256 // Connect 1257 ok_button_enabler.add(value); 1254 1258 cancel_button.addActionListener(this); 1255 1259 ok_button.addActionListener(this); 1256 1260 subject_tree.addTreeSelectionListener(this); 1257 ok_button_enabler.add(value); 1258 // Layout 1261 // Layout 1259 1262 subject_tree_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 1260 1263 subject_tree_pane.setLayout(new BorderLayout()); … … 1299 1302 GValueModel model = Gatherer.c_man.msm.getValueTree(current_element); 1300 1303 if(add_type) { 1304 ///ystem.err.println("Add type - insert node: " + value.getText() + " into " + subject_node); 1301 1305 // Add this value to the tree. 1302 GValueNode parent = null;1303 1306 model.addValue(value.getText(), subject_node, alias.getText()); 1304 parent = null;1305 1307 } 1306 1308 else { … … 1343 1345 } 1344 1346 // Inform the tree model what two nodes structures have changed (origin and destination). 1345 subject_node.unmap();1346 old_subject_node.unmap();1347 //subject_node.unmap(); 1348 //old_subject_node.unmap(); 1347 1349 model.nodeStructureChanged(old_subject_node); 1348 1350 model.nodeStructureChanged(subject_node); … … 1443 1445 self.dispose(); 1444 1446 } 1447 } 1448 1449 /** This listener is responsible for keeping the root node of a value tree expanded where and when possible. */ 1450 private class KeepTreeRootExpandedListener 1451 implements TreeModelListener { 1452 /** Invoked after a node (or a set of siblings) has changed in some way. */ 1453 public void treeNodesChanged(TreeModelEvent e) { 1454 } 1455 /** Invoked after nodes have been inserted into the tree. */ 1456 public void treeNodesInserted(TreeModelEvent e) { 1457 element_values.expandPath(new TreePath(element_values.getModel().getRoot())); 1458 } 1459 /** Invoked after nodes have been removed from the tree. */ 1460 public void treeNodesRemoved(TreeModelEvent e) { 1461 } 1462 /** Invoked after the tree has drastically changed structure from a given node down. */ 1463 public void treeStructureChanged(TreeModelEvent e) { 1464 element_values.expandPath(new TreePath(element_values.getModel().getRoot())); 1465 } 1445 1466 } 1446 1467 … … 1593 1614 /** Used to enable a certain target component if and only if all the registered text fields contain non-zero length strings. */ 1594 1615 private class TextFieldEnabler 1595 extends KeyAdapter { 1616 implements DocumentListener { 1617 private boolean ignore = false; 1596 1618 private Component target = null; 1597 1619 private JTextComponent[] fields = null; … … 1601 1623 } 1602 1624 public void add(JTextComponent field) { 1603 field.addKeyListener(this);1625 // Record this field as being one we depend upon 1604 1626 if(fields == null) { 1605 1627 fields = new JTextComponent[1]; … … 1611 1633 temp[fields.length] = field; 1612 1634 fields = temp; 1613 } 1614 } 1615 public void keyReleased(KeyEvent event) { 1616 boolean enable = true; 1617 for(int i = 0; i < fields.length; i++) { 1618 enable = enable && fields[i].getText().length() > 0; 1619 } 1620 target.setEnabled(enable); 1635 temp = null; 1636 } 1637 // Add the appropriate listener 1638 field.getDocument().addDocumentListener(this); 1639 } 1640 /** Gives notification that an attribute or set of attributes changed. */ 1641 public void changedUpdate(DocumentEvent e) { 1642 canEnable(); 1643 } 1644 /** Gives notification that there was an insert into the document. */ 1645 public void insertUpdate(DocumentEvent e) { 1646 canEnable(); 1647 } 1648 /** Gives notification that a portion of the document has been removed. */ 1649 public void removeUpdate(DocumentEvent e) { 1650 canEnable(); 1651 } 1652 private void canEnable() { 1653 if(!ignore) { 1654 ignore = true; 1655 boolean can_enable = true; 1656 for(int i = 0; can_enable && i < fields.length; i++) { 1657 can_enable = can_enable && (fields[i].getText().length() > 0); 1658 } 1659 target.setEnabled(can_enable); 1660 ignore = false; 1661 } 1621 1662 } 1622 1663 } … … 1709 1750 atm.setTable(element_attributes); 1710 1751 1711 element_values.setModel(Gatherer.c_man.msm.getValueTree(current_element)); 1752 // Be careful not to add the keep_root_expanded_listener over and over! 1753 GValueModel value_model = Gatherer.c_man.msm.getValueTree(current_element); 1754 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there 1755 value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again. 1756 element_values.setModel(value_model); 1712 1757 card_layout.show(details_pane, ELEMENT); 1713 1758 // Meanwhile disable/enable controls depending on this Element selection.
Note:
See TracChangeset
for help on using the changeset viewer.