org.eclipse.wst.jsdt.debug.rhino.ui_1.0.1.v201201112313

org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector;

class RhinoLocalLaunchDelegate$ConnectRunnable
  implements Runnable
{
  VirtualMachine vm;
  Exception exception;
  private AttachingConnector connector;
  private Map args;
  final RhinoLocalLaunchDelegate this$0;
  
  RhinoLocalLaunchDelegate$ConnectRunnable(RhinoLocalLaunchDelegate paramRhinoLocalLaunchDelegate, AttachingConnector connector, Map args)
  {
    this$0 = paramRhinoLocalLaunchDelegate;vm = null;exception = null;this.connector = null;this.args = null;
    this.connector = connector;
    this.args = args;
  }
  
  public void run()
  {
    try
    {
      long start = System.currentTimeMillis();
      Exception inner = null;
      do
      {
        try
        {
          vm = connector.attach(args);
        }
        catch (Exception e)
        {
          inner = e;
        }
      } while ((vm == null) && (System.currentTimeMillis() < start + 15000L));
      if (vm == null) {
        throw inner;
      }
    }
    catch (Exception e)
    {
      exception = e;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoLocalLaunchDelegate.ConnectRunnable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import java.io.File;
import java.io.FileFilter;
import org.eclipse.wst.jsdt.core.JavaScriptCore;

class RhinoLocalLaunchDelegate$Filter
  implements FileFilter
{
  final RhinoLocalLaunchDelegate this$0;
  
  RhinoLocalLaunchDelegate$Filter(RhinoLocalLaunchDelegate paramRhinoLocalLaunchDelegate)
  {
    this$0 = paramRhinoLocalLaunchDelegate;
  }
  
  public boolean accept(File pathname)
  {
    return (pathname.isDirectory()) || (JavaScriptCore.isJavaScriptLikeFileName(pathname.getName()));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoLocalLaunchDelegate.Filter
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.SocketUtil;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.jsdt.core.ITypeRoot;
import org.eclipse.wst.jsdt.core.JavaScriptCore;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector;
import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector;
import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget;
import org.eclipse.wst.jsdt.debug.internal.rhino.jsdi.connect.RhinoAttachingConnector;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.RhinoUIPlugin;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.refactoring.Refactoring;
import org.mozilla.javascript.JavaScriptException;
import org.osgi.framework.Bundle;

public class RhinoLocalLaunchDelegate
  implements ILaunchConfigurationDelegate2
{
  public static final String DEBUG_SHELL_CLASS = "org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugMain";
  public static final String RHINO_MAIN_CLASS = "org.mozilla.javascript.tools.shell.Main";
  public static final String MOZILLA_JAVASCRIPT_BUNDLE = "org.mozilla.javascript";
  public static final String DEBUG_TRANSPORT_BUNDLE = "org.eclipse.wst.jsdt.debug.transport";
  private static final String RHINO_DEBUGGER_BUNDLE = "org.eclipse.wst.jsdt.debug.rhino.debugger";
  
  class ConnectRunnable
    implements Runnable
  {
    VirtualMachine vm = null;
    Exception exception = null;
    private AttachingConnector connector = null;
    private Map args = null;
    
    ConnectRunnable(AttachingConnector connector, Map args)
    {
      this.connector = connector;
      this.args = args;
    }
    
    public void run()
    {
      try
      {
        long start = System.currentTimeMillis();
        Exception inner = null;
        do
        {
          try
          {
            vm = connector.attach(args);
          }
          catch (Exception e)
          {
            inner = e;
          }
        } while ((vm == null) && (System.currentTimeMillis() < start + 15000L));
        if (vm == null) {
          throw inner;
        }
      }
      catch (Exception e)
      {
        exception = e;
      }
    }
  }
  
  class Filter
    implements FileFilter
  {
    Filter() {}
    
    public boolean accept(File pathname)
    {
      return (pathname.isDirectory()) || (JavaScriptCore.isJavaScriptLikeFileName(pathname.getName()));
    }
  }
  
  public static final String[] REQUIRED_BUNDLES = { "org.mozilla.javascript", "org.eclipse.wst.jsdt.debug.transport", "org.eclipse.wst.jsdt.debug.rhino.debugger" };
  private ArrayList scope = null;
  private ITypeRoot script = null;
  
  synchronized ITypeRoot getScript(ILaunchConfiguration configuration)
    throws CoreException
  {
    if (script == null)
    {
      IResource resource = Refactoring.getScript(configuration);
      if (resource != null) {
        script = ((ITypeRoot)JavaScriptCore.create((IFile)resource));
      }
    }
    return script;
  }
  
  public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor localmonitor = SubMonitor.convert(monitor, NLS.bind(Messages.launching__, configuration.getName()), 8);
    int port = SocketUtil.findFreePort();
    localmonitor.subTask(Messages.starting_rhino_interpreter);
    if (localmonitor.isCanceled()) {
      return;
    }
    localmonitor.worked(1);
    VirtualMachine vm = null;
    Process p = null;
    try
    {
      localmonitor.subTask(Messages.configuring_rhino_debugger);
      if (localmonitor.isCanceled()) {}
      for (;;)
      {
        return;
        
        localmonitor.worked(1);
        
        ArrayList cmdargs = new ArrayList();
        addVMArgs(configuration, launch, cmdargs);
        addConnectionArgs(port, cmdargs);
        addECMAVersion(configuration, cmdargs);
        addEncoding(launch, cmdargs);
        addOptLevel(configuration, cmdargs);
        addStrictMode(configuration, cmdargs);
        addFArg(cmdargs);
        
        p = DebugPlugin.exec((String[])cmdargs.toArray(new String[cmdargs.size()]), null);
        HashMap args = new HashMap();
        args.put("host", "localhost");
        args.put("port", Integer.toString(port));
        
        localmonitor.subTask(Messages.creating_rhino_vm);
        if (localmonitor.isCanceled())
        {
          cancel(vm, p);
        }
        else
        {
          localmonitor.worked(1);
          RhinoAttachingConnector connector = new RhinoAttachingConnector();
          ConnectRunnable runnable = new ConnectRunnable(connector, args);
          Thread thread = new Thread(runnable, Messages.connect_thread);
          thread.setDaemon(true);
          thread.start();
          while (thread.isAlive())
          {
            if (localmonitor.isCanceled())
            {
              cancel(vm, p);
              thread.interrupt();
            }
            try
            {
              Thread.sleep(100L);
            }
            catch (Exception localException1) {}
          }
          if (exception != null) {
            throw exception;
          }
          if (vm == null) {
            throw new IOException("Failed to connect to Rhino interpreter.");
          }
          vm = vm;
          localmonitor.subTask(Messages.starting_rhino_process);
          if (localmonitor.isCanceled())
          {
            cancel(vm, p);
          }
          else
          {
            localmonitor.worked(1);
            RhinoProcess process = new RhinoProcess(launch, p, computeProcessName(connector, args));
            process.setAttribute(IProcess.ATTR_CMDLINE, formatCommandlineArgs(cmdargs));
            launch.addProcess(process);
            localmonitor.subTask(Messages.creating_js_debug_target);
            if (localmonitor.isCanceled())
            {
              cancel(vm, p);
            }
            else
            {
              localmonitor.worked(1);
              JavaScriptDebugTarget target = new JavaScriptDebugTarget(vm, process, launch, true, false);
              launch.addDebugTarget(target);
              if (!localmonitor.isCanceled()) {
                break;
              }
              cancel(vm, p);
            }
          }
        }
      }
      localmonitor.worked(1);
    }
    catch (IOException ioe)
    {
      cancel(vm, p);
      RhinoUIPlugin.log(ioe);
    }
    catch (Exception e)
    {
      while ((e instanceof JavaScriptException)) {
        if (configuration.getAttribute("logexceptions", true))
        {
          RhinoUIPlugin.log(e);
          
          return;
        }
      }
      cancel(vm, p);
      RhinoUIPlugin.log(e);
    }
    finally
    {
      if (scope != null)
      {
        scope.clear();
        scope = null;
      }
      script = null;
    }
    launch.terminate();
  }
  
  void cancel(VirtualMachine vm, Process process)
  {
    if (process != null) {
      process.destroy();
    }
    if (vm != null) {
      vm.terminate();
    }
  }
  
  void addFArg(ArrayList args)
  {
    args.add("-f");
    args.addAll(scope);
  }
  
  void addVMArgs(ILaunchConfiguration configuration, ILaunch launch, ArrayList args)
    throws CoreException, IOException
  {
    IVMInstall vm = JavaRuntime.getDefaultVMInstall();
    File loc = vm.getInstallLocation();
    if (loc == null) {
      throw new CoreException(new Status(4, "org.eclipse.wst.jsdt.debug.rhino.ui", "Could not locate the default VM install"));
    }
    File exe = StandardVMType.findJavaExecutable(vm.getInstallLocation());
    if (exe == null) {
      throw new CoreException(new Status(4, "org.eclipse.wst.jsdt.debug.rhino.ui", "Could not find the Java executable for the default VM install"));
    }
    args.add(exe.getAbsolutePath());
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < REQUIRED_BUNDLES.length; i++)
    {
      Bundle bundle = Platform.getBundle(REQUIRED_BUNDLES[i]);
      if (bundle == null) {
        throw new CoreException(new Status(4, "org.eclipse.wst.jsdt.debug.rhino.ui", NLS.bind("Could not locate the {0} bundle", REQUIRED_BUNDLES[i])));
      }
      File file = FileLocator.getBundleFile(bundle);
      if (file.isDirectory())
      {
        if ("org.mozilla.javascript".equals(REQUIRED_BUNDLES[i]))
        {
          buffer.append(escapePath(file, false));
        }
        else
        {
          file = new File(file, "bin");
          if (file.exists()) {
            buffer.append(escapePath(file, false));
          }
        }
      }
      else {
        buffer.append(escapePath(file, false));
      }
      if (i < REQUIRED_BUNDLES.length - 1) {
        appendSep(buffer);
      }
    }
    String encoding = getEncoding(launch);
    if (encoding != null) {
      args.add(encoding);
    }
    args.add("-cp");
    args.add(buffer.toString());
    args.add("org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugMain");
  }
  
  String getEncoding(ILaunch launch)
  {
    String encoding = launch.getAttribute("org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING");
    if (encoding != null)
    {
      StringBuffer buffer = new StringBuffer("-Dfile.encoding=");
      buffer.append(encoding);
      return buffer.toString();
    }
    return null;
  }
  
  String escapePath(File file, boolean singlequote)
  {
    String path = file.getAbsolutePath();
    StringCharacterIterator iter = new StringCharacterIterator(path);
    StringBuffer buffer = new StringBuffer();
    boolean hasspace = false;
    char c = iter.current();
    while (c != 65535)
    {
      if (c == '\\')
      {
        buffer.append("/");
      }
      else if (c == '"')
      {
        buffer.append("\"");
      }
      else if (c == ' ')
      {
        hasspace = true;
        buffer.append(c);
      }
      else
      {
        buffer.append(c);
      }
      c = iter.next();
    }
    if ((hasspace) && (!singlequote))
    {
      buffer.insert(0, "\"");
      buffer.append("\"");
      return buffer.toString();
    }
    return path;
  }
  
  void appendSep(StringBuffer buffer)
  {
    if (Platform.getOS().equals("win32")) {
      buffer.append(';');
    } else {
      buffer.append(':');
    }
  }
  
  void addConnectionArgs(int port, ArrayList args)
  {
    args.add("-port");
    args.add(Integer.toString(port));
    args.add("-suspend");
    args.add("y");
  }
  
  void addECMAVersion(ILaunchConfiguration configuration, ArrayList args)
    throws CoreException
  {
    args.add("-version");
    args.add(configuration.getAttribute("ecmaversion", "170"));
  }
  
  void addEncoding(ILaunch launch, ArrayList args)
  {
    String encoding = launch.getAttribute("org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING");
    if (encoding != null)
    {
      args.add("-encoding");
      args.add(encoding);
    }
  }
  
  void addOptLevel(ILaunchConfiguration configuration, ArrayList args)
    throws CoreException
  {
    int opt = configuration.getAttribute("optlevel", -1);
    args.add("-opt");
    args.add(Integer.toString(opt));
  }
  
  void addStrictMode(ILaunchConfiguration configuration, ArrayList args)
    throws CoreException
  {
    boolean strict = configuration.getAttribute("strictmode", false);
    if (strict) {
      args.add("-strict");
    }
  }
  
  synchronized void computeScriptScope(ILaunchConfiguration configuration, IProgressMonitor monitor)
    throws CoreException
  {
    if (scope == null)
    {
      scope = new ArrayList();
      List list = configuration.getAttribute("includepath", null);
      if (list != null)
      {
        String entry = null;
        for (Iterator i = list.iterator(); i.hasNext();)
        {
          entry = (String)i.next();
          int kind = Integer.parseInt(entry.substring(0, 1));
          switch (kind)
          {
          case 1: 
            String value = entry.substring(1);
            IFile ifile = (IFile)ResourcesPlugin.getWorkspace().getRoot().findMember(value);
            if ((ifile != null) && (ifile.exists()))
            {
              File file = URIUtil.toFile(ifile.getLocationURI());
              value = escapePath(file, true);
              if (!scope.contains(value)) {
                scope.add(value);
              }
            }
            break;
          case 2: 
            String f = entry.substring(1);
            File file = new File(f);
            if ((file.exists()) && (!scope.contains(file.getAbsolutePath()))) {
              scope.add(file.getAbsolutePath());
            }
            break;
          }
        }
      }
      addScriptAttribute(configuration, scope);
    }
  }
  
  void addScriptAttribute(ILaunchConfiguration configuration, ArrayList args)
    throws CoreException
  {
    ITypeRoot root = getScript(configuration);
    File file = URIUtil.toFile(root.getResource().getLocationURI());
    String value = escapePath(file, true);
    args.remove(value);
    
    args.add(value);
  }
  
  public ILaunch getLaunch(ILaunchConfiguration configuration, String mode)
    throws CoreException
  {
    return null;
  }
  
  public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
    throws CoreException
  {
    return false;
  }
  
  public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
    throws CoreException
  {
    return true;
  }
  
  public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
    throws CoreException
  {
    monitor.subTask(Messages.computing_script_scope);
    computeScriptScope(configuration, monitor);
    if (scope.isEmpty())
    {
      scope = null;
      throw new CoreException(new Status(4, "org.eclipse.wst.jsdt.debug.rhino.ui", Messages.failed_to_compute_scope));
    }
    return true;
  }
  
  boolean hasProblems(ILaunchConfiguration configuration)
    throws CoreException
  {
    String name = configuration.getAttribute("script", "");
    IResource script = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(name));
    if (script.isAccessible())
    {
      IMarker[] problems = script.findMarkers("org.eclipse.wst.jsdt.core.problem", true, 2);
      return problems.length > 0;
    }
    return false;
  }
  
  String formatCommandlineArgs(ArrayList args)
  {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < args.size(); i++)
    {
      buffer.append(args.get(i));
      if (i < args.size() - 1) {
        buffer.append(" ");
      }
    }
    return buffer.toString();
  }
  
  String formatConnectionArguments(Map args)
  {
    StringBuffer buffer = new StringBuffer();
    Map.Entry entry = null;
    for (Iterator iter = args.entrySet().iterator(); iter.hasNext();)
    {
      entry = (Map.Entry)iter.next();
      buffer.append(entry.getKey()).append(':').append(entry.getValue());
      if (iter.hasNext()) {
        buffer.append(',');
      }
    }
    return buffer.toString();
  }
  
  String computeProcessName(Connector connector, Map args)
  {
    StringBuffer buffer = new StringBuffer(connector.name());
    String timestamp = DateFormat.getDateTimeInstance(2, 2).format(new Date(System.currentTimeMillis()));
    return NLS.bind(Messages.process_label, new String[] { buffer.toString(), formatConnectionArguments(args), timestamp });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoLocalLaunchDelegate
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class RhinoMainTab$1
  extends SelectionAdapter
{
  final RhinoMainTab this$0;
  
  RhinoMainTab$1(RhinoMainTab paramRhinoMainTab)
  {
    this$0 = paramRhinoMainTab;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    RhinoMainTab.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoMainTab.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;

class RhinoMainTab$2
  implements ModifyListener
{
  final RhinoMainTab this$0;
  
  RhinoMainTab$2(RhinoMainTab paramRhinoMainTab)
  {
    this$0 = paramRhinoMainTab;
  }
  
  public void modifyText(ModifyEvent e)
  {
    RhinoMainTab.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoMainTab.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.jsdt.core.IJavaScriptUnit;

class RhinoMainTab$3
  extends SelectionAdapter
{
  final RhinoMainTab this$0;
  
  RhinoMainTab$3(RhinoMainTab paramRhinoMainTab)
  {
    this$0 = paramRhinoMainTab;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    IJavaScriptUnit unit = this$0.chooseScript();
    if (unit != null) {
      this$0.script.setText(unit.getPath().toString());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoMainTab.3
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.wst.jsdt.core.IJavaScriptElement;
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
import org.eclipse.wst.jsdt.core.IMember;
import org.eclipse.wst.jsdt.core.ITypeRoot;
import org.eclipse.wst.jsdt.core.JavaScriptCore;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.RhinoImageRegistry;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.RhinoUIPlugin;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.refactoring.Refactoring;
import org.eclipse.wst.jsdt.debug.internal.ui.SWTFactory;
import org.eclipse.wst.jsdt.debug.internal.ui.dialogs.ScriptSelectionDialog;

public class RhinoMainTab
  extends AbstractLaunchConfigurationTab
{
  public static final String TAB_ID = "rhino.main.tab";
  public static final String[] VERSIONS = { "100", "110", "120", "130", "140", "150", "160", "170" };
  public static final String[] OPTIMIZATIONS = { "-1 [interpret only]", "0 [no optimizations]", "1 [all optimizations]" };
  SelectionAdapter defaultAdapter = new SelectionAdapter()
  {
    public void widgetSelected(SelectionEvent e)
    {
      updateLaunchConfigurationDialog();
    }
  };
  Text script = null;
  Button logging = null;
  Button strict = null;
  Combo ecmaversion = null;
  Combo optlevel = null;
  
  public void createControl(Composite parent)
  {
    Composite comp = SWTFactory.createComposite(parent, 1, 1, 768);
    Group group = SWTFactory.createGroup(comp, Messages._script, 2, 1, 768);
    script = SWTFactory.createSingleText(group, 1);
    script.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        updateLaunchConfigurationDialog();
      }
    });
    script.getLayoutData()).grabExcessHorizontalSpace = true;
    Button browse = SWTFactory.createPushButton(group, Messages.bro_wse, null);
    browse.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        IJavaScriptUnit unit = chooseScript();
        if (unit != null) {
          script.setText(unit.getPath().toString());
        }
      }
    });
    group = SWTFactory.createGroup(comp, Messages.options_group_name, 2, 1, 768);
    Label lbl = SWTFactory.createWrapLabel(group, Messages.ecma_version_to_interpret_with, 1);
    getLayoutDatagrabExcessHorizontalSpace = true;
    ecmaversion = SWTFactory.createCombo(group, 12, 1, VERSIONS);
    ecmaversion.addSelectionListener(defaultAdapter);
    GridData data = (GridData)ecmaversion.getLayoutData();
    grabExcessHorizontalSpace = false;
    horizontalAlignment = 16777224;
    lbl = SWTFactory.createWrapLabel(group, Messages.rhino_opt_level, 1);
    getLayoutDatagrabExcessHorizontalSpace = true;
    optlevel = SWTFactory.createCombo(group, 12, 1, OPTIMIZATIONS);
    optlevel.addSelectionListener(defaultAdapter);
    data = (GridData)optlevel.getLayoutData();
    grabExcessHorizontalSpace = false;
    horizontalAlignment = 16777224;
    strict = SWTFactory.createCheckButton(group, Messages.strict_mode, null, false, 2);
    strict.addSelectionListener(defaultAdapter);
    logging = SWTFactory.createCheckButton(group, Messages.log_interpreter_exceptions, null, false, 2);
    logging.addSelectionListener(defaultAdapter);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, "org.eclipse.wst.jsdt.debug.rhino.ui.rhino_main_tab_context");
    setControl(comp);
  }
  
  public String getHelpContextId()
  {
    return "org.eclipse.wst.jsdt.debug.rhino.ui.rhino_main_tab_context";
  }
  
  IJavaScriptUnit chooseScript()
  {
    ScriptSelectionDialog dialog = new ScriptSelectionDialog(getShell(), false, ResourcesPlugin.getWorkspace().getRoot());
    dialog.setTitle(Messages.script_selection);
    if (dialog.open() == 0)
    {
      IFile file = (IFile)dialog.getFirstResult();
      return (IJavaScriptUnit)JavaScriptCore.create(file);
    }
    return null;
  }
  
  public boolean isValid(ILaunchConfiguration launchConfig)
  {
    String text2 = script.getText().trim();
    boolean hasscript = text2.length() > 0;
    if (!hasscript)
    {
      setErrorMessage(Messages.provide_script_for_project);
      return false;
    }
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(text2));
    if (resource != null)
    {
      if (resource.getType() != 1)
      {
        setErrorMessage(NLS.bind(Messages.script_not_a_file, text2));
        return false;
      }
      if (!resource.isAccessible())
      {
        setErrorMessage(NLS.bind(Messages.script_not_accessible, text2));
        return false;
      }
    }
    else
    {
      setErrorMessage(NLS.bind(Messages.script_not_in_workspace, text2));
      return false;
    }
    setErrorMessage(null);
    setMessage(Messages.launch_script);
    return true;
  }
  
  public void setDefaults(ILaunchConfigurationWorkingCopy configuration)
  {
    IJavaScriptElement element = getContext();
    if (element != null)
    {
      if ((element instanceof IMember))
      {
        IMember member = (IMember)element;
        if (member.isBinary()) {
          element = member.getClassFile();
        } else {
          element = member.getJavaScriptUnit();
        }
      }
      String pname = element.getJavaScriptProject().getProject().getName();
      String name = pname;
      ITypeRoot root = null;
      if ((element.getElementType() == 6) || 
        (element.getElementType() == 5))
      {
        root = (ITypeRoot)element;
        String tname = root.getElementName();
        configuration.setAttribute("script", root.getPath().toString());
        name = NLS.bind(Messages.config_name, new String[] { pname, tname });
      }
      name = getLaunchConfigurationDialog().generateName(name);
      configuration.rename(name);
      Refactoring.mapResources(configuration);
    }
    configuration.setAttribute("logexceptions", true);
    configuration.setAttribute("ecmaversion", "170");
    configuration.setAttribute("optlevel", -1);
    configuration.setAttribute("strictmode", false);
  }
  
  IJavaScriptElement getContext()
  {
    IWorkbenchPage page = RhinoUIPlugin.getActivePage();
    if (page != null)
    {
      ISelection selection = page.getSelection();
      if ((selection instanceof IStructuredSelection))
      {
        IStructuredSelection ss = (IStructuredSelection)selection;
        if (!ss.isEmpty())
        {
          Object obj = ss.getFirstElement();
          if ((obj instanceof IJavaScriptElement)) {
            return (IJavaScriptElement)obj;
          }
          if ((obj instanceof IResource))
          {
            IJavaScriptElement je = JavaScriptCore.create((IResource)obj);
            if (je == null)
            {
              IProject pro = ((IResource)obj).getProject();
              je = JavaScriptCore.create(pro);
            }
            if (je != null) {
              return je;
            }
          }
        }
      }
      IEditorPart part = page.getActiveEditor();
      if (part != null)
      {
        IEditorInput input = part.getEditorInput();
        return (IJavaScriptElement)input.getAdapter(IJavaScriptElement.class);
      }
    }
    return null;
  }
  
  public void initializeFrom(ILaunchConfiguration configuration)
  {
    try
    {
      String text = configuration.getAttribute("script", null);
      if (text != null) {
        script.setText(text);
      }
      boolean value = configuration.getAttribute("logexceptions", true);
      logging.setSelection(value);
      value = configuration.getAttribute("strictmode", false);
      strict.setSelection(value);
      text = configuration.getAttribute("ecmaversion", "170");
      int idx = ecmaversion.indexOf(text);
      if (idx < 0) {
        idx = 7;
      }
      ecmaversion.select(idx);
      int opt = configuration.getAttribute("optlevel", -1);
      optlevel.select(opt + 1);
    }
    catch (CoreException localCoreException) {}
  }
  
  public void performApply(ILaunchConfigurationWorkingCopy configuration)
  {
    String scpt = script.getText().trim();
    if (scpt.length() < 1) {
      configuration.removeAttribute("script");
    } else {
      configuration.setAttribute("script", scpt);
    }
    configuration.setAttribute("logexceptions", logging.getSelection());
    configuration.setAttribute("strictmode", strict.getSelection());
    configuration.setAttribute("ecmaversion", ecmaversion.getText());
    configuration.setAttribute("optlevel", optlevel.getSelectionIndex() - 1);
    Refactoring.mapResources(configuration);
  }
  
  public String getName()
  {
    return Messages.main;
  }
  
  public String getId()
  {
    return "rhino.main.tab";
  }
  
  public Image getImage()
  {
    return RhinoImageRegistry.getSharedImage("IMG_MAIN_TAB");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoMainTab
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.internal.core.StreamsProxy;
import org.eclipse.wst.jsdt.debug.internal.core.launching.JavaScriptProcess;

public class RhinoProcess
  extends JavaScriptProcess
{
  public static final String TYPE = "rhino";
  private Process process = null;
  private StreamsProxy streamproxy = null;
  
  public RhinoProcess(ILaunch launch, Process p, String name)
  {
    super(launch, name);
    process = p;
    String capture = launch.getAttribute("org.eclipse.debug.core.capture_output");
    boolean needsstreams = capture == null ? true : Boolean.valueOf(capture).booleanValue();
    if (needsstreams) {
      streamproxy = new StreamsProxy(p, launch.getAttribute("org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING"));
    }
    setAttribute(IProcess.ATTR_PROCESS_TYPE, "rhino");
  }
  
  public void terminate()
    throws DebugException
  {
    process.destroy();
    if (streamproxy != null) {
      streamproxy.close();
    }
    super.terminate();
  }
  
  public IStreamsProxy getStreamsProxy()
  {
    return streamproxy;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoProcess
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;

import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;

public class RhinoTabGroup
  extends AbstractLaunchConfigurationTabGroup
{
  public void createTabs(ILaunchConfigurationDialog dialog, String mode)
  {
    SourceLookupTab stab = new SourceLookupTab();
    CommonTab ctab = new CommonTab();
    setTabs(new ILaunchConfigurationTab[] {
      new RhinoMainTab(), 
      new IncludeTab(), 
      stab, 
      ctab });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching.RhinoTabGroup
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences.messages";
  public static String rhino_pref_page_desc;
  public static String suspend_execution;
  public static String suspend_for_stdin;
  
  static
  {
    NLS.initializeMessages("org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences.Messages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.wst.jsdt.debug.internal.rhino.ui.RhinoUIPlugin;
import org.eclipse.wst.jsdt.debug.internal.ui.SWTFactory;

public class RhinoDebugPreferencePage
  extends FieldEditorPreferencePage
  implements IWorkbenchPreferencePage
{
  public static final String PAGE_ID = "org.eclipse.wst.jsdt.debug.rhino.ui.debug.pref.page";
  
  public RhinoDebugPreferencePage()
  {
    super(1);
    setDescription(Messages.rhino_pref_page_desc);
    setPreferenceStore(RhinoUIPlugin.getCorePreferenceStore());
  }
  
  public void init(IWorkbench workbench) {}
  
  protected void createFieldEditors() {}
  
  public void createControl(Composite parent)
  {
    super.createControl(parent);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.wst.jsdt.debug.rhino.ui.rhino_preference_page");
  }
  
  protected Control createContents(Composite parent)
  {
    Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, 768, 0, 0);
    Group group = SWTFactory.createGroup(comp, Messages.suspend_execution, 1, 1, 768);
    BooleanFieldEditor editor = new BooleanFieldEditor("org.eclipse.wst.jsdt.debug.rhino.suspend_on_stdin_load", Messages.suspend_for_stdin, group);
    initEditor(editor, RhinoUIPlugin.getCorePreferenceStore());
    
    GridLayout lo = (GridLayout)group.getLayout();
    marginWidth = 5;
    marginHeight = 5;
    return comp;
  }
  
  void initEditor(FieldEditor editor, IPreferenceStore store)
  {
    addField(editor);
    editor.setPage(this);
    editor.setPropertyChangeListener(this);
    editor.setPreferenceStore(store);
    editor.load();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.preferences.RhinoDebugPreferencePage
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.refactoring;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.ltk.core.refactoring.Change;

public class FolderChange
  extends RhinoChange
{
  public FolderChange(ILaunchConfiguration configuration, String oldname, String newname)
  {
    super(configuration, oldname, newname);
  }
  
  public Change perform(IProgressMonitor pm)
    throws CoreException
  {
    ILaunchConfigurationWorkingCopy copy = configuration.getWorkingCopy();
    if (!configuration.isLocal())
    {
      IContainer cont = (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(newname);
      copy.setContainer(cont);
    }
    String script = computeNewScriptName(configuration);
    if (script != null) {
      copy.setAttribute("script", script);
    }
    updateIncludeEntries(copy);
    
    Refactoring.mapResources(copy);
    if (copy.isDirty())
    {
      configuration = copy.doSave();
      return new FolderChange(configuration, newname, oldname);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.ui.refactoring.FolderChange
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.refactoring;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.MoveArguments;
import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;

public class FolderMoveParticipant
  extends MoveParticipant
{
  private IFolder folder = null;
  
  protected boolean initialize(Object element)
  {
    folder = ((IFolder)element);
    return true;
  }
  
  public String getName()
  {
    return Messages.rhino_lc_participant;
  }
  
  public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context)
    throws OperationCanceledException
  {
    return new RefactoringStatus();
  }
  
  public Change createChange(IProgressMonitor pm)
    throws CoreException, OperationCanceledException
  {
    IContainer locale = (IContainer)getArguments().getDestination();
    return Refactoring.createChangesForFolderRename(folder, locale.getFullPath().append(folder.getName()).makeAbsolute().toOSString());
  }
}

/* Location:
 * Qualified Na
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd