TreeViewerColumn dstColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
dstColumn.getColumn().setText(
UIText.GitBranchSynchronizeWizardPage_destination);
dstColumn.getColumn().setImage(branchImage);
dstColumn.getColumn().setWidth(200);
final ComboBoxCellEditor branchesEditor = new ComboBoxCellEditor(
treeViewer.getTree(), new String[0]);
branchesEditor
.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION
| ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION);
((CCombo) branchesEditor.getControl()).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CCombo combo = (CCombo) e.widget;
TreeSelection sel = (TreeSelection) treeViewer.getSelection();
int selectedIdx = combo.getSelectionIndex();
Repository repo = (Repository) sel.getFirstElement();
if (selectedIdx != -1) {
selectedBranches.put(repo, combo.getItem(selectedIdx));
setPageComplete(true);
} else {
selectedBranches.put(repo, null);
setPageComplete(false);
}
}
});
dstColumn.setEditingSupport(new EditingSupport(treeViewer) {
@Override
protected void setValue(Object element, Object value) {
int intValue = ((Integer) value).intValue();
if (intValue == -1)
return;
CCombo combo = (CCombo) branchesEditor.getControl();
String branch = combo.getItem(intValue);
selectedBranches.put((Repository) element, branch);
treeViewer.refresh(element, true);
validatePage();
}
@Override
protected Object getValue(Object element) {
String branch = selectedBranches.get(element);
CCombo combo = (CCombo) branchesEditor.getControl();
int index = branch == null ? 0 : combo.indexOf(branch);
return Integer.valueOf(index);
}
@Override
protected CellEditor getCellEditor(Object element) {
Repository repo = (Repository) element;
List<String> refs = new LinkedList<String>(repo.getAllRefs()
.keySet());
List<Ref> additionalRefs;
try {
additionalRefs = repo.getRefDatabase().getAdditionalRefs();
} catch (IOException e) {
additionalRefs = null;
}
if (additionalRefs != null)
for (Ref ref : additionalRefs)
refs.add(ref.getName());
Collections.sort(refs, CommonUtils.STRING_ASCENDING_COMPARATOR);
branchesEditor.setItems(refs.toArray(new String[refs.size()]));
return branchesEditor;
}
@Override