Skip to content
75 changes: 75 additions & 0 deletions .github/workflows/m3-jface-selection-source-20261022.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* IBM Corporation - initial API and implementation
* Sebastian Davids - bug 69254
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 430873
* Hitesh Soliwal (Synexia) - clear absent selections without overwriting callbacks
*******************************************************************************/

package org.eclipse.jface.viewers;
Expand Down Expand Up @@ -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);
Expand All @@ -224,7 +229,6 @@ protected void listSetSelection(int[] ixs) {
protected void listDeselectAll() {
if (combo == null) {
ccombo.deselectAll();
ccombo.clearSelection();
} else {
combo.deselectAll();
combo.clearSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <code>reveal</code> is
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -2134,6 +2224,9 @@ protected final void updateItem(Widget widget, Object element) {
* the selection, or <code>null</code> if none
*/
protected void updateSelection(ISelection selection) {
if (m3PreservingSelection && inChange) {
return;
}
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
fireSelectionChanged(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,9 +33,10 @@
* <ul>
* <li>{@link #apply} applies a delta now, on the UI thread, with consecutive
* operations of one kind batched into one viewer call;</li>
* <li>{@link #post} queues a delta from any thread. Deltas posted in a burst
* are merged and applied once, after {@code delayMillis} without a newer post
* (superseding-generation debounce), and at the latest after four delays;</li>
* <li>{@link #post(StructuredViewer, M3ViewerDelta, int)} queues a delta from any
* thread. Deltas posted in a burst are merged and applied once, after
* {@code delayMillis} without a newer post
* (rescheduled debounce), and at the latest after four initial delays;</li>
* <li>{@link #flush} applies a queued delta at once. The viewers call it
* before every {@code refresh}, so a refresh never runs ahead of queued
* deltas.</li>
Expand All @@ -60,7 +63,8 @@ private M3Viewers() {

/**
* Applies {@code delta} to {@code viewer} now. Must run on the viewer's UI
* thread.
* thread. ComboViewer UPDATE runs preserve their logical selection, including
* explicit selection requests made by callbacks.
*
* @param viewer the viewer
* @param delta the delta; it is not changed
Expand Down Expand Up @@ -90,6 +94,37 @@ public static void apply(StructuredViewer viewer, M3ViewerDelta delta) {
}
}

/**
* Applies {@code delta} now, preserving the viewer's selection across the
* complete sequence. A selected element may be removed and reinserted by the
* patch without exposing an intermediate selection change. An explicit
* selection set by a callback takes precedence over restoring the old one.
* Nested calls join the current selection boundary.
* <p>
* Checkbox viewers use their existing check-state preservation, including
* the authority of an installed check-state provider. This method does not
* save or restore a tree's expansion state. Exceptions propagate as for
* {@link #apply}; a partially applied delta is not rolled back.
* </p>
* <p>
* Must run on the viewer's UI thread. This entry point preserves selection
* across the complete delta. Ordinary {@link #apply} and
* {@link #post(StructuredViewer, M3ViewerDelta, int)} preserve ComboViewer
* selection within each UPDATE run.
* </p>
*
* @param viewer the viewer
* @param delta the delta; it is not changed
* @since 3.43 (M3 enhanced API)
*/
public static void applyPreservingSelection(StructuredViewer viewer, M3ViewerDelta delta) {
Control control = viewer.getControl();
if (control == null || control.isDisposed() || delta.isEmpty()) {
return;
}
StructuredViewerInternals.preservingSelection(viewer, () -> apply(viewer, delta));
}

/* applies the run of operations starting at i; returns the index after it */
private static int run(StructuredViewer viewer, M3ViewerDelta delta, int i) {
byte kind = delta.kind(i);
Expand Down Expand Up @@ -117,7 +152,13 @@ private static int run(StructuredViewer viewer, M3ViewerDelta delta, int i) {
&& Arrays.equals(delta.properties(end), delta.properties(i))) {
end++;
}
viewer.update(elements(delta, i, end), delta.properties(i));
Object[] updated = elements(delta, i, end);
String[] properties = delta.properties(i);
if (viewer instanceof ComboViewer) {
StructuredViewerInternals.preservingSelection(viewer, () -> viewer.update(updated, properties));
} else {
viewer.update(updated, properties);
}
}
default -> {
if (delta.element(i) == null) {
Expand Down
Loading
Loading