<commit_before>package ee.ut.cs.rum.workspace.internal.ui;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import ee.ut.cs.rum.controller.RumController;
import ee.ut.cs.rum.database.domain.Project;
import ee.ut.cs.rum.database.util.ProjectAccess;
import ee.ut.cs.rum.enums.ControllerEntityType;
import ee.ut.cs.rum.enums.ControllerUpdateType;
import ee.ut.cs.rum.interfaces.RumUpdatableView;
import ee.ut.cs.rum.workspace.internal.Activator;
import ee.ut.cs.rum.workspace.internal.ui.project.ProjectTabFolder;
import ee.ut.cs.rum.workspace.ui.WorkspaceUI;

public class ProjectSelectorCombo extends Combo implements RumUpdatableView {
	private static final long serialVersionUID = -1671918025859199853L;

	private Display display;
	private RumController rumController;

	private List<Project> projects;
	private List<ProjectTabFolder> projectsDetails;
	private WorkspaceUI workspaceUI;
	private WorkspaceHeader workspaceHeader;

	public ProjectSelectorCombo(WorkspaceHeader workspaceHeader, WorkspaceUI workspaceUI, RumController rumController) {
		super(workspaceHeader, SWT.READ_ONLY);

		this.display=Display.getCurrent();
		this.rumController=rumController;
		rumController.registerView(this, ControllerEntityType.PROJECT);

		this.workspaceUI=workspaceUI;
		this.workspaceHeader=workspaceHeader;

		this.add("Workspace overview");
		this.setVisibleItemCount(10);
		this.select(0);
		updateWorkspaceSelector();

		this.addListener(SWT.Selection, new Listener() {
			private static final long serialVersionUID = -1752969541573951231L;

			public void handleEvent(Event e) {
				updateSelectedProjectDetails();
			}
		});
	}

	private void updateWorkspaceSelector() {
		this.projects = new ArrayList<Project>();
		this.projects.add(null);
		this.projects.addAll(ProjectAccess.getProjectsDataFromDb());
		createProjectDetailsList(projects.size());

		for (Project project : projects) {
			if (project!=null) {
				this.add(project.getName());
			}
		}
	}

	public void updateSelectedProjectDetails() {
		int selectedIndex = ProjectSelectorCombo.this.getSelectionIndex();
		StackLayout workspaceContainerLayout = (StackLayout)workspaceUI.getWorkspaceContainer().getLayout();

		if (selectedIndex==0) {
			workspaceContainerLayout.topControl=workspaceUI.getWorkspaceOverview();
		} else {
			ProjectTabFolder selectedWorkspaceDetails = projectsDetails.get(selectedIndex);
			if (selectedWorkspaceDetails==null) {
				selectedWorkspaceDetails = new ProjectTabFolder(workspaceUI.getWorkspaceContainer(), projects.get(selectedIndex));
				projectsDetails.add(selectedIndex, selectedWorkspaceDetails);
			}
			workspaceContainerLayout.topControl=selectedWorkspaceDetails;
		}
		workspaceUI.getWorkspaceContainer().layout();


		if (projects.get(selectedIndex)!=null) {
			workspaceHeader.setHeaderTitle("Project: " + projects.get(selectedIndex).getName());
			Activator.getLogger().info("Opened project: " + projects.get(selectedIndex).toString());
		} else {
			workspaceHeader.setHeaderTitle("Workspace overview");
			Activator.getLogger().info("Opened projects overview");
		}
	}
	

	public void selectProject(Project project) {
		int projectIndex = findProjectIndex(project);
		if (projectIndex != -1) {
			this.select(projectIndex);
			updateSelectedProjectDetails();
		}
		
	}

	private void createProjectDetailsList(int size) {
		this.projectsDetails = new ArrayList<ProjectTabFolder>();
		for (int i = 0; i < size; i++) {<commit_msg>Minor code adjustments<commit_after>package ee.ut.cs.rum.workspace.internal.ui;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import ee.ut.cs.rum.controller.RumController;
import ee.ut.cs.rum.database.domain.Project;
import ee.ut.cs.rum.database.util.ProjectAccess;
import ee.ut.cs.rum.enums.ControllerEntityType;
import ee.ut.cs.rum.enums.ControllerUpdateType;
import ee.ut.cs.rum.interfaces.RumUpdatableView;
import ee.ut.cs.rum.workspace.internal.Activator;
import ee.ut.cs.rum.workspace.internal.ui.project.ProjectTabFolder;
import ee.ut.cs.rum.workspace.ui.WorkspaceUI;

public class ProjectSelectorCombo extends Combo implements RumUpdatableView {
	private static final long serialVersionUID = -1671918025859199853L;

	private Display display;
	private RumController rumController;

	private List<Project> projects;
	private List<ProjectTabFolder> projectsDetails;
	private WorkspaceUI workspaceUI;
	private WorkspaceHeader workspaceHeader;

	public ProjectSelectorCombo(WorkspaceHeader workspaceHeader, WorkspaceUI workspaceUI, RumController rumController) {
		super(workspaceHeader, SWT.READ_ONLY);

		this.display=Display.getCurrent();
		this.rumController=rumController;
		rumController.registerView(this, ControllerEntityType.PROJECT);

		this.workspaceUI=workspaceUI;
		this.workspaceHeader=workspaceHeader;

		this.add("Workspace overview");
		this.setVisibleItemCount(10);
		this.select(0);
		updateWorkspaceSelector();

		this.addListener(SWT.Selection, new Listener() {
			private static final long serialVersionUID = -1752969541573951231L;

			public void handleEvent(Event e) {
				updateSelectedProjectDetails();
			}
		});
	}

	private void updateWorkspaceSelector() {
		this.projects = new ArrayList<Project>();
		this.projects.add(null);
		this.projects.addAll(ProjectAccess.getProjectsDataFromDb());
		createProjectDetailsList(projects.size());

		for (Project project : projects) {
			if (project!=null) {
				this.add(project.getName());
			}
		}
	}

	public void selectProject(Project project) {
		int projectIndex = findProjectIndex(project);
		if (projectIndex != -1) {
			this.select(projectIndex);
			updateSelectedProjectDetails();
		}

	}

	private void updateSelectedProjectDetails() {
		int selectedIndex = ProjectSelectorCombo.this.getSelectionIndex();
		StackLayout workspaceContainerLayout = (StackLayout)workspaceUI.getWorkspaceContainer().getLayout();

		if (selectedIndex==0) {
			workspaceContainerLayout.topControl=workspaceUI.getWorkspaceOverview();
		} else {
			ProjectTabFolder selectedWorkspaceDetails = projectsDetails.get(selectedIndex);
			if (selectedWorkspaceDetails==null) {
				selectedWorkspaceDetails = new ProjectTabFolder(workspaceUI.getWorkspaceContainer(), projects.get(selectedIndex));
				projectsDetails.add(selectedIndex, selectedWorkspaceDetails);
			}
			workspaceContainerLayout.topControl=selectedWorkspaceDetails;
		}
		workspaceUI.getWorkspaceContainer().layout();


		if (projects.get(selectedIndex)!=null) {
			workspaceHeader.setHeaderTitle("Project: " + projects.get(selectedIndex).getName());
			Activator.getLogger().info("Opened project: " + projects.get(selectedIndex).toString());
		} else {
			workspaceHeader.setHeaderTitle("Workspace overview");
			Activator.getLogger().info("Opened projects overview");
		}
	}

	private void createProjectDetailsList(int size) {
		this.projectsDetails = new ArrayList<ProjectTabFolder>();
		for (int i = 0; i < size; i++) {
{'fraction_non_alphanumeric': 0.11053634631091751, 'fraction_numerical': 0.01197930846719303, 'mean_word_length': 5.885660731021556, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '421693', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2169, 'n_words': 366}