diff --git a/.github/workflows/m3-jface-selection-source-20261022.yml b/.github/workflows/m3-jface-selection-source-20261022.yml new file mode 100644 index 00000000000..5aefa0e5e01 --- /dev/null +++ b/.github/workflows/m3-jface-selection-source-20261022.yml @@ -0,0 +1,75 @@ +# SPDX-FileCopyrightText: 2026 Hitesh Soliwal and Contributors to the Synexia Project +# SPDX-License-Identifier: Apache-2.0 +name: M3 JFace Selection Source and Model Gate +on: + push: + branches: + - codex/eclipse-jface-selection-on-36-20261022 + paths: + - 'bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/**' + - 'tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/**' + - '.github/workflows/m3-jface-selection-source-20261022.yml' + pull_request: + branches: + - codex/eclipse-jface-best-merged-20261022 + paths: + - 'bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/**' + - 'tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/**' + - '.github/workflows/m3-jface-selection-source-20261022.yml' +permissions: + contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + source-and-model: + name: Verify exact JFace atoms plus pinned Java21 model (not native SWT) + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Checkout the exact Eclipse PR head + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Setup Java21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + - name: Verify all source-sealed JFace postimages and original fast lanes + shell: bash + run: | + set -euo pipefail + cat <<'M3_POSTIMAGES' | sha256sum --check --status + b6ca713a0c886912fe38247206e38a2e423caf32bb5ff843764ea93de9c792af bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java + 62a94bdf7717b59a10bd341ebae84b3a57149d1792af19ac7755f2538c23d830 bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewerInternals.java + 615b01136455c2202fd0cc2fd3ef551c7968902ca3919f23fefcb9dc1c9f3a0b bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java + 2ee741c25d27fb3b04bedafd6ad7c9ba08efff865c3b749b883a6466d534437a bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java + ba85eecc3c7f91bcdb7df8249e009390771bb9b6f68572402d0e411a2fea968a tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDifferential.java + c998c56be9bc6033057df3a62e65874cdbaacd6e6bbb0c45820c8e6acf74008e tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3SelectionReceiverTest.java + M3_POSTIMAGES + observed=$(git hash-object bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewerDelta.java) + test "$observed" = 'b68f93b3854e49ad0571905ad274823c9c502bae' + grep -q 'public static void applyPreservingSelection' bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java + - name: Checkout the pinned canonical Synexia recipe and isolated oracle + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + repository: hsoliwal/com.synexia + ref: 48fde6ad83d5889126aa3570deaa247801b95c8e + path: canonical + persist-credentials: false + - name: Refuse queue loss and execute strict Java21 selection model + shell: bash + run: | + set -euo pipefail + python3 - <<'PY' + from pathlib import Path + prefix = 'bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java' + post = Path(prefix).read_bytes() + donor = Path('canonical/synexia-openrewrite-recipes/src/main/resources/com/synexia/rewrite/hash-pinned-java/m3-eclipse-selection-m3viewers-20261022/pre/postimage.java.txt').read_bytes() + marker = b'\tprivate static final class Queue {' + assert marker in post and marker in donor + assert post[post.index(marker):] == donor[donor.index(marker):], 'M3 queue contract was overwritten' + print('PASS: original M3 five-lane append and owner queue preserved') + PY + bash canonical/synexia-openrewrite-recipes/recipe-crates/m3-eclipse-jface-selection-20261022/evidence/model/verify-isolated.sh diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java index 3769dbbe51e..b3712effc5e 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java @@ -12,6 +12,7 @@ * IBM Corporation - initial API and implementation * Sebastian Davids - bug 69254 * Lars Vogel - Bug 430873 + * Hitesh Soliwal (Synexia) - clear absent selections without overwriting callbacks *******************************************************************************/ package org.eclipse.jface.viewers; @@ -209,6 +210,10 @@ public void reveal(Object element) { @Override protected void listSetSelection(int[] ixs) { + if (ixs.length == 0) { + listDeselectAll(); + return; + } if (combo == null) { for (int ix : ixs) { ccombo.select(ix); @@ -224,7 +229,6 @@ protected void listSetSelection(int[] ixs) { protected void listDeselectAll() { if (combo == null) { ccombo.deselectAll(); - ccombo.clearSelection(); } else { combo.deselectAll(); combo.clearSelection(); diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java index 043068ed885..48afb6ae826 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java @@ -103,6 +103,16 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel */ private boolean inChange; + /** True only while an M3 caller requests selection preservation. */ + private boolean m3PreservingSelection; + + /** The active M3 owner, distinct from calls made by its final listeners. */ + private boolean m3SelectionActive; + + private boolean m3SelectionRequested; + private ISelection m3RequestedSelection; + private boolean m3RequestedReveal; + /** * Used while a selection change is in progress on this viewer to indicates * whether the selection should be restored. @@ -816,6 +826,9 @@ public void run() { * @see #addPostSelectionChangedListener(ISelectionChangedListener) */ protected void firePostSelectionChanged(final SelectionChangedEvent event) { + if (m3PreservingSelection && inChange) { + return; + } for (ISelectionChangedListener l : postSelectionChangedListeners) { SafeRunnable.run(new SafeRunnable() { @Override @@ -1358,6 +1371,74 @@ protected void preservingSelection(Runnable updateCode) { preservingSelection(updateCode, false); } + /* Reuse virtual preservation, including subclass check-state ownership. */ + void m3PreservingSelection(Runnable updateCode) { + if (!getPreserveSelection()) { + updateCode.run(); + return; + } + boolean previous = m3PreservingSelection; + m3PreservingSelection = true; + try { + preservingSelection(updateCode); + } finally { + m3PreservingSelection = previous; + } + } + + private void preservingM3Selection(Runnable updateCode, boolean reveal) { + if (m3SelectionActive) { + updateCode.run(); + return; + } + if (!preserveSelection) { + return; + } + boolean previousInChange = inChange; + boolean previousRestoreSelection = restoreSelection; + boolean previousRequested = m3SelectionRequested; + ISelection previousSelection = m3RequestedSelection; + boolean previousReveal = m3RequestedReveal; + ISelection oldSelection = getSelection(); + m3SelectionActive = true; + m3SelectionRequested = false; + m3RequestedSelection = null; + m3RequestedReveal = false; + try { + inChange = restoreSelection = true; + updateCode.run(); + } finally { + try { + Control control = getControl(); + if (control != null && !control.isDisposed() && (m3SelectionRequested || restoreSelection)) { + ISelection selection = m3SelectionRequested ? m3RequestedSelection : oldSelection; + boolean restoreReveal = m3SelectionRequested ? m3RequestedReveal : reveal; + ISelection currentSelection = getSelection(); + boolean unchanged = selection == null ? currentSelection.isEmpty() : currentSelection.equals(selection); + if (restoreReveal || !unchanged) { + setSelectionToWidget(selection, restoreReveal); + } + } + } finally { + // Native restoration may call setSelection again through Modify. + // Its request wins, without replaying restoration in a loop. + inChange = previousInChange; + restoreSelection = previousRestoreSelection && restoreSelection; + m3SelectionActive = false; + m3SelectionRequested = previousRequested; + m3RequestedSelection = previousSelection; + m3RequestedReveal = previousReveal; + } + Control control = getControl(); + if (!previousInChange && control != null && !control.isDisposed()) { + ISelection newSelection = getSelection(); + if (!newSelection.equals(oldSelection)) { + handleInvalidSelection(oldSelection, newSelection); + } + } + } + } + /** * Attempts to preserves the current selection across a run of the given * code, with a best effort to avoid scrolling if reveal is @@ -1383,6 +1464,10 @@ protected void preservingSelection(Runnable updateCode) { * @since 3.3 */ void preservingSelection(Runnable updateCode, boolean reveal) { + if (m3PreservingSelection) { + preservingM3Selection(updateCode, reveal); + return; + } if (!preserveSelection) { return; } @@ -1674,6 +1759,11 @@ public void setSelection(ISelection selection, boolean reveal) { firePostSelectionChanged(new SelectionChangedEvent(this, sel)); } else { restoreSelection = false; + if (m3SelectionActive) { + m3SelectionRequested = true; + m3RequestedSelection = selection; + m3RequestedReveal = reveal; + } setSelectionToWidget(selection, reveal); } } @@ -2134,6 +2224,9 @@ protected final void updateItem(Widget widget, Object element) { * the selection, or null if none */ protected void updateSelection(ISelection selection) { + if (m3PreservingSelection && inChange) { + return; + } SelectionChangedEvent event = new SelectionChangedEvent(this, selection); fireSelectionChanged(event); } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewerInternals.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewerInternals.java index b99249fe3d6..1553e02186a 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewerInternals.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewerInternals.java @@ -92,4 +92,17 @@ protected static Widget[] getItems(StructuredViewer viewer, Object element) { return viewer.findItems(element); } + /** + * Internal access for the explicit M3 delta selection boundary. The viewer + * remains the owner of selection and subclass check-state preservation. + * + * @param viewer the viewer + * @param updateCode the synchronous update + * @since 3.43 + */ + @NoReference + public static void preservingSelection(StructuredViewer viewer, Runnable updateCode) { + viewer.m3PreservingSelection(updateCode); + } + } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java index d38f0bc33eb..fcadd56125b 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java @@ -21,7 +21,9 @@ import org.eclipse.jface.viewers.AbstractListViewer; import org.eclipse.jface.viewers.AbstractTableViewer; import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.StructuredViewerInternals; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -31,9 +33,10 @@ *