示例#1
0
    @Override
    public String getColumnText(final Object elem, final int columnIndex) {
      String result = null;
      if (elem instanceof CabalImplementation) {
        CabalImplementation impl = (CabalImplementation) elem;
        switch (columnIndex) {
          case 0:
            {
              result = impl.getUserIdentifier();
              break;
            }
          case 1:
            result = impl.getInstallVersion();
            break;
          case 2:
            result = impl.getLibraryVersion();
            break;
          case 3:
            {
              result = impl.getCabalExecutableName().toOSString();
              break;
            }
        }
      } else {
        result = elem.toString();
      }

      return result;
    }
示例#2
0
 private void update(final String identifier, final CabalImplementation theImpl) {
   CabalImplementation impl = findImplementation(identifier);
   if (impl != null) {
     // Update the fields.
     impl.copy(theImpl);
   }
 }
示例#3
0
 @Override
 public int compare(final Viewer viewer, final Object e1, final Object e2) {
   int result = super.compare(viewer, e1, e2);
   if ((e1 instanceof CabalImplementation) && (e2 instanceof CabalImplementation)) {
     CabalImplementation left = (CabalImplementation) e1;
     CabalImplementation right = (CabalImplementation) e2;
     result = left.getLibraryVersion().compareToIgnoreCase(right.getLibraryVersion());
   }
   return result;
 }
示例#4
0
 private CabalImplementation findImplementation(final String ident) {
   CabalImplementation retval = null;
   for (CabalImplementation impl : impls) {
     if (impl.getUserIdentifier().equals(ident)) {
       retval = impl;
       break;
     }
   }
   return retval;
 }
示例#5
0
  Composite createControl(final Composite parent, final PreferencePage prefParent) {
    Composite composite = new Composite(parent, SWT.NONE);
    Font parentFont = parent.getFont();

    GridLayout glayout = new GridLayout(2, false);
    glayout.marginHeight = 0;
    glayout.marginWidth = 0;
    composite.setLayout(glayout);
    composite.setFont(parentFont);

    Label tableLabel = new Label(composite, SWT.NONE);
    tableLabel.setText(UITexts.cabalImplsBlock_installed);
    GridData gdata = new GridData(SWT.FILL, SWT.TOP, true, false);
    gdata.horizontalSpan = 2;
    tableLabel.setLayoutData(gdata);
    tableLabel.setFont(parentFont);

    Composite tableComposite = new Composite(composite, SWT.NONE);
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    table = SWTUtil.createTable(tableComposite);
    createColumns(tableComposite);
    createViewer();

    // Deep copy the implementations, replace them later.
    CabalImplementationManager cMgr = CabalImplementationManager.getInstance();
    impls.clear();
    for (CabalImplementation impl : cMgr.getCabalImplementations()) {
      impls.add(new CabalImplementation(impl));
    }

    viewer.setInput(impls);

    // And set the current default (checked) implementation
    CabalImplementation defImpl = cMgr.getDefaultCabalImplementation();
    if (defImpl != null) {
      CabalImplementation impl = findImplementation(defImpl.getUserIdentifier());
      setCheckedCabalImplementation(impl);
    }

    Composite buttonsComp = new Composite(composite, SWT.NONE);

    glayout = new GridLayout(1, true);
    glayout.marginHeight = 0;
    glayout.marginWidth = 0;
    buttonsComp.setLayout(glayout);
    buttonsComp.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
    buttonsComp.setFont(parentFont);
    createButtons(buttonsComp);
    enableButtons();

    return composite;
  }
示例#6
0
 @Override
 public int compare(final Viewer viewer, final Object e1, final Object e2) {
   int result = super.compare(viewer, e1, e2);
   if ((e1 instanceof CabalImplementation) && (e2 instanceof CabalImplementation)) {
     CabalImplementation left = (CabalImplementation) e1;
     CabalImplementation right = (CabalImplementation) e2;
     String pathLeft = left.getCabalExecutableName().toOSString();
     String pathRight = right.getCabalExecutableName().toOSString();
     result = pathLeft.compareToIgnoreCase(pathRight);
   }
   return result;
 }
示例#7
0
  /** Put the Cabal implementation preferences into the preference store. */
  public boolean updateCabalImplementations() {
    CabalImplementationManager cMgr = CabalImplementationManager.getInstance();
    Object[] selected = viewer.getCheckedElements();
    CabalImplementation impl = (CabalImplementation) selected[0];
    String defaultImplIdent = new String();
    if (impl != null) {
      defaultImplIdent = impl.getUserIdentifier();
    }

    cMgr.setCabalImplementations(impls, defaultImplIdent);
    return true;
  }
示例#8
0
 private void editCabalImplementation() {
   IStructuredSelection prev = (IStructuredSelection) getSelection();
   int selected = table.getSelectionIndex();
   if (selected >= 0) {
     CabalImplementation impl = impls.get(selected);
     String implIdent = impl.getUserIdentifier();
     CabalImplementationDialog dialog = new CabalImplementationDialog(table.getShell(), impl);
     dialog.setTitle(UITexts.cabalImplsBlock_dlgEdit);
     if (dialog.open() == Window.OK) {
       CabalImplementation updatedImpl = dialog.getResult();
       if (validateImpl(updatedImpl)) {
         update(implIdent, updatedImpl);
         setCheckedCabalImplementation(updatedImpl.getUserIdentifier());
         viewer.setInput(impl);
       }
       viewer.refresh();
       autoSelectSingle(prev);
     }
   }
 }
示例#9
0
 private boolean validateImpl(final CabalImplementation impl) {
   return (impl != null)
       && CabalImplementationManager.isUniqueUserIdentifier(impl.getUserIdentifier(), impls);
 }