<commit_before>/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * 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 com.google.eclipse.mechanic.plugin.ui;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import com.google.eclipse.mechanic.internal.EpfFileModel;
import com.google.eclipse.mechanic.internal.TaskType;
import com.google.eclipse.mechanic.plugin.core.MechanicLog;

/**
 * The dialog to obtain properties for outputting an EPF file.
 * 
 * @author <EMAIL> (<NAME>)
 */
public class EpfOutputDialog extends Dialog {

  /**
   * Provides labels and colors for cells to the saved preferences table. Handles
   * null values specially to make them visually distinct and easy to read.
   */
  private class EPFOutputLabelProvider extends LabelProvider 
      implements ITableLabelProvider, ITableColorProvider {
    public Image getColumnImage(Object element, int columnIndex) {
      return null;
    }

    public String getColumnText(Object element, int columnIndex) {
      String key = (String) element;
      switch (columnIndex) {
        case 0:
          return key;

        case 1:
          String value = preferences.get(key);
          return value != null ? value : "(null)";

        default:
          return null;
      }
    }

    public Color getBackground(Object element, int columnIndex) {
      return getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE);
    }

    public Color getForeground(Object element, int columnIndex) {
      String key = (String) element;
      int systemTextColor;
      if (columnIndex == 1 && preferences.get(key) == null) {
        systemTextColor = SWT.COLOR_DARK_GRAY;
      } else {
        systemTextColor = SWT.COLOR_BLACK;
      }
      return getShell().getDisplay().getSystemColor(systemTextColor);
    }
  }

  private Map<String, String> preferences;
  private String title = "";
  private String description = "";
  private String savedFileLocation = "";
  private int taskType;
  private ITableLabelProvider labelProvider = new EPFOutputLabelProvider();
  private Set<String> selectedKeys;
  private boolean willVerifyOverwrite = true;

  /**
   * Create an output dialog for the given shell.
   * 
   * @param parentShell the shell to create this dialog in.
   * @param preferences the set of preferences that can be added to the
   *        resulting EPF file. The dialog allows the user to select a subset to
   *        export.
   */
  public EpfOutputDialog(Shell parentShell, Map<String, String> preferences) {
    super(parentShell);
    this.preferences = new HashMap<String, String>(preferences);
    this.selectedKeys = preferences.keySet();
  }

  @Override
  protected boolean isResizable() {
    return true;
  }
  
  @Override
  protected Point getInitialSize() {
    Point p =  super.getInitialSize();
    
    return new Point(p.x, p.y * 3 / 2);
  }
  
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    
    // Initial values for the dialog aren't valid, so set the button to 
    // be disabled initially
    getButton(IDialogConstants.OK_ID).setEnabled(false); 
  }

  @Override
  protected Control createDialogArea(Composite parent) {
    final Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(3, false);<commit_msg>Fix issue 12, no title bar in preference recorder.<commit_after>/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * 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 com.google.eclipse.mechanic.plugin.ui;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import com.google.eclipse.mechanic.internal.EpfFileModel;
import com.google.eclipse.mechanic.internal.TaskType;
import com.google.eclipse.mechanic.plugin.core.MechanicLog;

/**
 * The dialog to obtain properties for outputting an EPF file.
 * 
 * @author <EMAIL> (<NAME>)
 */
public class EpfOutputDialog extends Dialog {

  /**
   * Provides labels and colors for cells to the saved preferences table. Handles
   * null values specially to make them visually distinct and easy to read.
   */
  private class EPFOutputLabelProvider extends LabelProvider 
      implements ITableLabelProvider, ITableColorProvider {
    public Image getColumnImage(Object element, int columnIndex) {
      return null;
    }

    public String getColumnText(Object element, int columnIndex) {
      String key = (String) element;
      switch (columnIndex) {
        case 0:
          return key;

        case 1:
          String value = preferences.get(key);
          return value != null ? value : "(null)";

        default:
          return null;
      }
    }

    public Color getBackground(Object element, int columnIndex) {
      return getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE);
    }

    public Color getForeground(Object element, int columnIndex) {
      String key = (String) element;
      int systemTextColor;
      if (columnIndex == 1 && preferences.get(key) == null) {
        systemTextColor = SWT.COLOR_DARK_GRAY;
      } else {
        systemTextColor = SWT.COLOR_BLACK;
      }
      return getShell().getDisplay().getSystemColor(systemTextColor);
    }
  }

  private Map<String, String> preferences;
  private String title = "";
  private String description = "";
  private String savedFileLocation = "";
  private int taskType;
  private ITableLabelProvider labelProvider = new EPFOutputLabelProvider();
  private Set<String> selectedKeys;
  private boolean willVerifyOverwrite = true;

  /**
   * Create an output dialog for the given shell.
   * 
   * @param parentShell the shell to create this dialog in.
   * @param preferences the set of preferences that can be added to the
   *        resulting EPF file. The dialog allows the user to select a subset to
   *        export.
   */
  public EpfOutputDialog(Shell parentShell, Map<String, String> preferences) {
    super(parentShell);
    this.preferences = new HashMap<String, String>(preferences);
    this.selectedKeys = preferences.keySet();
  }

  @Override
  protected boolean isResizable() {
    return true;
  }
  
  @Override
  protected Point getInitialSize() {
    Point p =  super.getInitialSize();
    
    return new Point(p.x, p.y * 3 / 2);
  }
  
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    
    // Initial values for the dialog aren't valid, so set the button to 
    // be disabled initially
    getButton(IDialogConstants.OK_ID).setEnabled(false); 
  }

  
  @Override
  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText("Preference Recorder");
  }

  @Override
  protected Control createDialogArea(Composite parent) {
    final Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(3, false);
{'fraction_non_alphanumeric': 0.12201911478147907, 'fraction_numerical': 0.002783706040642108, 'mean_word_length': 4.02705223880597, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '145667', 'n_tokens_mistral': 3130, 'n_tokens_neox': 3045, 'n_words': 781}