<commit_before>/*******************************************************************************
 * Copyright (c) 2004 - 2005 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.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.core.IMylarContext;
import org.eclipse.mylar.core.IMylarContextListener;
import org.eclipse.mylar.core.IMylarContextNode;
import org.eclipse.mylar.core.IMylarStructureBridge;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.ui.actions.ApplyMylarToProblemsListAction;
import org.eclipse.mylar.ui.internal.BrowseFilteredListener;
import org.eclipse.mylar.ui.internal.UiUtil;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.internal.Workbench;

/**
 * @author <NAME>
 */
public class MylarViewerManager implements IMylarContextListener {
	
	private List<StructuredViewer> managedViewers = new ArrayList<StructuredViewer>();
	private Map<StructuredViewer, BrowseFilteredListener> listenerMap = new HashMap<StructuredViewer, BrowseFilteredListener>();
	
	public void addManagedViewer(StructuredViewer viewer) {
		managedViewers.add(viewer);
		BrowseFilteredListener listener = new BrowseFilteredListener(viewer);
		listenerMap.put(viewer, listener);
		viewer.getControl().addMouseListener(listener);
	}
	
	public void removeManagedViewer(StructuredViewer viewer) {
		managedViewers.remove(viewer);
		BrowseFilteredListener listener = listenerMap.get(viewer);
		if (listener != null) {
			viewer.getControl().removeMouseListener(listener);
		}  
	}
	
	public void contextActivated(IMylarContext taskscape) {
        IMylarContextNode activeNode = taskscape.getActiveNode();
        if (activeNode != null) {
            MylarUiPlugin.getDefault().getUiBridge(activeNode.getStructureKind()).open(activeNode);
        }
        refreshViewers();
    }

    public void contextDeactivated(IMylarContext context) {
//    	boolean confirmed = IDE.saveAllEditors(ResourcesPlugin.getWorkspace().getRoot().getProjects(), true);
//        if (confirmed) {
        	if (MylarUiPlugin.getPrefs().getBoolean(MylarPlugin.TASKLIST_EDITORS_CLOSE)) {
        		UiUtil.closeAllEditors(true);
        	} else {
        		// TODO: enable closing of interesting editors
//		    	for (IMylarContextNode node : MylarPlugin.getContextManager().getInterestingResources(context)) {
//		            MylarUiPlugin.getDefault().getUiBridge(node.getStructureKind()).close(node);
//		        }       		
        	}
//        }
        refreshViewers();<commit_msg>Minor change to refresh order<commit_after>/*******************************************************************************
 * Copyright (c) 2004 - 2005 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.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.core.IMylarContext;
import org.eclipse.mylar.core.IMylarContextListener;
import org.eclipse.mylar.core.IMylarContextNode;
import org.eclipse.mylar.core.IMylarStructureBridge;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.ui.actions.ApplyMylarToProblemsListAction;
import org.eclipse.mylar.ui.internal.BrowseFilteredListener;
import org.eclipse.mylar.ui.internal.UiUtil;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.internal.Workbench;

/**
 * @author <NAME>
 */
public class MylarViewerManager implements IMylarContextListener {
	
	private List<StructuredViewer> managedViewers = new ArrayList<StructuredViewer>();
	private Map<StructuredViewer, BrowseFilteredListener> listenerMap = new HashMap<StructuredViewer, BrowseFilteredListener>();
	
	public void addManagedViewer(StructuredViewer viewer) {
		managedViewers.add(viewer);
		BrowseFilteredListener listener = new BrowseFilteredListener(viewer);
		listenerMap.put(viewer, listener);
		viewer.getControl().addMouseListener(listener);
	}
	
	public void removeManagedViewer(StructuredViewer viewer) {
		managedViewers.remove(viewer);
		BrowseFilteredListener listener = listenerMap.get(viewer);
		if (listener != null) {
			viewer.getControl().removeMouseListener(listener);
		}  
	}
	
	public void contextActivated(IMylarContext taskscape) {
        IMylarContextNode activeNode = taskscape.getActiveNode();
        if (activeNode != null) {
            MylarUiPlugin.getDefault().getUiBridge(activeNode.getStructureKind()).open(activeNode);
        }
        refreshViewers();
    }

    public void contextDeactivated(IMylarContext context) {
        refreshViewers();
//    	boolean confirmed = IDE.saveAllEditors(ResourcesPlugin.getWorkspace().getRoot().getProjects(), true);
//      if (confirmed) {
      	if (MylarUiPlugin.getPrefs().getBoolean(MylarPlugin.TASKLIST_EDITORS_CLOSE)) {
      		UiUtil.closeAllEditors(true);
      	} else {
      		// TODO: enable closing of interesting editors
//		    	for (IMylarContextNode node : MylarPlugin.getContextManager().getInterestingResources(context)) {
//		            MylarUiPlugin.getDefault().getUiBridge(node.getStructureKind()).close(node);
//		        }       		
      	}
{'fraction_non_alphanumeric': 0.14743172951885566, 'fraction_numerical': 0.0039011703511053317, 'mean_word_length': 4.697222222222222, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '142282', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1747, 'n_words': 333}