Skip to content

Commit 2d1f274

Browse files
authored
Bug 577923 - Allow hiding scope items in marker support filter dialog eclipse-platform#17 (eclipse-platform#17)
This change allows RCP applications to provide a customised ScopeArea implementation for FiltersConfigurationDialog. This is a summary of the code changes required. - ScopeArea class was made public allowing it be extended by RCP applications. - A new protected method 'createScopeArea' was added to FiltersConfigurationDialog. - In ScopeArea, the buttons and the scope fields were made protected makeing them accessable to overridden ScopeArea. - MarkerFilterGroup class was made public to allow ScopeArea methods to be visible to RCP applications. - Constants used for Indexing ScopeArea buttons were made public in MarkerFilterGroup, allowing them be used by RCP applications. Fixes : eclipse-platform#17
1 parent 5ccec01 commit 2d1f274

File tree

8 files changed

+261
-13
lines changed

8 files changed

+261
-13
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/FiltersConfigurationDialog.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class FiltersConfigurationDialog extends TrayDialog {
9696
private Button limitButton;
9797
private Text limitText;
9898

99-
private GroupFilterConfigurationArea scopeArea = new ScopeArea();
99+
private GroupFilterConfigurationArea scopeArea = createScopeArea();
100100
private ScrolledForm form;
101101

102102
private Collection<FilterConfigurationArea> configAreas;
@@ -176,6 +176,15 @@ protected Control createDialogArea(Composite parent) {
176176
return container;
177177
}
178178

179+
/**
180+
* Create a new ScopeArea for the receiver.
181+
*
182+
* @return ScopeArea
183+
*/
184+
protected ScopeArea createScopeArea() {
185+
return new ScopeArea();
186+
}
187+
179188
private void initUI() {
180189
configsTable.setInput(filterGroups);
181190
IStructuredSelection selection = getInitialSelection();

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerFieldFilterGroup.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
* @since 3.4
5757
*/
58-
class MarkerFieldFilterGroup {
58+
public class MarkerFieldFilterGroup {
5959

6060
private static final String ATTRIBUTE_ON_ANY_IN_SAME_CONTAINER = "ON_ANY_IN_SAME_CONTAINER";//$NON-NLS-1$
6161
private static final String ATTRIBUTE_ON_SELECTED_AND_CHILDREN = "ON_SELECTED_AND_CHILDREN";//$NON-NLS-1$
@@ -73,25 +73,25 @@ class MarkerFieldFilterGroup {
7373
/**
7474
* Constant for any element.
7575
*/
76-
static final int ON_ANY = 0;
76+
public static final int ON_ANY = 0;
7777

7878
/**
7979
* Constant for any element in same container.
8080
*/
81-
static final int ON_ANY_IN_SAME_CONTAINER = 3;
81+
public static final int ON_ANY_IN_SAME_CONTAINER = 3;
8282

8383
/**
8484
* Constant for selected element and children.
8585
*/
86-
static final int ON_SELECTED_AND_CHILDREN = 2;
86+
public static final int ON_SELECTED_AND_CHILDREN = 2;
8787
/**
8888
* Constant for any selected element only.
8989
*/
90-
static final int ON_SELECTED_ONLY = 1;
90+
public static final int ON_SELECTED_ONLY = 1;
9191
/**
9292
* Constant for on working set.
9393
*/
94-
static final int ON_WORKING_SET = 4;
94+
public static final int ON_WORKING_SET = 4;
9595

9696
static final String TAG_ENABLED = "enabled"; //$NON-NLS-1$
9797
private static final String TAG_SCOPE = "scope"; //$NON-NLS-1$
@@ -274,7 +274,6 @@ IResource[] getResourcesInWorkingSet() {
274274
* @see #ON_SELECTED_ONLY
275275
* @see #ON_WORKING_SET
276276
*/
277-
@SuppressWarnings("javadoc")
278277
public int getScope() {
279278
return scope;
280279
}

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ScopeArea.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.jface.dialogs.IDialogConstants;
1919
import org.eclipse.jface.window.Window;
2020
import org.eclipse.osgi.util.NLS;
21-
2221
import org.eclipse.swt.SWT;
2322
import org.eclipse.swt.events.SelectionAdapter;
2423
import org.eclipse.swt.events.SelectionEvent;
@@ -38,10 +37,10 @@
3837
*
3938
* @since 3.4
4039
*/
41-
class ScopeArea extends GroupFilterConfigurationArea {
40+
public class ScopeArea extends GroupFilterConfigurationArea {
4241

43-
private Button[] buttons;
44-
int scope;
42+
protected Button[] buttons;
43+
protected int scope;
4544
private WorkingSetArea workingSetArea;
4645

4746
private class WorkingSetArea {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Enda O'Brien and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors: IBM Corporation - initial API and implementation
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.swt.widgets.Button;
15+
import org.eclipse.swt.widgets.Composite;
16+
import org.eclipse.ui.internal.views.markers.MarkerFieldFilterGroup;
17+
import org.eclipse.ui.internal.views.markers.ScopeArea;
18+
import org.eclipse.ui.views.markers.internal.MarkerMessages;
19+
20+
/**
21+
* CustomScopeArea is a custom implementation of ScopeArea that handles the
22+
* scope of the filter in FiltersConfigurationDialog.
23+
*
24+
* @since 3.5
25+
*/
26+
27+
public class CustomScopeArea extends ScopeArea {
28+
29+
/**
30+
* Create a new instance of the receiver.
31+
*/
32+
public CustomScopeArea() {
33+
super();
34+
}
35+
36+
@Override
37+
public void applyToGroup(MarkerFieldFilterGroup group) {
38+
group.setScope(scope);
39+
}
40+
41+
@Override
42+
public void createContents(Composite parent) {
43+
44+
buttons = new Button[5];
45+
46+
buttons[MarkerFieldFilterGroup.ON_ANY] = createRadioButton(parent, MarkerMessages.filtersDialog_anyResource,
47+
MarkerFieldFilterGroup.ON_ANY);
48+
buttons[MarkerFieldFilterGroup.ON_SELECTED_ONLY] = createRadioButton(parent,
49+
MarkerMessages.filtersDialog_selectedResource, MarkerFieldFilterGroup.ON_SELECTED_ONLY);
50+
}
51+
52+
@Override
53+
public String getTitle() {
54+
return MarkerMessages.filtersDialog_scopeTitle;
55+
}
56+
57+
@Override
58+
public void initializeFromGroup(MarkerFieldFilterGroup group) {
59+
buttons[scope].setSelection(false);
60+
scope = group.getScope();
61+
buttons[scope].setSelection(true);
62+
}
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Enda O'Brien and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors: IBM Corporation - initial API and implementation
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.swt.widgets.Composite;
15+
import org.eclipse.swt.widgets.Shell;
16+
import org.eclipse.ui.internal.views.markers.FiltersConfigurationDialog;
17+
import org.eclipse.ui.internal.views.markers.MarkerContentGenerator;
18+
import org.eclipse.ui.internal.views.markers.ScopeArea;
19+
import org.eclipse.ui.views.markers.MarkerSupportView;
20+
21+
/**
22+
* @since 3.5
23+
*
24+
*/
25+
public class ScopeAreaTestView extends MarkerSupportView {
26+
public static final String ID = "org.eclipse.ui.tests.customScopeTestView";
27+
28+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.customScopeContentGenerator";
29+
30+
Composite scopeAreaParent;
31+
32+
FiltersConfigurationDialog dialog;
33+
34+
public FiltersConfigurationDialog getDialog() {
35+
return dialog;
36+
}
37+
38+
public ScopeAreaTestView() {
39+
super(CONTENT_GEN_ID);
40+
}
41+
42+
public Composite getScopeArea() {
43+
return scopeAreaParent;
44+
}
45+
46+
@Override
47+
protected FiltersConfigurationDialog createFilterConfigurationDialog(MarkerContentGenerator gen) {
48+
dialog = new FiltersConfigurationDialogWithMyScope(
49+
getSite().getWorkbenchWindow().getShell(), gen);
50+
51+
// don't block for test purposes
52+
dialog.setBlockOnOpen(false);
53+
return dialog;
54+
}
55+
56+
class FiltersConfigurationDialogWithMyScope extends FiltersConfigurationDialog {
57+
/**
58+
* @param parentShell
59+
* @param generator
60+
*/
61+
public FiltersConfigurationDialogWithMyScope(Shell parentShell, MarkerContentGenerator generator) {
62+
super(parentShell, generator);
63+
}
64+
65+
@Override
66+
public ScopeArea createScopeArea() {
67+
68+
CustomScopeArea myScopeArea = new CustomScopeArea() {
69+
@Override
70+
public void createContents(Composite parent) {
71+
super.createContents(parent);
72+
scopeAreaParent = parent;
73+
}
74+
};
75+
76+
return myScopeArea;
77+
78+
}
79+
}
80+
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.ui.tests.markers.MarkerViewTests;
2929
import org.eclipse.ui.tests.markers.MarkerViewUtilTest;
3030
import org.eclipse.ui.tests.markers.ResourceMappingMarkersTest;
31+
import org.eclipse.ui.tests.markers.ScopeAreaTest;
3132
import org.junit.runner.RunWith;
3233
import org.junit.runners.Suite;
3334

@@ -66,5 +67,6 @@
6667
Bug549139Test.class,
6768
LargeFileLimitsPreferenceHandlerTest.class,
6869
WorkbookEditorsHandlerTest.class,
70+
ScopeAreaTest.class,
6971
})
7072
public class InternalTestSuite {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Enda O'Brien and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors: IBM Corporation - initial API and implementation
11+
*******************************************************************************/
12+
13+
package org.eclipse.ui.tests.markers;
14+
15+
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertTrue;
17+
18+
import java.lang.reflect.InvocationTargetException;
19+
import java.lang.reflect.Method;
20+
21+
import org.eclipse.swt.widgets.Button;
22+
import org.eclipse.swt.widgets.Composite;
23+
import org.eclipse.swt.widgets.Control;
24+
import org.eclipse.ui.PlatformUI;
25+
import org.eclipse.ui.internal.views.markers.ExtendedMarkersView;
26+
import org.eclipse.ui.tests.ScopeAreaTestView;
27+
import org.eclipse.ui.views.markers.MarkerSupportView;
28+
import org.eclipse.ui.views.markers.internal.MarkerMessages;
29+
import org.junit.After;
30+
import org.junit.Test;
31+
32+
public class ScopeAreaTest {
33+
ScopeAreaTestView view;
34+
Composite composite;
35+
36+
@After
37+
public void cleanup() {
38+
if (view.getDialog() != null) {
39+
view.getDialog().close();
40+
}
41+
}
42+
43+
@Test
44+
public void canCreateCustomScopeArea() throws Exception {
45+
view = (ScopeAreaTestView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
46+
.getActivePage().showView(ScopeAreaTestView.ID);
47+
48+
openFiltersDialog(view);
49+
50+
assertTrue(MarkerMessages.filtersDialog_anyResource,
51+
isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResource));
52+
assertFalse(MarkerMessages.filtersDialog_anyResourceInSameProject,
53+
isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResourceInSameProject));
54+
assertFalse(MarkerMessages.filtersDialog_anyResourceInSameProject,
55+
isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResourceInSameProject));
56+
assertFalse(MarkerMessages.filtersDialog_selectedAndChildren,
57+
isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_selectedAndChildren));
58+
assertTrue(MarkerMessages.filtersDialog_selectedResource,
59+
isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_selectedResource));
60+
}
61+
62+
void openFiltersDialog(MarkerSupportView view) {
63+
Method openFiltersDialog;
64+
try {
65+
openFiltersDialog = ExtendedMarkersView.class.getDeclaredMethod("openFiltersDialog");
66+
openFiltersDialog.setAccessible(true);
67+
openFiltersDialog.invoke(view);
68+
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
69+
| InvocationTargetException e) {
70+
throw new RuntimeException(e);
71+
}
72+
}
73+
74+
boolean isButtonAvailable(Composite composite, String buttonText) {
75+
Control[] children = composite.getChildren();
76+
for (Control ctrl : children) {
77+
if (ctrl instanceof Button) {
78+
if (((Button) ctrl).getText().contains(buttonText)) {
79+
return true;
80+
}
81+
} else if (ctrl instanceof Composite && isButtonAvailable((Composite) ctrl, buttonText)) {
82+
return true;
83+
}
84+
}
85+
return false;
86+
}
87+
}

tests/org.eclipse.ui.tests/plugin.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -3409,6 +3409,9 @@
34093409
<markerContentGenerator
34103410
id="org.eclipse.ui.tests.filterHelpContentGenerator">
34113411
</markerContentGenerator>
3412+
<markerContentGenerator
3413+
id="org.eclipse.ui.tests.customScopeContentGenerator">
3414+
</markerContentGenerator>
34123415
</extension>
34133416
<extension
34143417
id="categoryTestMarker"
@@ -3923,7 +3926,12 @@
39233926
class="org.eclipse.ui.tests.FilterHelpTestView"
39243927
id="org.eclipse.ui.tests.filterHelpTestView"
39253928
name="Marker Filter Help View">
3926-
</view>
3929+
</view>
3930+
<view
3931+
class="org.eclipse.ui.tests.ScopeAreaTestView"
3932+
id="org.eclipse.ui.tests.customScopeTestView"
3933+
name="Custom Scope Area View">
3934+
</view>
39273935
</extension>
39283936
<extension
39293937
point="org.eclipse.ui.statusHandlers">

0 commit comments

Comments
 (0)