Anonymous avatar Anonymous committed 1df09ea

Made main launch tab functional.

Comments (0)

Files changed (3)

src/org/lispdev/replview/LocalLaunchConfigurationTabGroup.java

 package org.lispdev.replview;
 
 import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.EnvironmentTab;
 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
 import org.eclipse.debug.ui.ILaunchConfigurationTab;
 
   public void createTabs(ILaunchConfigurationDialog dialog, String mode)
   {
     setTabs(new ILaunchConfigurationTab[]{
-        new MainLocalLaunchConfigurationTab()});
+        new MainLocalLaunchConfigurationTab(),
+        new EnvironmentTab(),
+        new CommonTab()});
   }
 
 }

src/org/lispdev/replview/LocalLispLaunchDelegate.java

         ILaunchManager.RUN_MODE.equals(mode),
         "Wrong mode");
     LispProcess p = launch(config,launch,new SwankRunnableDriver());
-    final ReplConsole c = new ReplConsole("REPL", null, p);
+    final ReplConsole c = new ReplConsole("REPL: "+config.getName(), null, p);
     final IConsoleManager cm = ConsolePlugin.getDefault().getConsoleManager();
     cm.addConsoles(new IConsole[] {c});
     final IWorkbench wk = PlatformUI.getWorkbench();

src/org/lispdev/replview/MainLocalLaunchConfigurationTab.java

 package org.lispdev.replview;
 
-import java.util.Arrays;
+import java.io.File;
 import java.util.HashMap;
 
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.swt.SWT;
+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.Font;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.lispdev.swank.AvailablePortFinder;
 
 public class MainLocalLaunchConfigurationTab extends
     AbstractLaunchConfigurationTab
 {
+  private Text exeText;
+  private Text swankText;
+  private Text portText;
 
   @Override
   public void createControl(Composite parent)
   {
+    Font font = parent.getFont();
+
+    Composite comp = new Composite(parent, SWT.NONE);
+    setControl(comp);
+    GridLayout topLayout = new GridLayout();
+    topLayout.verticalSpacing = 0;
+    topLayout.numColumns = 3;
+    comp.setLayout(topLayout);
+    comp.setFont(font);
+
+    createVerticalSpacer(comp, 3);
+
+    Label exeLabel = new Label(comp, SWT.NONE);
+    exeLabel.setText("&Lisp Executable:");
+    GridData gd = new GridData(GridData.BEGINNING);
+    exeLabel.setLayoutData(gd);
+    exeLabel.setFont(font);
+
+    exeText = new Text(comp, SWT.SINGLE | SWT.BORDER);
+    gd = new GridData(GridData.FILL_HORIZONTAL);
+    exeText.setLayoutData(gd);
+    exeText.setFont(font);
+    exeText.addModifyListener(new ModifyListener(){
+      public void modifyText(ModifyEvent e)
+      {
+        updateLaunchConfigurationDialog();
+      }
+    });
+
+    final Button exeButton = createPushButton(comp, "&Browse...", null);
+    exeButton.addSelectionListener(new SelectionAdapter() {
+      @Override
+      public void widgetSelected(SelectionEvent e)
+      {
+        final FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
+        fd.setText("Open Lisp Executable");
+
+        if( System.getProperty("os.name").toLowerCase().contains("windows"))
+        {
+          fd.setFilterExtensions(new String[] {"*.exe"});
+        }
+        exeText.setText(fd.open());
+      }
+    });
+
+    createVerticalSpacer(comp, 3);
+
+    Label swankLabel = new Label(comp, SWT.NONE);
+    swankLabel.setText("&Swank Loader:");
+    gd = new GridData(GridData.BEGINNING);
+    swankLabel.setLayoutData(gd);
+    swankLabel.setFont(font);
+
+    swankText = new Text(comp, SWT.SINGLE | SWT.BORDER);
+    gd = new GridData(GridData.FILL_HORIZONTAL);
+    swankText.setLayoutData(gd);
+    swankText.setFont(font);
+    swankText.addModifyListener(new ModifyListener(){
+      public void modifyText(ModifyEvent e)
+      {
+        updateLaunchConfigurationDialog();
+      }
+    });
+
+    final Button swankButton = createPushButton(comp, "B&rowse...", null);
+    swankButton.addSelectionListener(new SelectionAdapter(){
+      @Override
+      public void widgetSelected(SelectionEvent e)
+      {
+        final DirectoryDialog dd = new DirectoryDialog(getShell(), SWT.OPEN);
+        dd.setText("Open folder containing swank-loader.lisp");
+        swankText.setText(dd.open());
+      }
+    });
+
+    createVerticalSpacer(comp, 3);
+
+    Label portLabel = new Label(comp, SWT.NONE);
+    portLabel.setText("&Port:");
+    gd = new GridData(GridData.BEGINNING);
+    portLabel.setLayoutData(gd);
+    portLabel.setFont(font);
+
+    portText = new Text(comp,SWT.BORDER);
+    gd = new GridData(GridData.FILL_HORIZONTAL);
+    portText.setLayoutData(gd);
+    portText.setFont(font);
+    portText.addListener(SWT.Verify, new Listener(){
+      public void handleEvent(Event e)
+      {
+        String string = e.text;
+        char[] chars = new char[string.length()];
+        string.getChars(0, chars.length, chars, 0);
+        for(int i = 0; i < chars.length; i++)
+        {
+          if( !('0' <= chars[i] && chars[i] <= '9') )
+          {
+            e.doit = false;
+            return;
+          }
+        }
+      }
+    });
+    portText.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        updateLaunchConfigurationDialog();
+      }
+    });
+    new Label(comp, SWT.NONE).setText("");
   }
 
   @Override
   }
 
   @Override
-  public void initializeFrom(ILaunchConfiguration configuration)
+  public void initializeFrom(ILaunchConfiguration c)
   {
+    try
+    {
+      exeText.setText(c.getAttribute(LocalLispLaunchDelegate.ATTR_EXE, ""));
+      swankText.setText(c.getAttribute(LocalLispLaunchDelegate.ATTR_SWANK, ""));
+      portText.setText(String.valueOf(
+          c.getAttribute(LocalLispLaunchDelegate.ATTR_PORT, 0)));
+    }
+    catch(CoreException e)
+    {
+      setErrorMessage(e.getMessage());
+    }
   }
 
   @Override
   public void performApply(ILaunchConfigurationWorkingCopy wc)
   {
+    wc.setAttribute(LocalLispLaunchDelegate.ATTR_EXE, exeText.getText());
+    wc.setAttribute(LocalLispLaunchDelegate.ATTR_SWANK, swankText.getText());
+    wc.setAttribute(LocalLispLaunchDelegate.ATTR_PORT,
+        Integer.parseInt(portText.getText()));
+  }
+
+  @Override
+  public void setDefaults(ILaunchConfigurationWorkingCopy wc)
+  {
     wc.setAttribute(LocalLispLaunchDelegate.ATTR_EXE,
         "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\sbcl\\sbcl.exe");
-    wc.setAttribute(LocalLispLaunchDelegate.ATTR_CMD_PARAMS,
-        Arrays.asList("--load",
-            "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\slime\\swank-loader.lisp"));
+    wc.setAttribute(LocalLispLaunchDelegate.ATTR_SWANK,
+        "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\slime\\");
     wc.setAttribute(LocalLispLaunchDelegate.ATTR_ENV,
-        new HashMap<String,String>()
-        {private static final long serialVersionUID = 1L;
-        {put("SBCL_HOME","D:\\projects\\lispdev\\ws\\org.lispdev.swank\\sbcl\\");}});
+        new HashMap<String, String>(){
+          private static final long serialVersionUID = 1L;
+          {
+            put("SBCL_HOME",
+                "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\sbcl\\");
+          }
+        });
     wc.setAttribute(LocalLispLaunchDelegate.ATTR_EXT,
         "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\");
     wc.setAttribute(LocalLispLaunchDelegate.ATTR_PORT, 4005);
-
   }
 
   @Override
-  public void setDefaults(ILaunchConfigurationWorkingCopy configuration)
+  public boolean isValid(ILaunchConfiguration launchConfig)
   {
+    setErrorMessage(null);
+    setMessage(null);
+    if( exeText.getText().length() > 0 )
+    {
+      File cmd = new File(exeText.getText());
+      if( !cmd.exists() )
+      {
+        setErrorMessage("The lisp program file does not exist");
+        return false;
+      }
+      if( !cmd.canExecute() )
+      {
+        setErrorMessage("The lisp program file is not executable");
+        return false;
+      }
+    }
+    if ( swankText.getText().length() > 0 )
+    {
+      File swankf = new File(swankText.getText(),"swank-loader.lisp");
+      if( !swankf.exists() )
+      {
+        setErrorMessage("Swank was not found in the specified folder");
+        return false;
+      }
+    }
+    if ( portText.getText().length() > 0 )
+    {
+      try
+      {
+        int p = Integer.parseInt(portText.getText());
+        if( p < AvailablePortFinder.MIN_PORT_NUMBER
+            || p > AvailablePortFinder.MAX_PORT_NUMBER )
+        {
+          setErrorMessage("Port should be an integer between "+
+              AvailablePortFinder.MIN_PORT_NUMBER + " and " +
+              AvailablePortFinder.MAX_PORT_NUMBER);
+          return false;
+        }
+      }
+      catch(NumberFormatException e)
+      {
+        setErrorMessage("Port should be an integer number");
+        return false;
+      }
+    }
+    if( exeText.getText().length() == 0 )
+    {
+      setMessage("Specify lisp program");
+    }
+    else if ( swankText.getText().length() == 0 )
+    {
+      setMessage("Specify swank folder");
+    }
+    else if ( portText.getText().length() == 0 )
+    {
+      setMessage("Specify port");
+    }
+    return true;
   }
-
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.