use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitSynchronizeWizard method getSelectedResources.
private Set<IResource> getSelectedResources(Repository repo) {
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Set<IResource> result = new HashSet<>();
IStructuredSelection sel = (IStructuredSelection) selection;
if (sel.size() == 0)
return null;
File workTree = repo.getWorkTree();
for (Object o : sel.toArray()) {
if (o == null) {
continue;
}
IResource res = AdapterUtils.adaptToAnyResource(o);
if (res == null) {
continue;
}
int type = res.getType();
if (type == IResource.FOLDER) {
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping == null) {
continue;
}
Repository selRepo = mapping.getRepository();
if (workTree.equals(selRepo.getWorkTree()))
result.add(res);
}
}
return result;
}
return null;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitSynchronizeWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
for (IProject project : ROOT.getProjects()) {
RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
if (repositoryMapping == null)
continue;
Repository repo = repositoryMapping.getRepository();
Set<IProject> projects = resources.get(repo);
if (projects == null) {
projects = new HashSet<>();
resources.put(repo, projects);
}
projects.add(project);
}
treeViewer = new TreeViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
treeViewer.getTree().setLinesVisible(true);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TreeViewerColumn projectsColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
projectsColumn.getColumn().setText(UIText.GitBranchSynchronizeWizardPage_repository);
projectsColumn.getColumn().setImage(repositoryImage);
projectsColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Repository) {
Repository repo = (Repository) element;
// $NON-NLS-1$
String descr = "";
try {
// $NON-NLS-1$ //$NON-NLS-2$
descr += " [" + repo.getBranch() + "]";
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
}
Color decorationsColor = JFaceResources.getColorRegistry().get(JFacePreferences.DECORATIONS_COLOR);
String repoName = repo.getWorkTree().getName();
int repoNameLen = repoName.length();
StyleRange styleRange = new StyleRange(repoNameLen, repoNameLen + descr.length(), decorationsColor, null);
cell.setImage(repositoryImage);
cell.setText(repoName + descr);
cell.setStyleRanges(new StyleRange[] { styleRange });
}
super.update(cell);
}
});
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<>(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
protected boolean canEdit(Object element) {
return true;
}
});
dstColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String branch = selectedBranches.get(element);
// $NON-NLS-1$
return branch == null ? "" : branch;
}
});
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// nothing to do
}
@Override
public void dispose() {
// nothing to do
}
@Override
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
});
List<Repository> repositoriesList = new ArrayList<>(resources.keySet());
Collections.sort(repositoriesList, new Comparator<Repository>() {
@Override
public int compare(Repository o1, Repository o2) {
String name1 = o1.getWorkTree().getName();
String name2 = o2.getWorkTree().getName();
return name1.compareToIgnoreCase(name2);
}
});
treeViewer.setInput(repositoriesList.toArray(new Repository[repositoriesList.size()]));
projectsColumn.getColumn().pack();
Composite buttonsComposite = new Composite(composite, SWT.NONE);
layout = new GridLayout(4, false);
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
buttonsComposite.setLayout(layout);
buttonsComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
final Button fetchChanges = new Button(buttonsComposite, SWT.CHECK);
fetchChanges.setText(UIText.GitBranchSynchronizeWizardPage_fetchChangesFromRemote);
fetchChanges.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
forceFetch = fetchChanges.getSelection();
}
});
fetchChanges.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
fetchChanges.setSelection(Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.SYNC_VIEW_FETCH_BEFORE_LAUNCH));
final Button includeLocal = new Button(buttonsComposite, SWT.CHECK);
includeLocal.setText(UIText.GitBranchSynchronizeWizardPage_includeUncommitedChanges);
includeLocal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
shouldIncludeLocal = includeLocal.getSelection();
}
});
includeLocal.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Dialog.applyDialogFont(composite);
setPageComplete(false);
setControl(composite);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitOpenInCompareAction method getCachedFileElement.
private ITypedElement getCachedFileElement(GitModelBlob blob) {
try {
IPath location = blob.getLocation();
RepositoryMapping mapping = RepositoryMapping.getMapping(location);
if (mapping == null) {
return null;
}
Repository repo = mapping.getRepository();
String repoRelativePath = mapping.getRepoRelativePath(location);
return CompareUtils.getIndexTypedElement(repo, repoRelativePath);
} catch (IOException e) {
return null;
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class LocalNonWorkspaceTypedElement method fireChanges.
private void fireChanges() {
fireContentChanged();
// external file change must be reported explicitly, see bug 481682
Repository myRepository = repository;
boolean updated = false;
if (!myRepository.isBare()) {
updated = refreshRepositoryState(myRepository);
}
if (!updated) {
RepositoryMapping mapping = RepositoryMapping.getMapping(path);
if (mapping != null) {
mapping.getRepository().fireEvent(new IndexChangedEvent());
}
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitVariableResolver method getGitDir.
private String getGitDir(String argument) throws CoreException {
IResource res = getResource(argument);
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping != null)
return mapping.getRepository().getDirectory().getAbsolutePath();
else
// $NON-NLS-1$
return "";
}
Aggregations