<commit_before>package org.curriki.gwt.client.pages;

import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.xpn.xwiki.gwt.api.client.Document;
import com.xpn.xwiki.gwt.api.client.VersionInfo;
import org.curriki.gwt.client.Main;
import org.curriki.gwt.client.Constants;
import org.curriki.gwt.client.CurrikiService;
import org.curriki.gwt.client.CurrikiAsyncCallback;
import org.curriki.gwt.client.utils.WindowUtils;
import org.curriki.gwt.client.editor.Editor;
import org.curriki.gwt.client.widgets.modaldialogbox.ChoiceDialog;
import org.curriki.gwt.client.widgets.preview.PreviewDialog;
import org.gwtwidgets.client.util.SimpleDateFormat;

import java.util.List;
import java.util.Date;
/**
 * Copyright 2006,XpertNet SARL,and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software;you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation;either version2.1of
 * the License,or(at your option)any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY;without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software;if not,write to the Free
 * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
 * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
 *
 * @author ldubost
 */

/**
 * Copyright 2006,XpertNet SARL,and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software;you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation;either version2.1of
 * the License,or(at your option)any later version.
 *
 *This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY;without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software;if not,write to the Free
 * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
 * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
 *
 * @author ldubost
 */

public class HistoryPage extends AbstractPage {
    private int start = 0;
    private String toSelection = "";
    private String fromSelection = "";
    private boolean isComposite = false;

    public HistoryPage(){
        panel.setStyleName("history-page");
        initWidget(panel);
    }

    public void init() {
        super.init();
        panel.clear();
        loadHistory(0);
    }

    public boolean isSourceAssetPage() {
        return true;
    }

    private void loadHistory(int newStart) {
        start = newStart;
        Document currentAsset = Main.getSingleton().getEditor().getCurrentAsset();
        isComposite = (currentAsset.getObject(Constants.COMPOSITEASSET_CLASS) != null);

        CurrikiService.App.getInstance().getDocumentVersions(currentAsset.getFullName(), Constants.DEFAULT_NB_VERSIONS, start, new CurrikiAsyncCallback() {
            public void onFailure(Throwable caught) {
                super.onFailure(caught);
                panel.clear();
                panel.add(new HTML(Main.getTranslation("history.errorgettinghistory")));
            }

            public void onSuccess(Object result) {
                super.onSuccess(result);
                panel.clear();
                refreshHistory((List) result);
            }
        });
    }


    class MyRadioButton extends RadioButton {
        private String value;

        public MyRadioButton(String name, String text, String value) {
            super(name, text);
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    private void refreshHistory(List versionsList) {
        String dateFormat = "MMM-dd-yy hh:mm a";
        panel.clear();
        FlexTable table = new FlexTable();
        panel.add(table);
        table.setStyleName("history-versions");
        int startCol = 0;
        if (!isComposite) {
            table.setText(0, 0, Main.getTranslation("history.to"));
            table.setText(0, 1, Main.getTranslation("history.from"));
            startCol = 2;
        }
        table.getRowFormatter().setStyleName(0, "history-versions-title");
        table.setText(0, startCol, Main.getTranslation("history.version"));
        table.setText(0, startCol + 1, Main.getTranslation("history.author"));
        table.setText(0, startCol + 2, Main.getTranslation("history.date"));
        table.setText(0, startCol + 3, Main.getTranslation("history.comment"));
        table.setText(0, startCol + 4, Main.getTranslation("history.rollback"));

        for (int row = 0;row < versionsList.size(); row++) {
            final VersionInfo vinfo = (VersionInfo) versionsList.get(row);
            final String version = vinfo.getVersion();
            startCol = 0;
            if (!isComposite) {
                MyRadioButton toButton = new MyRadioButton("to", "", version);<commit_msg>CURRIKI-840 History page classes for styling<commit_after>package org.curriki.gwt.client.pages;

import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.xpn.xwiki.gwt.api.client.Document;
import com.xpn.xwiki.gwt.api.client.VersionInfo;
import org.curriki.gwt.client.Main;
import org.curriki.gwt.client.Constants;
import org.curriki.gwt.client.CurrikiService;
import org.curriki.gwt.client.CurrikiAsyncCallback;
import org.curriki.gwt.client.utils.WindowUtils;
import org.curriki.gwt.client.editor.Editor;
import org.curriki.gwt.client.widgets.modaldialogbox.ChoiceDialog;
import org.curriki.gwt.client.widgets.preview.PreviewDialog;
import org.gwtwidgets.client.util.SimpleDateFormat;

import java.util.List;
import java.util.Date;
/**
 * Copyright 2006,XpertNet SARL,and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software;you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation;either version2.1of
 * the License,or(at your option)any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY;without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software;if not,write to the Free
 * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
 * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
 *
 * @author ldubost
 */

/**
 * Copyright 2006,XpertNet SARL,and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software;you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation;either version2.1of
 * the License,or(at your option)any later version.
 *
 *This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY;without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software;if not,write to the Free
 * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
 * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
 *
 * @author ldubost
 */

public class HistoryPage extends AbstractPage {
    private int start = 0;
    private String toSelection = "";
    private String fromSelection = "";
    private boolean isComposite = false;

    public HistoryPage(){
        panel.setStyleName("history-page");
        initWidget(panel);
    }

    public void init() {
        super.init();
        panel.clear();
        loadHistory(0);
    }

    public boolean isSourceAssetPage() {
        return true;
    }

    private void loadHistory(int newStart) {
        start = newStart;
        Document currentAsset = Main.getSingleton().getEditor().getCurrentAsset();
        isComposite = (currentAsset.getObject(Constants.COMPOSITEASSET_CLASS) != null);

        CurrikiService.App.getInstance().getDocumentVersions(currentAsset.getFullName(), Constants.DEFAULT_NB_VERSIONS, start, new CurrikiAsyncCallback() {
            public void onFailure(Throwable caught) {
                super.onFailure(caught);
                panel.clear();
                panel.add(new HTML(Main.getTranslation("history.errorgettinghistory")));
            }

            public void onSuccess(Object result) {
                super.onSuccess(result);
                panel.clear();
                refreshHistory((List) result);
            }
        });
    }


    class MyRadioButton extends RadioButton {
        private String value;

        public MyRadioButton(String name, String text, String value) {
            super(name, text);
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    private void refreshHistory(List versionsList) {
        String dateFormat = "MMM-dd-yy hh:mm a";
        panel.clear();
        FlexTable table = new FlexTable();
        panel.add(table);
        table.setStyleName("history-versions");
        int startCol = 0;
        if (!isComposite) {
            table.setText(0, 0, Main.getTranslation("history.to"));
            table.setText(0, 1, Main.getTranslation("history.from"));
            table.getCellFormatter().setStyleName(0, 0, "to");
            table.getCellFormatter().setStyleName(0, 1, "from");
            startCol = 2;
        }
        table.getRowFormatter().setStyleName(0, "history-versions-title");
        table.setText(0, startCol, Main.getTranslation("history.version"));
        table.setText(0, startCol + 1, Main.getTranslation("history.author"));
        table.setText(0, startCol + 2, Main.getTranslation("history.date"));
        table.setText(0, startCol + 3, Main.getTranslation("history.comment"));
        table.setText(0, startCol + 4, Main.getTranslation("history.rollback"));
        table.getCellFormatter().setStyleName(0, startCol, "version");
        table.getCellFormatter().setStyleName(0, startCol + 1, "author");
        table.getCellFormatter().setStyleName(0, startCol + 2, "date");
        table.getCellFormatter().setStyleName(0, startCol + 3, "comment");
        table.getCellFormatter().setStyleName(0, startCol + 4, "rollback");

        for (int row = 0;row < versionsList.size(); row++) {
            final VersionInfo vinfo = (VersionInfo) versionsList.get(row);
            final String version = vinfo.getVersion();
            startCol = 0;
            if (!isComposite) {
                MyRadioButton toButton = new MyRadioButton("to", "", version);
{'fraction_non_alphanumeric': 0.10346294563090275, 'fraction_numerical': 0.01055049774525653, 'mean_word_length': 3.08408617095205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3521759', 'n_tokens_mistral': 3369, 'n_tokens_neox': 3212, 'n_words': 905}