Exemple #1
0
  public static void sortTable(Table table, Comparator<TableItem> comparator) {
    int columnCount = table.getColumnCount();
    String[] values = new String[columnCount];
    TableItem[] items = table.getItems();
    for (int i = 1; i < items.length; i++) {
      for (int j = 0; j < i; j++) {
        TableItem item = items[i];
        if (comparator.compare(item, items[j]) < 0) {
          for (int k = 0; k < columnCount; k++) {
            values[k] = item.getText(k);
          }
          Object data = item.getData();
          boolean checked = item.getChecked();
          item.dispose();

          item = new TableItem(table, SWT.NONE, j);
          item.setText(values);
          item.setData(data);
          item.setChecked(checked);
          items = table.getItems();
          break;
        }
      }
    }
  }
  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
   }
 }
  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;
  }
  /** 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);
      }
    }
  }
  @Override
  public void modelChanged(IModelChangedEvent event) {
    if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      fHeader = null;
      markStale();
      return;
    }

    if (getExportedPackageHeader().equals(event.getChangedProperty())) {
      refresh();
      // Bug 171896
      // Since the model sends a CHANGE event instead of
      // an INSERT event on the very first addition to the empty table
      // Selection should fire here to take this first insertion into account
      Object lastElement =
          fPackageViewer.getElementAt(fPackageViewer.getTable().getItemCount() - 1);
      if (lastElement != null) {
        fPackageViewer.setSelection(new StructuredSelection(lastElement));
      }

      return;
    }

    Object[] objects = event.getChangedObjects();
    for (Object changedObject : objects) {
      if (changedObject instanceof ExportPackageObject) {
        ExportPackageObject object = (ExportPackageObject) changedObject;
        switch (event.getChangeType()) {
          case IModelChangedEvent.INSERT:
            fPackageViewer.add(object);
            fPackageViewer.setSelection(new StructuredSelection(object), false);
            fPackageViewer.getTable().setFocus();
            break;
          case IModelChangedEvent.REMOVE:
            Table table = fPackageViewer.getTable();
            int index = table.getSelectionIndex();
            fPackageViewer.remove(object);
            table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
            break;
          default:
            fPackageViewer.refresh(object);
        }
      }
    }
  }
 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);
 }
Exemple #8
0
 public static TableItem getNextTableItem(Table table, TableItem item) {
   TableItem[] items = table.getItems();
   for (int i = 0; i < items.length - 1; i++) {
     if (items[i] == item) {
       return items[i + 1];
     }
   }
   return null;
 }
 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);
     }
   }
 }
  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;
  }
 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 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);
     }
   }
 }
 protected TableItem newIdMapsTableItem(IdMap idmap, boolean selected) {
   // find index where to insert table entry
   TableItem[] items = fIdMapsTable.getItems();
   int i = 0;
   while (i < items.length && idmap.getName().compareToIgnoreCase(items[i].getText(0)) > 0) i++;
   TableItem item = new TableItem(fIdMapsTable, SWT.NULL, i);
   String[] values =
       new String[] {
         idmap.getName(),
         (idmap.isInternal())
             ? XMLCompareMessages.XMLComparePreference_topTableColumn2internal
             : XMLCompareMessages.XMLComparePreference_topTableColumn2user,
         idmap.getExtension()
       };
   item.setText(values);
   item.setData(idmap);
   if (selected) {
     fIdMapsTable.setSelection(i);
     fIdMapsTable.setFocus();
     selectionChanged();
   }
   return item;
 }
  /* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
   */
  public void modelChanged(IModelChangedEvent e) {
    // No need to call super, handling world changed event here
    if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      handleModelEventWorldChanged(e);
      return;
    }
    Object[] objects = e.getChangedObjects();
    if (e.getChangeType() == IModelChangedEvent.INSERT) {
      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.add(objects[i]);
      }
    } else if (e.getChangeType() == IModelChangedEvent.REMOVE) {

      Table table = fPluginTable.getTable();
      int index = table.getSelectionIndex();

      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.remove(objects[i]);
      }

      // Update Selection

      int count = table.getItemCount();

      if (count == 0) {
        // Nothing to select
      } else if (index < count) {
        table.setSelection(index);
      } else {
        table.setSelection(count - 1);
      }

    } else if (e.getChangeType() == IModelChangedEvent.CHANGE) {
      fPluginTable.refresh();
    }
    updateRemoveButtons(false, true);
  }
 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
   }
 }
Exemple #17
0
 public static void maxTableColumnsWidth(Table table) {
   table.setRedraw(false);
   try {
     int columnCount = table.getColumnCount();
     if (columnCount > 0) {
       int totalWidth = 0;
       final TableColumn[] columns = table.getColumns();
       for (TableColumn tc : columns) {
         tc.pack();
         totalWidth += tc.getWidth();
       }
       final Rectangle clientArea = table.getClientArea();
       if (totalWidth < clientArea.width) {
         int extraSpace = clientArea.width - totalWidth;
         extraSpace /= columnCount;
         for (TableColumn tc : columns) {
           tc.setWidth(tc.getWidth() + extraSpace);
         }
       }
     }
   } finally {
     table.setRedraw(true);
   }
 }
  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();
        }
      }
    }
  }
 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);
       }
     }
   }
 }
Exemple #20
0
  public static void packColumns(Table table, boolean fit) {
    table.setRedraw(false);
    try {
      int totalWidth = 0;
      final TableColumn[] columns = table.getColumns();
      for (TableColumn column : columns) {
        column.pack();
        totalWidth += column.getWidth();
      }
      final Rectangle clientArea = table.getClientArea();
      if (clientArea.width > 0 && totalWidth > clientArea.width) {
        for (TableColumn column : columns) {
          int colWidth = column.getWidth();
          if (colWidth > totalWidth / 3) {
            // If some columns is too big (more than 33% of total width)
            // Then shrink it to 30%
            column.setWidth(totalWidth / 3);
            totalWidth -= colWidth;
            totalWidth += column.getWidth();
          }
        }
        int extraSpace = totalWidth - clientArea.width;

        for (TableColumn tc : columns) {
          double ratio = (double) tc.getWidth() / totalWidth;
          int newWidth = (int) (tc.getWidth() - extraSpace * ratio);
          tc.setWidth(newWidth);
        }
      }
      if (fit && totalWidth < clientArea.width) {
        int sbWidth = 0;
        if (table.getVerticalBar() != null) {
          sbWidth = table.getVerticalBar().getSize().x;
        }
        if (columns.length > 0) {
          float extraSpace = (clientArea.width - totalWidth - sbWidth) / columns.length;
          for (TableColumn tc : columns) {
            tc.setWidth((int) (tc.getWidth() + extraSpace));
          }
        }
      }
    } finally {
      table.setRedraw(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);
       }
     }
   }
 }
  /** @see PreferencePage#createContents(Composite) */
  protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);

    // layout the top table & its buttons
    Label label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_topTableLabel);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fIdMapsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fIdMapsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fIdMapsTable.getItemHeight() * 4;
    fIdMapsTable.setLayoutData(data);
    fIdMapsTable.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            selectionChanged();
          }
        });

    String column2Text = XMLCompareMessages.XMLComparePreference_topTableColumn2;
    String column3Text = XMLCompareMessages.XMLComparePreference_topTableColumn3;
    ColumnLayoutData columnLayouts[] = {
      new ColumnWeightData(1),
      new ColumnPixelData(convertWidthInCharsToPixels(column2Text.length() + 2), true),
      new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 5), true)
    };
    TableLayout tablelayout = new TableLayout();
    fIdMapsTable.setLayout(tablelayout);
    for (int i = 0; i < 3; i++) tablelayout.addColumnData(columnLayouts[i]);
    TableColumn column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_topTableColumn1);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column2Text);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column3Text);

    fillIdMapsTable();

    Composite buttons = new Composite(parent, SWT.NULL);
    buttons.setLayout(new GridLayout());
    data = new GridData();
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    buttons.setLayoutData(data);

    fAddIdMapButton = new Button(buttons, SWT.PUSH);
    fAddIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topAdd);
    fAddIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addIdMap(fAddIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fAddIdMapButton.setLayoutData(data);

    fRenameIdMapButton = new Button(buttons, SWT.PUSH);
    fRenameIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRename);
    fRenameIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            renameIdMap(fRenameIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRenameIdMapButton.setLayoutData(data);

    fRemoveIdMapButton = new Button(buttons, SWT.PUSH);
    fRemoveIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRemove);
    fRemoveIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeIdMap(fRemoveIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fRemoveIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRemoveIdMapButton.setLayoutData(data);

    createSpacer(buttons);

    fEditIdMapButton = new Button(buttons, SWT.PUSH);
    fEditIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topEdit);
    fEditIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editIdMap(fEditIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fEditIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fEditIdMapButton.setLayoutData(data);

    // Spacer
    label = new Label(parent, SWT.LEFT);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    // layout the middle table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_middleTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fMappingsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fMappingsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fMappingsTable.getItemHeight() * 4;
    data.widthHint = convertWidthInCharsToPixels(70);
    fMappingsTable.setLayoutData(data);

    column3Text = XMLCompareMessages.XMLComparePreference_middleTableColumn3;
    String column4Text = XMLCompareMessages.XMLComparePreference_middleTableColumn4;
    columnLayouts =
        new ColumnLayoutData[] {
          new ColumnWeightData(10),
          new ColumnWeightData(18),
          new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 1), true),
          new ColumnPixelData(convertWidthInCharsToPixels(column4Text.length() + 3), true)
        };
    tablelayout = new TableLayout();
    fMappingsTable.setLayout(tablelayout);
    for (int i = 0; i < 4; i++) tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn1);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn2);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column3Text);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column4Text);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewMappingsButton = new Button(buttons, SWT.PUSH);
    fNewMappingsButton.setLayoutData(getButtonGridData(fNewMappingsButton));
    fNewMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleNew);
    fNewMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addMapping(fAddIdMapButton.getShell());
          }
        });

    fEditMappingsButton = new Button(buttons, SWT.PUSH);
    fEditMappingsButton.setLayoutData(getButtonGridData(fEditMappingsButton));
    fEditMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleEdit);
    fEditMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editMapping(fEditMappingsButton.getShell());
          }
        });

    fRemoveMappingsButton = new Button(buttons, SWT.PUSH);
    fRemoveMappingsButton.setLayoutData(getButtonGridData(fRemoveMappingsButton));
    fRemoveMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleRemove);
    fRemoveMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeMapping(fRemoveMappingsButton.getShell());
          }
        });

    createSpacer(buttons);

    // layout the botton table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_bottomTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fOrderedTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fOrderedTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fOrderedTable.getItemHeight() * 2;
    data.widthHint = convertWidthInCharsToPixels(70);
    fOrderedTable.setLayoutData(data);

    columnLayouts = new ColumnLayoutData[] {new ColumnWeightData(1), new ColumnWeightData(1)};
    tablelayout = new TableLayout();
    fOrderedTable.setLayout(tablelayout);
    for (int i = 0; i < 2; i++) tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn1);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn2);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewOrderedButton = new Button(buttons, SWT.PUSH);
    fNewOrderedButton.setLayoutData(getButtonGridData(fNewOrderedButton));
    fNewOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomNew);
    fNewOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addOrdered(fNewOrderedButton.getShell());
          }
        });

    fEditOrderedButton = new Button(buttons, SWT.PUSH);
    fEditOrderedButton.setLayoutData(getButtonGridData(fEditOrderedButton));
    fEditOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomEdit);
    fEditOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editOrdered(fEditOrderedButton.getShell());
          }
        });

    fRemoveOrderedButton = new Button(buttons, SWT.PUSH);
    fRemoveOrderedButton.setLayoutData(getButtonGridData(fRemoveOrderedButton));
    fRemoveOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomRemove);
    fRemoveOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeOrdered(fRemoveOrderedButton.getShell());
          }
        });

    createSpacer(buttons);

    fIdMapsTable.setSelection(0);
    fIdMapsTable.setFocus();
    selectionChanged();

    return parent;
  }
  @Override
  public void createPartControl(Composite parent) {
    final IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbar = actionBars.getToolBarManager();
    mSymbolEntryText = new TextContributionItem(""); // $NON-NLS-1$
    toolbar.add(mSymbolEntryText);
    toolbar.add(new AddSymbolAction(mSymbolEntryText, this));

    final Table table =
        new Table(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.BORDER);
    table.setHeaderVisible(true);
    mViewer = new TableViewer(table);
    GridDataFactory.defaultsFor(table).applyTo(table);

    final MarketDataItemComparator comparator = new MarketDataItemComparator();
    mViewer.setComparator(comparator);

    SelectionListener listener =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            // determine new sort column and direction
            TableColumn sortColumn = table.getSortColumn();
            TableColumn currentColumn = (TableColumn) e.widget;
            final int index = table.indexOf(currentColumn);
            int dir = table.getSortDirection();
            if (sortColumn == currentColumn) {
              dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
            } else {
              table.setSortColumn(currentColumn);
              dir = SWT.UP;
            }
            table.setSortDirection(dir);
            comparator.setSort(dir == SWT.UP ? 1 : -1);
            comparator.setIndex(index);
            mViewer.refresh();
          }
        };

    // create columns, using FIXFieldLocalizer to preserve backwards
    // compatibility
    TableViewerColumn symbolColumn =
        new TableViewerColumn(
            mViewer,
            createColumn(
                table,
                FIXFieldLocalizer.getLocalizedFIXFieldName(Symbol.class.getSimpleName()),
                SWT.LEFT,
                listener));
    symbolColumn.setEditingSupport(new SymbolEditingSupport());
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(LastPx.class.getSimpleName()),
        SWT.RIGHT,
        listener);
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(LastQty.class.getSimpleName()),
        SWT.RIGHT,
        listener);
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(BidSize.class.getSimpleName()),
        SWT.RIGHT,
        listener);
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(BidPx.class.getSimpleName()),
        SWT.RIGHT,
        listener);
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(OfferPx.class.getSimpleName()),
        SWT.RIGHT,
        listener);
    createColumn(
        table,
        FIXFieldLocalizer.getLocalizedFIXFieldName(OfferSize.class.getSimpleName()),
        SWT.RIGHT,
        listener);

    // restore table state if it exists
    if (mViewState != null) {
      ColumnState.restore(table, mViewState);
      for (TableColumn column : table.getColumns()) {
        if (column.getWidth() == 0) {
          column.setResizable(false);
        }
      }
    }

    registerContextMenu();
    getSite().setSelectionProvider(mViewer);

    ObservableListContentProvider content = new ObservableListContentProvider();
    mViewer.setContentProvider(content);
    IObservableSet domain = content.getKnownElements();
    IObservableMap[] maps =
        new IObservableMap[] {
          BeansObservables.observeMap(domain, MarketDataViewItem.class, "symbol"), // $NON-NLS-1$
          createCompositeMap(
              domain, "latestTick", MDPackage.Literals.MD_LATEST_TICK__PRICE), // $NON-NLS-1$
          createCompositeMap(
              domain, "latestTick", MDPackage.Literals.MD_LATEST_TICK__SIZE), // $NON-NLS-1$
          createCompositeMap(
              domain, "topOfBook", MDPackage.Literals.MD_TOP_OF_BOOK__BID_SIZE), // $NON-NLS-1$
          createCompositeMap(
              domain, "topOfBook", MDPackage.Literals.MD_TOP_OF_BOOK__BID_PRICE), // $NON-NLS-1$
          createCompositeMap(
              domain, "topOfBook", MDPackage.Literals.MD_TOP_OF_BOOK__ASK_PRICE), // $NON-NLS-1$
          createCompositeMap(
              domain, "topOfBook", MDPackage.Literals.MD_TOP_OF_BOOK__ASK_SIZE) // $NON-NLS-1$
        };
    mViewer.setLabelProvider(new ObservableMapLabelProvider(maps));
    mViewer.setUseHashlookup(true);
    mItems = WritableList.withElementType(MarketDataViewItem.class);
    mViewer.setInput(mItems);
  }