<commit_before>package dynamake.dragndrop;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;

import javax.swing.JPopupMenu;

import dynamake.commands.DualCommand;
import dynamake.commands.DualCommandPair;
import dynamake.menubuilders.ActionRunner;
import dynamake.menubuilders.CompositeMenuBuilder;
import dynamake.models.Location;
import dynamake.models.Model;
import dynamake.models.ModelComponent;
import dynamake.models.LiveModel.LivePanel;
import dynamake.tools.InteractionPresenter;
import dynamake.transcription.DualCommandFactory;
import dynamake.transcription.Collector;
import dynamake.transcription.Connection;
import dynamake.transcription.Trigger;

public class ViewDragDropPopupBuilder implements DragDropPopupBuilder {
	private Connection<Model> connection; 
	private InteractionPresenter interactionPresenter;
	
	public ViewDragDropPopupBuilder(Connection<Model> connection, InteractionPresenter interactionPresenter) {
		this.connection = connection;
		this.interactionPresenter = interactionPresenter;
	}

	@Override
	public void buildFromSelectionAndTarget(final ModelComponent livePanel,
			JPopupMenu popup, final ModelComponent selection,
			final ModelComponent target, final Point dropPointOnTarget, final Rectangle dropBoundsOnTarget) {
		ActionRunner runner = new ActionRunner() {
			@Override
			public void run(final Object action) {
				connection.trigger(new Trigger<Model>() {
					@SuppressWarnings("unchecked")
					@Override
					public void run(Collector<Model> collector) {
						interactionPresenter.reset(collector);
						
						((Trigger<Model>)action).run(collector);
						collector.commit();
					}
				});
			}
		};
		
		CompositeMenuBuilder transactionTargetContentMapBuilder = new CompositeMenuBuilder();
		
		transactionTargetContentMapBuilder.addMenuBuilder("Appliance", new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
				collector.execute(new DualCommandFactory<Model>() {
					@Override
					public Model getReference() {
						return selection.getModelBehind();
					}
					
					@Override
					public void createDualCommands(Location location, List<DualCommand<Model>> dualCommands) {
						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
						if(currentView == null)
							currentView = Model.VIEW_APPLIANCE;
						dualCommands.add(new DualCommandPair<Model>(
							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, Model.VIEW_APPLIANCE),
							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, currentView)
						));
					}
				});
			}
		});
		
		transactionTargetContentMapBuilder.addMenuBuilder("Engineering", new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
				collector.execute(new DualCommandFactory<Model>() {
					@Override
					public Model getReference() {
						return selection.getModelBehind();
					}
					
					@Override
					public void createDualCommands(Location location, List<DualCommand<Model>> dualCommands) {
						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
						if(currentView == null)
							currentView = Model.VIEW_APPLIANCE;
						dualCommands.add(new DualCommandPair<Model>(
							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, Model.VIEW_ENGINEERING),
							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, currentView)
						));
					}
				});
			}
		});
		
		transactionTargetContentMapBuilder.appendTo(popup, runner, "Selection to target");
	}
	
	@Override
	public void cancelPopup(LivePanel livePanel) {
		connection.trigger(new Trigger<Model>() {
			public void run(Collector<Model> collector) {
				interactionPresenter.reset(collector);
				
				collector.reject();
			}
		});
	}
}<commit_msg>Added usage of command state in view tool.<commit_after>package dynamake.dragndrop;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;

import javax.swing.JPopupMenu;

import dynamake.commands.CommandState;
import dynamake.commands.CommandStateFactory;
import dynamake.commands.PendingCommandState;
import dynamake.commands.DualCommand;
import dynamake.commands.DualCommandPair;
import dynamake.menubuilders.ActionRunner;
import dynamake.menubuilders.CompositeMenuBuilder;
import dynamake.models.Location;
import dynamake.models.Model;
import dynamake.models.ModelComponent;
import dynamake.models.LiveModel.LivePanel;
import dynamake.tools.InteractionPresenter;
import dynamake.transcription.DualCommandFactory;
import dynamake.transcription.Collector;
import dynamake.transcription.Connection;
import dynamake.transcription.Trigger;

public class ViewDragDropPopupBuilder implements DragDropPopupBuilder {
	private Connection<Model> connection; 
	private InteractionPresenter interactionPresenter;
	
	public ViewDragDropPopupBuilder(Connection<Model> connection, InteractionPresenter interactionPresenter) {
		this.connection = connection;
		this.interactionPresenter = interactionPresenter;
	}

	@Override
	public void buildFromSelectionAndTarget(final ModelComponent livePanel,
			JPopupMenu popup, final ModelComponent selection,
			final ModelComponent target, final Point dropPointOnTarget, final Rectangle dropBoundsOnTarget) {
		ActionRunner runner = new ActionRunner() {
			@Override
			public void run(final Object action) {
				connection.trigger(new Trigger<Model>() {
					@SuppressWarnings("unchecked")
					@Override
					public void run(Collector<Model> collector) {
						interactionPresenter.reset(collector);
						
						((Trigger<Model>)action).run(collector);
						collector.commit();
					}
				});
			}
		};
		
		CompositeMenuBuilder transactionTargetContentMapBuilder = new CompositeMenuBuilder();
		
		transactionTargetContentMapBuilder.addMenuBuilder("Appliance", new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
//				collector.execute(new DualCommandFactory<Model>() {
//					@Override
//					public Model getReference() {
//						return selection.getModelBehind();
//					}
//					
//					@Override
//					public void createDualCommands(Location location, List<DualCommand<Model>> dualCommands) {
//						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
//						if(currentView == null)
//							currentView = Model.VIEW_APPLIANCE;
//						dualCommands.add(new DualCommandPair<Model>(
//							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, Model.VIEW_APPLIANCE),
//							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, currentView)
//						));
//					}
//				});
				
				collector.execute(new CommandStateFactory<Model>() {
					@Override
					public Model getReference() {
						return selection.getModelBehind();
					}
					
					@Override
					public void createDualCommands(List<CommandState<Model>> commandStates) {
						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
						if(currentView == null)
							currentView = Model.VIEW_APPLIANCE;
						commandStates.add(new PendingCommandState<Model>(
							new Model.SetPropertyCommand2(Model.PROPERTY_VIEW, Model.VIEW_APPLIANCE),
							new Model.SetPropertyCommand2(Model.PROPERTY_VIEW, currentView)
						));
					}
				});
			}
		});
		
		transactionTargetContentMapBuilder.addMenuBuilder("Engineering", new Trigger<Model>() {
			@Override
			public void run(Collector<Model> collector) {
//				collector.execute(new DualCommandFactory<Model>() {
//					@Override
//					public Model getReference() {
//						return selection.getModelBehind();
//					}
//					
//					@Override
//					public void createDualCommands(Location location, List<DualCommand<Model>> dualCommands) {
//						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
//						if(currentView == null)
//							currentView = Model.VIEW_APPLIANCE;
//						dualCommands.add(new DualCommandPair<Model>(
//							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, Model.VIEW_ENGINEERING),
//							new Model.SetPropertyCommand(location, Model.PROPERTY_VIEW, currentView)
//						));
//					}
//				});
				
				collector.execute(new CommandStateFactory<Model>() {
					@Override
					public Model getReference() {
						return selection.getModelBehind();
					}
					
					@Override
					public void createDualCommands(List<CommandState<Model>> commandStates) {
						Integer currentView = (Integer)selection.getModelBehind().getProperty(Model.PROPERTY_VIEW);
						if(currentView == null)
							currentView = Model.VIEW_APPLIANCE;
						commandStates.add(new PendingCommandState<Model>(
							new Model.SetPropertyCommand2(Model.PROPERTY_VIEW, Model.VIEW_ENGINEERING),
							new Model.SetPropertyCommand2(Model.PROPERTY_VIEW, currentView)
						));
					}
				});
			}
		});
		
		transactionTargetContentMapBuilder.appendTo(popup, runner, "Selection to target");
	}
	
	@Override
	public void cancelPopup(LivePanel livePanel) {
		connection.trigger(new Trigger<Model>() {
			public void run(Collector<Model> collector) {
				interactionPresenter.reset(collector);
				
				collector.reject();
			}
		});
	}
}
{'fraction_non_alphanumeric': 0.1000651182982418, 'fraction_numerical': 0.0004341219882787063, 'mean_word_length': 4.311239193083574, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '6034598', 'n_tokens_mistral': 3217, 'n_tokens_neox': 2579, 'n_words': 467}