<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.java;

import java.util.List;

import org.eclipse.core.resources.IResource;
import org.eclipse.mylar.ide.MylarIdePlugin;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.team.internal.core.subscribers.ActiveChangeSet;
import org.eclipse.team.internal.core.subscribers.SubscriberChangeSetCollector;

/**
 * @author <NAME>
 */
public class TaskContextChangeSet extends ActiveChangeSet {

	private static final String LABEL_PREFIX = "Mylar Task";
	private List<IResource> resources;
	private ITask task;
	
	public TaskContextChangeSet(ITask task, SubscriberChangeSetCollector collector) {
		super(collector, LABEL_PREFIX);
		this.task = task;
		super.setTitle(LABEL_PREFIX + ": " + this.task.getDescription(true));
	}
	
	@Override
	public String getComment() {
		ITask task = TaskListView.getDefault().getSelectedTask();
		if (task != null) {
			return generateComment(task);
		} else {
			return "";
		}
	}
	
	@Override
	public IResource[] getResources() {
		if (MylarIdePlugin.getDefault() != null) {
			resources = MylarIdePlugin.getDefault().getInterestingResources();
		}
		return resources.toArray(new IResource[resources.size()]);
	}
	
    public boolean contains(IResource local) {
    	return resources.contains(local);
    }

	protected String generateComment(ITask task) {
		String prefix = "";
		if (task.isCompleted()) {
			prefix = "Completed "; 
		} else {
			prefix = "Progress on ";
		}
		if (task.isDirectlyModifiable()) {
			return prefix + task.getDescription(false);
		} else { // bug report
			return prefix + "Bug " + task.getDescription(false);
		}
	}
}
<commit_msg>Completed Bug 115705: dynamic change set in a sync view is not refreshed on task change<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.java;

import java.util.List;

import org.eclipse.core.resources.IResource;
import org.eclipse.mylar.ide.MylarIdePlugin;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.core.subscribers.ActiveChangeSet;
import org.eclipse.team.internal.core.subscribers.SubscriberChangeSetCollector;

/**
 * @author <NAME>
 */
public class TaskContextChangeSet extends ActiveChangeSet {

	private static final String LABEL_PREFIX = "Mylar Task";
	private List<IResource> resources;
	private ITask task;
	
	public TaskContextChangeSet(ITask task, SubscriberChangeSetCollector collector) {
		super(collector, LABEL_PREFIX);
		this.task = task;
		super.setTitle(LABEL_PREFIX + ": " + this.task.getDescription(true));
	}
	
	@Override
	public String getComment() {
		String prefix = "";
		if (task.isCompleted()) {
			prefix = "Completed "; 
		} else {
			prefix = "Progress on ";
		}
		if (task.isDirectlyModifiable()) {
			return prefix + task.getDescription(false);
		} else { // bug report
			return prefix + "Bug " + task.getDescription(false);
		}
	}
	
	@Override
	public void remove(IResource resource) {
		super.remove(resource);
		resources.remove(resource);
	}

	@Override
	public void remove(IResource[] newResources) {
		super.remove(newResources);
		for (int i = 0; i < newResources.length; i++) resources.remove(newResources[i]);
	} 

	@Override
	public void add(IResource[] newResources) throws TeamException {
		super.add(newResources);
		for (int i = 0; i < newResources.length; i++) resources.add(newResources[i]);
	}

	@Override
	public IResource[] getResources() {
		if (MylarIdePlugin.getDefault() != null) {
			resources = MylarIdePlugin.getDefault().getInterestingResources();
		}
		return resources.toArray(new IResource[resources.size()]);
	}
	
    public boolean contains(IResource local) {
    	return resources.contains(local);
    }

}

{'fraction_non_alphanumeric': 0.16878328553871363, 'fraction_numerical': 0.006554690700532569, 'mean_word_length': 4.751472320376914, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, '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': '5398904', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1367, 'n_words': 348}