use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider in project xtext-eclipse by eclipse.
the class XtextEObjectSearchDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite container) {
Composite parent = (Composite) super.createDialogArea(container);
if (enableStyledLabels && labelProvider instanceof IStyledLabelProvider) {
final Table table = getTableViewer().getTable();
final IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) labelProvider;
TableOwnerDrawSupport.install(table);
Listener listener = new Listener() {
@Override
public void handleEvent(Event event) {
handleSetData(event);
}
protected void handleSetData(Event event) {
TableItem item = (TableItem) event.item;
IEObjectDescription description = (IEObjectDescription) item.getData();
if (description != null) {
StyledString styledString = styledLabelProvider.getStyledText(description);
String displayString = styledString.toString();
StyleRange[] styleRanges = styledString.getStyleRanges();
item.setText(displayString);
TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
}
}
};
table.addListener(SWT.SetData, listener);
}
messageLabel = new Label(parent, SWT.NONE);
setDefaultGridData(messageLabel);
EObjectDescriptionContentProvider contentProvider = new EObjectDescriptionContentProvider();
getTableViewer().setContentProvider(contentProvider);
getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (!structuredSelection.isEmpty()) {
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IEObjectDescription) {
IEObjectDescription eObjectDescription = (IEObjectDescription) firstElement;
URI resourceURI = eObjectDescription.getEObjectURI().trimFragment();
if (resourceURI.isPlatform()) {
messageLabel.setText(resourceURI.toPlatformString(true));
} else if (resourceURI.isFile()) {
messageLabel.setText(resourceURI.toFileString());
} else {
messageLabel.setText(resourceURI.toString());
}
return;
}
}
}
// $NON-NLS-1$
messageLabel.setText("");
}
});
applyFilter();
return parent;
}
use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider in project egit by eclipse.
the class RevertFailureDialog method createCustomArea.
@Override
protected Control createCustomArea(Composite parent) {
if (reasons == null || reasons.isEmpty())
return null;
Composite fileArea = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).applyTo(fileArea);
GridLayoutFactory.fillDefaults().applyTo(fileArea);
TreeViewer viewer = new TreeViewer(fileArea);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
viewer.setContentProvider(new WorkbenchContentProvider() {
@Override
public Object[] getElements(Object element) {
return ((Collection) element).toArray();
}
});
final IStyledLabelProvider styleProvider = new WorkbenchStyledLabelProvider() {
@Override
public StyledString getStyledText(Object element) {
// supported
if (element instanceof RevertFailure)
return ((RevertFailure) element).getStyledText(element);
if (element instanceof Path)
return ((Path) element).getStyledText(element);
return super.getStyledText(element);
}
};
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
viewer.setComparator(new ViewerComparator());
Map<MergeFailureReason, RevertFailure> failures = new HashMap<>();
for (Entry<String, MergeFailureReason> reason : reasons.entrySet()) {
RevertFailure failure = failures.get(reason.getValue());
if (failure == null) {
failure = new RevertFailure(reason.getValue());
failures.put(reason.getValue(), failure);
}
failure.add(reason.getKey());
}
viewer.setInput(failures.values());
return fileArea;
}
use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider in project webtools.sourceediting by eclipse.
the class ConfigurableContentOutlinePage method setConfiguration.
/**
* Configures (or reconfigures) the page according to the given
* configuration.
*
* @param configuration
*/
public void setConfiguration(ContentOutlineConfiguration configuration) {
// intentionally do not check to see if the new configuration != old
// configuration
unconfigure();
fConfiguration = configuration;
if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
// (re)set the providers
ILabelProvider labelProvider = getConfiguration().getLabelProvider(getTreeViewer());
if (labelProvider instanceof IStyledLabelProvider) {
getTreeViewer().setLabelProvider(new DelegatingStyledCellLabelProvider((IStyledLabelProvider) labelProvider));
} else {
getTreeViewer().setLabelProvider(labelProvider);
}
getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));
// view toolbar
IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
if (toolbar != null) {
IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
if (toolbarItems != null) {
for (int i = 0; i < toolbarItems.length; i++) {
toolbar.add(toolbarItems[i]);
}
toolbar.update(true);
}
}
// view menu
IContributionManager menu = getSite().getActionBars().getMenuManager();
if (menu != null) {
IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
if (menuItems != null) {
for (int i = 0; i < menuItems.length; i++) {
menuItems[i].setVisible(true);
menu.add(menuItems[i]);
menuItems[i].update();
}
menu.update(true);
}
}
// add the allowed DnD listeners and types
TransferDragSourceListener[] dragListeners = getConfiguration().getTransferDragSourceListeners(getTreeViewer());
if (fDragAdapter != null && dragListeners.length > 0) {
for (int i = 0; i < dragListeners.length; i++) {
fDragAdapter.addDragSourceListener(dragListeners[i]);
}
fActiveDragListeners = dragListeners;
fDragSource.addDragListener(fDragAdapter);
fDragSource.setTransfer(fDragAdapter.getTransfers());
}
TransferDropTargetListener[] dropListeners = getConfiguration().getTransferDropTargetListeners(getTreeViewer());
if (fDropAdapter != null && dropListeners.length > 0) {
for (int i = 0; i < dropListeners.length; i++) {
fDropAdapter.addDropTargetListener(dropListeners[i]);
}
fActiveDropListeners = dropListeners;
fDropTarget.addDropListener(fDropAdapter);
fDropTarget.setTransfer(fDropAdapter.getTransfers());
}
// add the key listeners
KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
getControl().addKeyListener(listeners[i]);
}
}
}
if (fInput != null) {
setInput(fInput);
}
}
use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider 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;
}
Aggregations