<commit_before>/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.editor.rcp;

import org.csstudio.display.builder.model.DisplayModel;
import org.csstudio.display.builder.model.WidgetClassSupport;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;

/** Content of the {@link NewDisplayWizard}
 *  @author <NAME>
 */
@SuppressWarnings("nls")
public class NewDisplayWizardPage extends WizardPage
{
    private final ISelection selection;
    private Text containerText;
    private Text fileText;

    public NewDisplayWizardPage(final ISelection selection)
    {
        super("page1");
        this.selection = selection;
        setTitle(Messages.NewDisplay_Title);
        setDescription(Messages.NewDisplay_Description);
    }

    @Override
    public void createControl(final Composite parent)
    {
        final Composite container = new Composite(parent, SWT.NULL);
        final GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        layout.verticalSpacing = 9;
        container.setLayout(layout);

        Label label = new Label(container, SWT.NULL);
        label.setText(Messages.NewDisplay_Container);

        containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
        containerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final ModifyListener value_check = e -> checkValues();
        containerText.addModifyListener(value_check);

        final Button button = new Button(container, SWT.PUSH);
        button.setText(Messages.NewDisplay_Browse);
        button.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                handleBrowse();
            }
        });
        label = new Label(container, SWT.NULL);
        label.setText(Messages.NewDisplay_Filename);

        fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
        fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        fileText.addModifyListener(value_check);
        initialize();
        checkValues();
        setControl(container);
    }

    private void initialize()
    {
        // Try to determine container from selection
        if (selection instanceof IStructuredSelection  &&  !selection.isEmpty())
        {
            final IStructuredSelection ssel = (IStructuredSelection) selection;
            if (ssel.size() > 1)
                return;
            final Object obj = ssel.getFirstElement();
            if (obj instanceof IResource)
            {
                final IContainer container;
                if (obj instanceof IContainer)
                    container = (IContainer) obj;
                else
                    container = ((IResource) obj).getParent();
                containerText.setText(container.getFullPath().toString());
            }
        }
        fileText.setText(Messages.NewDisplay_InitialName);
    }

    private void handleBrowse()
    {
        final ContainerSelectionDialog dialog = new ContainerSelectionDialog(
            getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
            Messages.NewDisplay_BrowseTitle);
        if (dialog.open() != ContainerSelectionDialog.OK)<commit_msg>New display wizard: Select and focus on file name if container known<commit_after>/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.editor.rcp;

import org.csstudio.display.builder.model.DisplayModel;
import org.csstudio.display.builder.model.WidgetClassSupport;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;

/** Content of the {@link NewDisplayWizard}
 *  @author <NAME>
 */
@SuppressWarnings("nls")
public class NewDisplayWizardPage extends WizardPage
{
    private final ISelection selection;
    private Text containerText;
    private Text fileText;

    public NewDisplayWizardPage(final ISelection selection)
    {
        super("page1");
        this.selection = selection;
        setTitle(Messages.NewDisplay_Title);
        setDescription(Messages.NewDisplay_Description);
    }

    @Override
    public void createControl(final Composite parent)
    {
        final Composite container = new Composite(parent, SWT.NULL);
        final GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        layout.verticalSpacing = 9;
        container.setLayout(layout);

        Label label = new Label(container, SWT.NULL);
        label.setText(Messages.NewDisplay_Container);

        containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
        containerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final ModifyListener value_check = e -> checkValues();
        containerText.addModifyListener(value_check);

        final Button button = new Button(container, SWT.PUSH);
        button.setText(Messages.NewDisplay_Browse);
        button.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                handleBrowse();
            }
        });
        label = new Label(container, SWT.NULL);
        label.setText(Messages.NewDisplay_Filename);

        fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
        fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        fileText.addModifyListener(value_check);
        final boolean have_container = initialize();
        checkValues();
        setControl(container);
        if (have_container)
        {   // Focus on the file name, container already set
            fileText.selectAll();
            fileText.forceFocus();
        }
        else // First need container
            containerText.forceFocus();
    }

    private boolean initialize()
    {
        boolean have_container = false;
        // Try to determine container from selection
        if (selection instanceof IStructuredSelection  &&  !selection.isEmpty())
        {
            final IStructuredSelection ssel = (IStructuredSelection) selection;
            if (ssel.size() >= 1)
            {
                final Object obj = ssel.getFirstElement();
                if (obj instanceof IResource)
                {
                    final IContainer container;
                    if (obj instanceof IContainer)
                        container = (IContainer) obj;
                    else
                        container = ((IResource) obj).getParent();
                    containerText.setText(container.getFullPath().toString());
                    have_container = true;
                }
            }
        }
        fileText.setText(Messages.NewDisplay_InitialName);
        return have_container;
    }

    private void handleBrowse()
    {
        final ContainerSelectionDialog dialog = new ContainerSelectionDialog(
            getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
            Messages.NewDisplay_BrowseTitle);
        if (dialog.open() != ContainerSelectionDialog.OK)
{'fraction_non_alphanumeric': 0.12169255490091055, 'fraction_numerical': 0.0034279592929833957, 'mean_word_length': 2.9425675675675675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4946148', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2365, 'n_words': 528}