Skip to content

Commit 6740b64

Browse files
jjohnstnfedejeanne
authored andcommitted
Add scope changed notification to SearchDialog
- add new IScopeChangedListener, IScopeChangeProvider, ScopeChangedEvent classes - have SearchDialog implement new IScopeChangeProvider - bump up minor version with new public interfaces - fixes #3096
1 parent 0e4942b commit 6740b64

File tree

5 files changed

+170
-3
lines changed

5 files changed

+170
-3
lines changed

bundles/org.eclipse.jface/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jface;singleton:=true
5-
Bundle-Version: 3.37.100.qualifier
5+
Bundle-Version: 3.38.0.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.jface,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jface.dialogs;
15+
16+
/**
17+
* @since 3.38
18+
*
19+
*/
20+
public interface IScopeChangeProvider {
21+
22+
/**
23+
* Adds a listener for scope changes in this scope change provider. Has no
24+
* effect if an identical listener is already registered.
25+
*
26+
* @param listener a scope changed listener
27+
*/
28+
void addScopeChangedListener(IScopeChangedListener listener);
29+
30+
/**
31+
* Removes the given scope change listener from this page change provider. Has
32+
* no effect if an identical listener is not registered.
33+
*
34+
* @param listener a scope changed listener
35+
*/
36+
void removeScopeChangedListener(IScopeChangedListener listener);
37+
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jface.dialogs;
15+
16+
/**
17+
* A listener which is notified when the scope for the search page is changed.
18+
*
19+
* @see IScopeChangeProvider
20+
* @see ScopeChangedEvent
21+
*
22+
* @since 3.38
23+
*/
24+
public interface IScopeChangedListener {
25+
/**
26+
* Notifies that the selected scope has changed.
27+
*
28+
* @param event event object describing the change
29+
*/
30+
public void scopeChanged(ScopeChangedEvent event);
31+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
* Red Hat Inc. - copied and modified from PageChangedEvent.java
14+
*******************************************************************************/
15+
package org.eclipse.jface.dialogs;
16+
17+
import java.util.EventObject;
18+
19+
/**
20+
* Event object describing a page selection change. The source of these events
21+
* is a page change provider.
22+
*
23+
* @see IPageChangeProvider
24+
* @see IPageChangedListener
25+
*
26+
* @since 3.38
27+
*/
28+
public class ScopeChangedEvent extends EventObject {
29+
30+
private static final long serialVersionUID = -2652600407410991930L;
31+
32+
/**
33+
* The changed scope.
34+
*/
35+
protected int scope;
36+
37+
/**
38+
* Creates a new event for the given source and new scope.
39+
*
40+
* @param source the page change provider
41+
* @param scope the new scope. In the JFace provided dialogs this will be an
42+
* <code>ISearchPageContainer</code> constant.
43+
*/
44+
public ScopeChangedEvent(IPageChangeProvider source,
45+
int scope) {
46+
super(source);
47+
this.scope = scope;
48+
}
49+
50+
/**
51+
* Returns the new scope.
52+
*
53+
* @return the new scope. In dialogs implemented by JFace, this will be an
54+
* <code>ISearchPageContainer</code> constant.
55+
*/
56+
public int getScope() {
57+
return scope;
58+
}
59+
60+
/**
61+
* Returns the scope change provider that is the source of this event.
62+
*
63+
* @return the originating scope change provider
64+
*/
65+
public IScopeChangeProvider getPageChangeProvider() {
66+
return (IScopeChangeProvider) getSource();
67+
}
68+
}

bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -60,7 +60,10 @@
6060
import org.eclipse.jface.dialogs.IDialogSettings;
6161
import org.eclipse.jface.dialogs.IPageChangeProvider;
6262
import org.eclipse.jface.dialogs.IPageChangedListener;
63+
import org.eclipse.jface.dialogs.IScopeChangeProvider;
64+
import org.eclipse.jface.dialogs.IScopeChangedListener;
6365
import org.eclipse.jface.dialogs.PageChangedEvent;
66+
import org.eclipse.jface.dialogs.ScopeChangedEvent;
6467
import org.eclipse.jface.operation.IRunnableContext;
6568
import org.eclipse.jface.resource.ImageDescriptor;
6669
import org.eclipse.jface.util.SafeRunnable;
@@ -91,7 +94,8 @@
9194
import org.eclipse.search.ui.ISearchPageScoreComputer;
9295

9396

94-
public class SearchDialog extends ExtendedDialogWindow implements ISearchPageContainer, IPageChangeProvider {
97+
public class SearchDialog extends ExtendedDialogWindow
98+
implements ISearchPageContainer, IPageChangeProvider, IScopeChangeProvider {
9599

96100
// Dialog store id constants
97101
private static final String DIALOG_NAME= "SearchDialog"; //$NON-NLS-1$
@@ -150,6 +154,7 @@ protected void layout(Composite composite, boolean flushCache) {
150154
private Button fCustomizeButton;
151155
private Button fReplaceButton;
152156
private ListenerList<IPageChangedListener> fPageChangeListeners;
157+
private ListenerList<IScopeChangedListener> fScopeChangeListeners;
153158

154159
private final IWorkbenchWindow fWorkbenchWindow;
155160
private final ISelection fCurrentSelection;
@@ -706,6 +711,18 @@ public void setPerformActionEnabled(boolean state) {
706711
*/
707712
public void notifyScopeSelectionChanged() {
708713
setPerformActionEnabled(fLastEnableState);
714+
if (fScopeChangeListeners != null && !fScopeChangeListeners.isEmpty()) {
715+
// Fires the scope change event
716+
final ScopeChangedEvent event = new ScopeChangedEvent(this, getSelectedScope());
717+
for (IScopeChangedListener l : fScopeChangeListeners) {
718+
SafeRunner.run(new SafeRunnable() {
719+
@Override
720+
public void run() {
721+
l.scopeChanged(event);
722+
}
723+
});
724+
}
725+
}
709726
}
710727

711728
private Control createPageControl(Composite parent, final SearchPageDescriptor descriptor) {
@@ -828,4 +845,17 @@ public void run() {
828845
}
829846
}
830847
}
848+
849+
@Override
850+
public void addScopeChangedListener(IScopeChangedListener listener) {
851+
if (fScopeChangeListeners == null) {
852+
fScopeChangeListeners = new ListenerList<>();
853+
}
854+
fScopeChangeListeners.add(listener);
855+
}
856+
857+
@Override
858+
public void removeScopeChangedListener(IScopeChangedListener listener) {
859+
fScopeChangeListeners.remove(listener);
860+
}
831861
}

0 commit comments

Comments
 (0)