package org.cytoscape.view.vizmap.gui.internal.bypass;

import java.awt.Component;

import org.cytoscape.model.CyTableEntry;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.vizmap.gui.SelectedVisualStyleManager;
import org.cytoscape.view.vizmap.gui.editor.ValueEditor;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.TaskMonitor;

/**
 * Task to execute visual style bypass.
 * 
 * @param <T>
 */
public class BypassTask<T extends CyTableEntry> extends AbstractTask {

	// Target view object. Node or Edge.
	private final View<T> view;
	private final VisualProperty<Object> vp;
	private final ValueEditor<Object> editor;

	private final Component parent;
	private final CyNetworkView networkView;
	
	private final SelectedVisualStyleManager selectedManager;

	public BypassTask(Component parent, ValueEditor<?> editor,
			final VisualProperty<?> vp, final View<T> view,
			final CyNetworkView networkView, final SelectedVisualStyleManager selectedManager) {
		this.view = view;
		this.vp = (VisualProperty<Object>) vp;
		this.editor = (ValueEditor<Object>) editor;
		this.parent = parent;

		this.networkView = networkView;
		this.selectedManager = selectedManager;
	}

	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {

		final boolean lock = view.isValueLocked(vp);

		if (!lock) {
			final Object newValue = editor.showEditor(parent,
					view.getVisualProperty(vp));
			view.setLockedValue(vp, newValue);
		} else {
			// Unlock it
			view.clearValueLock(vp);
		}
		
		selectedManager.getCurrentVisualStyle().apply(networkView);
		networkView.updateView();
	}

}

@@ -819,17 +819,16 @@
 rkView;%0A
-%09
 %0A%09privat
@@ -939,20 +939,17 @@
  editor,
-%0A%09%09%09
+ 
 final Vi
@@ -1480,14 +1480,9 @@
 ent,
-%0A%09%09%09%09%09
+ 
 view
@@ -1603,18 +1603,16 @@
 p);%0A%09%09%7D%0A
-%09%09
 %0A%09%09selec

Reformat only.