Skip to content

Commit d50e66d

Browse files
eobrienPilzjukzi
authored andcommitted
Squashed commit of the following:
commit f67c61a Author: Enda O Brien <[email protected]> Date: Tue Sep 24 14:40:50 2024 +0100 579498 filter dialog types #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 #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 7c018ef commit d50e66d

File tree

10 files changed

+374
-4
lines changed

10 files changed

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

0 commit comments

Comments
 (0)