use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider in project egit by eclipse.
the class MergeResultDialog method createDialogArea.
@Override
public Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
// result
Label resultLabel = new Label(composite, SWT.NONE);
resultLabel.setText(UIText.MergeResultDialog_result);
resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text resultText = new Text(composite, SWT.READ_ONLY);
MergeStatus status = mergeResult.getMergeStatus();
resultText.setText(status.toString());
resultText.setSelection(resultText.getCaretPosition());
resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
if (status == MergeStatus.FAILED) {
resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
StringBuilder paths = new StringBuilder();
Label pathsLabel = new Label(composite, SWT.NONE);
pathsLabel.setText(UIText.MergeResultDialog_failed);
pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Text pathsText = new Text(composite, SWT.READ_ONLY);
pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
int n = 0;
for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
if (n > 0)
paths.append(Text.DELIMITER);
paths.append(e.getValue());
// $NON-NLS-1$
paths.append("\t");
paths.append(e.getKey());
n++;
if (n > 10 && failedPaths.size() > 15)
break;
}
if (n < failedPaths.size()) {
paths.append(Text.DELIMITER);
paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
}
pathsText.setText(paths.toString());
}
if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
// new head
Label newHeadLabel = new Label(composite, SWT.NONE);
newHeadLabel.setText(UIText.MergeResultDialog_newHead);
newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text newHeadText = new Text(composite, SWT.READ_ONLY);
ObjectId newHead = mergeResult.getNewHead();
if (newHead != null)
newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
// Merge Input
Label mergeInputLabel = new Label(composite, SWT.NONE);
mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
TableViewer viewer = new TableViewer(composite);
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// empty
}
@Override
public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
// empty
}
@Override
public Object[] getElements(Object inputElement) {
return getCommits(mergeResult.getMergedCommits());
}
});
final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {
private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();
@Override
public void removeListener(ILabelProviderListener listener) {
// Empty
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
wrapped.dispose();
}
@Override
public void addListener(ILabelProviderListener listener) {
// Empty
}
@Override
public StyledString getStyledText(Object element) {
// supported
if (element instanceof RepositoryCommit)
return ((RepositoryCommit) element).getStyledText(element);
return new StyledString(wrapped.getText(element));
}
@Override
public Image getImage(Object element) {
return wrapped.getImage(element);
}
};
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
applyDialogFont(composite);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
viewer.setInput(mergeResult);
new OpenAndLinkWithEditorHelper(viewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection selection, boolean activate) {
handleOpen(selection, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
}
};
return composite;
}
use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider in project egit by eclipse.
the class CommitSearchPage method addRepositoryControl.
private void addRepositoryControl(Composite parent) {
repositoryGroup = new Group(parent, SWT.NONE);
repositoryGroup.setBackgroundMode(SWT.INHERIT_DEFAULT);
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(repositoryGroup);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(repositoryGroup);
this.repositoryViewer = CheckboxTableViewer.newCheckList(repositoryGroup, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
this.repositoryViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new RepositoriesViewLabelProvider()));
this.repositoryViewer.setContentProvider(new RepositoriesViewContentProvider());
this.repositoryViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
this.repositoryViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
updateOKStatus();
repositoryGroup.setText(getRepositoryText());
}
});
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 40).applyTo(this.repositoryViewer.getControl());
ToolBar checkBar = new ToolBar(repositoryGroup, SWT.FLAT | SWT.VERTICAL);
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).grab(false, true).applyTo(checkBar);
ToolItem checkItem = new ToolItem(checkBar, SWT.PUSH);
checkItem.setToolTipText(UIText.CommitSearchPage_CheckAll);
Image checkImage = UIIcons.CHECK_ALL.createImage();
UIUtils.hookDisposal(checkItem, checkImage);
checkItem.setImage(checkImage);
checkItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
repositoryViewer.setAllChecked(true);
repositoryGroup.setText(getRepositoryText());
updateOKStatus();
}
});
ToolItem uncheckItem = new ToolItem(checkBar, SWT.PUSH);
uncheckItem.setToolTipText(UIText.CommitSearchPage_UncheckAll);
Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
UIUtils.hookDisposal(uncheckItem, uncheckImage);
uncheckItem.setImage(uncheckImage);
uncheckItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
repositoryViewer.setAllChecked(false);
repositoryGroup.setText(getRepositoryText());
updateOKStatus();
}
});
this.searchAllBranchesButton = new Button(repositoryGroup, SWT.CHECK);
this.searchAllBranchesButton.setText(UIText.CommitSearchPage_SearchAllBranches);
GridDataFactory.swtDefaults().grab(true, false).span(2, 1).applyTo(this.searchAllBranchesButton);
repositoryGroup.setText(getRepositoryText());
}
use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider in project egit by eclipse.
the class CommitSearchResultsPage method configureViewer.
private void configureViewer(StructuredViewer viewer) {
viewer.setComparator(new CommitSorter());
viewer.setContentProvider(new WorkbenchContentProvider() {
@Override
public Object[] getElements(Object element) {
if (getLayout() == FLAG_LAYOUT_TREE) {
Map<Repository, RepositoryMatch> repos = new HashMap<>();
for (Object inputElement : getInput().getElements()) {
RepositoryCommit commit = (RepositoryCommit) inputElement;
RepositoryMatch match = repos.get(commit.getRepository());
if (match == null) {
match = new RepositoryMatch(commit.getRepository());
repos.put(commit.getRepository(), match);
}
match.addCommit(commit);
}
return repos.values().toArray();
}
return super.getElements(element);
}
});
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new CommitResultLabelProvider(getLayout())));
}
Aggregations