|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2004, 2024 IBM Corporation and others. |
| 2 | + * Copyright (c) 2004, 2025 IBM Corporation and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made available under the
|
5 | 5 | * terms of the Eclipse Public License 2.0 which is available at
|
|
15 | 15 | import java.beans.PropertyChangeSupport;
|
16 | 16 | import java.util.ArrayList;
|
17 | 17 | import java.util.List;
|
| 18 | +import java.util.function.BiConsumer; |
| 19 | +import java.util.function.Function; |
18 | 20 |
|
19 | 21 | import org.eclipse.swt.SWT;
|
20 | 22 | import org.eclipse.swt.accessibility.ACC;
|
|
52 | 54 | import org.eclipse.jface.action.IAction;
|
53 | 55 | import org.eclipse.jface.action.IContributionItem;
|
54 | 56 | import org.eclipse.jface.action.MenuManager;
|
| 57 | +import org.eclipse.jface.preference.IPreferenceStore; |
55 | 58 | import org.eclipse.jface.resource.ImageDescriptor;
|
56 | 59 | import org.eclipse.jface.resource.JFaceResources;
|
57 | 60 | import org.eclipse.jface.util.IPropertyChangeListener;
|
@@ -264,10 +267,25 @@ private Control createFlyoutControlButton(Composite parent) {
|
264 | 267 | * @param prefs {@link Plugin#getPluginPreferences() a plugin's Preferences}
|
265 | 268 | * @return a default implementation of FlyoutPreferences that stores the
|
266 | 269 | * settings in the given Preferences
|
| 270 | + * @deprecated Use {@link #createFlyoutPreferences(IPreferenceStore)} instead. |
| 271 | + * This method will be removed after the 2027-06 release. |
267 | 272 | * @since 3.2
|
268 | 273 | */
|
| 274 | + @Deprecated(forRemoval = true, since = "3.22.0") |
269 | 275 | public static FlyoutPreferences createFlyoutPreferences(Preferences prefs) {
|
270 |
| - return new DefaultFlyoutPreferences(prefs); |
| 276 | + return new DefaultFlyoutPreferences(prefs::getInt, prefs::setValue); |
| 277 | + } |
| 278 | + |
| 279 | + /** |
| 280 | + * This is a convenient method to get a default FlyoutPreferences object. |
| 281 | + * |
| 282 | + * @param prefs an {@link IPreferenceStore} |
| 283 | + * @return a default implementation of FlyoutPreferences that stores the |
| 284 | + * settings in the given Preferences |
| 285 | + * @since 3.22 |
| 286 | + */ |
| 287 | + public static FlyoutPreferences createFlyoutPreferences(IPreferenceStore prefs) { |
| 288 | + return new DefaultFlyoutPreferences(prefs::getInt, prefs::setValue); |
271 | 289 | }
|
272 | 290 |
|
273 | 291 | private Composite createPaletteContainer() {
|
@@ -1505,40 +1523,42 @@ private static class DefaultFlyoutPreferences implements FlyoutPreferences {
|
1505 | 1523 | private static final String PALETTE_SIZE = "org.eclipse.gef.psize"; //$NON-NLS-1$
|
1506 | 1524 | private static final String PALETTE_STATE = "org.eclipse.gef.pstate"; //$NON-NLS-1$
|
1507 | 1525 |
|
1508 |
| - private final Preferences prefs; |
| 1526 | + private final Function<String, Integer> getter; |
| 1527 | + private final BiConsumer<String, Integer> setter; |
1509 | 1528 |
|
1510 |
| - private DefaultFlyoutPreferences(Preferences preferences) { |
1511 |
| - prefs = preferences; |
| 1529 | + private DefaultFlyoutPreferences(Function<String, Integer> getter, BiConsumer<String, Integer> setter) { |
| 1530 | + this.getter = getter; |
| 1531 | + this.setter = setter; |
1512 | 1532 | }
|
1513 | 1533 |
|
1514 | 1534 | @Override
|
1515 | 1535 | public int getDockLocation() {
|
1516 |
| - return prefs.getInt(PALETTE_DOCK_LOCATION); |
| 1536 | + return getter.apply(PALETTE_DOCK_LOCATION); |
1517 | 1537 | }
|
1518 | 1538 |
|
1519 | 1539 | @Override
|
1520 | 1540 | public int getPaletteState() {
|
1521 |
| - return prefs.getInt(PALETTE_STATE); |
| 1541 | + return getter.apply(PALETTE_STATE); |
1522 | 1542 | }
|
1523 | 1543 |
|
1524 | 1544 | @Override
|
1525 | 1545 | public int getPaletteWidth() {
|
1526 |
| - return prefs.getInt(PALETTE_SIZE); |
| 1546 | + return getter.apply(PALETTE_SIZE); |
1527 | 1547 | }
|
1528 | 1548 |
|
1529 | 1549 | @Override
|
1530 | 1550 | public void setDockLocation(int location) {
|
1531 |
| - prefs.setValue(PALETTE_DOCK_LOCATION, location); |
| 1551 | + setter.accept(PALETTE_DOCK_LOCATION, location); |
1532 | 1552 | }
|
1533 | 1553 |
|
1534 | 1554 | @Override
|
1535 | 1555 | public void setPaletteState(int state) {
|
1536 |
| - prefs.setValue(PALETTE_STATE, state); |
| 1556 | + setter.accept(PALETTE_STATE, state); |
1537 | 1557 | }
|
1538 | 1558 |
|
1539 | 1559 | @Override
|
1540 | 1560 | public void setPaletteWidth(int width) {
|
1541 |
| - prefs.setValue(PALETTE_SIZE, width); |
| 1561 | + setter.accept(PALETTE_SIZE, width); |
1542 | 1562 | }
|
1543 | 1563 | }
|
1544 | 1564 |
|
|
0 commit comments