<commit_before>package com.codeaffine.extras.ide.internal.workingset;

import static com.codeaffine.extras.ide.internal.Images.WORKING_SET_WIZBAN;
import static org.eclipse.jface.dialogs.Dialog.applyDialogFont;
import static org.eclipse.jface.layout.GridDataFactory.swtDefaults;
import static org.eclipse.jface.viewers.StructuredSelection.EMPTY;
import static org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS;

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.dialogs.IWorkingSetPage;
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;

import com.codeaffine.extras.ide.internal.Images;
import com.codeaffine.extras.ide.internal.workingset.ValidationStatus.Severity;


public class DynamicWorkingSetPage extends WizardPage implements  IWorkingSetPage {

  private final ProjectsProvider projectsProvider;
  private final Validator validator;
  private boolean visible;
  private IWorkingSet workingSet;
  Composite composite;
  Text nameText;
  Text patternText;
  Label previewLabel;
  TableViewer previewViewer;
  PreviewLabelProvider previewLabelProvider;

  public DynamicWorkingSetPage() {
    this( new WorkspaceProjectsProvider(), new JdtFeature() );
  }

  public DynamicWorkingSetPage( ProjectsProvider projectsProvider, JdtFeature jdtFeature ) {
    super( "DynamicWorkingSetWizardPage" );
    this.projectsProvider = projectsProvider;
    this.validator = new Validator( projectsProvider, jdtFeature );
    setTitle( "Dynamic Project Working Set" );
    setDescription( "Enter a pattern to include matching projects in this working set" );
    setImageDescriptor( Images.getImageDescriptor( WORKING_SET_WIZBAN ) );
  }

  @Override
  public void createControl( Composite parent ) {
    createControls( parent );
    defineTabOrder();
    attachListeners();
    layoutControls();
    setControl( composite );
    applyDialogFont( composite );
    applySelection();
  }

  @Override
  public void setVisible( boolean visible ) {
    super.setVisible( visible );
    if( visible ) {
      updateVisibleState();
      updateStatusMessage( new ValidationStatus( Severity.NONE, "" ) );
      setPageComplete( false );
    }
  }

  @Override
  public void finish() {
    workingSet.setName( getPatternText() );
    workingSet.setLabel( getNameText() );
  }

  @Override
  public IWorkingSet getSelection() {
    return workingSet;
  }

  @Override
  public void setSelection( IWorkingSet workingSet ) {
    this.workingSet = workingSet;
  }

  private void createControls( Composite parent ) {
    composite = new Composite( parent, SWT.NONE );
    Label nameLabel = new Label( composite, SWT.NONE );
    nameLabel.setText( "&Name" );
    nameText = new Text( composite, SWT.BORDER );
    Label patternLabel = new Label( composite, SWT.NONE );
    patternLabel.setText( "&Pattern" );
    patternText = new Text( composite, SWT.BORDER );
    installPatternContentAssist();
    previewLabel = new Label( composite, SWT.NONE );
    previewLabel.setText( "Preview" );
    previewViewer = new TableViewer( composite, SWT.SINGLE | SWT.FULL_SELECTION );
    previewViewer.getControl().setBackground( getWidgetBackgroundColor() );
    previewViewer.getControl().addListener( SWT.FocusOut, new PreviewFocusOutListener() );
    previewLabelProvider = new PreviewLabelProvider( getShell().getDisplay() );
    previewViewer.setLabelProvider( previewLabelProvider );
    previewViewer.setContentProvider( ArrayContentProvider.getInstance() );
    previewViewer.setInput( projectsProvider.getProjects() );
    previewViewer.setComparator( new PreviewComparator( "" ) );
  }

  private void layoutControls() {
    composite.setLayout( GridLayoutFactory.swtDefaults().numColumns( 2 ).spacing( 10, 5 ).create() );
    swtDefaults().align( SWT.FILL, SWT.TOP ).grab( true, false ).applyTo( composite );
    swtDefaults().align( SWT.FILL, SWT.CENTER ).grab( true, false ).applyTo( nameText );
    swtDefaults().align( SWT.FILL, SWT.CENTER ).grab( true, false ).applyTo( patternText );
    swtDefaults().align( SWT.FILL, SWT.TOP ).grab( false, false ).indent( 0, 10 ).applyTo( previewLabel );<commit_msg>Draw border around dynamic projects preview<commit_after>package com.codeaffine.extras.ide.internal.workingset;

import static com.codeaffine.extras.ide.internal.Images.WORKING_SET_WIZBAN;
import static org.eclipse.jface.dialogs.Dialog.applyDialogFont;
import static org.eclipse.jface.layout.GridDataFactory.swtDefaults;
import static org.eclipse.jface.viewers.StructuredSelection.EMPTY;
import static org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS;

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.dialogs.IWorkingSetPage;
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;

import com.codeaffine.extras.ide.internal.Images;
import com.codeaffine.extras.ide.internal.workingset.ValidationStatus.Severity;


public class DynamicWorkingSetPage extends WizardPage implements  IWorkingSetPage {

  private final ProjectsProvider projectsProvider;
  private final Validator validator;
  private boolean visible;
  private IWorkingSet workingSet;
  Composite composite;
  Text nameText;
  Text patternText;
  Label previewLabel;
  TableViewer previewViewer;
  PreviewLabelProvider previewLabelProvider;

  public DynamicWorkingSetPage() {
    this( new WorkspaceProjectsProvider(), new JdtFeature() );
  }

  public DynamicWorkingSetPage( ProjectsProvider projectsProvider, JdtFeature jdtFeature ) {
    super( "DynamicWorkingSetWizardPage" );
    this.projectsProvider = projectsProvider;
    this.validator = new Validator( projectsProvider, jdtFeature );
    setTitle( "Dynamic Project Working Set" );
    setDescription( "Enter a pattern to include matching projects in this working set" );
    setImageDescriptor( Images.getImageDescriptor( WORKING_SET_WIZBAN ) );
  }

  @Override
  public void createControl( Composite parent ) {
    createControls( parent );
    defineTabOrder();
    attachListeners();
    layoutControls();
    setControl( composite );
    applyDialogFont( composite );
    applySelection();
  }

  @Override
  public void setVisible( boolean visible ) {
    super.setVisible( visible );
    if( visible ) {
      updateVisibleState();
      updateStatusMessage( new ValidationStatus( Severity.NONE, "" ) );
      setPageComplete( false );
    }
  }

  @Override
  public void finish() {
    workingSet.setName( getPatternText() );
    workingSet.setLabel( getNameText() );
  }

  @Override
  public IWorkingSet getSelection() {
    return workingSet;
  }

  @Override
  public void setSelection( IWorkingSet workingSet ) {
    this.workingSet = workingSet;
  }

  private void createControls( Composite parent ) {
    composite = new Composite( parent, SWT.NONE );
    Label nameLabel = new Label( composite, SWT.NONE );
    nameLabel.setText( "&Name" );
    nameText = new Text( composite, SWT.BORDER );
    Label patternLabel = new Label( composite, SWT.NONE );
    patternLabel.setText( "&Pattern" );
    patternText = new Text( composite, SWT.BORDER );
    installPatternContentAssist();
    previewLabel = new Label( composite, SWT.NONE );
    previewLabel.setText( "Preview" );
    previewViewer = new TableViewer( composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER );
    previewViewer.getControl().setBackground( getWidgetBackgroundColor() );
    previewViewer.getControl().addListener( SWT.FocusOut, new PreviewFocusOutListener() );
    previewLabelProvider = new PreviewLabelProvider( getShell().getDisplay() );
    previewViewer.setLabelProvider( previewLabelProvider );
    previewViewer.setContentProvider( ArrayContentProvider.getInstance() );
    previewViewer.setInput( projectsProvider.getProjects() );
    previewViewer.setComparator( new PreviewComparator( "" ) );
  }

  private void layoutControls() {
    composite.setLayout( GridLayoutFactory.swtDefaults().numColumns( 2 ).spacing( 10, 5 ).create() );
    swtDefaults().align( SWT.FILL, SWT.TOP ).grab( true, false ).applyTo( composite );
    swtDefaults().align( SWT.FILL, SWT.CENTER ).grab( true, false ).applyTo( nameText );
    swtDefaults().align( SWT.FILL, SWT.CENTER ).grab( true, false ).applyTo( patternText );
    swtDefaults().align( SWT.FILL, SWT.TOP ).grab( false, false ).indent( 0, 10 ).applyTo( previewLabel );
{'fraction_non_alphanumeric': 0.1028408512371449, 'fraction_numerical': 0.0014255167498218105, 'mean_word_length': 4.8920215956808635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7595364', 'n_tokens_mistral': 2940, 'n_tokens_neox': 2859, 'n_words': 612}