// Path: java/com/google/devtools/bazel/e4b/Activator.java
// public class Activator extends AbstractUIPlugin {
// 
//   // The plug-in ID
//   public static final String PLUGIN_ID = "com.google.devtools.bazel.e4b"; //$NON-NLS-1$
// 
//   // The shared instance
//   private static Activator plugin;
// 
//   private BazelCommand command;
// 
//   /**
//    * The constructor
//    */
//   public Activator() {}
// 
//   /*
//    * (non-Javadoc)
//    *
//    * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
//    */
//   @Override
//   public void start(BundleContext context) throws Exception {
//     plugin = this;
//     super.start(context);
//     this.command = new BazelCommand(new BazelAspectLocationImpl(), new CommandConsoleFactoryImpl());
//     // Get the bazel path from the settings
//     this.command.setBazelPath(getPreferenceStore().getString("BAZEL_PATH"));
//     getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
//       @Override
//       public void propertyChange(PropertyChangeEvent event) {
//         if (event.getProperty().equals("BAZEL_PATH")) {
//           command.setBazelPath(event.getNewValue().toString());
//         }
//       }
//     });
//   }
// 
//   /*
//    * (non-Javadoc)
//    *
//    * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
//    */
//   @Override
//   public void stop(BundleContext context) throws Exception {
//     plugin = null;
//     this.command = null;
//     super.stop(context);
//   }
// 
//   /**
//    * Returns the shared instance
//    *
//    * @return the shared instance
//    */
//   public static Activator getDefault() {
//     return plugin;
//   }
// 
//   /**
//    * Returns the unique instance of {@link BazelCommand}.
//    */
//   public BazelCommand getCommand() {
//     return command;
//   }
// 
//   /**
//    * Log an error to eclipse.
//    */
//   public static void error(String message) {
//     plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, message));
//   }
// 
//   /**
//    * Log an error to eclipse, with an attached exception.
//    */
//   public static void error(String message, Throwable exception) {
//     plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, message, exception));
//   }
// }
// 
// Path: java/com/google/devtools/bazel/e4b/command/BazelNotFoundException.java
// public class BazelNotFoundException extends Exception {
//   private static final long serialVersionUID = 1L;
// 
//   private BazelNotFoundException(String msg) {
//     super(msg);
//   }
// 
//   public static final class BazelNotSetException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelNotSetException() {
//       super("Path to Bazel binary is not set, please set it "
//           + "(Preferences... > Bazel Plugins Preferences)");
//     }
//   }
// 
//   public static final class BazelNotExecutableException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelNotExecutableException() {
//       super("Path to Bazel is wrong (does not point to a binary), please set it "
//           + "(Preferences... > Bazel Plugins Preferences)");
//     }
//   }
// 
//   public static final class BazelTooOldException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelTooOldException(String version) {
//       super("Bazel version (" + version + ") is unsupported (too old or development version), "
//           + "please update your Bazel binary.");
//     }
//   }
// }


import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
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.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import com.google.common.collect.ImmutableList;
import com.google.devtools.bazel.e4b.Activator;
import com.google.devtools.bazel.e4b.command.BazelNotFoundException;

  // A simple helper to use lambdas to create a SelectionListener that does the same action on all
  // cases.
  private static SelectionListener createSelectionListener(Consumer<SelectionEvent> f) {
    return new SelectionListener() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        f.accept(e);

      }

      @Override
      public void widgetDefaultSelected(SelectionEvent e) {
        f.accept(e);
      }
    };
  }

  private Button createButton(String text, Consumer<SelectionEvent> handler) {
    Button result = new Button(container, SWT.DEFAULT);
    result.setText(text);
    result.addSelectionListener(createSelectionListener(handler));
    result.setEnabled(false);
    return result;
  }

  private void createWorkspaceSelectionControls() {
    Label label = new Label(container, SWT.NONE);
    label.setText("Workpsace root: ");

// Path: java/com/google/devtools/bazel/e4b/Activator.java
// public class Activator extends AbstractUIPlugin {
// 
//   // The plug-in ID
//   public static final String PLUGIN_ID = "com.google.devtools.bazel.e4b"; //$NON-NLS-1$
// 
//   // The shared instance
//   private static Activator plugin;
// 
//   private BazelCommand command;
// 
//   /**
//    * The constructor
//    */
//   public Activator() {}
// 
//   /*
//    * (non-Javadoc)
//    *
//    * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
//    */
//   @Override
//   public void start(BundleContext context) throws Exception {
//     plugin = this;
//     super.start(context);
//     this.command = new BazelCommand(new BazelAspectLocationImpl(), new CommandConsoleFactoryImpl());
//     // Get the bazel path from the settings
//     this.command.setBazelPath(getPreferenceStore().getString("BAZEL_PATH"));
//     getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
//       @Override
//       public void propertyChange(PropertyChangeEvent event) {
//         if (event.getProperty().equals("BAZEL_PATH")) {
//           command.setBazelPath(event.getNewValue().toString());
//         }
//       }
//     });
//   }
// 
//   /*
//    * (non-Javadoc)
//    *
//    * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
//    */
//   @Override
//   public void stop(BundleContext context) throws Exception {
//     plugin = null;
//     this.command = null;
//     super.stop(context);
//   }
// 
//   /**
//    * Returns the shared instance
//    *
//    * @return the shared instance
//    */
//   public static Activator getDefault() {
//     return plugin;
//   }
// 
//   /**
//    * Returns the unique instance of {@link BazelCommand}.
//    */
//   public BazelCommand getCommand() {
//     return command;
//   }
// 
//   /**
//    * Log an error to eclipse.
//    */
//   public static void error(String message) {
//     plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, message));
//   }
// 
//   /**
//    * Log an error to eclipse, with an attached exception.
//    */
//   public static void error(String message, Throwable exception) {
//     plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, message, exception));
//   }
// }
// 
// Path: java/com/google/devtools/bazel/e4b/command/BazelNotFoundException.java
// public class BazelNotFoundException extends Exception {
//   private static final long serialVersionUID = 1L;
// 
//   private BazelNotFoundException(String msg) {
//     super(msg);
//   }
// 
//   public static final class BazelNotSetException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelNotSetException() {
//       super("Path to Bazel binary is not set, please set it "
//           + "(Preferences... > Bazel Plugins Preferences)");
//     }
//   }
// 
//   public static final class BazelNotExecutableException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelNotExecutableException() {
//       super("Path to Bazel is wrong (does not point to a binary), please set it "
//           + "(Preferences... > Bazel Plugins Preferences)");
//     }
//   }
// 
//   public static final class BazelTooOldException extends BazelNotFoundException {
//     private static final long serialVersionUID = 1L;
// 
//     public BazelTooOldException(String version) {
//       super("Bazel version (" + version + ") is unsupported (too old or development version), "
//           + "please update your Bazel binary.");
//     }
//   }
// }


// Path: java/com/google/devtools/bazel/e4b/wizard/WorkspaceWizardPage.java
import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
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.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import com.google.common.collect.ImmutableList;
import com.google.devtools.bazel.e4b.Activator;
import com.google.devtools.bazel.e4b.command.BazelNotFoundException;


  // A simple helper to use lambdas to create a SelectionListener that does the same action on all
  // cases.
  private static SelectionListener createSelectionListener(Consumer<SelectionEvent> f) {
    return new SelectionListener() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        f.accept(e);

      }

      @Override
      public void widgetDefaultSelected(SelectionEvent e) {
        f.accept(e);
      }
    };
  }

  private Button createButton(String text, Consumer<SelectionEvent> handler) {
    Button result = new Button(container, SWT.DEFAULT);
    result.setText(text);
    result.addSelectionListener(createSelectionListener(handler));
    result.setEnabled(false);
    return result;
  }

  private void createWorkspaceSelectionControls() {
    Label label = new Label(container, SWT.NONE);
    label.setText("Workpsace root: ");

    workspaceRoot = new Label(container, SWT.BORDER);