<commit_before>/*
 * Copyright 2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.jailer.ui;

import java.awt.CardLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import jsyntaxpane.DefaultSyntaxKit;
import net.sf.jailer.CommandLineParser;
import net.sf.jailer.DDLCreator;
import net.sf.jailer.Jailer;
import net.sf.jailer.ScriptFormat;
import net.sf.jailer.database.DMLTransformer;
import net.sf.jailer.database.Session;
import net.sf.jailer.database.TemporaryTableScope;
import net.sf.jailer.datamodel.Association;
import net.sf.jailer.datamodel.DataModel;
import net.sf.jailer.datamodel.DataModel.NoPrimaryKeyException;
import net.sf.jailer.datamodel.Table;
import net.sf.jailer.modelbuilder.ModelBuilder;
import net.sf.jailer.render.HtmlDataModelRenderer;
import net.sf.jailer.ui.databrowser.DataBrowser;
import net.sf.jailer.ui.graphical_view.LayoutStorage;

/**
 * Main frame of Extraction-Model-Editor.
 * 
 * @author <NAME>
 */
public class ExtractionModelFrame extends javax.swing.JFrame {

	/**
	 * The embedded editor.
	 */
	ExtractionModelEditor extractionModelEditor;
	
	/**
	 * Dialog for DB-connects.
	 */
	private DbConnectionDialog dbConnectionDialog;
	
	/**
	 * The filter editor.
	 */
	private final FilterEditorDialog filterEditorDialog;
	
	/**
	 * The "Find Table" dialog.
	 */
	final ClosureView closureView;

	/**
	 * The border browser.
	 */
	final ClosureBorderDialog closureBorderView;

	/**
	 * The "Cycle View" dialog.
	 */
	final CyclesView cycleViewDialog;

	/**
	 * File in which plaf-setting is stored.
	 */
	private static final String PLAFSETTING = ".plaf2.ui";

	/**
	 * File in which orientation is stored.
	 */
	private static final String ORIENTATIONSETTING = ".orientation.ui";

    /**
     *  Creates new form ExtractionModelFrame.
     *  
     *  @param extractionModelFile file containing the model, <code>null</code> for new model
     *  @param isHorizonal 
     */
    public ExtractionModelFrame(String extractionModelFile, boolean isHorizonal) {
        initComponents();
        initAnimationSteptime();
        isHorizontalLayout = isHorizonal;
        horizontalLayoutMenuItem.setSelected(isHorizontalLayout);
        editorPanel.add(extractionModelEditor = new ExtractionModelEditor(extractionModelFile, this, isHorizontalLayout, getConnectivityState(), getConnectivityStateToolTip()), "editor");
        extractionModelEditor.extractionModelFile = extractionModelFile;
        pack();
        updateTitle(extractionModelEditor.needsSave);
        dbConnectionDialog = new DbConnectionDialog(this, Jailer.APPLICATION_NAME);
        try {
	        for (final LookAndFeelInfo lfInfo: UIManager.getInstalledLookAndFeels()) {
	        	JMenuItem mItem = new JMenuItem();
	        	mItem.setText(lfInfo.getName());
	        	view.add(mItem);
	        	mItem.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						setPLAF(lfInfo.getClassName());
					}
	        	});
	        }
        } catch (Throwable t) {
        }
        updateMenuItems();
        closureView = new ClosureView(this);
        closureBorderView = new ClosureBorderDialog(this) {
			private static final long serialVersionUID = -7426280043553389753L;
			@Override
			protected Table getRoot() {
				return extractionModelEditor.root;
			}
			@Override
			protected DataModel getDataModel() {
				return extractionModelEditor.dataModel;
			}
			@Override
			protected void removeRestrictions(Collection<Association> associations) {
				extractionModelEditor.removeRestrictions(associations);
			}
        };
        
        cycleViewDialog = new CyclesView(this);
        filterEditorDialog = new FilterEditorDialog(this, new ParameterSelector.ParametersGetter() {
			@Override
			public Set<String> getParameters() {
				return extractionModelEditor.dataModel.getParameters(extractionModelEditor.condition.getText());
			}
		});
    }
    
    /**
     * Updates state of some menu items.
     */
    private void updateMenuItems() {
		connectDb.setSelected(dbConnectionDialog.isConnected);
		extractionModelEditor.connectivityState.setText(getConnectivityState());
		extractionModelEditor.connectivityState.setToolTipText(getConnectivityStateToolTip());
    }
	
	private String getConnectivityState() {
		if (dbConnectionDialog != null && dbConnectionDialog.isConnected) {
			return dbConnectionDialog.currentConnection.user + "@" + (dbConnectionDialog.currentConnection.alias);
		} else {
			return "offline";
		}
	}
	<commit_msg>preparing release 3.7.9<commit_after>/*
 * Copyright 2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.jailer.ui;

import java.awt.CardLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import jsyntaxpane.DefaultSyntaxKit;
import net.sf.jailer.CommandLineParser;
import net.sf.jailer.DDLCreator;
import net.sf.jailer.Jailer;
import net.sf.jailer.ScriptFormat;
import net.sf.jailer.database.DMLTransformer;
import net.sf.jailer.database.Session;
import net.sf.jailer.database.TemporaryTableScope;
import net.sf.jailer.datamodel.Association;
import net.sf.jailer.datamodel.DataModel;
import net.sf.jailer.datamodel.DataModel.NoPrimaryKeyException;
import net.sf.jailer.datamodel.Table;
import net.sf.jailer.modelbuilder.ModelBuilder;
import net.sf.jailer.render.HtmlDataModelRenderer;
import net.sf.jailer.ui.databrowser.DataBrowser;
import net.sf.jailer.ui.graphical_view.LayoutStorage;

/**
 * Main frame of Extraction-Model-Editor.
 * 
 * @author <NAME>
 */
public class ExtractionModelFrame extends javax.swing.JFrame {

	/**
	 * The embedded editor.
	 */
	ExtractionModelEditor extractionModelEditor;
	
	/**
	 * Dialog for DB-connects.
	 */
	private DbConnectionDialog dbConnectionDialog;
	
	/**
	 * The filter editor.
	 */
	private final FilterEditorDialog filterEditorDialog;
	
	/**
	 * The "Find Table" dialog.
	 */
	final ClosureView closureView;

	/**
	 * The border browser.
	 */
	final ClosureBorderDialog closureBorderView;

	/**
	 * The "Cycle View" dialog.
	 */
	final CyclesView cycleViewDialog;

	/**
	 * File in which plaf-setting is stored.
	 */
	private static final String PLAFSETTING = ".plaf2.ui";

	/**
	 * File in which orientation is stored.
	 */
	private static final String ORIENTATIONSETTING = ".orientation.ui";

    /**
     *  Creates new form ExtractionModelFrame.
     *  
     *  @param extractionModelFile file containing the model, <code>null</code> for new model
     *  @param isHorizonal 
     */
    public ExtractionModelFrame(String extractionModelFile, boolean isHorizonal) {
        initComponents();
        initAnimationSteptime();
        isHorizontalLayout = isHorizonal;
        horizontalLayoutMenuItem.setSelected(isHorizontalLayout);
        editorPanel.add(extractionModelEditor = new ExtractionModelEditor(extractionModelFile, this, isHorizontalLayout, getConnectivityState(), getConnectivityStateToolTip()), "editor");
        extractionModelEditor.extractionModelFile = extractionModelFile;
        pack();
        updateTitle(extractionModelEditor.needsSave);
        dbConnectionDialog = new DbConnectionDialog(this, Jailer.APPLICATION_NAME);
        try {
	        for (final LookAndFeelInfo lfInfo: UIManager.getInstalledLookAndFeels()) {
	        	JMenuItem mItem = new JMenuItem();
	        	mItem.setText(lfInfo.getName());
	        	view.add(mItem);
	        	mItem.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						setPLAF(lfInfo.getClassName());
					}
	        	});
	        }
        } catch (Throwable t) {
        }
        updateMenuItems();
        closureView = new ClosureView(this);
        closureBorderView = new ClosureBorderDialog(this) {
			private static final long serialVersionUID = -7426280043553389753L;
			@Override
			protected Table getRoot() {
				return extractionModelEditor == null? null : extractionModelEditor.root;
			}
			@Override
			protected DataModel getDataModel() {
				return extractionModelEditor == null? null : extractionModelEditor.dataModel;
			}
			@Override
			protected void removeRestrictions(Collection<Association> associations) {
				if (extractionModelEditor != null) {
					extractionModelEditor.removeRestrictions(associations);
				}
			}
        };
        
        cycleViewDialog = new CyclesView(this);
        filterEditorDialog = new FilterEditorDialog(this, new ParameterSelector.ParametersGetter() {
			@Override
			public Set<String> getParameters() {
				return extractionModelEditor.dataModel.getParameters(extractionModelEditor.condition.getText());
			}
		});
    }
    
    /**
     * Updates state of some menu items.
     */
    private void updateMenuItems() {
		connectDb.setSelected(dbConnectionDialog.isConnected);
		extractionModelEditor.connectivityState.setText(getConnectivityState());
		extractionModelEditor.connectivityState.setToolTipText(getConnectivityStateToolTip());
    }
	
	private String getConnectivityState() {
		if (dbConnectionDialog != null && dbConnectionDialog.isConnected) {
			return dbConnectionDialog.currentConnection.user + "@" + (dbConnectionDialog.currentConnection.alias);
		} else {
			return "offline";
		}
	}
	
{'fraction_non_alphanumeric': 0.09601357082273113, 'fraction_numerical': 0.005173876166242579, 'mean_word_length': 3.958368376787216, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7584313', 'n_tokens_mistral': 3662, 'n_tokens_neox': 3371, 'n_words': 777}