<commit_before>package dynamake.tools;

import java.awt.Point;

import javax.swing.JComponent;

import dynamake.commands.PendingCommandState;
import dynamake.commands.RedoCommand;
import dynamake.commands.UndoCommand;
import dynamake.models.Model;
import dynamake.models.ModelComponent;
import dynamake.models.LiveModel.ProductionPanel;
import dynamake.transcription.Collector;
import dynamake.transcription.Connection;
import dynamake.transcription.TransactionHandler;
import dynamake.transcription.PostOnlyTransactionHandler;
import dynamake.transcription.SimplePendingCommandFactory;
import dynamake.transcription.Trigger;

public class UndoTool implements Tool {
	@Override
	public void mouseReleased(ProductionPanel productionPanel, final ModelComponent modelOver, Connection<Model> connection, Collector<Model> collector, JComponent sourceComponent, Point mousePoint) {
		collector.startTransaction(modelOver.getModelBehind(), PostOnlyTransactionHandler.class);
		collector.execute(new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
				if(modelOver.getModelBehind().canUndo()) {
					collector.execute(new SimplePendingCommandFactory<Model>(modelOver.getModelBehind(), new PendingCommandState<Model>(
						new UndoCommand(false),
						new RedoCommand(false)
					)) {
						@Override
						public Class<? extends TransactionHandler<Model>> getTransactionHandlerClass() {
							return PostOnlyTransactionHandler.class;
						}
					});
					
					collector.commitTransaction();
				}
			}
		});
	}

	@Override
	public void mousePressed(ProductionPanel productionPanel, ModelComponent modelOver, Connection<Model> connection, Collector<Model> collector, JComponent sourceComponent, Point mousePoint) { }

	@Override
	public void mouseDragged(ProductionPanel productionPanel, ModelComponent modelOver, Collector<Model> collector, Connection<Model> connection, JComponent sourceComponent, Point mousePoint) { }

	@Override
	public void rollback(ProductionPanel productionPanel, Collector<Model> collector) { }
}<commit_msg>Added rollback logic for collector in undo tool.<commit_after>package dynamake.tools;

import java.awt.Point;

import javax.swing.JComponent;

import dynamake.commands.PendingCommandState;
import dynamake.commands.RedoCommand;
import dynamake.commands.UndoCommand;
import dynamake.models.Model;
import dynamake.models.ModelComponent;
import dynamake.models.LiveModel.ProductionPanel;
import dynamake.transcription.Collector;
import dynamake.transcription.Connection;
import dynamake.transcription.TransactionHandler;
import dynamake.transcription.PostOnlyTransactionHandler;
import dynamake.transcription.SimplePendingCommandFactory;
import dynamake.transcription.Trigger;

public class UndoTool implements Tool {
	@Override
	public void mouseReleased(ProductionPanel productionPanel, final ModelComponent modelOver, Connection<Model> connection, Collector<Model> collector, JComponent sourceComponent, Point mousePoint) {
		collector.startTransaction(modelOver.getModelBehind(), PostOnlyTransactionHandler.class);
		collector.execute(new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
				if(modelOver.getModelBehind().canUndo()) {
					collector.execute(new SimplePendingCommandFactory<Model>(modelOver.getModelBehind(), new PendingCommandState<Model>(
						new UndoCommand(false),
						new RedoCommand(false)
					)) {
						@Override
						public Class<? extends TransactionHandler<Model>> getTransactionHandlerClass() {
							return PostOnlyTransactionHandler.class;
						}
					});
					
					collector.commitTransaction();
				}
			}
		});
	}

	@Override
	public void mousePressed(ProductionPanel productionPanel, ModelComponent modelOver, Connection<Model> connection, Collector<Model> collector, JComponent sourceComponent, Point mousePoint) { }

	@Override
	public void mouseDragged(ProductionPanel productionPanel, ModelComponent modelOver, Collector<Model> collector, Connection<Model> connection, JComponent sourceComponent, Point mousePoint) { }

	@Override
	public void rollback(ProductionPanel productionPanel, Collector<Model> collector) { 
		collector.rejectTransaction();
	}
}
{'fraction_non_alphanumeric': 0.08460438512869399, 'fraction_numerical': 0.0, 'mean_word_length': 6.37609841827768, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '118451', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1073, 'n_words': 238}