// 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 com.google.devtools.bazel.e4b.Activator;
import com.google.devtools.bazel.e4b.command.BazelNotFoundException;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.bazel.e4b.preferences;


/**
 * Page to configure the e4b plugin. The only configuration parameter is the path to the Bazel
 * binary so this page provide a file field to specify it.
 */
public class BazelPreferencePage extends FieldEditorPreferencePage
    implements
      IWorkbenchPreferencePage {

  private static class BazelBinaryFieldEditor extends FileFieldEditor {
    BazelBinaryFieldEditor(Composite parent) {
      super("BAZEL_PATH", "Path to the &Bazel binary:", true, parent);
      setValidateStrategy(VALIDATE_ON_KEY_STROKE);
    }

    @Override
    protected boolean doCheckState() {
      try {
        Activator.getDefault().getCommand().checkVersion(getTextControl().getText());
        return true;
// 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/preferences/BazelPreferencePage.java
import com.google.devtools.bazel.e4b.Activator;
import com.google.devtools.bazel.e4b.command.BazelNotFoundException;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.bazel.e4b.preferences;


/**
 * Page to configure the e4b plugin. The only configuration parameter is the path to the Bazel
 * binary so this page provide a file field to specify it.
 */
public class BazelPreferencePage extends FieldEditorPreferencePage
    implements
      IWorkbenchPreferencePage {

  private static class BazelBinaryFieldEditor extends FileFieldEditor {
    BazelBinaryFieldEditor(Composite parent) {
      super("BAZEL_PATH", "Path to the &Bazel binary:", true, parent);
      setValidateStrategy(VALIDATE_ON_KEY_STROKE);
    }

    @Override
    protected boolean doCheckState() {
      try {
        Activator.getDefault().getCommand().checkVersion(getTextControl().getText());
        return true;
      } catch (BazelNotFoundException e) {