Tree view prior update of state machine selection
356488
def update_selection_self_prior(self):
        """"""
        if self._do_selection_update:
            return
        self._do_selection_update = True
        tree_selection, selected_model_list, sm_selection, sm_selected_model_set = self.get_selections()
        if isinstance(sm_selection, Selection):
            # current sm_selected_model_set will be updated and hand it back
            self.iter_tree_with_handed_function(self.update_selection_self_prior_condition,
                                                sm_selected_model_set, selected_model_list)
            sm_selection.handle_prepared_selection_of_core_class_elements(self.CORE_ELEMENT_CLASS, sm_selected_model_set)
            # TODO check if we can solve the difference that occurs e.g. while complex actions?, or same state paths!
            # -> models in selection for core element not in the tree the function iter tree + condition tolerates this
            if not set(selected_model_list) == sm_selected_model_set:
                self._logger.verbose("Difference between tree view selection: \n{0} \nand state machine selection: "
                                     "\n{1}".format(set(selected_model_list), sm_selected_model_set))

        # TODO check why sometimes not consistent with sm selection. e.g while modification history test
        if self.check_selection_consistency(sm_check=False):
            self.update_selection_sm_prior()
        self._do_selection_update = False
1304752
def execution_history_focus(self, model, prop_name, info):
        
        if state_machine_execution_engine.status.execution_mode in \
                [StateMachineExecutionStatus.STARTED, StateMachineExecutionStatus.STOPPED,
                 StateMachineExecutionStatus.FINISHED]:
            if self.parent is not None and hasattr(self.parent, "focus_notebook_page_of_controller"):
                # request focus -> which has not have to be satisfied
                self.parent.focus_notebook_page_of_controller(self)

        if state_machine_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
            if not self.model.selected_state_machine_id == self.model.state_machine_manager.active_state_machine_id:
                pass
            else:
                self.update()
1151690
protected void updateOutgoingEdgesStateDL(
			int currS, int currL,
			int prevS, int prevL,
			Emissions emission
	){
		updateOutgoingEdges(currS, currL, States.DL, prevS, prevL, States.DL, Transitions.t_DL_in, emission);
		updateOutgoingEdges(currS, currL, States.DL, prevS, prevL, States.S, Transitions.t_S_to_DL, emission);
	}
318694
def search_for_present_state_root(blockstore, state_view_factory):
    
    # If there is no chain to process, then we are done.
    block = blockstore.chain_head
    if block is None:
        return None, None

    # Check the head first
    if state_db_has_root(state_view_factory, block.state_root_hash):
        return None, None

    prev_state_root = INIT_ROOT_KEY
    for block in blockstore.get_block_iter(reverse=False):
        if not state_db_has_root(state_view_factory, block.state_root_hash):
            return block, prev_state_root
        prev_state_root = block.state_root_hash

    # This should never happen, since we already checked that the chain head
    # didn't have a state root
    raise ExecutionError(
        "Chain head state both missing but all blocks had state root present")
1261235
private void updateSelection(Object node)
    {
        State newState = getSelectionState(node);
        List<Object> descendants = 
            JTrees.getAllDescendants(getModel(), node);
        for (Object descendant : descendants)
        {
            setSelectionState(descendant, newState, false);
        }
        
        Object ancestor = JTrees.getParent(getModel(), node);
        while (ancestor != null)
        {
            List<Object> childrenOfAncestor = 
                JTrees.getChildren(getModel(), ancestor);
            State stateForAncestor = computeState(childrenOfAncestor);
            setSelectionState(ancestor, stateForAncestor, false);
            ancestor = JTrees.getParent(getModel(), ancestor);
        }
    }
475853
function (state, action) {
    const {bunsenId, value} = action

    const newState = {
      lastAction: CHANGE_VALUE
    }

    if (bunsenId === null) {
      Object.assign(newState, changeEntireFormValue({
        model: state.model,
        nextValue: value,
        prevValue: state.value
      }))
    } else {
      Object.assign(newState, changeNestedFormValue({
        bunsenId,
        formValue: state.value,
        model: state.model,
        value
      }))
    }

    newState.model = state.model || state.baseModel

    // If the value actually changed then we need to re-compute the model and view
    // so conditionals are correctly applied
    if (newState.valueChangeSet.size > 0) {
      const newModel = evaluateConditions(state.baseModel, newState.value, undefined, newState.value)
      newState.model = _.isEqual(state.model, newModel) ? state.model : newModel

      if (state.baseView) {
        const newView = evaluateViewConditions(state.baseView, newState.value)
        newState.view = _.isEqual(state.view, newView) ? state.view : newView
      }
    }

    return _.defaults(newState, state)
  }
11257
def _add_new_state(self, *event, **kwargs):
        
        if react_to_event(self.view, self.view['state_machine_tree_view'], event):
            state_type = StateType.EXECUTION if 'state_type' not in kwargs else kwargs['state_type']
            gui_helper_state_machine.add_new_state(self._selected_sm_model, state_type)
            return True
1343658
function () {
			var oModel = this._oDialog.getModel("view"),
				oTreeData = oModel.getProperty("/DebugModules")[0];

			this._treeHelper.recursiveSelect(oTreeData, false);
			this._updateTreeInfos();
		}
784061
public static void apply(Program program, TreeGP manager)
   {
      int iMaxProgramDepth = manager.getMaxProgramDepth();
      TGPMutationStrategy method = manager.getMutationStrategy();
      RandEngine randEngine = manager.getRandEngine();
      
      if (method == TGPMutationStrategy.MUTATION_SUBTREE || method == TGPMutationStrategy.MUTATION_SUBTREE_KINNEAR)
      {
         TreeNode node = program.anyNode(randEngine)._1();
         int depth = program.calcDepth();

         TreeNode root = program.getRoot();

         if (method == TGPMutationStrategy.MUTATION_SUBTREE)
         {
            int node_depth = root.depth2Node(node);
            node.getChildren().clear();

            node.setPrimitive(program.anyPrimitive(randEngine));

            if (!node.getPrimitive().isTerminal())
            {
               int max_depth = iMaxProgramDepth - node_depth;
               TreeGenerator.createWithDepth(program, node, max_depth, TGPInitializationStrategy.INITIALIZATION_METHOD_GROW, randEngine);
            }
         }
         else
         {
            int subtree_depth = root.depth2Node(node);
            int current_depth = depth - subtree_depth;
            int max_depth = (int)(depth * 1.15) - current_depth;

            node.getChildren().clear();
            node.setPrimitive(program.anyPrimitive(randEngine));

            if (!node.getPrimitive().isTerminal())
            {
               TreeGenerator.createWithDepth(program, node, max_depth, TGPInitializationStrategy.INITIALIZATION_METHOD_GROW, randEngine);
            }
         }
      }
      else if (method == TGPMutationStrategy.MUTATION_HOIST)
      {
         TreeNode node = program.anyNode(randEngine)._1();

         if (node != program.getRoot())
         {
            program.setRoot(node);
         }
      }
      else if (method == TGPMutationStrategy.MUTATION_SHRINK)
      {
         TreeNode node = program.anyNode(randEngine)._1();
         node.getChildren().clear();
         node.setPrimitive(program.anyTerminal(randEngine));
      }

      program.calcDepth();
      program.calcLength();
   }
874059
def _execute_current_child(self):
        

        self.child_state.input_data = self.get_inputs_for_state(self.child_state)
        self.child_state.output_data = self.create_output_dictionary_for_state(self.child_state)

        # process data of last state
        if self.last_error:
            self.child_state.input_data['error'] = copy.deepcopy(self.last_error)
        self.last_error = None
        if self.last_child:
            # do not set the last state to inactive before executing the new one
            self.last_child.state_execution_status = StateExecutionStatus.INACTIVE

        self.child_state.generate_run_id()
        if not self.backward_execution:  # only add history item if it is not a backward execution
            self.execution_history.push_call_history_item(
                self.child_state, CallType.EXECUTE, self, self.child_state.input_data)
        self.child_state.start(self.execution_history, backward_execution=self.backward_execution,
                               generate_run_id=False)

        self.child_state.join()

        # this line is important to indicate the parent the current execution status
        # it may also change during the execution of an hierarchy state
        # e.g. a hierarchy state may be started in forward execution mode but can leave in backward execution mode
        # print(self.child_state)
        # print(self.child_state.backward_execution)
        self.backward_execution = self.child_state.backward_execution
        # for h in self.execution_history._history_items:
        #     print(h)

        if self.preempted:
            if self.backward_execution:
                # this is the case if the user backward step through its state machine and stops it
                # as preemption behaviour in backward mode is not defined, set the state to forward mode
                # to ensure clean state machine shutdown
                self.backward_execution = False

        # set last_error and self.last_child
        if self.child_state.final_outcome is not None:  # final outcome can be None if only one state in a
            # hierarchy state is executed and immediately backward executed
            if self.child_state.final_outcome.outcome_id == -1:  # if the child_state aborted save the error
                self.last_error = ""
                if 'error' in self.child_state.output_data:
                    self.last_error = self.child_state.output_data['error']
        self.last_child = self.child_state
561545
private Collection<State> updateStateListForChar(Iterable<State> states, int index) {
    Collection<State> result = new LinkedList<>();
    for (State state : states) {
      updateStateForChar(state, index, result);
    }
    return simplifyStates(result);
  }
1288444
def clean_history(self, widget, event=None):
        
        self.history_tree_store.clear()
        selected_sm_m = self.model.get_selected_state_machine_model()
        if selected_sm_m:
            # the core may continue running without the GUI and for this it needs its execution histories
            if state_machine_execution_engine.finished_or_stopped():
                selected_sm_m.state_machine.destroy_execution_histories()
                self.update()
355768
private void postTraversalProcessing() {
		int nc1 = treeSize;
		info[KR] = new int[leafCount];
		info[RKR] = new int[leafCount];

		int lc = leafCount;
		int i = 0;

		// compute left-most leaf descendants
		// go along the left-most path, remember each node and assign to it the path's
		// leaf
		// compute right-most leaf descendants (in reversed postorder)
		for (i = 0; i < treeSize; i++) {
			if (paths[LEFT][i] == -1) {
				info[POST2_LLD][i] = i;
			} else {
				info[POST2_LLD][i] = info[POST2_LLD][paths[LEFT][i]];
			}
			if (paths[RIGHT][i] == -1) {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						(treeSize - 1 - info[POST2_PRE][i]);
			} else {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						info[RPOST2_RLD][treeSize - 1
								- info[POST2_PRE][paths[RIGHT][i]]];
			}
		}

		// compute key root nodes
		// compute reversed key root nodes (in revrsed postorder)
		boolean[] visited = new boolean[nc1];
		boolean[] visitedR = new boolean[nc1];
		Arrays.fill(visited, false);
		int k = lc - 1;
		int kR = lc - 1;
		for (i = nc1 - 1; i >= 0; i--) {
			if (!visited[info[POST2_LLD][i]]) {
				info[KR][k] = i;
				visited[info[POST2_LLD][i]] = true;
				k--;
			}
			if (!visitedR[info[RPOST2_RLD][i]]) {
				info[RKR][kR] = i;
				visitedR[info[RPOST2_RLD][i]] = true;
				kR--;
			}
		}

		// compute minimal key roots for every subtree
		// compute minimal reversed key roots for every subtree (in reversed postorder)
		int parent = -1;
		int parentR = -1;
		for (i = 0; i < leafCount; i++) {
			parent = info[KR][i];
			while (parent > -1 && info[POST2_MIN_KR][parent] == -1) {
				info[POST2_MIN_KR][parent] = i;
				parent = info[POST2_PARENT][parent];
			}
			parentR = info[RKR][i];
			while (parentR > -1 && info[RPOST2_MIN_RKR][parentR] == -1) {
				info[RPOST2_MIN_RKR][parentR] = i;
				parentR =
						info[POST2_PARENT][info[RPOST2_POST][parentR]]; // get parent's postorder
				if (parentR > -1) {
					parentR = treeSize - 1 - info[POST2_PRE][parentR]; // if parent exists get its
					// rev. postorder
				}
			}
		}
	}
625213
function virtualRaf (state, view, vdom) {
  state = state || {}

  assert.equal(typeof state, 'object')
  assert.equal(typeof view, 'function')
  assert.equal(typeof vdom, 'object')

  var inRenderingTransaction = false
  var redrawScheduled = false
  var currentState = null
  var target = null
  var tree = null

  return { render: render, update: update }

  // return the vdom tree
  // null -> obj
  function render () {
    tree = view(state)
    target = vdom.create(tree)
    return target
  }

  // update the state and render function
  // obj -> null
  function update (state) {
    assert.ifError(inRenderingTransaction, 'infinite loop detected')

    // request a redraw for next frame
    if (currentState === null && !redrawScheduled) {
      redrawScheduled = true

      raf(function redraw () {
        redrawScheduled = false
        if (!currentState) return

        inRenderingTransaction = true
        var newTree = view(currentState)
        const patches = vdom.diff(tree, newTree)
        inRenderingTransaction = false

        target = vdom.patch(target, patches)
        tree = newTree
        currentState = null
      })
    }

    // update data for redraw
    currentState = state
  }
}
249490
def get_view_selection(self):
        """"""
        if not self.MODEL_STORAGE_ID:
            return None, None

        # avoid selection requests on empty tree views -> case warnings in gtk3
        if len(self.store) == 0:
            paths = []
        else:
            model, paths = self._tree_selection.get_selected_rows()

        # get all related models for selection from respective tree store field
        selected_model_list = []
        for path in paths:
            model = self.store[path][self.MODEL_STORAGE_ID]
            selected_model_list.append(model)
        return self._tree_selection, selected_model_list
1263418
private List<AbstractBaseDTNode<I, D>> updateDTTargets(List<TTTTransition<I, D>> transitions, boolean hard) {

        final List<AbstractBaseDTNode<I, D>> nodes = new ArrayList<>(transitions.size());
        final List<Word<I>> prefixes = new ArrayList<>(transitions.size());

        for (final TTTTransition<I, D> t : transitions) {
            if (!t.isTree()) {
                AbstractBaseDTNode<I, D> dt = t.getNonTreeTarget();

                nodes.add(dt);
                prefixes.add(t.getAccessSequence());
            }
        }

        final Iterator<AbstractBaseDTNode<I, D>> leavesIter = dtree.sift(nodes, prefixes, hard).iterator();
        final List<AbstractBaseDTNode<I, D>> result = new ArrayList<>(transitions.size());

        for (final TTTTransition<I, D> t : transitions) {
            if (t.isTree()) {
                result.add(t.getTreeTarget().dtLeaf);
            } else {
                AbstractBaseDTNode<I, D> leaf = leavesIter.next();
                t.setNonTreeTarget(leaf);
                result.add(leaf);
            }
        }

        assert !leavesIter.hasNext();
        return result;
    }
993054
def inputs(ctx, client, revision, paths):
    
    """
    from renku.models.provenance import ProcessRun

    graph = Graph(client)
    paths = set(paths)
    nodes = graph.build(revision=revision)

    commits = {node.commit for node in nodes}
    candidates = {(node.commit, node.path)
                  for node in nodes if not paths or node.path in paths}

    input_paths = set()

    for commit in commits:
        activity = graph.activities[commit]

        if isinstance(activity, ProcessRun):
            for usage in activity.qualified_usage:
                for entity in usage.entity.entities:
                    path = str((usage.client.path / entity.path).relative_to(
                        client.path
                    ))
                    usage_key = (entity.commit, entity.path)

                    if path not in input_paths and usage_key in candidates:
                        input_paths.add(path)

    click.echo('\n'.join(graph._format_path(path) for path in input_paths))
    ctx.exit(0 if not paths or len(input_paths) == len(paths) else 1)