<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.felix.sigil.eclipse.ui.internal.views.resolution;

import org.apache.felix.sigil.eclipse.SigilCore;
import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPartReference;

public class EditorViewPartListener implements IPartListener2
{

    private BundleResolverView bundleResolverView;

    public EditorViewPartListener(BundleResolverView bundleResolverView)
    {
        this.bundleResolverView = bundleResolverView;
    }

    public void partActivated(IWorkbenchPartReference partRef)
    {
        checkRef(partRef);
    }

    public void partBroughtToTop(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partClosed(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partDeactivated(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partHidden(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partInputChanged(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partOpened(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partVisible(IWorkbenchPartReference partRef)
    {
        // no action
    }

    private void checkRef(IWorkbenchPartReference partRef)
    {
        IEditorPart editor = partRef.getPage().getActiveEditor();
        if (editor != null)
        {
            IEditorInput input = editor.getEditorInput();
            if (input instanceof IFileEditorInput)
            {
                IFileEditorInput f = (IFileEditorInput) input;
                IProject project = f.getFile().getProject();
                try
                {
                    ISigilProjectModel model = SigilCore.create(project);
                    if (model != null)
                    {
                        bundleResolverView.setInput(model);
                    }
                }
                catch (CoreException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

}<commit_msg>tidy up noisy exception when using sigil with non sigil projects<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.felix.sigil.eclipse.ui.internal.views.resolution;

import org.apache.felix.sigil.eclipse.SigilCore;
import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPartReference;

public class EditorViewPartListener implements IPartListener2
{

    private BundleResolverView bundleResolverView;

    public EditorViewPartListener(BundleResolverView bundleResolverView)
    {
        this.bundleResolverView = bundleResolverView;
    }

    public void partActivated(IWorkbenchPartReference partRef)
    {
        checkRef(partRef);
    }

    public void partBroughtToTop(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partClosed(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partDeactivated(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partHidden(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partInputChanged(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partOpened(IWorkbenchPartReference partRef)
    {
        // no action
    }

    public void partVisible(IWorkbenchPartReference partRef)
    {
        // no action
    }

    private void checkRef(IWorkbenchPartReference partRef)
    {
        IEditorPart editor = partRef.getPage().getActiveEditor();
        if (editor != null)
        {
            IEditorInput input = editor.getEditorInput();
            if (input instanceof IFileEditorInput)
            {
                IFileEditorInput f = (IFileEditorInput) input;
                IProject project = f.getFile().getProject();
                if ( SigilCore.isSigilProject(project)) {
                    try
                    {
                        ISigilProjectModel model = SigilCore.create(project);
                        if (model != null)
                        {
                            bundleResolverView.setInput(model);
                        }
                    }
                    catch (CoreException e)
                    {
                        SigilCore.error("Failed to update resolver view", e);
                    }
                }
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.07027840481565087, 'fraction_numerical': 0.0018058690744920992, 'mean_word_length': 2.2999006951340615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2283159', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1676, 'n_words': 479}