<commit_before>package hu.elte.txtuml.export.papyrus.wizardz;

import hu.elte.txtuml.export.papyrus.preferences.PreferencesManager;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.core.SourceType;
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;

/**
 * The Page for txtUML visualization.
 *
 * @author <NAME>
 */
@SuppressWarnings("restriction")
public class VisualizeTxtUMLPage extends WizardPage {
	
	private static final String browseButtonText = "Browse...";
	
	private Composite container;
	private Text txtUMLModel;
	//private List<Text> txtUMLLayout = new LinkedList<>();
	private Text txtUMLProject;
	private Button generateSMDs;
	private ScrolledComposite sc;
	
	private Map<Integer, Text> txtUMLLayout = new HashMap<>();
	
	/**
	 * The Constructor
	 */
	public VisualizeTxtUMLPage() {
		super("Visualize txtUML Page");
		setTitle("Visualize txtUML page");
	    setDescription("Give your txtUML project and model class to be visualized");
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		container = new Composite(sc, SWT.NONE);
		
		GridLayout layout = new GridLayout(4,false);
	    container.setLayout(layout);
	    
	    
	    Label label1 = new Label(container, SWT.NONE);
	    label1.setText("txtUML Project: ");
	    txtUMLProject = new Text(container, SWT.BORDER | SWT.SINGLE);
	    txtUMLProject.setText(PreferencesManager.getString(PreferencesManager.TXTUML_VISUALIZE_TXTUML_PROJECT));
	    Button browseProject = new Button(container, SWT.NONE);
	    browseProject.setText(browseButtonText);
	    browseProject.addSelectionListener(new  SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ElementTreeSelectionDialog   dialog =
						new ElementTreeSelectionDialog(
								container.getShell(),
							    new WorkbenchLabelProvider(),
							    new WorkbenchContentProvider(){
									@Override
									public Object[] getChildren(Object element) {
										if(element instanceof IWorkspaceRoot){
											return ((IWorkspaceRoot) element).getProjects();
										}
										return new Object[0];
									}
								});
				dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
				dialog.setTitle("Project Selection");
				dialog.open();
				Object[] result = dialog.getResult();
				if(result != null && result.length > 0){
					txtUMLProject.setText(((IProject) result[0]).getName());
				}
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
	    
	    
	
	    Label label2 = new Label(container, SWT.NONE);
	    label2.setText("txtUML Model: ");
	    txtUMLModel = new Text(container, SWT.BORDER | SWT.SINGLE);
	    txtUMLModel.setText(PreferencesManager.getString(PreferencesManager.TXTUML_VISUALIZE_TXTUML_MODEL));
	    Button browseModel = new Button(container, SWT.NONE);
	    browseModel.setText(browseButtonText );
	    browseModel.addSelectionListener(new  SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				FilteredTypesSelectionDialog dialog=
						new FilteredTypesSelectionDialog(container.getShell(),false,
								PlatformUI.getWorkbench().getProgressService(),
								SearchEngine.createWorkspaceScope(),
								IJavaSearchConstants.CLASS_AND_INTERFACE);
				dialog.open();
				Object[] result = dialog.getResult();
				if(result != null && result.length > 0 && result[0] instanceof SourceType){
					SourceType item = (SourceType) result[0];
					txtUMLModel.setText(item.getFullyQualifiedName());
				}
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});

	    
	    /** Future improvement - adding multiple descriptons **
	     */
	    Button addDiagrambtn = new Button(container, SWT.NONE);
	    addDiagrambtn.setText("Add txtUML diagram description");
	    addDiagrambtn.addSelectionListener(new SelectionListener() {
	    	
			@Override
			public void widgetSelected(SelectionEvent e) {<commit_msg>Updated the txtUML model visualization page to support split models.<commit_after>package hu.elte.txtuml.export.papyrus.wizardz;

import hu.elte.txtuml.eclipseutils.NotFoundException;
import hu.elte.txtuml.eclipseutils.PackageUtils;
import hu.elte.txtuml.eclipseutils.ProjectUtils;
import hu.elte.txtuml.export.papyrus.preferences.PreferencesManager;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.core.SourceType;
import org.eclipse.jdt.internal.core.search.JavaSearchScope;
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;

/**
 * The Page for txtUML visualization.
 *
 * @author <NAME>
 */
@SuppressWarnings("restriction")
public class VisualizeTxtUMLPage extends WizardPage {
	
	private static final String browseButtonText = "Browse...";
	
	private Composite container;
	private Text txtUMLModel;
	//private List<Text> txtUMLLayout = new LinkedList<>();
	private Text txtUMLProject;
	private Button generateSMDs;
	private ScrolledComposite sc;
	
	private Map<Integer, Text> txtUMLLayout = new HashMap<>();
	
	/**
	 * The Constructor
	 */
	public VisualizeTxtUMLPage() {
		super("Visualize txtUML Page");
		setTitle("Visualize txtUML page");
	    setDescription("Give your txtUML project and model class to be visualized");
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		container = new Composite(sc, SWT.NONE);
		
		GridLayout layout = new GridLayout(4,false);
	    container.setLayout(layout);
	    
	    
	    Label label1 = new Label(container, SWT.NONE);
	    label1.setText("txtUML Project: ");
	    txtUMLProject = new Text(container, SWT.BORDER | SWT.SINGLE);
	    txtUMLProject.setText(PreferencesManager.getString(PreferencesManager.TXTUML_VISUALIZE_TXTUML_PROJECT));
	    Button browseProject = new Button(container, SWT.NONE);
	    browseProject.setText(browseButtonText);
	    browseProject.addSelectionListener(new  SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ElementTreeSelectionDialog   dialog =
						new ElementTreeSelectionDialog(
								container.getShell(),
							    new WorkbenchLabelProvider(),
							    new WorkbenchContentProvider(){
									@Override
									public Object[] getChildren(Object element) {
										if(element instanceof IWorkspaceRoot){
											return ((IWorkspaceRoot) element).getProjects();
										}
										return new Object[0];
									}
								});
				dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
				dialog.setTitle("Project Selection");
				dialog.open();
				Object[] result = dialog.getResult();
				if(result != null && result.length > 0){
					txtUMLProject.setText(((IProject) result[0]).getName());
				}
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
	    
	    
	
	    Label label2 = new Label(container, SWT.NONE);
	    label2.setText("txtUML Model: ");
	    txtUMLModel = new Text(container, SWT.BORDER | SWT.SINGLE);
	    txtUMLModel.setText(PreferencesManager.getString(PreferencesManager.TXTUML_VISUALIZE_TXTUML_MODEL));
	    Button browseModel = new Button(container, SWT.NONE);
	    browseModel.setText(browseButtonText );
	    browseModel.addSelectionListener(new  SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				JavaSearchScope scope = new JavaSearchScope();
				try {
					IJavaProject javaProject = ProjectUtils
							.findJavaProject(txtUMLProject.getText());
					for (IPackageFragmentRoot root : PackageUtils
							.getPackageFragmentRoots(javaProject)) {
						scope.add(root);
					}
				} catch (JavaModelException | NotFoundException ex) {
				}
				PackageSelectionDialog dialog = new PackageSelectionDialog(
						getShell(), getContainer(),
						PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE
								& PackageSelectionDialog.F_REMOVE_DUPLICATES,
						scope);

				dialog.setTitle("Project Selection");
				dialog.open();
				Object[] result = dialog.getResult();
				if (result != null && result.length > 0) {
					txtUMLModel.setText(((IPackageFragment) result[0])
							.getElementName());
				}
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {}
		});

	    
	    /** Future improvement - adding multiple descriptons **
	     */
	    Button addDiagrambtn = new Button(container, SWT.NONE);
	    addDiagrambtn.setText("Add txtUML diagram description");
	    addDiagrambtn.addSelectionListener(new SelectionListener() {
	    	
			@Override
			public void widgetSelected(SelectionEvent e) {
{'fraction_non_alphanumeric': 0.10655881835765782, 'fraction_numerical': 0.0018463161596623879, 'mean_word_length': 4.1964367291000455, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '5533363', 'n_tokens_mistral': 3935, 'n_tokens_neox': 3344, 'n_words': 634}