Repository navigation
Provide reusable breadcrumb viewer implementations in JFace #4495 #4496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LukasHackl2
wants to merge
1
commit into
eclipse-platform:master
Choose a base branch
from
LukasHackl2:feature/jface-breadcrumb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,649
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
315 changes: 315 additions & 0 deletions
315
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BreadcrumbItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,315 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2008, 2011 IBM Corporation and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| * Fabio Zadrozny - Bug 465666 | ||
| *******************************************************************************/ | ||
| package org.eclipse.jface.viewers; | ||
|
|
||
| import org.eclipse.swt.SWT; | ||
| import org.eclipse.swt.graphics.Color; | ||
| import org.eclipse.swt.graphics.Font; | ||
| import org.eclipse.swt.graphics.Image; | ||
| import org.eclipse.swt.graphics.Rectangle; | ||
| import org.eclipse.swt.layout.GridData; | ||
| import org.eclipse.swt.layout.GridLayout; | ||
| import org.eclipse.swt.widgets.Composite; | ||
| import org.eclipse.swt.widgets.Item; | ||
| import org.eclipse.swt.widgets.Shell; | ||
|
|
||
| /** | ||
| * An item in a breadcrumb viewer. | ||
| * <p> | ||
| * The item shows a label and an image. It also has the ability to expand, that | ||
| * is to open a drop down menu. | ||
| * </p> | ||
| * <p> | ||
| * The drop down allows to select any child of the items input element. The item | ||
| * shows the label and icon of its data element, if any. | ||
| * </p> | ||
| * | ||
| * @since 3.41 | ||
| */ | ||
| class BreadcrumbItem extends Item { | ||
|
|
||
| private final BreadcrumbViewer fParent; | ||
| private Composite fContainer; | ||
|
|
||
| private BreadcrumbItemDetails fDetailsBlock; | ||
| private BreadcrumbItemDropDown fExpandBlock; | ||
| private boolean fIsLast; | ||
|
|
||
| /** | ||
| * A new breadcrumb item which is shown inside the given viewer. | ||
| * | ||
| * @param viewer the items viewer | ||
| * @param parent the container containing the item | ||
| */ | ||
| public BreadcrumbItem(BreadcrumbViewer viewer, Composite parent) { | ||
| super(parent, SWT.NONE); | ||
|
|
||
| fParent = viewer; | ||
|
|
||
| fContainer = new Composite(parent, SWT.NONE); | ||
| fContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); | ||
| GridLayout layout = new GridLayout(2, false); | ||
| layout.marginBottom = 1; | ||
| layout.marginHeight = 0; | ||
| layout.marginWidth = 0; | ||
| layout.horizontalSpacing = 0; | ||
| fContainer.setLayout(layout); | ||
|
|
||
| fDetailsBlock = new BreadcrumbItemDetails(this, fContainer); | ||
|
|
||
| fExpandBlock = new BreadcrumbItemDropDown(this, fContainer); | ||
|
|
||
| fContainer.setData("org.eclipse.e4.ui.css.id", "BreadcrumbItemComposite"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| } | ||
|
|
||
| /** | ||
| * Returns this items viewer. | ||
| * | ||
| * @return the viewer showing this item | ||
| */ | ||
| public BreadcrumbViewer getViewer() { | ||
| return fParent; | ||
| } | ||
|
|
||
| /* | ||
| * @see org.eclipse.swt.widgets.Widget#dispose() | ||
| */ | ||
| @Override | ||
| public void dispose() { | ||
| Shell shell = fExpandBlock.getDropDownShell(); | ||
| if (shell != null && !shell.isDisposed()) { | ||
| shell.dispose(); | ||
| } | ||
| fContainer.dispose(); | ||
|
Copilot marked this conversation as resolved.
Resolved
|
||
| super.dispose(); | ||
| } | ||
|
|
||
| /** | ||
| * Should this item show a text label. | ||
| * | ||
| * @param enabled true if it should | ||
| */ | ||
| void setShowText(boolean enabled) { | ||
| fDetailsBlock.setTextVisible(enabled); | ||
| } | ||
|
|
||
| /** | ||
| * Does this item show a text label? | ||
| * | ||
| * @return true if it does. | ||
| */ | ||
| boolean isShowText() { | ||
| return fDetailsBlock.isTextVisible(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the width of this item. | ||
| * | ||
| * @return the width of this item | ||
| */ | ||
| int getWidth() { | ||
| return fDetailsBlock.getWidth() + fExpandBlock.getWidth() + 2; | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether this item has to be marked as selected or not. | ||
| * | ||
| * @param selected true if marked as selected | ||
| */ | ||
| void setSelected(boolean selected) { | ||
| fDetailsBlock.setSelected(selected); | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether this item has the keyboard focus. | ||
| * | ||
| * @param state <code>true</code> if it has focus, <code>false</code> otherwise | ||
| */ | ||
| void setFocus(boolean state) { | ||
| fDetailsBlock.setFocus(state); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether this item has the keyboard focus. | ||
| * | ||
| * @return <code>true</code> if this item has the keyboard focus | ||
| */ | ||
| boolean hasFocus() { | ||
| return fDetailsBlock.hasFocus(); | ||
| } | ||
|
|
||
| /** | ||
| * Redraws this item using the viewer's current providers. | ||
| */ | ||
| void refresh() { | ||
| IBaseLabelProvider labelProvider = fParent.getLabelProvider(); | ||
|
|
||
| if (labelProvider instanceof CellLabelProvider cellLabelProvider) { | ||
| BreadcrumbViewerRow row = new BreadcrumbViewerRow(fParent, this); | ||
| ViewerCell cell = row.getCell(0); | ||
| cellLabelProvider.update(cell); | ||
| } else { | ||
| ILabelProvider simpleLabelProvider = (ILabelProvider) labelProvider; | ||
| String text = simpleLabelProvider.getText(getData()); | ||
| Image image = simpleLabelProvider.getImage(getData()); | ||
|
|
||
| setText(text); | ||
| setImage(image); | ||
| } | ||
|
|
||
| refreshToolTip(); | ||
| refreshArrow(); | ||
| } | ||
|
|
||
| void refreshToolTip() { | ||
| ILabelProvider toolTipLabelProvider = fParent.getToolTipLabelProvider(); | ||
| if (toolTipLabelProvider != null) { | ||
| fDetailsBlock.setToolTip(toolTipLabelProvider.getText(getData())); | ||
| } else { | ||
| fDetailsBlock.setToolTip(getText()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Refresh the arrows visibility. | ||
| */ | ||
| void refreshArrow() { | ||
| ITreeContentProvider contentProvider = (ITreeContentProvider) fParent.getContentProvider(); | ||
| fExpandBlock.setEnabled(contentProvider.hasChildren(getData())); | ||
| } | ||
|
|
||
| /** | ||
| * Set whether this is the last item in the breadcrumb item chain or not. | ||
| * | ||
| * @param isLast <code>true</code> if this is the last item, <code>false</code> | ||
| * otherwise | ||
| */ | ||
| void setIsLastItem(boolean isLast) { | ||
| fIsLast = isLast; | ||
|
|
||
| GridData data = (GridData) fContainer.getLayoutData(); | ||
| data.grabExcessHorizontalSpace = isLast; | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether or not the this item should show the details (name and label). | ||
| * | ||
| * @param visible true if the item shows details | ||
| */ | ||
| void setDetailsVisible(boolean visible) { | ||
| fDetailsBlock.setVisible(visible); | ||
| } | ||
|
|
||
| /** | ||
| * Expand this item, shows the drop down menu. | ||
| */ | ||
| void openDropDownMenu() { | ||
| fExpandBlock.showMenu(); | ||
| } | ||
|
|
||
| /** | ||
| * @return true if this item is expanded | ||
| */ | ||
| boolean isMenuShown() { | ||
| return fExpandBlock.isMenuShown(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the drop down shell. | ||
| * | ||
| * @return the shell of the drop down if shown, <code>null</code> otherwise | ||
| */ | ||
| Shell getDropDownShell() { | ||
| return fExpandBlock.getDropDownShell(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the drop down selection provider of this item. | ||
| * | ||
| * @return the selection provider of the drop down or <code>null</code> | ||
| */ | ||
| ISelectionProvider getDropDownSelectionProvider() { | ||
| return fExpandBlock.getDropDownSelectionProvider(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the bounds of this item. | ||
| * | ||
| * @return the bounds of this item | ||
| */ | ||
| public Rectangle getBounds() { | ||
| return fContainer.getBounds(); | ||
| } | ||
|
|
||
| /** | ||
| * Set the tool tip of the item to the given text. | ||
| * | ||
| * @param text the tool tip for the item | ||
| */ | ||
| public void setToolTip(String text) { | ||
| fDetailsBlock.setToolTip(text); | ||
| } | ||
|
|
||
| Color getForeground() { | ||
| return fDetailsBlock.getForeground(); | ||
| } | ||
|
|
||
| void setForeground(Color color) { | ||
| fDetailsBlock.setForeground(color); | ||
| } | ||
|
|
||
| Color getBackground() { | ||
| return fDetailsBlock.getBackground(); | ||
| } | ||
|
|
||
| void setBackground(Color color) { | ||
| fDetailsBlock.setBackground(color); | ||
| } | ||
|
|
||
| Font getFont() { | ||
| return fDetailsBlock.getFont(); | ||
| } | ||
|
|
||
| void setFont(Font font) { | ||
| fDetailsBlock.setFont(font); | ||
| } | ||
|
|
||
| /* | ||
| * @see org.eclipse.swt.widgets.Item#setText(java.lang.String) | ||
| */ | ||
| @Override | ||
| public void setText(String string) { | ||
| if (string == null) { | ||
| string = ""; //$NON-NLS-1$ | ||
| } | ||
|
|
||
| super.setText(string); | ||
| fDetailsBlock.setText(string); | ||
|
|
||
| // more or less space might be required for the label | ||
| if (fIsLast) | ||
| fContainer.layout(true, true); | ||
| } | ||
|
|
||
| /* | ||
| * @see org.eclipse.swt.widgets.Item#setImage(org.eclipse.swt.graphics.Image) | ||
| */ | ||
| @Override | ||
| public void setImage(Image image) { | ||
| super.setImage(image); | ||
| fDetailsBlock.setImage(image); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.eclipse.debug.ui also has a class called "BreadcrumbItem". Looks like we already have a copy of the JDT think there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was so nice, we did it twice:
It will be even nicer when we do it only once in a reusable way. 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukasHackl2 : could you please check if you also can provide platform PR and replace classes added in eclipse-platform/eclipse.platform@56f6a79 to use new API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can check this. I see that the Debug UI breadcrumb implementation has diverged somewhat from the JDT version, in particular around the TreePath-based content/label providers and its custom drop-down handling. I’ll check what is needed to adapt it to the new JFace API and provide a corresponding Platform PR if feasible.