@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.getUserIdentifier().compareToIgnoreCase(right.getUserIdentifier()); } return result; }
@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; }
private CabalImplementation findImplementation(final String ident) { CabalImplementation retval = null; for (CabalImplementation impl : impls) { if (impl.getUserIdentifier().equals(ident)) { retval = impl; break; } } return retval; }
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); } } }
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; }
/** 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; }
private boolean validateImpl(final CabalImplementation impl) { return (impl != null) && CabalImplementationManager.isUniqueUserIdentifier(impl.getUserIdentifier(), impls); }