use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class RepositoriesView method createCommonViewer.
@Override
protected CommonViewer createCommonViewer(Composite aParent) {
CommonViewer viewer = super.createCommonViewer(aParent);
// handle the double-click event for tags and branches
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
TreeSelection sel = (TreeSelection) event.getSelection();
RepositoryTreeNode element = (RepositoryTreeNode) sel.getFirstElement();
// Disable checkout for bare repositories
if (element.getRepository().isBare()) {
return;
}
if (element instanceof RefNode) {
executeOpenCommandWithConfirmation(element, ((RefNode) element).getObject().getName());
} else if (element instanceof TagNode) {
executeOpenCommandWithConfirmation(element, ((TagNode) element).getObject().getName());
}
}
});
// handle open event for the working directory
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
TreeSelection sel = (TreeSelection) event.getSelection();
RepositoryTreeNode element = (RepositoryTreeNode) sel.getFirstElement();
if (element instanceof FileNode || element instanceof StashedCommitNode)
executeOpenCommand(element);
}
});
// react on selection changes
ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
srv.addPostSelectionListener(selectionChangedListener);
// react on changes in the configured repositories
repositoryUtil.getPreferences().addPreferenceChangeListener(configurationListener);
initRepositoriesAndListeners();
activateContextService();
emptyArea.setBackground(viewer.getControl().getBackground());
if (!repositories.isEmpty())
layout.topControl = viewer.getControl();
else
layout.topControl = emptyArea;
return viewer;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class AbstractBranchSelectionDialog method createDialogArea.
@Override
protected final Composite createDialogArea(Composite base) {
Composite parent = (Composite) super.createDialogArea(base);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
int selectionModel = -1;
if ((settings & ALLOW_MULTISELECTION) != 0)
selectionModel = SWT.MULTI;
else
selectionModel = SWT.SINGLE;
FilteredTree tree = new FilteredTree(composite, selectionModel | SWT.BORDER, new PatternFilter(), true);
branchTree = tree.getViewer();
branchTree.setUseHashlookup(true);
branchTree.setLabelProvider(new RepositoriesViewStyledCellLabelProvider());
branchTree.setContentProvider(new RepositoriesViewContentProvider());
ColumnViewerToolTipSupport.enableFor(branchTree);
GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
branchTree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String refName = refNameFromDialog();
refNameSelected(refName);
}
});
// double-click support
branchTree.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
RepositoryTreeNode node = (RepositoryTreeNode) ((IStructuredSelection) branchTree.getSelection()).getFirstElement();
if (node == null)
return;
final RepositoryTreeNodeType type = node.getType();
if (type != RepositoryTreeNodeType.REF && type != RepositoryTreeNodeType.TAG && type != RepositoryTreeNodeType.ADDITIONALREF)
branchTree.setExpandedState(node, !branchTree.getExpandedState(node));
else if (isOkButtonEnabled())
buttonPressed(OK);
}
});
branchTree.setComparator(new ViewerComparator(STRING_ASCENDING_COMPARATOR));
createCustomArea(composite);
setTitle(getTitle());
setMessage(getMessageText());
getShell().setText(getWindowTitle());
applyDialogFont(composite);
return composite;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class AbstractBranchSelectionDialog method refFromDialog.
/**
* @return the selected {@link Ref} from the tree, may be null
*/
protected Ref refFromDialog() {
IStructuredSelection sel = (IStructuredSelection) branchTree.getSelection();
if (sel.size() != 1)
return null;
RepositoryTreeNode node = (RepositoryTreeNode) sel.getFirstElement();
if (node.getType() == RepositoryTreeNodeType.REF || node.getType() == RepositoryTreeNodeType.TAG)
return ((Ref) node.getObject());
return null;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class AbstractBranchSelectionDialog method markRef.
/**
* Set the selection to a {@link Ref} if possible
*
* @param refName
* the name of the {@link Ref}
* @return <code>true</code> if the {@link Ref} with the given name was
* found
*/
protected boolean markRef(String refName) {
// selects the entry specified by the name
if (refName == null)
return false;
RepositoryTreeNode node;
try {
if (refName.startsWith(Constants.R_HEADS)) {
Ref ref = repo.exactRef(refName);
if (ref == null)
return false;
node = createRefNode(localBranches, repo, ref);
} else if (refName.startsWith(Constants.R_REMOTES)) {
Ref ref = repo.exactRef(refName);
if (ref == null)
return false;
node = createRefNode(remoteBranches, repo, ref);
} else if (Constants.HEAD.equals(refName)) {
Ref ref = repo.exactRef(refName);
if (ref == null)
return false;
node = new AdditionalRefNode(references, repo, ref);
} else {
String mappedRef = Activator.getDefault().getRepositoryUtil().mapCommitToRef(repo, refName, false);
if (mappedRef != null && mappedRef.startsWith(Constants.R_REMOTES)) {
Ref ref = repo.exactRef(mappedRef);
if (ref == null)
return false;
node = createRefNode(remoteBranches, repo, ref);
} else if (mappedRef != null && mappedRef.startsWith(Constants.R_TAGS)) {
Ref ref = repo.exactRef(mappedRef);
if (ref == null)
return false;
node = new TagNode(tags, repo, ref);
} else
return false;
}
} catch (IOException e) {
return false;
}
branchTree.setSelection(new StructuredSelection(node), true);
return true;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.
the class GitAdapterFactory method getAdapter.
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
return GitHistoryPageSource.INSTANCE;
}
if (IWorkbenchAdapter.class == adapterType) {
// property page names for git repository tree nodes
if (adaptableObject instanceof RepositoryTreeNode) {
return getRepositoryTreeNodeWorkbenchAdapter((RepositoryTreeNode) adaptableObject);
}
if (gitModelWorkbenchAdapter == null) {
gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
}
return gitModelWorkbenchAdapter;
}
if (adaptableObject instanceof IHistoryView && IShowInSource.class == adapterType) {
IHistoryView historyView = (IHistoryView) adaptableObject;
IHistoryPage historyPage = historyView.getHistoryPage();
if (historyPage instanceof GitHistoryPage) {
return historyPage;
}
}
if (adaptableObject instanceof IURIEditorInput && adapterType == Repository.class) {
return getRepository((IURIEditorInput) adaptableObject);
}
if (adaptableObject instanceof IURIEditorInput && adapterType == File.class) {
return getFile((IURIEditorInput) adaptableObject);
}
if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class) {
return GitObjectMapping.create((GitModelObject) adaptableObject);
}
if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
GitModelObject obj = (GitModelObject) adaptableObject;
if (obj instanceof GitModelBlob) {
IResource res = ResourceUtil.getFileForLocation(obj.getLocation(), false);
if (res == null) {
// Deleted resource?
res = getWorkspaceResourceFromGitPath(obj.getLocation());
}
return res;
}
if (obj instanceof GitModelTree) {
IResource res = root.getContainerForLocation(obj.getLocation());
if (res == null) {
res = root.getFolder(obj.getLocation());
}
return res;
}
}
if (adapterType == Repository.class) {
ResourceMapping m = AdapterUtils.adapt(adaptableObject, ResourceMapping.class);
if (m != null) {
return SelectionUtils.getRepository(new StructuredSelection(m));
}
}
return null;
}
Aggregations