Changeset 4489
- Timestamp:
- 2003-06-05T13:32:17+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/msm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MSMPrompt.java
r4460 r4489 67 67 private JButton replace = null; 68 68 private JButton skip = null; 69 private JDialog off_screen = null;70 69 private JDialog on_screen = null; 71 70 private JDialog dialog = null; … … 79 78 private Object result = null; 80 79 81 final static private Dimension MDE_SIZE = new Dimension(500,2 25);80 final static private Dimension MDE_SIZE = new Dimension(500,250); 82 81 final static private Dimension MDS_SIZE = new Dimension(800,425); 83 82 final static private Dimension PROGRESS_SIZE = new Dimension(500,105); … … 149 148 args[0] = mde_new.getAttribute("name"); 150 149 args[1] = get(reason, null); 151 JOptionPane.showMessageDialog( off_screen, get("Add_Failed", args), get("Add_Failed_Title", null), JOptionPane.ERROR_MESSAGE);150 JOptionPane.showMessageDialog(Gatherer.g_man, get("Add_Failed", args), get("Add_Failed_Title", null), JOptionPane.ERROR_MESSAGE); 152 151 } 153 152 … … 181 180 */ 182 181 public void endMerge() { 183 off_screen.dispose();184 off_screen = null;185 182 } 186 183 /** Method to indicate that yet another element has been succesfully merged, so that progress bar should reflect this. … … 193 190 /** Method to display the metadata element merging prompt, wherein the user determines how the attributes within an element should be merged. 194 191 * @param mde_cur The current <strong>Element</strong> we are merging against. 195 * @param att _cur The attribute <strong>Element</strong> of the current element in question.192 * @param atts_cur The list of matching attribute <strong>Elements</strong> of the current element in question. 196 193 * @param mde_new The <strong>Element</strong> which we have choosen to merge in, and whose attributes are being examined. 197 194 * @param att_new And the new elements attribute <strong>Element</strong>. 198 * @return An <i>int</i> specifying what further action should be undertaken, if any.199 */ 200 public int mDEPrompt(Element mde_cur, Element att_cur, Element mde_new, Element att_new) {195 * @return An object, which is either an Integer specifying what further action should be undertaken, if any, or if the action was replace, returns an Element, which is the attribute Element to replace with the new one 196 */ 197 public Object mDEPrompt(Element mde_cur, Element []atts_cur, Element mde_new, Element att_new) { 201 198 action = Declarations.NO_ACTION; 202 199 // Construction and configuration … … 208 205 JPanel content_pane = (JPanel)dialog.getContentPane(); 209 206 210 JLabel cur_name_label = new JLabel(get("Element_Name")); 211 212 JLabel cur_name = new JLabel(MSMUtils.getFullName(mde_cur)); 213 cur_name.setBackground(Color.white); 214 cur_name.setOpaque(true); 215 216 JLabel cur_att_label = new JLabel(get("Attribute")); 217 218 JLabel cur_att = new JLabel(att_cur.getAttribute("name") +" = " + MSMUtils.getValue(att_cur)); 219 cur_att.setBackground(Color.white); 220 cur_att.setOpaque(true); 221 222 JLabel new_name_label = new JLabel(cur_name_label.getText()); 223 224 JLabel new_name = new JLabel(MSMUtils.getFullName(mde_new)); 225 new_name.setBackground(Color.white); 226 new_name.setOpaque(true); 227 228 JLabel new_att_label = new JLabel(cur_att_label.getText()); 229 230 JLabel new_att = new JLabel(att_new.getAttribute("name") +" = " + MSMUtils.getValue(att_new)); 231 new_att.setBackground(Color.white); 232 new_att.setOpaque(true); 233 234 replace.setEnabled(true); 207 JLabel element_name_label = new JLabel(get("Element_Name")); 208 JLabel element_name = new JLabel(MSMUtils.getFullName(mde_cur)); 209 210 JLabel attribute_name_label = new JLabel(get("Attribute")); 211 JLabel attribute_name = new JLabel(att_new.getAttribute("name")); 212 213 add.setEnabled(true); 214 replace.setEnabled(false); 235 215 skip.setEnabled(true); 236 216 237 // Layout 217 JList cur_values = new JList(atts_cur); 218 cur_values.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 219 cur_values.setLayoutOrientation(JList.VERTICAL); 220 cur_values.setVisibleRowCount(3); 221 cur_values.setCellRenderer(new AttributeListCellRenderer()); 222 cur_values.addListSelectionListener(new ElementListListener(cur_values, replace)); 223 //Layout 224 JPanel title_pane = new JPanel(); 225 title_pane.setLayout(new GridLayout(2,2)); 226 title_pane.add(element_name_label); 227 title_pane.add(element_name); 228 title_pane.add(attribute_name_label); 229 title_pane.add(attribute_name); 230 238 231 JPanel current_pane = new JPanel(); 239 current_pane.setBorder(BorderFactory.createTitledBorder(get("Current_Element"))); 240 current_pane.setLayout(new GridLayout(2,2)); 241 current_pane.add(cur_name_label); 242 current_pane.add(cur_name); 243 current_pane.add(cur_att_label); 244 current_pane.add(cur_att); 232 current_pane.setLayout(new BorderLayout()); 233 current_pane.setBorder(BorderFactory.createTitledBorder(get("Current_Values"))); 234 JScrollPane scroll = new JScrollPane(cur_values); 235 current_pane.add(scroll, BorderLayout.CENTER); 245 236 246 237 JPanel new_pane = new JPanel(); 247 new_pane.setBorder(BorderFactory.createTitledBorder(get("New_Element"))); 248 new_pane.setLayout(new GridLayout(2,2)); 249 new_pane.add(new_name_label); 250 new_pane.add(new_name); 251 new_pane.add(new_att_label); 252 new_pane.add(new_att); 253 238 new_pane.setBorder(BorderFactory.createTitledBorder(get("New_Value"))); 239 new_pane.setLayout(new BorderLayout()); 240 JLabel new_att = new JLabel(MSMUtils.getValue(att_new)); 241 new_pane.add(new_att, BorderLayout.WEST); 254 242 JPanel central_pane = new JPanel(); 255 243 central_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 256 central_pane.setLayout(new GridLayout(2,1)); 244 central_pane.setLayout(new BoxLayout(central_pane, BoxLayout.Y_AXIS)); 245 central_pane.add(title_pane); 257 246 central_pane.add(current_pane); 258 247 central_pane.add(new_pane); … … 260 249 JPanel button_pane = new JPanel(); 261 250 button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); 262 button_pane.setLayout(new GridLayout(1,3)); 251 button_pane.setLayout(new GridLayout(1,4)); 252 button_pane.add(add); 263 253 button_pane.add(replace); 264 254 button_pane.add(skip); … … 270 260 271 261 // Display 262 272 263 dialog.setLocation((screen_size.width - MDE_SIZE.width) / 2, (screen_size.height - MDE_SIZE.height) / 2); 273 264 on_screen = dialog; 274 off_screen.setVisible(false); 275 on_screen.setVisible(true); 276 off_screen.setVisible(true); 265 on_screen.setVisible(true); // blocks until hidden 277 266 on_screen.dispose(); 278 267 268 // the return value - will either be an Integer containing the action, 269 // of the selected Element for a replace 270 Object result = new Integer(action); 271 // need to get the value of the list selection if replace was clicked 272 if (action == Declarations.REPLACE) { 273 result = cur_values.getSelectedValue(); 274 } 279 275 content_pane = null; 280 cur_name_label = null; 281 cur_name = null; 282 cur_att_label = null; 283 cur_att = null; 284 new_name_label = null; 285 new_name = null; 286 new_att_label = null; 276 element_name_label = null; 277 element_name = null; 278 attribute_name_label = null; 279 attribute_name=null; 280 cur_values = null; 281 title_pane=null; 282 current_pane = null; 283 scroll = null; 284 new_pane = null; 287 285 new_att = null; 288 current_pane = null;289 new_pane = null;290 286 central_pane = null; 291 287 button_pane = null; 292 screen_size = null;293 288 on_screen = null; 294 289 dialog = null; 295 296 return action;290 291 return result; 297 292 } 298 293 /** This method displays the metadata data set merging prompt, wherein the user determines how the elements within a set should be merged. … … 320 315 skip.setEnabled(true); 321 316 // Current details. 322 String str_cur[] = MSMUtils.getStructuralDetails(md e_cur);317 String str_cur[] = MSMUtils.getStructuralDetails(mds_cur, mde_cur); 323 318 String opt_cur[] = MSMUtils.getOptionListDetails(mde_cur); 324 319 String ass_cur[] = MSMUtils.getAssignedValuesDetails(mds_cur, mde_cur); 325 String details_cur = get("Structural" );320 String details_cur = get("Structural", str_cur); 326 321 if(opt_cur != null) { 327 322 details_cur = details_cur + "\n" + get("OptionList", opt_cur); … … 346 341 } 347 342 // New details. 348 String str_new[] = MSMUtils.getStructuralDetails(md e_new);343 String str_new[] = MSMUtils.getStructuralDetails(mds_new, mde_new); 349 344 String opt_new[] = MSMUtils.getOptionListDetails(mde_new); 350 345 String ass_new[] = MSMUtils.getAssignedValuesDetails(mds_new, mde_new); … … 402 397 dialog.setLocation((screen_size.width - MDS_SIZE.width) / 2, (screen_size.height - MDS_SIZE.height) / 2); 403 398 on_screen = dialog; 404 off_screen.setVisible(false);405 399 on_screen.setVisible(true); // Blocks until hidden. 406 off_screen.setVisible(true);407 400 on_screen.dispose(); 408 401 on_screen = null; … … 426 419 return action; 427 420 } 428 /** This method creates an initial JDialog which simply shows the MSMs progress towards merging the metadata sets.421 /** This method initialises the progress bar. 429 422 * @param element_count An <i>int</i> specifying the total number of elements to be merged. 430 423 */ 431 424 public void startMerge(int element_count) { 432 action = Declarations.NO_ACTION;433 JDialog dialog = new ModalDialog(Gatherer.g_man);434 dialog.setModal(false);435 dialog.setSize(PROGRESS_SIZE);436 dialog.setTitle(get("Merge_Progress"));437 //dialog.setJMenuBar(new SimpleMenuBar("0")); ?? do we want help here??438 439 JPanel content_pane = (JPanel)dialog.getContentPane();440 425 progress.setMaximum(element_count); 441 426 progress.setMinimum(0); 442 427 progress.setString("0%"); 443 428 progress.setValue(0); 444 // Layout. 445 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 446 content_pane.setLayout(new BorderLayout()); 447 content_pane.add(progress_label, BorderLayout.NORTH); 448 content_pane.add(progress, BorderLayout.CENTER); 449 // Display. 450 dialog.setLocation((screen_size.width - PROGRESS_SIZE.width) / 2, (screen_size.height - PROGRESS_SIZE.height) / 2); 451 off_screen = dialog; 452 dialog.setVisible(true); 453 content_pane = null; 454 dialog = null; 455 } 429 } 430 456 431 /** This method creates a prompt for renaming an Element. 457 432 * @param mde_new The <strong>Element</strong> we wish to rename. … … 515 490 dialog.setLocation((screen_size.width - RENAME_SIZE.width) / 2, (screen_size.height - RENAME_SIZE.height) / 2); 516 491 on_screen = dialog; 517 off_screen.setVisible(false);518 492 on_screen.setVisible(true); 519 off_screen.setVisible(true);520 493 on_screen.dispose(); 521 494 on_screen = null; … … 550 523 args[0] = mde_cur.getAttribute("name"); 551 524 args[1] = get(reason, null); 552 JOptionPane.showMessageDialog( off_screen, get("Remove_Failed", args), get("Remove_Failed_Title", null), JOptionPane.ERROR_MESSAGE);525 JOptionPane.showMessageDialog(Gatherer.g_man, get("Remove_Failed", args), get("Remove_Failed_Title", null), JOptionPane.ERROR_MESSAGE); 553 526 } 554 527 … … 563 536 args[1] = new_name; 564 537 args[2] = get(reason, null); 565 JOptionPane.showMessageDialog( off_screen, get("Rename_Failed", args), get("Rename_Failed_Title", null), JOptionPane.ERROR_MESSAGE);538 JOptionPane.showMessageDialog(Gatherer.g_man, get("Rename_Failed", args), get("Rename_Failed_Title", null), JOptionPane.ERROR_MESSAGE); 566 539 } 567 540 … … 611 584 dialog.setLocation((screen_size.width - SELECT_SIZE.width) / 2, (screen_size.height - SELECT_SIZE.height) / 2); 612 585 on_screen = dialog; 613 off_screen.setVisible(false);614 586 on_screen.setVisible(true); 615 off_screen.setVisible(true);616 587 on_screen.dispose(); 617 588 on_screen = null; … … 763 734 // Display 764 735 dialog.setLocation((screen_size.width - SELECT_ELEMENT_SIZE.width) / 2, (screen_size.height - SELECT_ELEMENT_SIZE.height) / 2); 765 System.err.println("Showing selection dialog. Block...");766 736 dialog.setVisible(true); 767 System.err.println("and release. Returning value.");768 737 // Deallocate everything because JDK1.4 won't. 769 738 // Why, oh why did I do this? … … 874 843 // Display 875 844 dialog.setLocation((screen_size.width - SELECT_SET_SIZE.width) / 2, (screen_size.height - SELECT_SET_SIZE.height) / 2); 876 System.err.println("Showing selection dialog. Block...");877 845 dialog.setVisible(true); 878 System.err.println("and release. Returning value.");879 846 Object value = set.getSelectedItem(); 880 847 if(value instanceof MetadataSet) { … … 905 872 } 906 873 public void actionPerformed(ActionEvent event) { 907 874 // Get the currently selected metadata set. 908 875 MetadataSet mds = (MetadataSet) set.getSelectedItem(); 909 876 String n = name; 910 877 // If we've been forced to go this far then any given namespace is complete bollocks. 911 878 while(n.indexOf(".") != -1 && !n.equals(".")) { 912 879 n = n.substring(n.indexOf(".") + 1); 913 880 } 914 881 // However, before we attempt to add a new element to the set, we should check that none already exists. 915 882 Element element = mds.getElement(name); 916 883 if(element == null) { … … 926 893 } 927 894 } 895 896 /** a ListCellRenderer for a list of Elements - the displayed value of the element is not Element.toString() */ 897 private class AttributeListCellRenderer extends DefaultListCellRenderer { 898 899 public AttributeListCellRenderer() { 900 super(); 901 } 902 public Component getListCellRendererComponent(JList list, 903 Object value, 904 int index, 905 boolean isSelected, 906 boolean cellHasFocus) { 907 908 setText(MSMUtils.getValue((Element)value)); 909 if (isSelected) { 910 setBackground(list.getSelectionBackground()); 911 setForeground(list.getSelectionForeground()); 912 } 913 else { 914 setBackground(list.getBackground()); 915 setForeground(list.getForeground()); 916 } 917 setEnabled(list.isEnabled()); 918 setFont(list.getFont()); 919 setOpaque(true); 920 return this; 921 } 922 923 924 } 925 928 926 /** This listener listens for selections within the select element to merge prompt, and once one has been made enables the ok button.*/ 929 927 private class ElementListListener … … 986 984 } 987 985 public void actionPerformed(ActionEvent event) { 988 986 // Return the currently selected element 989 987 result = (ElementWrapper)element.getSelectedItem(); 990 988 dialog.setVisible(false); … … 1020 1018 element.removeAllItems(); 1021 1019 MetadataSet mds = (MetadataSet) set.getSelectedItem(); 1022 System.err.println("Set selected: " + mds);1020 ///ystem.err.println("Set selected: " + mds); 1023 1021 if(mds != null) { 1024 1022 NodeList elements = mds.getElements(); … … 1067 1065 } 1068 1066 } 1067 1069 1068 } -
trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java
r4481 r4489 566 566 matched = true; 567 567 MetadataSet mds_cur = (MetadataSet)mds_hashtable.get(key); 568 //ystem.err.println("Merging " + mds_new + " into " + mds_cur); 569 MergeTask task = new MergeTask(mds_cur, mds_new); 570 task.start(); 568 ///ystem.err.println("Merging " + mds_new + " into " + mds_cur); 569 mergeMDS(mds_cur, mds_new); 571 570 } 572 571 } … … 576 575 } 577 576 // Fire setChanged() message. 578 //fireSetChanged(mds_new);577 fireSetChanged(mds_new); 579 578 return true; 580 579 } 581 580 // else we cancelled for some reason. 582 581 return false; 583 }584 585 private class MergeTask586 extends Thread {587 private MetadataSet mds_cur;588 private MetadataSet mds_new;589 MergeTask(MetadataSet mds_cur, MetadataSet mds_new) {590 this.mds_cur = mds_cur;591 this.mds_new = mds_new;592 }593 public void run() {594 mergeMDS(mds_cur, mds_new);595 fireSetChanged(mds_new);596 }597 582 } 598 583 … … 652 637 boolean cont = false; 653 638 Element mde_new = mds_new.getElement(i); 654 639 // See if the element already exists in the current set 655 640 Element mde_cur = mds_cur.getElement(mde_new.getAttribute("name")); 656 641 int option = Declarations.NO_ACTION; … … 765 750 */ 766 751 public boolean mergeMDE(MetadataSet mds_cur, Element mde_cur, MetadataSet mds_new, Element mde_new) { 767 while(true) { 768 for(Node mdn_new = mde_new.getFirstChild(); mdn_new != null; mdn_new = mdn_new.getNextSibling()) { 769 // Only merge the nodes whose name is 'Attribute' 770 if(mdn_new.getNodeName().equals("Attribute")) { 771 Element att_new = (Element) mdn_new; 772 // Unfortunately some attributes, such as author, can have several occurances, so match each in turn. 773 Element temp[] = MSMUtils.getAttributeNodesNamed(mde_cur, att_new.getAttribute("name")); 752 for(Node mdn_new = mde_new.getFirstChild(); mdn_new != null; mdn_new = mdn_new.getNextSibling()) { 753 // Only merge the nodes whose name is 'Attribute' 754 if(mdn_new.getNodeName().equals("Attribute")) { 755 Element att_new = (Element) mdn_new; 756 int action = Declarations.NO_ACTION; 757 Element replace_att = null; // replace this att with the new one 758 // Unfortunately some attributes, such as author, can have several occurances, so match each in turn. 759 Element temp[] = MSMUtils.getAttributeNodesNamed(mde_cur, att_new.getAttribute("name")); 760 if (temp==null) { 761 action = Declarations.ADD; 762 } else { 763 764 // look for an exact match 774 765 for(int i = 0; temp != null && i < temp.length; i++) { 775 766 Element att_cur = temp[i]; 776 boolean cont = false; 777 int action = Declarations.NO_ACTION; 778 while(!cont) { 779 if(att_cur != null) { 780 if(!MSMUtils.attributesEqual(att_cur, att_new)) { 781 action = prompt.mDEPrompt(mde_cur, att_cur, mde_new, att_new); 782 } 783 else { 784 action = Declarations.SKIP; 785 } 786 } 787 else { 788 action = Declarations.ADD; 789 } 790 switch (action) { 791 case Declarations.REPLACE: 792 // Out with the old. 793 mde_cur.removeChild(att_cur); 794 case Declarations.ADD: 795 // Simply add the new attribute. No clash is possible as we have already tested for it. 796 MSMUtils.add(mde_cur, att_new); 797 cont = true; 798 break; 799 case Declarations.SKIP: 800 // Do nothing. Move on to next attribute. 801 cont = true; 802 break; 803 case Declarations.CANCEL: 804 return false; 805 default: 806 cont = false; 807 } 767 if(MSMUtils.attributesEqual(att_cur, att_new)) { 768 action = Declarations.SKIP; 769 break; 808 770 } 809 771 att_cur = null; 810 772 } 811 temp = null; 812 att_new = null; 813 } 814 } 815 return mergeMDV(mds_cur, mde_cur, mds_new, mde_new); 816 } 817 } 773 if (action == Declarations.NO_ACTION) { 774 // we didn't find a match, so we have to prompt teh user for what to do 775 Object result = prompt.mDEPrompt(mde_cur, temp, mde_new, att_new); 776 if (result instanceof Integer) { 777 action = ((Integer)result).intValue(); 778 } else { 779 // we have a replace action, and the returned object is the Attribute to replace 780 action = Declarations.REPLACE; 781 replace_att = (Element)result; 782 } 783 } 784 } 785 786 // now do the required action 787 switch (action) { 788 case Declarations.REPLACE: 789 // Out with the old. 790 mde_cur.removeChild(replace_att); 791 case Declarations.ADD: 792 // Simply add the new attribute. No clash is possible as we have already tested for it. 793 MSMUtils.add(mde_cur, att_new); 794 break; 795 case Declarations.SKIP: 796 // Do nothing. Move on to next attribute. 797 break; 798 case Declarations.CANCEL: 799 return false; 800 default: 801 } 802 803 att_new = null; 804 temp = null; 805 replace_att = null; 806 } // if node nmae = attribute 807 } //for each child node 808 return mergeMDV(mds_cur, mde_cur, mds_new, mde_new); 809 } 810 818 811 /** Merge two metadata value trees. 819 812 * @param mds_cur The current MetadataSet. … … 833 826 MetadataSet set = (MetadataSet) mds_hashtable.get(namespace); 834 827 if(set != null) { 835 828 // Bugger. Get the old name -before- we remove the element from the set. 836 829 String old_name = element.toString(); 837 830 // Remove the element. 838 831 set.removeElement(element.getElement()); 839 832 // Fire event. 840 833 fireElementChanged(new MSMEvent(this, null, old_name)); 841 834 } 842 835 else { 843 836 ///ystem.err.println("no such set " + namespace); 844 837 } 845 838 // No such set. No such element.
Note:
See TracChangeset
for help on using the changeset viewer.