Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to Filter Problems View Programmatically
How to Filter Problems View Programmatically [message #671529] Wed, 18 May 2011 08:36 Go to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi all,

I want to filter some of the warnings, errors, etc. from the problems view programmatically? Is this supported by an API or extension? If so, could you please point me a starting point?

By the way, this seems possible as a user function through down_arrow/configure_contents menu.

Thanks, regards,
Re: How to Filter Problems View Programmatically [message #671809 is a reply to message #671529] Thu, 19 May 2011 03:37 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 18/05/11 2:06 PM, Kivanc Muslu wrote:
> Hi all,
> I want to filter some of the warnings, errors, etc. from the
> problems view programmatically? Is this supported by an API
> or extension? If so, could you please point me a starting
> point?

There is no API for this. You can start looking into the
FiltersConfigurationDialog for the internal calls made.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: How to Filter Problems View Programmatically [message #1830054 is a reply to message #671809] Thu, 16 July 2020 12:28 Go to previous messageGo to next message
Artsiom Chapialiou is currently offline Artsiom ChapialiouFriend
Messages: 3
Registered: July 2020
Junior Member
Just bump into the same problem. As it said there are no officail APIs to do that. Looking into eclipse source I see some of classes and methods are not public. So have to use some (black magic) reflections. :)
Override init() method at your ProblemsView / MarkerSupportView:

@Override
  public void init(IViewSite site, IMemento m) throws PartInitException {
    super.init(site, m);

    // Hack to set Filter to show only deepCode markers. No official APIs to do that.
    MarkerContentGenerator generator = null;
    try {
      Field fieldGenerator = ExtendedMarkersView.class.getDeclaredField("generator");
      fieldGenerator.setAccessible(true);
      generator = (MarkerContentGenerator) fieldGenerator.get(this); // getGenerator(this);
      if (generator == null) {
        return;
      }

      // creating our Filter from scratch.
      // class MarkerFieldFilterGroup is not public (and actually loaded with another classloader)
      Class<?> classMarkerFieldFilterGroup =
          this.getClass().getClassLoader().loadClass("org.eclipse.ui.internal.views.markers.MarkerFieldFilterGroup");
      Constructor<?> con =
          classMarkerFieldFilterGroup.getDeclaredConstructor(org.eclipse.core.runtime.IConfigurationElement.class,
              org.eclipse.ui.internal.views.markers.MarkerContentGenerator.class);
      con.setAccessible(true);
      Object filter = con.newInstance(null, generator);

      Field fieldName = classMarkerFieldFilterGroup.getDeclaredField("name");
      fieldName.setAccessible(true);
      fieldName.set(filter, "DeepCodeMarkersFilter");

      // to fill "filters" field at generator
      Method writeFiltersPreference = generator.getClass().getDeclaredMethod("writeFiltersPreference");
      writeFiltersPreference.setAccessible(true);
      writeFiltersPreference.invoke(generator);

      Field filtersField = MarkerContentGenerator.class.getDeclaredField("filters");
      filtersField.setAccessible(true);
      @SuppressWarnings("rawtypes")
      Collection filtersCollection = (Collection) filtersField.get(generator);
      // remove existing filters at "generator" and add our Filter
      filtersCollection.clear();
      filtersCollection.add(filter);

      // to fill "fieldFilters" field at new filter (MarkerFieldFilterGroup)
      writeFiltersPreference.invoke(generator);

      // getting field with MarkerTypeFieldFilter responsible for filtering by marker type
      Field fieldFilters = classMarkerFieldFilterGroup.getDeclaredField("fieldFilters");
      fieldFilters.setAccessible(true);
      MarkerFieldFilter[] MarkerFieldFilters = (MarkerFieldFilter[]) fieldFilters.get(filter);
      MarkerTypeFieldFilter markerTypeFieldFilter = null;
      for (MarkerFieldFilter markerFieldFilter : MarkerFieldFilters) {
        if (markerFieldFilter instanceof MarkerTypeFieldFilter) {
          markerTypeFieldFilter = (MarkerTypeFieldFilter) markerFieldFilter;
        }
      }
      if (markerTypeFieldFilter == null)
        throw new NoSuchFieldException("No MarkerTypeFieldFilter at: " + MarkerFieldFilters);
      
      // actually set to show only DeepCode type markers
      Field selectedTypes = MarkerTypeFieldFilter.class.getDeclaredField("selectedTypes");
      selectedTypes.setAccessible(true);
      @SuppressWarnings("unchecked")
      Collection<MarkerType> selectedTypesCollection = (Collection<MarkerType>) selectedTypes.get(markerTypeFieldFilter);
      
      selectedTypesCollection.removeIf(markerType -> {return !markerType.getId().equals("ai.deepcode.deepcodemarker");});

    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
        | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException e) {
      e.printStackTrace();
    }
  }


Replace "DeepCodeMarkersFilter" with desired filter name;
Replace "ai.deepcode.deepcodemarker" with marker id to filter only;
Change filtersCollection method calls if you need to let user modify filter and save it between the session.

PS If anyone know better way to solve that issue - will highly appreciate any advice.
Re: How to Filter Problems View Programmatically [message #1830081 is a reply to message #1830054] Fri, 17 July 2020 04:13 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

What's the use case for this?

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: How to Filter Problems View Programmatically [message #1831528 is a reply to message #1830081] Fri, 21 August 2020 17:54 Go to previous message
Artsiom Chapialiou is currently offline Artsiom ChapialiouFriend
Messages: 3
Registered: July 2020
Junior Member
The use case: "How to Filter Problems View Programmatically"
Previous Topic:eclipsec.exe command line
Next Topic:Eclipse IDE for RCP (2020-06) hangs opening build.xml files
Goto Forum:
  


Current Time: Tue Apr 16 14:20:55 GMT 2024

Powered by FUDForum. Page generated in 0.04132 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top