<commit_before>package org.openlca.app.editors.graphical.edit;


import java.beans.PropertyChangeEvent;
import java.util.Collections;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.*;
import org.eclipse.gef.commands.CommandStack;
import org.openlca.app.tools.graphics.figures.GridPos;
import org.openlca.app.editors.graphical.figures.MaximizedNodeFigure;
import org.openlca.app.editors.graphical.figures.MinimizedNodeFigure;
import org.openlca.app.editors.graphical.figures.NodeFigure;
import org.openlca.app.tools.graphics.model.Component;
import org.openlca.app.editors.graphical.model.Node;
import org.openlca.app.editors.graphical.requests.ExpandCollapseRequest;

import static org.openlca.app.tools.graphics.model.Side.INPUT;
import static org.openlca.app.tools.graphics.model.Side.OUTPUT;

public abstract class NodeEditPart extends AbstractVertexEditPart<Node> {

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeEditPolicy());
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,
				new NodeSelectionEditPolicy());
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		String prop = evt.getPropertyName();
		if (Component.SIZE_PROP.equals(prop)
			|| Component.LOCATION_PROP.equals(prop)
		  || Node.EXPANDED_PROP.equals(prop))
			refreshVisuals();
		else super.propertyChange(evt);
	}

	@Override
	public void performRequest(Request request) {
		if (request.getType() == RequestConstants.REQ_OPEN) {
			CommandStack stack = getViewer().getEditDomain().getCommandStack();
			var command = getCommand(request);
			if (command != null && command.canExecute()) {
				stack.execute(command);
			}
		}
	}

	@Override
	protected void refreshVisuals() {
		var bounds = new Rectangle(getModel().getLocation(), getModel().getSize());
		((GraphicalEditPart) getParent()).setLayoutConstraint(this,
			getFigure(), bounds);
		super.refreshVisuals();
	}

	protected void addButtonActionListener(NodeFigure figure) {
		figure.inputExpandButton.addActionListener($ -> {
			var command = getCommand(new ExpandCollapseRequest(getModel(), INPUT));
			if (command.canExecute())
				getViewer().getEditDomain().getCommandStack().execute(command);
		});
		figure.outputExpandButton.addActionListener($ -> {
			var command = getCommand(new ExpandCollapseRequest(getModel(), OUTPUT));
			if (command.canExecute())
				getViewer().getEditDomain().getCommandStack().execute(command);<commit_msg>Remove operation that was revealing the figures when clicking on it.<commit_after>package org.openlca.app.editors.graphical.edit;


import java.beans.PropertyChangeEvent;
import java.util.Collections;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.*;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.tools.TargetingTool;
import org.openlca.app.tools.graphics.figures.GridPos;
import org.openlca.app.editors.graphical.figures.MaximizedNodeFigure;
import org.openlca.app.editors.graphical.figures.MinimizedNodeFigure;
import org.openlca.app.editors.graphical.figures.NodeFigure;
import org.openlca.app.tools.graphics.model.Component;
import org.openlca.app.editors.graphical.model.Node;
import org.openlca.app.editors.graphical.requests.ExpandCollapseRequest;

import static org.openlca.app.tools.graphics.model.Side.INPUT;
import static org.openlca.app.tools.graphics.model.Side.OUTPUT;

public abstract class NodeEditPart extends AbstractVertexEditPart<Node> {

	@Override
	public DragTracker getDragTracker(Request request) {
		return new org.eclipse.gef.tools.DragEditPartsTracker(this) {
			/**
			 * This method is overriden to remove the use of
			 * <code>getCurrentViewer().reveal(getSourceEditPart());</code> in
			 * SelectEditPartTracker that moves the Canvas when clicking on a Node.
			 * @param button
			 *            the button being released
			 * @return
			 */
			@Override
			protected boolean handleButtonUp(int button) {
				if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
					eraseSourceFeedback();
					eraseTargetFeedback();
					performDrag();
					return true;
				}
				if (isInState(STATE_DRAG)) {
					performSelection();
					if (getFlag(TargetingTool.MAX_FLAG << 2))
						performDirectEdit();
					setState(STATE_TERMINAL);
					return true;
				}
				return false;
			}
		};
	}

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeEditPolicy());
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,
				new NodeSelectionEditPolicy());
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		String prop = evt.getPropertyName();
		if (Component.SIZE_PROP.equals(prop)
				|| Component.LOCATION_PROP.equals(prop)
				|| Node.EXPANDED_PROP.equals(prop))
			refreshVisuals();
		else super.propertyChange(evt);
	}

	@Override
	public void performRequest(Request request) {
		if (request.getType() == RequestConstants.REQ_OPEN) {
			CommandStack stack = getViewer().getEditDomain().getCommandStack();
			var command = getCommand(request);
			if (command != null && command.canExecute()) {
				stack.execute(command);
			}
		}
	}

	@Override
	protected void refreshVisuals() {
		var bounds = new Rectangle(getModel().getLocation(), getModel().getSize());
		((GraphicalEditPart) getParent()).setLayoutConstraint(this,
				getFigure(), bounds);
		super.refreshVisuals();
	}

	protected void addButtonActionListener(NodeFigure figure) {
		figure.inputExpandButton.addActionListener($ -> {
			var command = getCommand(new ExpandCollapseRequest(getModel(), INPUT));
			if (command.canExecute())
				getViewer().getEditDomain().getCommandStack().execute(command);
		});
		figure.outputExpandButton.addActionListener($ -> {
			var command = getCommand(new ExpandCollapseRequest(getModel(), OUTPUT));
			if (command.canExecute())
				getViewer().getEditDomain().getCommandStack().execute(command);
{'fraction_non_alphanumeric': 0.11902002979639133, 'fraction_numerical': 0.0008276775368316504, 'mean_word_length': 5.222451081359424, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '139832', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1831, 'n_words': 316}