<commit_before>package org.drools.brms.client.packages;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.drools.brms.client.common.ErrorPopup;
import org.drools.brms.client.common.FormStyleLayout;
import org.drools.brms.client.common.FormStylePopup;
import org.drools.brms.client.common.GenericCallback;
import org.drools.brms.client.common.LoadingPopup;
import org.drools.brms.client.rpc.BuilderResult;
import org.drools.brms.client.rpc.PackageConfigData;
import org.drools.brms.client.rpc.RepositoryServiceFactory;
import org.drools.brms.client.rpc.SnapshotInfo;
import org.drools.brms.client.rulelist.EditItemEvent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * This is the widget for building packages, validating etc. 
 * Visually decorates or wraps a rule editor widget with buttons for this purpose.
 * 
 * @author <NAME>
 */
public class PackageBuilderWidget extends Composite {


    public FormStyleLayout layout;
    private PackageConfigData conf;
    private EditItemEvent editEvent;

    
    public PackageBuilderWidget(final PackageConfigData conf, EditItemEvent editEvent) {
        layout = new FormStyleLayout("images/package_builder.png", "Verify and assemble package");
        this.conf = conf;
        this.editEvent = editEvent;
        
        final SimplePanel buildResults = new SimplePanel();

        Button b = new Button("Build package");
        b.setTitle( "This will validate and compile all the assets in a package." );
        b.addClickListener( new ClickListener() {
            public void onClick(Widget w) {
                doBuild(buildResults);
            }
        } );
        
        Button buildSource = new Button("Show package source");
        buildSource.addClickListener( new ClickListener() {
            public void onClick(Widget w) {
                doBuildSource(conf.uuid, conf.name);
            }
        } );
        layout.addAttribute( "View source for package", buildSource );
        layout.addAttribute( "Build binary package:", b);
        layout.addRow( new HTML("<i><small>Building a package will collect all the assets, validate and compile into a deployable package.</small></i>") );
        layout.addRow( buildResults );
        
        layout.setStyleName( "package-Editor" );
        
        layout.setWidth( "100%" );
        
        initWidget( layout );
    }
    
    
    
    /**
     * Actually build the source, and display it.
     */
    public static void doBuildSource(final String uuid, final String name) {
        LoadingPopup.showMessage( "Assembling package source..." );
        DeferredCommand.add( new Command() {
            public void execute() {
                RepositoryServiceFactory.getService().buildPackageSource( uuid, new GenericCallback() {
                    public void onSuccess(Object data) {
                        String content = (String) data;
                        showSource(content, name);
                    }
                });
            }
        } );
    }



    /**
     * Popup the view source dialog, showing the given content.
     */
    public static void showSource(String content, String name) {
        FormStylePopup pop = new FormStylePopup("images/view_source.gif", "Viewing source for: " + name);
        TextArea area = new TextArea();
        area.setVisibleLines( 30 );
        area.setWidth( "100%" );
        area.setCharacterWidth( 80 );
        pop.addRow( area );
        area.setText( content );
        pop.setPopupPosition( 30, 30 );
        LoadingPopup.close();
        pop.show();
    }



    /**
     * Actually do the building.
     * @param buildResults The panel to stuff the results in.
     */
    private void doBuild(final Panel buildResults) {

        buildResults.clear();
        
        final HorizontalPanel busy = new HorizontalPanel();
        busy.add( new Label("Validating and building package, please wait...") );
        busy.add( new Image("images/spinner.gif") );
        
        buildResults.add( busy );
        
        DeferredCommand.add( new Command() {
            public void execute() {
                RepositoryServiceFactory.getService().buildPackage( conf.uuid, new AsyncCallback() {
                    public void onSuccess(Object data) {
                        if (data == null) {
                            showSuccessfulBuild(buildResults);
                            
                        } else {
                            BuilderResult[] results = (BuilderResult[]) data;
                            showBuilderErrors(results, buildResults);<commit_msg>JBRULES-863 - Read only text area widget on View source action<commit_after>package org.drools.brms.client.packages;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.drools.brms.client.common.ErrorPopup;
import org.drools.brms.client.common.FormStyleLayout;
import org.drools.brms.client.common.FormStylePopup;
import org.drools.brms.client.common.GenericCallback;
import org.drools.brms.client.common.LoadingPopup;
import org.drools.brms.client.rpc.BuilderResult;
import org.drools.brms.client.rpc.PackageConfigData;
import org.drools.brms.client.rpc.RepositoryServiceFactory;
import org.drools.brms.client.rpc.SnapshotInfo;
import org.drools.brms.client.rulelist.EditItemEvent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * This is the widget for building packages, validating etc. 
 * Visually decorates or wraps a rule editor widget with buttons for this purpose.
 * 
 * @author <NAME>
 */
public class PackageBuilderWidget extends Composite {


    public FormStyleLayout layout;
    private PackageConfigData conf;
    private EditItemEvent editEvent;

    
    public PackageBuilderWidget(final PackageConfigData conf, EditItemEvent editEvent) {
        layout = new FormStyleLayout("images/package_builder.png", "Verify and assemble package");
        this.conf = conf;
        this.editEvent = editEvent;
        
        final SimplePanel buildResults = new SimplePanel();

        Button b = new Button("Build package");
        b.setTitle( "This will validate and compile all the assets in a package." );
        b.addClickListener( new ClickListener() {
            public void onClick(Widget w) {
                doBuild(buildResults);
            }
        } );
        
        Button buildSource = new Button("Show package source");
        buildSource.addClickListener( new ClickListener() {
            public void onClick(Widget w) {
                doBuildSource(conf.uuid, conf.name);
            }
        } );
        layout.addAttribute( "View source for package", buildSource );
        layout.addAttribute( "Build binary package:", b);
        layout.addRow( new HTML("<i><small>Building a package will collect all the assets, validate and compile into a deployable package.</small></i>") );
        layout.addRow( buildResults );
        
        layout.setStyleName( "package-Editor" );
        
        layout.setWidth( "100%" );
        
        initWidget( layout );
    }
    
    
    
    /**
     * Actually build the source, and display it.
     */
    public static void doBuildSource(final String uuid, final String name) {
        LoadingPopup.showMessage( "Assembling package source..." );
        DeferredCommand.add( new Command() {
            public void execute() {
                RepositoryServiceFactory.getService().buildPackageSource( uuid, new GenericCallback() {
                    public void onSuccess(Object data) {
                        String content = (String) data;
                        showSource(content, name);
                    }
                });
            }
        } );
    }



    /**
     * Popup the view source dialog, showing the given content.
     */
    public static void showSource(String content, String name) {
        FormStylePopup pop = new FormStylePopup("images/view_source.gif", "Viewing source for: " + name);
        TextArea area = new TextArea();
        area.setVisibleLines( 30 );
        area.setWidth( "100%" );
        area.setCharacterWidth( 80 );
        pop.addRow( area );
        area.setText( content );
        area.setEnabled( false );
        pop.setPopupPosition( 30, 30 );
        LoadingPopup.close();
        pop.show();
    }



    /**
     * Actually do the building.
     * @param buildResults The panel to stuff the results in.
     */
    private void doBuild(final Panel buildResults) {

        buildResults.clear();
        
        final HorizontalPanel busy = new HorizontalPanel();
        busy.add( new Label("Validating and building package, please wait...") );
        busy.add( new Image("images/spinner.gif") );
        
        buildResults.add( busy );
        
        DeferredCommand.add( new Command() {
            public void execute() {
                RepositoryServiceFactory.getService().buildPackage( conf.uuid, new AsyncCallback() {
                    public void onSuccess(Object data) {
                        if (data == null) {
                            showSuccessfulBuild(buildResults);
                            
                        } else {
                            BuilderResult[] results = (BuilderResult[]) data;
                            showBuilderErrors(results, buildResults);
{'fraction_non_alphanumeric': 0.1051787146804528, 'fraction_numerical': 0.0027631696229610484, 'mean_word_length': 2.464032108675517, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '423031', 'n_tokens_mistral': 3127, 'n_tokens_neox': 3052, 'n_words': 712}