private void removeMapping(Shell shell) {
    TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
    TableItem[] itemsMappings = fMappingsTable.getSelection();

    if (itemsMappings.length > 0 && itemsIdMaps.length > 0) {
      Mapping mapping = (Mapping) itemsMappings[0].getData();
      IdMap idmap = (IdMap) itemsIdMaps[0].getData();
      HashMap idmapHS = (HashMap) fIdMaps.get(idmap.getName());
      idmapHS.remove(mapping.getKey());
      Vector mappings = idmap.getMappings();
      mappings.remove(mapping);
      itemsMappings[0].dispose(); // Table is single selection
    }
  }
  protected TableItem newOrderedTableItem(Mapping mapping, boolean selected) {
    TableItem[] items = fOrderedTable.getItems();
    int i = 0;
    while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0)
      i++;

    TableItem item = new TableItem(fOrderedTable, SWT.NULL, i);

    String[] values = new String[] {mapping.getElement(), mapping.getSignature()};
    item.setText(values);
    item.setData(mapping);
    if (selected) fOrderedTable.setSelection(i);

    return item;
  }
 private void removeOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) {
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     idmapAL.remove(mapping.getKey());
     if (idmapAL.size() <= 0) fOrderedElements.remove(idmap.getName());
     ArrayList ordered = idmap.getOrdered();
     ordered.remove(mapping);
     if (ordered.size() <= 0) idmap.setOrdered(null);
     itemsOrdered[0].dispose(); // Table is single selection
   }
 }
 protected static void setOrdered(IdMap idmap, ArrayList idmapOrdered) {
   ArrayList Ordered = new ArrayList();
   for (Iterator iter_ordered = idmapOrdered.iterator(); iter_ordered.hasNext(); ) {
     Mapping mapping = new Mapping();
     String signature = (String) iter_ordered.next();
     int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR, signature.length() - 2);
     if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1)
       mapping.setSignature(""); // $NON-NLS-1$
     else
       mapping.setSignature(
           signature.substring(XMLStructureCreator.ROOT_ID.length() + 1, end_of_signature));
     mapping.setElement(signature.substring(end_of_signature + 1, signature.length() - 1));
     Ordered.add(mapping);
   }
   idmap.setOrdered(Ordered);
 }
 private void editOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     String idmapALKey = mapping.getKey();
     idmapAL.remove(idmapALKey);
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapALKey = mapping.getKey();
       idmapAL.add(idmapALKey);
       fOrderedTable.remove(fOrderedTable.indexOf(itemsOrdered[0]));
       newOrderedTableItem(mapping, true);
     }
   }
 }
 private void editMapping(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsMappings = fMappingsTable.getSelection();
   if (itemsMappings.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName());
     Mapping mapping = (Mapping) itemsMappings[0].getData();
     String idmapHMKey = mapping.getKey();
     idmapHM.remove(idmapHMKey);
     XMLCompareEditMappingDialog dialog =
         new XMLCompareEditMappingDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapHMKey = mapping.getKey();
       idmapHM.put(idmapHMKey, mapping.getIdAttribute());
       fMappingsTable.remove(fMappingsTable.indexOf(itemsMappings[0]));
       newMappingsTableItem(mapping, true);
     }
   }
 }
 private void fillIdMaps(boolean internal) {
   HashMap IdMaps = (internal) ? fIdMapsInternal : fIdMaps;
   HashMap OrderedElements = (internal) ? fOrderedElementsInternal : fOrderedElements;
   Set IdMapKeys = IdMaps.keySet();
   for (Iterator iter_internal = IdMapKeys.iterator(); iter_internal.hasNext(); ) {
     String IdMapName = (String) iter_internal.next();
     Vector Mappings = new Vector();
     IdMap idmap = new IdMap(IdMapName, internal, Mappings);
     // create mappings of internal idmaps
     HashMap idmapHM = (HashMap) IdMaps.get(IdMapName);
     Set idmapKeys = idmapHM.keySet();
     for (Iterator iter_idmap = idmapKeys.iterator(); iter_idmap.hasNext(); ) {
       Mapping mapping = new Mapping();
       String signature = (String) iter_idmap.next();
       int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR, signature.length() - 2);
       if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1)
         mapping.setSignature(""); // $NON-NLS-1$
       else
         mapping.setSignature(
             signature.substring(XMLStructureCreator.ROOT_ID.length() + 1, end_of_signature));
       mapping.setElement(signature.substring(end_of_signature + 1, signature.length() - 1));
       mapping.setIdAttribute((String) idmapHM.get(signature));
       Mappings.add(mapping);
     }
     // create ordered mappings
     ArrayList idmapOrdered = (ArrayList) OrderedElements.get(IdMapName);
     if (idmapOrdered != null) {
       setOrdered(idmap, idmapOrdered);
     }
     // set extension
     if (fIdExtensionToName.containsValue(IdMapName)) {
       Set keySet = fIdExtensionToName.keySet();
       String extension = new String();
       for (Iterator iter = keySet.iterator(); iter.hasNext(); ) {
         extension = (String) iter.next();
         if (((String) fIdExtensionToName.get(extension)).equals(IdMapName)) break;
       }
       idmap.setExtension(extension);
     }
     newIdMapsTableItem(idmap, false);
   }
 }
  protected TableItem newMappingsTableItem(Mapping mapping, boolean selected) {
    TableItem[] items = fMappingsTable.getItems();
    int i = 0;
    while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0)
      i++;
    TableItem item = new TableItem(fMappingsTable, SWT.NULL, i);
    String idtext = mapping.getIdAttribute();
    String idtype;
    if (idtext.charAt(0) == XMLStructureCreator.ID_TYPE_BODY) {
      idtext = idtext.substring(1, idtext.length());
      idtype = IDTYPE_CHILDBODY;
    } else idtype = IDTYPE_ATTRIBUTE;

    String[] values = new String[] {mapping.getElement(), mapping.getSignature(), idtext, idtype};
    item.setText(values);
    item.setData(mapping);
    if (selected) fMappingsTable.setSelection(i);

    return item;
  }
 private void addMapping(Shell shell) {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     IdMap idmap = (IdMap) items[0].getData();
     Mapping mapping = new Mapping();
     HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName());
     XMLCompareEditMappingDialog dialog =
         new XMLCompareEditMappingDialog(shell, mapping, idmapHM, false);
     if (dialog.open() == Window.OK) {
       String idmapHMKey = mapping.getKey();
       if (idmapHM == null) idmapHM = new HashMap();
       if (!idmapHM.containsKey(idmapHMKey)) {
         idmapHM.put(idmapHMKey, mapping.getIdAttribute());
         newMappingsTableItem(mapping, true);
         Vector mappings = idmap.getMappings();
         mappings.add(mapping);
       }
     }
   }
 }
 private void addOrdered(Shell shell) {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     //			Set orderedSet= fOrderedElements.keySet();
     //			for (Iterator iter= orderedSet.iterator(); iter.hasNext(); ) {
     //				String IdMapName= (String) iter.next();
     //				ArrayList ordered= (ArrayList) fOrderedElements.get(IdMapName);
     //				for (Iterator iter2= ordered.iterator(); iter2.hasNext(); ) {
     //					System.out.println(IdMapName + ": " + iter2.next()); //$NON-NLS-1$
     //				}
     //			}
     IdMap idmap = (IdMap) items[0].getData();
     Mapping mapping = new Mapping();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     if (idmapAL == null) idmapAL = new ArrayList();
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, idmapAL, false);
     if (dialog.open() == Window.OK) {
       String idmapALKey = mapping.getKey();
       if (!idmapAL.contains(idmapALKey)) {
         idmapAL.add(idmapALKey);
         newOrderedTableItem(mapping, true);
         ArrayList ordered = idmap.getOrdered();
         if (ordered == null) {
           ordered = new ArrayList();
           ordered.add(mapping);
           idmap.setOrdered(ordered);
         } else {
           ordered.add(mapping);
         }
         if (!fOrderedElements.containsKey(idmap.getName()))
           fOrderedElements.put(idmap.getName(), idmapAL);
       }
     }
   }
 }
  private void editIdMap(Shell shell) {
    TableItem[] items = fIdMapsTable.getSelection();
    if (items.length > 0) {
      IdMap idmap = (IdMap) items[0].getData();
      XMLCompareEditCopyIdMapDialog dialog =
          new XMLCompareEditCopyIdMapDialog(shell, idmap, fIdMaps, fIdMapsInternal);
      if (dialog.open() == Window.OK) {
        String new_idmapName = dialog.getResult();
        if (!fIdMaps.containsKey(new_idmapName)) {
          // copy over id mappings
          Vector newMappings = new Vector();
          IdMap newIdMap = new IdMap(new_idmapName, false, newMappings);
          HashMap newIdmapHM = new HashMap();
          fIdMaps.put(newIdMap.getName(), newIdmapHM);
          Vector Mappings = idmap.getMappings();
          for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
            Mapping mapping = (Mapping) enumeration.nextElement();
            Mapping newMapping =
                new Mapping(mapping.getElement(), mapping.getSignature(), mapping.getIdAttribute());
            newMappings.add(newMapping);
            newIdmapHM.put(newMapping.getKey(), newMapping.getIdAttribute());
          }
          // copy over ordered entries
          ArrayList orderedAL = idmap.getOrdered();
          if (orderedAL != null && orderedAL.size() > 0) {
            ArrayList newOrderedAL = new ArrayList();
            newIdMap.setOrdered(newOrderedAL);
            ArrayList idmapOrdered = new ArrayList();
            fOrderedElements.put(newIdMap.getName(), idmapOrdered);
            for (Iterator iter = orderedAL.iterator(); iter.hasNext(); ) {
              Mapping ordered = (Mapping) iter.next();
              Mapping newOrdered = new Mapping(ordered.getElement(), ordered.getSignature());
              newOrderedAL.add(newOrdered);
              idmapOrdered.add(newOrdered.getKey());
            }
          }

          newIdMapsTableItem(newIdMap, true);
          selectionChanged();
        }
      }
    }
  }