// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProviderParser.java
// public class ResourceTaskProviderParser {
// 
//   private static final Gson gson = new Gson();
// 
//   private final Function<String, String> variableParser;
// 
//   /**
//    * Create a new instance.
//    *
//    * @param variableParser used to perform variable substitution. One such translator is
//    * {@link VariableManagerStringParser#INSTANCE}. To get the raw values, pass
//    * {@code Functions.<String>identity()}
//    */
//   public ResourceTaskProviderParser(Function<String, String> variableParser) {
//     this.variableParser = Preconditions.checkNotNull(variableParser);
//   }
// 
//   public final String[] parse(String text) {
//     if (!text.startsWith("[")) {
//       // I would use Splitter, but I won't use split.
//       StringTokenizer st = new StringTokenizer(text, File.pathSeparator);
//       List<String> list = Lists.newArrayList();
//       while (st.hasMoreElements()) {
//         String elem = (String) st.nextElement();
//         // Historically paths named "null" somehow got added to default prefs
//         if (elem == null) {
//           continue;
//         }
//         String substituted = variableParser.apply(elem);
//         list.add(substituted);
//       }
//       return list.toArray(new String[0]);
//     } else {
//       return gson.fromJson(text, String[].class);
//     }
//   }
// 
//   public final String unparse(String... items) {
//     return gson.toJson(items);
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/VariableManagerStringParser.java
// public class VariableManagerStringParser implements Function<String, String> {
//   public static final VariableManagerStringParser INSTANCE = new VariableManagerStringParser();
// 
//   private VariableManagerStringParser() { }
// 
//   public String apply(String input) {
//     try {
//       IStringVariableManager stringManager =
//           VariablesPlugin.getDefault().getStringVariableManager();
//       return stringManager.performStringSubstitution(input);
//     } catch (CoreException e) {
//       return "";
//     }
//   }
// }


import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.swt.widgets.Composite;
import com.google.eclipse.mechanic.internal.ResourceTaskProviderParser;
import com.google.eclipse.mechanic.internal.VariableManagerStringParser;
/*******************************************************************************
 * Copyright (C) 2011, 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;



/**
 * An editor that lets the user select either a URL resource or
 * directory path. Adding a path uses a filesystem-aware
 * dialog box while the URL editor is a plain text box.
 */
public class DirectoryOrUrlEditor extends ListEditor {

  private static final ResourceTaskProviderParser parser =
      new ResourceTaskProviderParser(VariableManagerStringParser.INSTANCE);

  public DirectoryOrUrlEditor(String name, String labelText, Composite parent) {
    init(name, labelText);
    if (parent != null) {
      // For testing.
      createControl(parent);
    }
  }

  @Override
  protected String getNewInputObject() {
    TaskResourceDialog dialog = new TaskResourceDialog(getShell(), true);
    return (dialog.open() == Dialog.OK) ? dialog.getValue() : null;
  }

// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProviderParser.java
// public class ResourceTaskProviderParser {
// 
//   private static final Gson gson = new Gson();
// 
//   private final Function<String, String> variableParser;
// 
//   /**
//    * Create a new instance.
//    *
//    * @param variableParser used to perform variable substitution. One such translator is
//    * {@link VariableManagerStringParser#INSTANCE}. To get the raw values, pass
//    * {@code Functions.<String>identity()}
//    */
//   public ResourceTaskProviderParser(Function<String, String> variableParser) {
//     this.variableParser = Preconditions.checkNotNull(variableParser);
//   }
// 
//   public final String[] parse(String text) {
//     if (!text.startsWith("[")) {
//       // I would use Splitter, but I won't use split.
//       StringTokenizer st = new StringTokenizer(text, File.pathSeparator);
//       List<String> list = Lists.newArrayList();
//       while (st.hasMoreElements()) {
//         String elem = (String) st.nextElement();
//         // Historically paths named "null" somehow got added to default prefs
//         if (elem == null) {
//           continue;
//         }
//         String substituted = variableParser.apply(elem);
//         list.add(substituted);
//       }
//       return list.toArray(new String[0]);
//     } else {
//       return gson.fromJson(text, String[].class);
//     }
//   }
// 
//   public final String unparse(String... items) {
//     return gson.toJson(items);
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/VariableManagerStringParser.java
// public class VariableManagerStringParser implements Function<String, String> {
//   public static final VariableManagerStringParser INSTANCE = new VariableManagerStringParser();
// 
//   private VariableManagerStringParser() { }
// 
//   public String apply(String input) {
//     try {
//       IStringVariableManager stringManager =
//           VariablesPlugin.getDefault().getStringVariableManager();
//       return stringManager.performStringSubstitution(input);
//     } catch (CoreException e) {
//       return "";
//     }
//   }
// }


// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/ui/DirectoryOrUrlEditor.java
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.swt.widgets.Composite;
import com.google.eclipse.mechanic.internal.ResourceTaskProviderParser;
import com.google.eclipse.mechanic.internal.VariableManagerStringParser;

/*******************************************************************************
 * Copyright (C) 2011, 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;



/**
 * An editor that lets the user select either a URL resource or
 * directory path. Adding a path uses a filesystem-aware
 * dialog box while the URL editor is a plain text box.
 */
public class DirectoryOrUrlEditor extends ListEditor {

  private static final ResourceTaskProviderParser parser =
      new ResourceTaskProviderParser(VariableManagerStringParser.INSTANCE);

  public DirectoryOrUrlEditor(String name, String labelText, Composite parent) {
    init(name, labelText);
    if (parent != null) {
      // For testing.
      createControl(parent);
    }
  }

  @Override
  protected String getNewInputObject() {
    TaskResourceDialog dialog = new TaskResourceDialog(getShell(), true);
    return (dialog.open() == Dialog.OK) ? dialog.getValue() : null;
  }

  @Override