Skip to content

Commit

Permalink
Replace usage of actually internal SWT TypedListener
Browse files Browse the repository at this point in the history
Use the new API introduced in SWT via
eclipse-platform/eclipse.platform.swt#1112
  • Loading branch information
HannesWell committed Mar 21, 2024
1 parent ebe8db5 commit a75a0bf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion debug/org.eclipse.ui.console/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.ui.console,
org.eclipse.ui.console.actions,
org.eclipse.ui.internal.console;x-internal:=true
Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
Require-Bundle: org.eclipse.ui;bundle-version="[3.206.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012-2022 Mihai Nita and others
* Copyright (c) 2012, 2024 Mihai Nita and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.internal.console.ansi.participants;

import java.util.EventListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -20,8 +21,6 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TypedListener;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsolePageParticipant;
import org.eclipse.ui.part.IPageBookViewPage;
Expand Down Expand Up @@ -66,15 +65,8 @@ public void init(IPageBookViewPage page, IConsole console) {

// Find the document associated with the viewer
static IDocument getDocument(StyledText viewer) {
for (Listener listener : viewer.getListeners(ST.LineGetStyle)) {
if (listener instanceof TypedListener) {
Object evenListener = ((TypedListener) listener).getEventListener();
if (evenListener instanceof ITextViewer) {
return ((ITextViewer) evenListener).getDocument();
}
}
}
return null;
return viewer.getTypedListeners(ST.LineGetStyle, EventListener.class).filter(ITextViewer.class::isInstance)
.findFirst().map(v -> ((ITextViewer) v).getDocument()).orElse(null);
}

private void addViewer(StyledText viewer, IConsolePageParticipant participant) {
Expand Down
2 changes: 1 addition & 1 deletion team/bundles/org.eclipse.compare/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Export-Package: org.eclipse.compare,
org.eclipse.compare.internal.patch;x-friends:="org.eclipse.team.ui",
org.eclipse.compare.patch,
org.eclipse.compare.structuremergeviewer
Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
Require-Bundle: org.eclipse.ui;bundle-version="[3.206.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 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 @@ -145,6 +145,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent;
Expand Down Expand Up @@ -174,11 +175,9 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.TypedListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IKeyBindingService;
Expand Down Expand Up @@ -3107,15 +3106,8 @@ private void configureSourceViewer(SourceViewer sourceViewer, boolean editable,
}

private boolean isCursorLinePainterInstalled(SourceViewer viewer) {
Listener[] listeners = viewer.getTextWidget().getListeners(3001/*StyledText.LineGetBackground*/);
for (Listener l : listeners) {
if (l instanceof TypedListener) {
TypedListener listener = (TypedListener) l;
if (listener.getEventListener() instanceof CursorLinePainter)
return true;
}
}
return false;
return viewer.getTextWidget().getTypedListeners(ST.LineGetBackground, CursorLinePainter.class) //
.findFirst().isPresent();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ua/org.eclipse.help.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Export-Package: org.eclipse.help.ui,
org.eclipse.help.ui.internal.util;x-friends:="org.eclipse.ua.tests",
org.eclipse.help.ui.internal.views;x-friends:="org.eclipse.ui.cheatsheets,org.eclipse.ua.tests"
Require-Bundle: org.eclipse.help.base;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.ui;bundle-version="[3.6.0,4.0.0)";visibility:=reexport,
org.eclipse.ui;bundle-version="[3.206.0,4.0.0)";visibility:=reexport,
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)";visibility:=reexport,
org.eclipse.ui.forms;bundle-version="[3.5.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TypedListener;

/**
*
Expand Down Expand Up @@ -156,19 +155,19 @@ protected void paint(PaintEvent e) {

public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
if (listener == null) {
return;
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
addTypedListener(listener, SWT.Selection, SWT.DefaultSelection);
}

public void removeSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
if (listener == null) {
return;
removeListener(SWT.Selection, listener);
removeListener(SWT.DefaultSelection, listener);
}
removeTypedListener(SWT.Selection, listener);
removeTypedListener(SWT.DefaultSelection, listener);
}

@Override
Expand Down

0 comments on commit a75a0bf

Please sign in to comment.