Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2016 IBM Corporation and others.
* Copyright (c) 2003, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -39,7 +39,9 @@
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.DataFormatException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
Expand Down Expand Up @@ -78,6 +80,8 @@
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -614,11 +618,17 @@ public Color getBackground(Object element) {
private Button goToDefaultButton;

/**
* The button to expand the tree.
*
* @since 4.5
* The toolitem to expand the tree.
*/
private Button expandAllButton;
private ToolItem expandAllItem;

/**
* The toolitem to collapse the tree.
*/
private ToolItem collapseAllItem;

private Image expandImage;
private Image collapseImage;

/**
* Map of definition FontDefinition->FontData[] capturing the changes explicitly
Expand Down Expand Up @@ -829,43 +839,70 @@ protected Control createContents(Composite parent) {
if (appliedDialogFont != null) {
appliedDialogFont.dispose();
}
// Dispose custom images
if (expandImage != null) {
expandImage.dispose();
}
if (collapseImage != null) {
collapseImage.dispose();
}
});

final SashForm advancedComposite = new SashForm(parent, SWT.VERTICAL);
GridData sashData = new GridData(SWT.FILL, SWT.FILL, true, true);
advancedComposite.setLayoutData(sashData);
advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite mainColumn = new Composite(advancedComposite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
GridLayout layout = new GridLayout(2, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're inlining, which is fine, but as a reviewer it's not easy to see that this is identical. I trust that it is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling that out. Yes, this is functionally identical - new GridLayout(2, false) is equivalent to setting numColumns = 2 with the default makeColumnsEqualWidth = false.

I agree that the previous form may be easier to compare in a diff. I can revert to the expanded version if you prefer for readability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's more an observation. I like it simpler the way you wrote it! I trust that you are properly testing all the layout and appearance that the simpler expression produces good behavior.

layout.marginWidth = 0;
layout.marginHeight = 0;
mainColumn.setFont(parent.getFont());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? This might have an impact that I don't notice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — thanks for calling that out.

This line was removed during layout refactoring, but it’s not strictly required since SWT controls inherit the parent font by default.

That said, I agree that keeping it makes the intent explicit and avoids any platform-specific inconsistencies. Shall i restore it to be safe and keep behavior identical to the original implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better safe than sorry I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

mainColumn.setLayout(layout);

GridData data = new GridData(GridData.BEGINNING);
data.horizontalSpan = 2;
Label label = new Label(mainColumn, SWT.LEFT);
label.setText(RESOURCE_BUNDLE.getString("colorsAndFonts")); //$NON-NLS-1$
myApplyDialogFont(label);
label.setLayoutData(data);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));

createTree(mainColumn);
// LEFT COLUMN (tree + filter)
Composite leftColumn = new Composite(mainColumn, SWT.NONE);
leftColumn.setLayout(new GridLayout(1, false));
leftColumn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

// --- buttons
Composite controlColumn = new Composite(mainColumn, SWT.NONE);
data = new GridData(GridData.FILL_VERTICAL);
controlColumn.setLayoutData(data);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
controlColumn.setLayout(layout);
createTree(leftColumn);

// we need placeholder to offset the filter control of the table
Label placeholder = new Label(controlColumn, SWT.NONE);
GridData placeholderData = new GridData(SWT.TOP);
placeholderData.heightHint = convertVerticalDLUsToPixels(12);
placeholder.setLayoutData(placeholderData);
// RIGHT COLUMN (toolbar + buttons)
Composite controlColumn = new Composite(mainColumn, SWT.NONE);
controlColumn.setLayout(new GridLayout());
controlColumn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));

// Toolbar at TOP (aligned with filter text)
ToolBar treeToolbar = new ToolBar(controlColumn, SWT.FLAT);
treeToolbar.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, false));

// LOAD IMAGES ONCE
ImageDescriptor expandDesc = ResourceLocator
.imageDescriptorFromBundle("org.eclipse.ui", "icons/full/elcl16/expandall.svg") //$NON-NLS-1$ //$NON-NLS-2$
.orElse(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were to fail, the button will be useless (horribly ugly) won't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

		ImageDescriptor collapseDesc = ResourceLocator
				.imageDescriptorFromBundle("org.eclipse.ui", "icons/full/elcl16/collapseall.svg") //$NON-NLS-1$ //$NON-NLS-2$
			.orElse(null);

		collapseAllItem = new ToolItem(treeToolbar, SWT.PUSH);

		if (collapseDesc != null) {
			collapseImage = collapseDesc.createImage();
			collapseAllItem.setImage(collapseImage);
		} else {
			// Fallback to shared image
			collapseAllItem.setImage(
				PlatformUI.getWorkbench().getSharedImages()
					.getImage(org.eclipse.ui.ISharedImages.IMG_ELCL_COLLAPSEALL));
		}

		collapseAllItem.setToolTipText("Collapse All"); //$NON-NLS-1$

Thought of this way. But in the similar lines, icon for Expand All is not readily available in org.eclipse.ui.ISharedImages, how should this be handled in your opinion? can i use org.eclipse.ui.ISharedImages.IMG_ELCL_COLLAPSEALL or IMG_ELCL_REMOVE?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the past the tendency was to ensure that the icon was available locally in the bundle rather than to use fragile programmatic access.

Let's ask @HeikoKlare @BeckerWdf how one can best do something here that's not fragile.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could simply copy the PNG files into the bundle.
Alternatively add "Expand All" as org.eclipse.ui.ISharedImages as API and use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, let me correct my update and put it across again in some time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the insights @BeckerWdf and @merks
I tried exploring that way too but was unsure how to achieve it correct and complete.

My findings are : icons/images are already existing in below paths.

  1. ..\git\eclipse.platform.ui\bundles\org.eclipse.ui.ide\icons\full\elcl16 but here expandall.svg/png are not available.
  2. ..\git\eclipse.platform.ui\bundles\org.eclipse.ui.editors\icons\full\elcl16 has both.
  3. ..\git\eclipse.platform.ui\bundles\org.eclipse.ui\icons\full\elcl16 has both.
  4. ..\git\eclipse.platform.ui\bundles\org.eclipse.ui.navigator\icons\full\elcl16 but here expandall.svg/ png are not available.

So for this pr the respective java file is at "..\git\eclipse.platform.ui\bundles\org.eclipse.ui.workbench\eclipseui\org\eclipse\ui\internal\themes\ColorsAndFontsPreferencePage.java"

Option 1 - Add respective expandall, collapseall icons svg/png at freshly created path for this plugin "..\git\eclipse.platform.ui\bundles\org.eclipse.ui.workbench\icons\full\elcl16" and use like below

ImageDescriptor expandDesc = AbstractUIPlugin.imageDescriptorFromPlugin(
"org.eclipse.ui.workbench",
"icons/full/elcl16/expandall.svg"
);

expandImage = expandDesc.createImage();
expandAllItem.setImage(expandImage);

Option 2 - For API way, if i add "icons/full/elcl16/expandall.svg" corresponding entries(inline with collapseall.svg which is already accessible) in ISharedImages.java and WorkbenchImages.java. Are these the only 2 steps i need to perform or do i have to add anything else which i might have missed.

Another observation as well.
I also see entries in plugin.xml at "..\git\eclipse.platform.ui\bundles\org.eclipse.ui" as below

      <image
            commandId="org.eclipse.ui.navigate.collapseAll"
            icon="$nl$/icons/full/elcl16/collapseall.svg">
      </image>
      <image
            commandId="org.eclipse.ui.navigate.expandAll"
            icon="$nl$/icons/full/elcl16/expandall.svg">
      </image>

So anything in similar lines needs to be done? But I do understand these are used by the command framework and are not directly applicable for ToolItem usage but better to do, so that it is available as a generic solution if anywhere else - it can also be used(since collapseall is already available but not expandall)
Please let me know if my understanding is correct. Thanks in advance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the only steps i need to perform or do i have to add anywhere else which i missed.

I think yes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expand-all and collapse-all I think are heavily reused so it would seem a good thing for them to be shared across those usages, e.g.,

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep this as a generic one for everyone to use -> #3981

if (expandDesc != null) {
expandImage = expandDesc.createImage();
}
expandAllItem = new ToolItem(treeToolbar, SWT.PUSH);
if (expandImage != null) {
expandAllItem.setImage(expandImage);
}
expandAllItem.setToolTipText("Expand All"); //$NON-NLS-1$

ImageDescriptor collapseDesc = ResourceLocator
.imageDescriptorFromBundle("org.eclipse.ui", "icons/full/elcl16/collapseall.svg") //$NON-NLS-1$ //$NON-NLS-2$
.orElse(null);
if (collapseDesc != null) {
collapseImage = collapseDesc.createImage();
}
collapseAllItem = new ToolItem(treeToolbar, SWT.PUSH);
if (collapseImage != null) {
collapseAllItem.setImage(collapseImage);
}
collapseAllItem.setToolTipText("Collapse All"); //$NON-NLS-1$

fontChangeButton = createButton(controlColumn, RESOURCE_BUNDLE.getString("openChange")); //$NON-NLS-1$
fontSystemButton = createButton(controlColumn, WorkbenchMessages.FontsPreference_useSystemFont);
Expand All @@ -874,41 +911,28 @@ protected Control createContents(Composite parent) {
editDefaultButton = createButton(controlColumn, RESOURCE_BUNDLE.getString("editDefault")); //$NON-NLS-1$
goToDefaultButton = createButton(controlColumn, RESOURCE_BUNDLE.getString("goToDefault")); //$NON-NLS-1$
createSeparator(controlColumn);
expandAllButton = createButton(controlColumn, RESOURCE_BUNDLE.getString("expandAll")); //$NON-NLS-1$
expandAllButton.setEnabled(true);
// --- end of buttons
// end of buttons

createDescriptionControl(mainColumn);

Composite previewColumn = new Composite(advancedComposite, SWT.NONE);
GridLayout previewLayout = new GridLayout();
previewLayout.marginTop = 7;
previewLayout.marginWidth = 0;
previewLayout.marginHeight = 0;
previewColumn.setFont(parent.getFont());
previewColumn.setLayout(previewLayout);

// --- create preview control
Composite composite = new Composite(previewColumn, SWT.NONE);
previewColumn.setLayout(new GridLayout());
previewColumn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

GridData data2 = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(data2);
GridLayout layout2 = new GridLayout(1, true);
layout2.marginHeight = 0;
layout2.marginWidth = 0;
composite.setLayout(layout2);
// create preview control
Composite composite = new Composite(previewColumn, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Label label2 = new Label(composite, SWT.LEFT);
label2.setText(RESOURCE_BUNDLE.getString("preview")); //$NON-NLS-1$
myApplyDialogFont(label2);

previewComposite = new Composite(composite, SWT.NONE);
previewComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
previewComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
stackLayout = new StackLayout();
stackLayout.marginHeight = 0;
stackLayout.marginWidth = 0;
previewComposite.setLayout(stackLayout);
// -- end of preview control
// end of preview control

defaultFontPreview = createFontPreviewControl();
defaultColorPreview = createColorPreviewControl();
Expand Down Expand Up @@ -972,9 +996,10 @@ private String getText(Object element) {
};
filter.setIncludeLeadingWildcard(true);

tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, filter, true);
tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, filter, true, true);
tree.setQuickSelectionMode(true);
GridData data = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_FILL);

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = Math.max(285, convertWidthInCharsToPixels(30));
data.heightHint = Math.max(175, convertHeightInCharsToPixels(10));
tree.setLayoutData(data);
Expand All @@ -989,10 +1014,7 @@ private String getText(Object element) {
tree.getViewer().setComparator(new ViewerComparator() {
@Override
public int category(Object element) {
if (element instanceof ThemeElementCategory) {
return 0;
}
return 1;
return (element instanceof ThemeElementCategory) ? 0 : 1;
}
});
tree.getViewer().setInput(WorkbenchPlugin.getDefault().getThemeRegistry());
Expand Down Expand Up @@ -1261,9 +1283,8 @@ private void hookListeners() {
}
updateControls();
}));

expandAllButton.addSelectionListener(widgetSelectedAdapter(event -> tree.getViewer().expandAll()));

expandAllItem.addListener(SWT.Selection, e -> tree.getViewer().expandAll());
collapseAllItem.addListener(SWT.Selection, e -> tree.getViewer().collapseAll());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2003, 2014, 2015 IBM Corporation and others.
# Copyright (c) 2003, 2014, 2015, 2026 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,7 +17,9 @@ openChange=&Edit...
reset=&Reset
editDefault=Ed&it Default...
goToDefault=&Go to Default
expandAll=E&xpand All
#expandAll=E&xpand All
expandAll=Expand All
collapseAll=Collapse All
value=&Value
colorsAndFonts=Colors and &Fonts (font, size, type, ? = any character, * = any string) :
description=Descriptio&n:
Expand Down
Loading