<commit_before>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.java.ui.actions;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.internal.ui.filters.ImportDeclarationFilter;
import org.eclipse.jdt.internal.ui.filters.PackageDeclarationFilter;
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
import org.eclipse.mylar.internal.java.MylarJavaPlugin;
import org.eclipse.mylar.internal.java.MylarJavaPrefConstants;
import org.eclipse.mylar.internal.java.ui.JavaDeclarationsFilter;
import org.eclipse.mylar.internal.ui.actions.AbstractApplyMylarAction;
import org.eclipse.mylar.provisional.ui.InterestFilter;
import org.eclipse.mylar.provisional.ui.MylarUiPlugin;
import org.eclipse.ui.IViewPart;

/**
 * @author <NAME>
 */
public class ApplyMylarToPackageExplorerAction extends AbstractApplyMylarAction implements IPropertyChangeListener {

	public ApplyMylarToPackageExplorerAction() {
		super(new InterestFilter());
		MylarJavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
	} 
	
	public void init(IAction action) {
		super.init(action);
		configureAction();
	}

	@Override
	public void update() {
		super.update();
		configureAction();
	}

	@Override
	protected void valueChanged(IAction action, boolean on, boolean store) {
		super.valueChanged(action, on, store);
	}
	
	@Override
	public List<StructuredViewer> getViewers() {
		List<StructuredViewer> viewers = new ArrayList<StructuredViewer>();
		// TODO: get from super
		IViewPart part = super.getPartForAction();
		if (part instanceof PackageExplorerPart) {
			viewers.add(((PackageExplorerPart)part).getTreeViewer());
		}
		return viewers;
	}

	public void propertyChange(PropertyChangeEvent event) {
		if (MylarJavaPrefConstants.PACKAGE_EXPLORER_AUTO_FILTER_ENABLE.equals(event.getProperty())) {
			configureAction();
		}
	}

	private void configureAction() {
		try {
			if (MylarJavaPlugin.getDefault().getPreferenceStore().getBoolean(
					MylarJavaPrefConstants.PACKAGE_EXPLORER_AUTO_FILTER_ENABLE)) {
				MylarUiPlugin.getDefault().getViewerManager().addManagedAction(this);
			} else if (MylarUiPlugin.getDefault() != null) {
				MylarUiPlugin.getDefault().getViewerManager().removeManagedAction(this);
			}
		} catch (Exception e) {
			MylarStatusHandler.fail(e, "could not toggle Mylar on view: " + getPartForAction(), true);
		}
	}

	public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
		// ignore
	}
	
	@Override
	public List<Class> getPreservedFilters() {
		List<Class> preserved = new ArrayList<Class>();
		preserved.add(ImportDeclarationFilter.class);
		preserved.add(PackageDeclarationFilter.class);
		preserved.add(JavaDeclarationsFilter.class);
		return preserved;
	}
}<commit_msg>Progress on: merge 0.6 with 3.1<commit_after>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.java.ui.actions;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.internal.ui.filters.ImportDeclarationFilter;
import org.eclipse.jdt.internal.ui.filters.PackageDeclarationFilter;
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
import org.eclipse.mylar.internal.java.MylarJavaPlugin;
import org.eclipse.mylar.internal.java.MylarJavaPrefConstants;
import org.eclipse.mylar.internal.java.ui.JavaDeclarationsFilter;
import org.eclipse.mylar.internal.ui.actions.AbstractApplyMylarAction;
import org.eclipse.mylar.provisional.ui.InterestFilter;
import org.eclipse.mylar.provisional.ui.MylarUiPlugin;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;

/**
 * @author <NAME>
 */
public class ApplyMylarToPackageExplorerAction extends AbstractApplyMylarAction implements IPropertyChangeListener {

	public ApplyMylarToPackageExplorerAction() {
		super(new InterestFilter());
		MylarJavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
	}

	public void init(IAction action) {
		super.init(action);
		configureAction();
	}

	@Override
	public void update() {
		super.update();
		configureAction();
	}

	@Override
	protected void valueChanged(IAction action, boolean on, boolean store) {
		super.valueChanged(action, on, store);
	}

	@Override
	public List<StructuredViewer> getViewers() {
		List<StructuredViewer> viewers = new ArrayList<StructuredViewer>();
		// TODO: get from super
		IViewPart part = super.getPartForAction();
		if (part instanceof PackageExplorerPart) {
			viewers.add(((PackageExplorerPart) part).getTreeViewer());
		}
		return viewers;
	}

	public void propertyChange(PropertyChangeEvent event) {
		if (MylarJavaPrefConstants.PACKAGE_EXPLORER_AUTO_FILTER_ENABLE.equals(event.getProperty())) {
			configureAction();
		}
	}

	private void configureAction() {
		// can't do htis until the workbench/view is active
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

			public void run() {
				try {
					if (MylarJavaPlugin.getDefault().getPreferenceStore().getBoolean(
							MylarJavaPrefConstants.PACKAGE_EXPLORER_AUTO_FILTER_ENABLE)) {
						MylarUiPlugin.getDefault().getViewerManager().addManagedAction(ApplyMylarToPackageExplorerAction.this);
					} else if (MylarUiPlugin.getDefault() != null) {
						MylarUiPlugin.getDefault().getViewerManager().removeManagedAction(ApplyMylarToPackageExplorerAction.this);
					}
				} catch (Exception e) {
					MylarStatusHandler.fail(e, "could not toggle Mylar on view: " + getPartForAction(), true);
				}
			}
		});
	}

	public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
		// ignore
	}

	@Override
	public List<Class> getPreservedFilters() {
		List<Class> preserved = new ArrayList<Class>();
		preserved.add(ImportDeclarationFilter.class);
		preserved.add(PackageDeclarationFilter.class);
		preserved.add(JavaDeclarationsFilter.class);
		return preserved;
	}
}
{'fraction_non_alphanumeric': 0.14387044967880086, 'fraction_numerical': 0.003747323340471092, 'mean_word_length': 5.702242152466368, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1095662', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2180, 'n_words': 413}