Skip to content

Commit 8e7ce21

Browse files
committed
579498 filter dialog types eclipse-platform#144
Squashed commit of the following: commit 24db6db Author: Enda O Brien <[email protected]> Date: Fri Sep 20 13:19:55 2024 +0100 579498 filter dialog types eclipse-platform#144 Squashed commit of the following: commit 94f352d Author: Enda O Brien <[email protected]> Date: Thu Apr 4 17:07:02 2024 +0100 Fixed a couple of warnings in test code commit 49a195d Author: Enda O Brien <[email protected]> Date: Wed Aug 24 15:54:38 2022 +0100 put add and addAll back in previous order commit 7dd8032 Author: Enda O Brien <[email protected]> Date: Wed Aug 24 15:11:23 2022 +0100 Moved copyright to be first lines in files commit 87763b5 Author: Enda O Brien <[email protected]> Date: Wed Aug 24 14:41:46 2022 +0100 Modified copyright message in test code to include my name commit 1b08d4a Author: Enda O Brien <[email protected]> Date: Wed Aug 24 14:09:12 2022 +0100 updated documentation of markerSupport.exsd commit 579fca0 Author: Enda O Brien <[email protected]> Date: Wed Aug 24 12:04:44 2022 +0100 Added copyright notice to test code commit 1271c95 Author: Enda O Brien <[email protected]> Date: Wed Aug 24 11:49:13 2022 +0100 Fixed whitespace differences commit 36e50cd Author: Enda O Brien <[email protected]> Date: Thu Jun 9 14:16:44 2022 +0100 Test code for application attribute on marker type reference commit 01940b2 Author: Enda O Brien <[email protected]> Date: Thu Jun 9 10:57:55 2022 +0100 Added application attribute to type reference in marker content generator
1 parent 0986115 commit 8e7ce21

File tree

10 files changed

+375
-4
lines changed

10 files changed

+375
-4
lines changed

bundles/org.eclipse.ui.ide/schema/markerSupport.exsd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ ON_ANY_IN_SAME_CONTAINER: on any item with the same top level container as the s
192192
</appinfo>
193193
</annotation>
194194
</attribute>
195+
<attribute name="application">
196+
<annotation>
197+
<documentation>
198+
The application attribute describes how the reference should be applied.
199+
i.e. Does it refer to type only, type and subtypes or subtypes only.
200+
It is optionally included.
201+
If it is not specified it defaults to typeAndSubTypes.
202+
</documentation>
203+
</annotation>
204+
<simpleType>
205+
<restriction base="string">
206+
<enumeration value="subTypesOnly">
207+
</enumeration>
208+
<enumeration value="typeOnly">
209+
</enumeration>
210+
<enumeration value="typeAndSubTypes">
211+
</enumeration>
212+
</restriction>
213+
</simpleType>
214+
</attribute>
195215
</complexType>
196216
</element>
197217

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
* Lars Vogel <[email protected]> - Bug 430694
14+
* Enda O'Brien, Pilz Ireland - PR #144
1415
******************************************************************************/
1516

1617
package org.eclipse.ui.internal.views.markers;
@@ -71,6 +72,26 @@ public class MarkerSupportInternalUtilities {
7172
*/
7273
public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
7374

75+
/**
76+
* The application attribute from a configuration element.
77+
*/
78+
public static final String APPLICATION = "application"; //$NON-NLS-1$
79+
80+
/**
81+
* The sub type only attribute value from the application attribute.
82+
*/
83+
public static final String SUB_TYPES_ONLY = "subTypesOnly"; //$NON-NLS-1$
84+
85+
/**
86+
* The type only attribute value from the application attribute.
87+
*/
88+
public static final String TYPE_ONLY = "typeOnly"; //$NON-NLS-1$
89+
90+
/**
91+
* The type and subtype attribute value from the application attribute.
92+
*/
93+
public static final String TYPE_AND_SUBTYPE = "typeAndSubTypes"; //$NON-NLS-1$
94+
7495
/**
7596
* The name attribute name from a configuration element.
7697
*/

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Enda O'Brien, Pilz Ireland - PR #144
1314
******************************************************************************/
1415

1516
package org.eclipse.ui.views.markers.internal;
@@ -190,9 +191,25 @@ public Collection<MarkerType> getMarkerTypes() {
190191
IConfigurationElement[] markerTypeElements = configurationElement.getChildren(MarkerSupportRegistry.MARKER_TYPE_REFERENCE);
191192
for (IConfigurationElement configElement : markerTypeElements) {
192193
String elementName = configElement.getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID);
193-
MarkerType[] types = MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes();
194-
markerTypes.addAll(Arrays.asList(types));
195-
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
194+
195+
String application = configElement.getAttribute(MarkerSupportInternalUtilities.APPLICATION) == null
196+
? MarkerSupportInternalUtilities.TYPE_AND_SUBTYPE
197+
: configElement.getAttribute(MarkerSupportInternalUtilities.APPLICATION);
198+
199+
switch (application) {
200+
case MarkerSupportInternalUtilities.TYPE_ONLY:
201+
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
202+
break;
203+
case MarkerSupportInternalUtilities.SUB_TYPES_ONLY:
204+
markerTypes.addAll(
205+
Arrays.asList(MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes()));
206+
break;
207+
case MarkerSupportInternalUtilities.TYPE_AND_SUBTYPE:
208+
default:
209+
markerTypes.addAll(
210+
Arrays.asList(MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes()));
211+
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
212+
}
196213
}
197214
if (markerTypes.isEmpty()) {
198215
MarkerType[] types = MarkerTypesModel.getInstance().getType(IMarker.PROBLEM).getAllSubTypes();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: Enda O'Brien, Pilz Ireland - PR #144
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
/**
17+
* A test view that does not define the markerTypeReference application
18+
* attribute in its content generator (CONTENT_GEN_ID).
19+
*
20+
*/
21+
public class NoApplicationAttribTestView extends MarkerSupportView {
22+
public static final String ID = "org.eclipse.ui.tests.noApplicationAttribTestView";
23+
24+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.noApplicationAttribTestViewContentGenerator";
25+
26+
public NoApplicationAttribTestView() {
27+
super(CONTENT_GEN_ID);
28+
}
29+
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: Enda O'Brien, Pilz Ireland - PR #144
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
/**
17+
* A test view that defines a markerTypeReference application attribute of
18+
* subTypesOnly in it content generator (CONTENT_GEN_ID).
19+
*/
20+
public class SubTypeOnlyTestView extends MarkerSupportView {
21+
public static final String ID = "org.eclipse.ui.tests.subTypeOnlyTestView";
22+
23+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.subTypeOnlyTestViewContentGenerator";
24+
25+
public SubTypeOnlyTestView() {
26+
super(CONTENT_GEN_ID);
27+
}
28+
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: Enda O'Brien, Pilz Ireland - PR #144
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
/**
17+
* A test view that defines a markerTypeReference application attribute of
18+
* typeAndSubTypes in it content generator (CONTENT_GEN_ID).
19+
*/
20+
public class TypeAndSubTypeTestView extends MarkerSupportView {
21+
public static final String ID = "org.eclipse.ui.tests.typeAndSubTypeTestView";
22+
23+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.typeAndSubTypeTestViewContentGenerator";
24+
25+
public TypeAndSubTypeTestView() {
26+
super(CONTENT_GEN_ID);
27+
}
28+
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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: Enda O'Brien, Pilz Ireland - PR #144
11+
*******************************************************************************/
12+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
/**
17+
* A test view that defines a markerTypeReference application attribute of
18+
* typeOnly in it content generator (CONTENT_GEN_ID).
19+
*
20+
*/
21+
public class TypeOnlyTestView extends MarkerSupportView {
22+
23+
public static final String ID = "org.eclipse.ui.tests.typeOnlyTestView";
24+
25+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.typeOnlyTestViewContentGenerator";
26+
27+
public TypeOnlyTestView() {
28+
super(CONTENT_GEN_ID);
29+
}
30+
31+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.ui.tests.markers.MarkerSupportRegistryTests;
2626
import org.eclipse.ui.tests.markers.MarkerSupportViewTest;
2727
import org.eclipse.ui.tests.markers.MarkerTesterTest;
28+
import org.eclipse.ui.tests.markers.MarkerTypeTests;
2829
import org.eclipse.ui.tests.markers.MarkerViewTests;
2930
import org.eclipse.ui.tests.markers.MarkerViewUtilTest;
3031
import org.eclipse.ui.tests.markers.ResourceMappingMarkersTest;
@@ -68,5 +69,6 @@
6869
LargeFileLimitsPreferenceHandlerTest.class,
6970
WorkbookEditorsHandlerTest.class,
7071
ScopeAreaTest.class,
72+
MarkerTypeTests.class
7173
})
7274
public class InternalTestSuite {}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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.assertEquals;
16+
import static org.junit.Assert.assertTrue;
17+
18+
import java.lang.reflect.Field;
19+
import java.util.Arrays;
20+
import java.util.Collection;
21+
import java.util.HashSet;
22+
23+
import org.eclipse.ui.PlatformUI;
24+
import org.eclipse.ui.internal.views.markers.ExtendedMarkersView;
25+
import org.eclipse.ui.internal.views.markers.MarkerContentGenerator;
26+
import org.eclipse.ui.tests.NoApplicationAttribTestView;
27+
import org.eclipse.ui.tests.SubTypeOnlyTestView;
28+
import org.eclipse.ui.tests.TypeAndSubTypeTestView;
29+
import org.eclipse.ui.tests.TypeOnlyTestView;
30+
import org.eclipse.ui.views.markers.MarkerSupportView;
31+
import org.eclipse.ui.views.markers.internal.ContentGeneratorDescriptor;
32+
import org.eclipse.ui.views.markers.internal.MarkerType;
33+
import org.eclipse.ui.views.markers.internal.MarkerTypesModel;
34+
import org.junit.Test;
35+
36+
public class MarkerTypeTests {
37+
38+
static final String PROBLEM_MARKER = "org.eclipse.core.resources.problemmarker";
39+
40+
@Test
41+
public void canIncludeTypeOnly() throws Exception {
42+
MarkerSupportView view = (MarkerSupportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
43+
.getActivePage().showView(TypeOnlyTestView.ID);
44+
45+
MarkerContentGenerator generator = getMarkerContentGenerator(view);
46+
Collection<MarkerType> filterDialogTypes = getMarkerTypes(generator);
47+
48+
assertEquals(1, filterDialogTypes.size());
49+
assertEquals(PROBLEM_MARKER, filterDialogTypes.stream().map(type -> type.getId()).findFirst().get());
50+
}
51+
52+
@Test
53+
public void canIncludeTypeAndSubTypes() throws Exception {
54+
MarkerSupportView view = (MarkerSupportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
55+
.getActivePage().showView(TypeAndSubTypeTestView.ID);
56+
57+
MarkerContentGenerator generator = getMarkerContentGenerator(view);
58+
Collection<MarkerType> filterDialogTypes = getMarkerTypes(generator);
59+
60+
Collection<MarkerType> markerTypes = new HashSet<>();
61+
markerTypes.add(MarkerTypesModel.getInstance().getType(PROBLEM_MARKER));
62+
markerTypes.addAll(Arrays.asList(MarkerTypesModel.getInstance().getType(PROBLEM_MARKER).getAllSubTypes()));
63+
64+
assertEquals(markerTypes.size(), filterDialogTypes.size());
65+
assertEquals(PROBLEM_MARKER, filterDialogTypes.stream().map(type -> type.getId())
66+
.filter(s -> s.equals(PROBLEM_MARKER)).findFirst().get());
67+
68+
for (MarkerType type : markerTypes) {
69+
assertTrue(filterDialogTypes.contains(type));
70+
}
71+
}
72+
73+
@Test
74+
public void canIncludeSubtypesOnly() throws Exception {
75+
MarkerSupportView view = (MarkerSupportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
76+
.getActivePage().showView(SubTypeOnlyTestView.ID);
77+
78+
MarkerContentGenerator generator = getMarkerContentGenerator(view);
79+
Collection<MarkerType> filterDialogTypes = getMarkerTypes(generator);
80+
81+
Collection<MarkerType> markerTypes = new HashSet<>();
82+
markerTypes.addAll(Arrays.asList(MarkerTypesModel.getInstance().getType(PROBLEM_MARKER).getAllSubTypes()));
83+
84+
assertEquals(markerTypes.size(), filterDialogTypes.size());
85+
assertTrue(PROBLEM_MARKER, filterDialogTypes.stream().map(type -> type.getId())
86+
.filter(s -> s.equals(PROBLEM_MARKER)).findFirst().isEmpty());
87+
for (MarkerType type : markerTypes) {
88+
assertTrue(filterDialogTypes.contains(type));
89+
}
90+
}
91+
92+
@Test
93+
public void typeAndSubTypesIsDefault() throws Exception {
94+
MarkerSupportView view = (MarkerSupportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
95+
.getActivePage().showView(NoApplicationAttribTestView.ID);
96+
97+
MarkerContentGenerator generator = getMarkerContentGenerator(view);
98+
Collection<MarkerType> filterDialogTypes = getMarkerTypes(generator);
99+
100+
Collection<MarkerType> markerTypes = new HashSet<>();
101+
markerTypes.add(MarkerTypesModel.getInstance().getType(PROBLEM_MARKER));
102+
markerTypes.addAll(Arrays.asList(MarkerTypesModel.getInstance().getType(PROBLEM_MARKER).getAllSubTypes()));
103+
104+
assertEquals(markerTypes.size(), filterDialogTypes.size());
105+
assertEquals(PROBLEM_MARKER, filterDialogTypes.stream().map(type -> type.getId())
106+
.filter(s -> s.equals(PROBLEM_MARKER)).findFirst().get());
107+
108+
for (MarkerType type : markerTypes) {
109+
assertTrue(filterDialogTypes.contains(type));
110+
}
111+
}
112+
113+
public static MarkerContentGenerator getMarkerContentGenerator(MarkerSupportView view) {
114+
MarkerContentGenerator generator = null;
115+
try {
116+
Field fieldGenerator = ExtendedMarkersView.class.getDeclaredField("generator");
117+
fieldGenerator.setAccessible(true);
118+
generator = (MarkerContentGenerator) fieldGenerator.get(view);
119+
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
120+
}
121+
return generator;
122+
}
123+
124+
@SuppressWarnings("unchecked")
125+
public static Collection<MarkerType> getMarkerTypes(MarkerContentGenerator generator) {
126+
Collection<MarkerType> selectedTypesCollection = null;
127+
try {
128+
Field generatorDescriptor = MarkerContentGenerator.class.getDeclaredField("generatorDescriptor");
129+
generatorDescriptor.setAccessible(true);
130+
131+
ContentGeneratorDescriptor contentGeneratorDescriptor = (ContentGeneratorDescriptor) generatorDescriptor
132+
.get(generator);
133+
134+
Field markerTypesField = ContentGeneratorDescriptor.class.getDeclaredField("markerTypes");
135+
markerTypesField.setAccessible(true);
136+
137+
selectedTypesCollection = (Collection<MarkerType>) markerTypesField.get(contentGeneratorDescriptor);
138+
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
139+
}
140+
return selectedTypesCollection;
141+
}
142+
}

0 commit comments

Comments
 (0)