<commit_before>package org.sagebionetworks.web.client.widget.entity.renderer;

import java.util.List;

import org.sagebionetworks.repo.model.v2.wiki.V2WikiHeader;
import org.sagebionetworks.repo.model.v2.wiki.V2WikiOrderHint;
import org.sagebionetworks.web.client.SynapseClientAsync;
import org.sagebionetworks.web.client.utils.CallbackP;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.shared.WikiPageKey;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class WikiSubpagesOrderEditor {
	
	private WikiSubpagesOrderEditorView view;
	private WikiSubpageOrderEditorTree editorTree;
	private String ownerObjectName;
	private SynapseAlert synAlert;
	private SynapseClientAsync synapseClient;
	private WikiPageKey wikiKey;
	private CallbackP<String> refreshCallback;
	@Inject
	public WikiSubpagesOrderEditor(
			WikiSubpagesOrderEditorView view, 
			WikiSubpageOrderEditorTree editorTree,
			SynapseAlert synAlert,
			SynapseClientAsync synapseClient) {
		this.view = view;
		this.editorTree = editorTree;
		this.synAlert = synAlert;
		this.synapseClient = synapseClient;
		refreshCallback = new CallbackP<String>() {
			@Override
			public void invoke(String selectWikiPageId) {
				refresh(selectWikiPageId);
			}
		};
		view.configure(editorTree);
	}
	
	public void configure(WikiPageKey wikiKey, final String ownerObjectName) {
		//get wiki headers, and order
		this.wikiKey = wikiKey;
		this.ownerObjectName = ownerObjectName;
		
		refresh(null);
	}
	
	public void refresh(final String selectWikiPageId) {
		synAlert.clear();
		view.setLoadingVisible(true);
		synapseClient.getV2WikiHeaderTree(wikiKey.getOwnerObjectId(), wikiKey.getOwnerObjectType(), new AsyncCallback<List<V2WikiHeader>>() {
			@Override
			public void onSuccess(final List<V2WikiHeader> wikiHeaders) {
				synapseClient.getV2WikiOrderHint(wikiKey, new AsyncCallback<V2WikiOrderHint>() {
					@Override
					public void onSuccess(V2WikiOrderHint hint) {
						// "Sort" stuff'
						WikiOrderHintUtils.sortHeadersByOrderHint(wikiHeaders, hint);
						editorTree.configure(selectWikiPageId, wikiKey, wikiHeaders, ownerObjectName, hint, refreshCallback);
						view.setLoadingVisible(false);
					}
					@Override
					public void onFailure(Throwable caught) {
						// Failed to get order hint. Just ignore it.
						synAlert.handleException(caught);
						view.setLoadingVisible(false);
					}
				});
			}
			
			@Override
			public void onFailure(Throwable caught) {
				synAlert.handleException(caught);
				view.setLoadingVisible(false);
			}
		});
	}
	
	public void initializeState() {
		view.initializeState();
	}
	
	/**
	 * Generate the WikiSubpagesOrderEditor Widget
	 */
	public Widget asWidget() {
		return view.asWidget();
	}
	
	public WikiSubpageOrderEditorTree getTree() {
		return editorTree;
	}
}<commit_msg>initialize state when editor is configured<commit_after>package org.sagebionetworks.web.client.widget.entity.renderer;

import java.util.List;

import org.sagebionetworks.repo.model.v2.wiki.V2WikiHeader;
import org.sagebionetworks.repo.model.v2.wiki.V2WikiOrderHint;
import org.sagebionetworks.web.client.SynapseClientAsync;
import org.sagebionetworks.web.client.utils.CallbackP;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.shared.WikiPageKey;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class WikiSubpagesOrderEditor {
	
	private WikiSubpagesOrderEditorView view;
	private WikiSubpageOrderEditorTree editorTree;
	private String ownerObjectName;
	private SynapseAlert synAlert;
	private SynapseClientAsync synapseClient;
	private WikiPageKey wikiKey;
	private CallbackP<String> refreshCallback;
	@Inject
	public WikiSubpagesOrderEditor(
			WikiSubpagesOrderEditorView view, 
			WikiSubpageOrderEditorTree editorTree,
			SynapseAlert synAlert,
			SynapseClientAsync synapseClient) {
		this.view = view;
		this.editorTree = editorTree;
		this.synAlert = synAlert;
		this.synapseClient = synapseClient;
		refreshCallback = new CallbackP<String>() {
			@Override
			public void invoke(String selectWikiPageId) {
				refresh(selectWikiPageId);
			}
		};
		view.configure(editorTree);
	}
	
	public void configure(WikiPageKey wikiKey, final String ownerObjectName) {
		//get wiki headers, and order
		this.wikiKey = wikiKey;
		this.ownerObjectName = ownerObjectName;
		view.initializeState();
		refresh(null);
	}
	
	public void refresh(final String selectWikiPageId) {
		synAlert.clear();
		view.setLoadingVisible(true);
		synapseClient.getV2WikiHeaderTree(wikiKey.getOwnerObjectId(), wikiKey.getOwnerObjectType(), new AsyncCallback<List<V2WikiHeader>>() {
			@Override
			public void onSuccess(final List<V2WikiHeader> wikiHeaders) {
				synapseClient.getV2WikiOrderHint(wikiKey, new AsyncCallback<V2WikiOrderHint>() {
					@Override
					public void onSuccess(V2WikiOrderHint hint) {
						// "Sort" stuff'
						WikiOrderHintUtils.sortHeadersByOrderHint(wikiHeaders, hint);
						editorTree.configure(selectWikiPageId, wikiKey, wikiHeaders, ownerObjectName, hint, refreshCallback);
						view.setLoadingVisible(false);
					}
					@Override
					public void onFailure(Throwable caught) {
						// Failed to get order hint. Just ignore it.
						synAlert.handleException(caught);
						view.setLoadingVisible(false);
					}
				});
			}
			
			@Override
			public void onFailure(Throwable caught) {
				synAlert.handleException(caught);
				view.setLoadingVisible(false);
			}
		});
	}
	
	/**
	 * Generate the WikiSubpagesOrderEditor Widget
	 */
	public Widget asWidget() {
		return view.asWidget();
	}
	
	public WikiSubpageOrderEditorTree getTree() {
		return editorTree;
	}
}
{'fraction_non_alphanumeric': 0.09189925119128659, 'fraction_numerical': 0.0034036759700476512, 'mean_word_length': 4.773084479371317, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5836786', 'n_tokens_mistral': 2142, 'n_tokens_neox': 1839, 'n_words': 338}