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
    }
  }
 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
   }
 }
  /** Updates the state (enabled, not enabled) of the buttons */
  private void updateEnabledState() {
    TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
    if (itemsIdMaps.length > 0) {
      IdMap idmap = (IdMap) itemsIdMaps[0].getData();
      if (idmap.isInternal()) {
        fRenameIdMapButton.setEnabled(false);
        fRemoveIdMapButton.setEnabled(false);
        fEditIdMapButton.setEnabled(true);

        fNewMappingsButton.setEnabled(false);
        fEditMappingsButton.setEnabled(false);
        fRemoveMappingsButton.setEnabled(false);

        fNewOrderedButton.setEnabled(false);
        fEditOrderedButton.setEnabled(false);
        fRemoveOrderedButton.setEnabled(false);
      } else {
        fRenameIdMapButton.setEnabled(true);
        fRemoveIdMapButton.setEnabled(true);
        fEditIdMapButton.setEnabled(false);

        fNewMappingsButton.setEnabled(true);
        fEditMappingsButton.setEnabled(true);
        fRemoveMappingsButton.setEnabled(true);

        fNewOrderedButton.setEnabled(true);
        fEditOrderedButton.setEnabled(true);
        fRemoveOrderedButton.setEnabled(true);
      }
    }
  }
 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 updateRemoveButtons(boolean updateRemove, boolean updateRemoveAll) {
   TablePart tablePart = getTablePart();
   Table table = tablePart.getTableViewer().getTable();
   TableItem[] tableSelection = table.getSelection();
   if (updateRemove) {
     ISelection selection = getViewerSelection();
     tablePart.setButtonEnabled(
         3,
         isEditable()
             && !selection.isEmpty()
             && selection instanceof IStructuredSelection
             && ((IStructuredSelection) selection).getFirstElement() instanceof IProductPlugin);
   }
   int count = fPluginTable.getTable().getItemCount();
   if (updateRemoveAll) tablePart.setButtonEnabled(4, isEditable() && count > 0);
   tablePart.setButtonEnabled(2, isEditable() && count > 0);
   tablePart.setButtonEnabled(5, isEditable() && tableSelection.length == 1);
 }
  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();
        }
      }
    }
  }
 protected void selectionChanged() {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     // Refresh Mappings Table
     fMappingsTable.removeAll();
     Vector Mappings = ((IdMap) items[0].getData()).getMappings();
     for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
       newMappingsTableItem((Mapping) enumeration.nextElement(), false);
     }
     // Refresh Ordered Table
     fOrderedTable.removeAll();
     ArrayList Ordered = ((IdMap) items[0].getData()).getOrdered();
     if (Ordered != null) {
       for (Iterator iter_ordered = Ordered.iterator(); iter_ordered.hasNext(); ) {
         newOrderedTableItem((Mapping) iter_ordered.next(), false);
       }
     }
   }
   updateEnabledState();
 }
 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 renameIdMap(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   if (itemsIdMaps.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     String old_name = idmap.getName();
     String old_extension = idmap.getExtension();
     HashMap idmapHS = (HashMap) fIdMaps.get(old_name);
     XMLCompareAddIdMapDialog dialog =
         new XMLCompareAddIdMapDialog(
             shell, idmap, fIdMaps, fIdMapsInternal, fIdExtensionToName, true);
     if (dialog.open() == Window.OK) {
       fIdMaps.remove(old_name);
       fIdExtensionToName.remove(old_extension);
       fIdMaps.put(idmap.getName(), idmapHS);
       if (!idmap.getExtension().equals("")) // $NON-NLS-1$
       fIdExtensionToName.put(idmap.getExtension(), idmap.getName());
       fIdMapsTable.remove(fIdMapsTable.indexOf(itemsIdMaps[0]));
       newIdMapsTableItem(idmap, true);
     }
   }
 }
 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 removeIdMap(Shell shell) {
   TableItem[] itemsIdMap = fIdMapsTable.getSelection();
   if (itemsIdMap.length > 0) {
     //			fIdMaps.remove(itemsIdMap[0].getText());
     String IdMapName = ((IdMap) itemsIdMap[0].getData()).getName();
     fIdMaps.remove(IdMapName);
     fOrderedElements.remove(IdMapName);
     // All the corresponding ID Mappings must be removed as well
     TableItem[] itemsMappings = fMappingsTable.getItems();
     for (int i = 0; i < itemsMappings.length; i++) {
       itemsMappings[i].dispose();
     }
     // All the corresponding Ordered entries must be removed as well
     TableItem[] itemsOrdered = fOrderedTable.getItems();
     for (int i = 0; i < itemsOrdered.length; i++) {
       itemsOrdered[i].dispose();
     }
     // Remove extension
     if (!itemsIdMap[0].getText(2).equals("")) { // $NON-NLS-1$
       fIdExtensionToName.remove(itemsIdMap[0].getText(2));
     }
     itemsIdMap[0].dispose(); // Table is single selection
   }
 }