<commit_before>/*
 * Copyright 2012 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.kie.workbench.common.screens.projecteditor.client.messages;

import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.ListDataProvider;
import org.guvnor.common.services.project.builder.model.BuildMessage;
import org.guvnor.common.services.project.builder.model.BuildResults;
import org.guvnor.common.services.project.builder.model.IncrementalBuildResults;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.client.workbench.PanelManager;

/**
 * Service for Message Console, the Console is a screen that shows compile time errors.
 * This listens to Messages and if the Console is not open it opens it.
 */
@ApplicationScoped
public class ProblemsService {

    private static final String HOME_PERSPECTIVE = "Home";
    private static final String ARTIFACT_PERSPECTIVE = "org.guvnor.m2repo.client.perspectives.GuvnorM2RepoPerspective";

    private final PlaceManager placeManager;
    private final PanelManager panelManager;
    private final ListDataProvider<BuildMessage> dataProvider = new ListDataProvider<BuildMessage>();

    @Inject
    public ProblemsService( final PlaceManager placeManager,
                            final PanelManager panelManager ) {
        this.placeManager = placeManager;
        this.panelManager = panelManager;
    }

    public void addBuildMessages( final @Observes BuildResults results ) {
        List<BuildMessage> list = dataProvider.getList();
        list.clear();
        for ( BuildMessage buildMessage : results.getMessages() ) {
            list.add( buildMessage );
        }
        if ( !panelManager.getPerspective().getName().equals( HOME_PERSPECTIVE ) ) {
            placeManager.goTo( "org.kie.guvnor.Problems" );
        }
    }

    public void addIncrementalBuildMessages( final @Observes IncrementalBuildResults results ) {
        final List<BuildMessage> addedMessages = results.getAddedMessages();
        final List<BuildMessage> removedMessages = results.getRemovedMessages();

        List<BuildMessage> list = dataProvider.getList();
        for ( BuildMessage buildMessage : removedMessages ) {
            list.remove( buildMessage );
        }
        for ( BuildMessage buildMessage : addedMessages ) {
            list.add( buildMessage );
        }
        if ( !panelManager.getPerspective().getName().equals( HOME_PERSPECTIVE ) &&
                !panelManager.getPerspective().getName().equals( ARTIFACT_PERSPECTIVE ) ) {
            placeManager.goTo( "org.kie.guvnor.Problems" );
        }
    }

    public void addDataDisplay( HasData<BuildMessage> display ) {
        dataProvider.addDataDisplay( display );
    }
}
<commit_msg>Showing Problems Panel only on Authoring Perspectives<commit_after>/*
 * Copyright 2012 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.kie.workbench.common.screens.projecteditor.client.messages;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.ListDataProvider;
import org.guvnor.common.services.project.builder.model.BuildMessage;
import org.guvnor.common.services.project.builder.model.BuildResults;
import org.guvnor.common.services.project.builder.model.IncrementalBuildResults;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.client.workbench.PanelManager;
import org.uberfire.client.workbench.events.PerspectiveChange;

/**
 * Service for Message Console, the Console is a screen that shows compile time errors.
 * This listens to Messages and if the Console is not open it opens it.
 */
@ApplicationScoped
public class ProblemsService {

    private final PlaceManager placeManager;
    private final PanelManager panelManager;
    private final ListDataProvider<BuildMessage> dataProvider = new ListDataProvider<BuildMessage>();

    private List<String> allowedPerspectives = new ArrayList<String>();

    private String currentPerspective;

    @Inject
    public ProblemsService( final PlaceManager placeManager,
                            final PanelManager panelManager ) {
        this.placeManager = placeManager;
        this.panelManager = panelManager;
    }

    @PostConstruct
    protected void init() {
        allowedPerspectives.add("org.kie.workbench.drools.client.perspectives.DroolsAuthoringPerspective");
        allowedPerspectives.add("org.kie.workbench.client.perspectives.DroolsAuthoringPerspective");
    }

    public void addBuildMessages( final @Observes BuildResults results ) {
        List<BuildMessage> list = dataProvider.getList();
        list.clear();
        for ( BuildMessage buildMessage : results.getMessages() ) {
            list.add( buildMessage );
        }
        if (allowedPerspectives.contains(currentPerspective)) {
            placeManager.goTo( "org.kie.guvnor.Problems" );
        }
    }

    public void addIncrementalBuildMessages( final @Observes IncrementalBuildResults results ) {
        final List<BuildMessage> addedMessages = results.getAddedMessages();
        final List<BuildMessage> removedMessages = results.getRemovedMessages();

        List<BuildMessage> list = dataProvider.getList();
        for ( BuildMessage buildMessage : removedMessages ) {
            list.remove( buildMessage );
        }
        for ( BuildMessage buildMessage : addedMessages ) {
            list.add( buildMessage );
        }
        if ( allowedPerspectives.contains(currentPerspective) ) {
            placeManager.goTo( "org.kie.guvnor.Problems" );
        }
    }

    public void addDataDisplay( HasData<BuildMessage> display ) {
        dataProvider.addDataDisplay( display );
    }

    public void onPerspectiveChange(@Observes PerspectiveChange perspectiveChange) {
        currentPerspective = perspectiveChange.getIdentifier();
    }
}

{'fraction_non_alphanumeric': 0.08586068411577344, 'fraction_numerical': 0.0024927295388450354, 'mean_word_length': 3.55359394703657, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1572622', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1863, 'n_words': 505}