Skip to content

Commit 99c91af

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 99c91af

File tree

9 files changed

+346
-4
lines changed

9 files changed

+346
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ public class MarkerSupportInternalUtilities {
7171
*/
7272
public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
7373

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

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,25 @@ public Collection<MarkerType> getMarkerTypes() {
190190
IConfigurationElement[] markerTypeElements = configurationElement.getChildren(MarkerSupportRegistry.MARKER_TYPE_REFERENCE);
191191
for (IConfigurationElement configElement : markerTypeElements) {
192192
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));
193+
194+
String application = configElement.getAttribute(MarkerSupportInternalUtilities.APPLICATION) == null
195+
? MarkerSupportInternalUtilities.TYPE_AND_SUBTYPE
196+
: configElement.getAttribute(MarkerSupportInternalUtilities.APPLICATION);
197+
198+
switch (application) {
199+
case MarkerSupportInternalUtilities.TYPE_ONLY:
200+
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
201+
break;
202+
case MarkerSupportInternalUtilities.SUB_TYPES_ONLY:
203+
markerTypes.addAll(
204+
Arrays.asList(MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes()));
205+
break;
206+
case MarkerSupportInternalUtilities.TYPE_AND_SUBTYPE:
207+
default:
208+
markerTypes.addAll(
209+
Arrays.asList(MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes()));
210+
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
211+
}
196212
}
197213
if (markerTypes.isEmpty()) {
198214
MarkerType[] types = MarkerTypesModel.getInstance().getType(IMarker.PROBLEM).getAllSubTypes();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.eclipse.ui.tests;
2+
3+
import org.eclipse.ui.views.markers.MarkerSupportView;
4+
5+
/**
6+
* @since 3.5
7+
*
8+
*/
9+
public class NoApplicationAttribTestView extends MarkerSupportView {
10+
public static final String ID = "org.eclipse.ui.tests.noApplicationAttribTestView";
11+
12+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.noApplicationAttribTestViewContentGenerator";
13+
14+
public NoApplicationAttribTestView() {
15+
super(CONTENT_GEN_ID);
16+
}
17+
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
public class SubTypeOnlyTestView extends MarkerSupportView {
17+
public static final String ID = "org.eclipse.ui.tests.subTypeOnlyTestView";
18+
19+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.subTypeOnlyTestViewContentGenerator";
20+
21+
public SubTypeOnlyTestView() {
22+
super(CONTENT_GEN_ID);
23+
}
24+
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
public class TypeAndSubTypeTestView extends MarkerSupportView {
17+
public static final String ID = "org.eclipse.ui.tests.typeAndSubTypeTestView";
18+
19+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.typeAndSubTypeTestViewContentGenerator";
20+
21+
public TypeAndSubTypeTestView() {
22+
super(CONTENT_GEN_ID);
23+
}
24+
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
package org.eclipse.ui.tests;
13+
14+
import org.eclipse.ui.views.markers.MarkerSupportView;
15+
16+
public class TypeOnlyTestView extends MarkerSupportView {
17+
18+
public static final String ID = "org.eclipse.ui.tests.typeOnlyTestView";
19+
20+
static final String CONTENT_GEN_ID = "org.eclipse.ui.tests.typeOnlyTestViewContentGenerator";
21+
22+
public TypeOnlyTestView() {
23+
super(CONTENT_GEN_ID);
24+
}
25+
26+
}
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+
}

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,26 @@
190190
class="org.eclipse.ui.tests.api.workbenchpart.ViewWithCreateControlsException"
191191
id="org.eclipse.ui.tests.api.workbenchpart.ViewWithCreateControlsException">
192192
</view>
193-
193+
<view
194+
class="org.eclipse.ui.tests.TypeOnlyTestView"
195+
id="org.eclipse.ui.tests.typeOnlyTestView"
196+
name="TypeOnlyTestView">
197+
</view>
198+
<view
199+
class="org.eclipse.ui.tests.SubTypeOnlyTestView"
200+
id="org.eclipse.ui.tests.subTypeOnlyTestView"
201+
name="SubTypeOnlyTestView">
202+
</view>
203+
<view
204+
class="org.eclipse.ui.tests.TypeAndSubTypeTestView"
205+
id="org.eclipse.ui.tests.typeAndSubTypeTestView"
206+
name="TypeAndSubTypeTestView">
207+
</view>
208+
<view
209+
class="org.eclipse.ui.tests.NoApplicationAttribTestView"
210+
id="org.eclipse.ui.tests.noApplicationAttribTestView"
211+
name="NoApplicationAttribTestView">
212+
</view>
194213
</extension>
195214

196215
<extension
@@ -3408,6 +3427,37 @@
34083427
</markerContentGeneratorExtension>
34093428
<markerContentGenerator
34103429
id="org.eclipse.ui.tests.filterHelpContentGenerator">
3430+
</markerContentGenerator>
3431+
<markerContentGenerator
3432+
id="org.eclipse.ui.tests.typeAndSubTypeTestViewContentGenerator"
3433+
name="typeAndSubTypeTestViewContentGenerator">
3434+
<markerTypeReference
3435+
application="typeAndSubTypes"
3436+
id="org.eclipse.core.resources.problemmarker">
3437+
</markerTypeReference>
3438+
</markerContentGenerator>
3439+
<markerContentGenerator
3440+
id="org.eclipse.ui.tests.typeOnlyTestViewContentGenerator"
3441+
name="typeOnlyTestViewContentGenerator">
3442+
<markerTypeReference
3443+
application="typeOnly"
3444+
id="org.eclipse.core.resources.problemmarker">
3445+
</markerTypeReference>
3446+
</markerContentGenerator>
3447+
<markerContentGenerator
3448+
id="org.eclipse.ui.tests.subTypeOnlyTestViewContentGenerator"
3449+
name="subTypeOnlyTestViewContentGenerator">
3450+
<markerTypeReference
3451+
application="subTypesOnly"
3452+
id="org.eclipse.core.resources.problemmarker">
3453+
</markerTypeReference>
3454+
</markerContentGenerator>
3455+
<markerContentGenerator
3456+
id="org.eclipse.ui.tests.noApplicationAttribTestViewContentGenerator"
3457+
name="noApplicationAttribTestViewContentGenerator">
3458+
<markerTypeReference
3459+
id="org.eclipse.core.resources.problemmarker">
3460+
</markerTypeReference>
34113461
</markerContentGenerator>
34123462
<markerContentGenerator
34133463
id="org.eclipse.ui.tests.customScopeContentGenerator">

0 commit comments

Comments
 (0)