<commit_before>package com.clarkparsia.sbol.editor.dialog;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.TableRowSorter;

import org.sbolstandard.core2.ComponentDefinition;
import org.sbolstandard.core2.SBOLDocument;
import org.sbolstandard.core2.SBOLValidationException;

import com.clarkparsia.sbol.SBOLUtils;
import com.clarkparsia.sbol.editor.Part;
import com.clarkparsia.sbol.editor.Parts;
import com.clarkparsia.swing.FormBuilder;
import com.google.common.collect.Lists;

/**
 * A GUI for choosing a root CD from an SBOLDocument
 * 
 * @author <NAME>
 */
public class RootInputDialog extends InputDialog<SBOLDocument> {
	private static final String TITLE = "Select a root ComponentDefinition to open";

	private JTable table;
	private JLabel tableLabel;

	private JComboBox<Part> roleSelection;
	private JCheckBox onlyShowRootCDs;
	private static final Part ALL_PARTS = new Part("All parts", "All");

	private SBOLDocument doc;

	/**
	 * this.getInput() returns an SBOLDocument with a single rootCD selected
	 * from the rootCDs in doc.
	 */
	public RootInputDialog(final Component parent, SBOLDocument doc) {
		super(parent, TITLE);

		this.doc = doc;
	}

	@Override
	protected String initMessage() {
		return "There are multiple root ComponentDefinitions.  Which would you like to load?  (You will be editing a new partial design)";
	}

	@Override
	public void initFormPanel(FormBuilder builder) {
		List<Part> parts = Lists.newArrayList(Parts.sorted());
		parts.add(0, ALL_PARTS);

		roleSelection = new JComboBox<Part>(parts.toArray(new Part[0]));
		roleSelection.setRenderer(new PartCellRenderer());
		roleSelection.setSelectedItem(ALL_PARTS);
		roleSelection.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				updateTable();
			}
		});
		builder.add("Part role", roleSelection);

		onlyShowRootCDs = new JCheckBox("Only show root ComponentDefinitions");
		onlyShowRootCDs.setSelected(true);
		onlyShowRootCDs.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				updateTable();
			}
		});
		builder.add("", onlyShowRootCDs);
<commit_msg>Added button to delete CD in RootInputDialog.<commit_after>package com.clarkparsia.sbol.editor.dialog;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.TableRowSorter;

import org.sbolstandard.core2.ComponentDefinition;
import org.sbolstandard.core2.SBOLDocument;
import org.sbolstandard.core2.SBOLValidationException;
import org.sbolstandard.core2.SBOLWriter;

import com.clarkparsia.sbol.SBOLUtils;
import com.clarkparsia.sbol.editor.Part;
import com.clarkparsia.sbol.editor.Parts;
import com.clarkparsia.swing.FormBuilder;
import com.google.common.collect.Lists;

/**
 * A GUI for choosing a root CD from an SBOLDocument
 * 
 * @author <NAME>
 */
public class RootInputDialog extends InputDialog<SBOLDocument> {
	private static final String TITLE = "Select a root ComponentDefinition to open";

	private JTable table;
	private JLabel tableLabel;

	private JComboBox<Part> roleSelection;
	private JCheckBox onlyShowRootCDs;
	private static final Part ALL_PARTS = new Part("All parts", "All");

	private JButton deleteCD;

	private SBOLDocument doc;

	/**
	 * this.getInput() returns an SBOLDocument with a single rootCD selected
	 * from the rootCDs in doc.
	 */
	public RootInputDialog(final Component parent, SBOLDocument doc) {
		super(parent, TITLE);

		this.doc = doc;
	}

	@Override
	protected String initMessage() {
		return "There are multiple root ComponentDefinitions.  Which would you like to load?  (You will be editing a new partial design)";
	}

	@Override
	public void initFormPanel(FormBuilder builder) {
		List<Part> parts = Lists.newArrayList(Parts.sorted());
		parts.add(0, ALL_PARTS);

		roleSelection = new JComboBox<Part>(parts.toArray(new Part[0]));
		roleSelection.setRenderer(new PartCellRenderer());
		roleSelection.setSelectedItem(ALL_PARTS);
		roleSelection.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				updateTable();
			}
		});
		builder.add("Part role", roleSelection);

		onlyShowRootCDs = new JCheckBox("Only show root ComponentDefinitions");
		onlyShowRootCDs.setSelected(true);
		onlyShowRootCDs.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				updateTable();
			}
		});
		builder.add("", onlyShowRootCDs);

		deleteCD = new JButton("Delete selected ComponentDefinition. (This will resave the file)");
		deleteCD.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					int row = table.convertRowIndexToModel(table.getSelectedRow());
					ComponentDefinition comp = ((ComponentDefinitionTableModel) table.getModel()).getElement(row);
					doc.removeComponentDefinition(comp);
					File file = SBOLUtils.setupFile();
					SBOLWriter.write(doc, new FileOutputStream(file));
					updateTable();
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(rootPane, "Failed to delete CD: " + e1.getMessage());
					e1.printStackTrace();
				}
			}
		});
		builder.add("", deleteCD);

{'fraction_non_alphanumeric': 0.10237103492470362, 'fraction_numerical': 0.002242870874719641, 'mean_word_length': 5.181188118811881, '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': '4667902', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1873, 'n_words': 460}