Skip to content

Commit

Permalink
support for options in install.packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Apr 25, 2011
1 parent e267621 commit 965dd32
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 28 deletions.
Expand Up @@ -216,7 +216,7 @@ public void execute()
}
}

private void doInstallPackage(PackageInstallContext installContext)
private void doInstallPackage(final PackageInstallContext installContext)
{
// if install options have not yet intialized the default library
// path then set it now from the context
Expand All @@ -238,15 +238,27 @@ public void execute(PackageInstallRequest request)
{
installOptions_ = request.getOptions();

String command = "install.packages(\"" +
request.getPackages().get(0) +
"\"";


boolean usingDefaultLibrary =
request.getOptions().getLibraryPath().equals(
installContext.getDefaultLibraryPath());

command += ")";

StringBuilder command = new StringBuilder();
command.append("install.packages(\"");
command.append(request.getPackageName());
command.append("\"");
if (!usingDefaultLibrary)
{
command.append(", lib=\"");
command.append(request.getOptions().getLibraryPath());
command.append("\"");
}
if (!request.getOptions().getInstallDependencies())
command.append(", dependencies = FALSE");

events_.fireEvent(new SendToConsoleEvent(command, true));
command.append(")");
String cmd = command.toString();
events_.fireEvent(new SendToConsoleEvent(cmd, true));
}
});
}
Expand Down
Expand Up @@ -12,20 +12,18 @@
*/
package org.rstudio.studio.client.workbench.views.packages.model;

import java.util.ArrayList;

public class PackageInstallRequest
{
public PackageInstallRequest(ArrayList<String> packages,
public PackageInstallRequest(String packageName,
PackageInstallOptions options)
{
packages_ = packages;
packageName_ = packageName;
options_ = options;
}

public ArrayList<String> getPackages()
public String getPackageName()
{
return packages_;
return packageName_;
}

public PackageInstallOptions getOptions()
Expand All @@ -34,7 +32,7 @@ public PackageInstallOptions getOptions()
}


private final ArrayList<String> packages_;
private final String packageName_;
private final PackageInstallOptions options_;


Expand Down
@@ -1,9 +1,12 @@

.mainWidget {
width: 320px;
width: 360px;
}

.packageNameSuggestBox {
.extraBottomPad {
margin-bottom: 10px;
}

.installDependenciesCheckBox {
}

Expand Up @@ -30,7 +30,10 @@
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.VerticalPanel;
Expand Down Expand Up @@ -60,20 +63,28 @@ public InstallPackageDialog(
@Override
protected PackageInstallRequest collectInput()
{
ArrayList<String> packages = new ArrayList<String>();
// package
String packageName = packageNameSuggestBox_.getText().trim();
if (packageName.length() > 0)
packages.add(packageName);

return new PackageInstallRequest(packages, defaultInstallOptions_);

// library
String libraryPath = installContext_.getWriteableLibraryPaths().get(
libraryListBox_.getSelectedIndex());

// install dependencies
boolean installDependencies = installDependenciesCheckBox_.getValue();

return new PackageInstallRequest(packageName,
PackageInstallOptions.create(
libraryPath,
installDependencies));
}


@Override
protected boolean validate(PackageInstallRequest request)
{
// check for package name
if (request.getPackages().size() < 1)
if (request.getPackageName().length() == 0)
{
globalDisplay_.showErrorMessage(
"Package Name Required",
Expand All @@ -94,17 +105,52 @@ protected Widget createMainWidget()
{
// vertical panel
VerticalPanel mainPanel = new VerticalPanel();
mainPanel.setSpacing(3);
mainPanel.setSpacing(2);
mainPanel.setStylePrimaryName(RESOURCES.styles().mainWidget());

mainPanel.add(new Label("Package name:"));
mainPanel.add(new Label("Package Name:"));

packageNameSuggestBox_ = new SuggestBox(new PackageOracle());
packageNameSuggestBox_.setWidth("100%");
packageNameSuggestBox_.setLimit(20);
packageNameSuggestBox_.addStyleName(RESOURCES.styles().packageNameSuggestBox());
packageNameSuggestBox_.addStyleName(RESOURCES.styles().extraBottomPad());
mainPanel.add(packageNameSuggestBox_);


mainPanel.add(new Label("Install to Library:"));

// library list box
libraryListBox_ = new ListBox();
libraryListBox_.setWidth("100%");
libraryListBox_.addStyleName(RESOURCES.styles().extraBottomPad());
JsArrayString libPaths = installContext_.getWriteableLibraryPaths();
int selectedIndex = 0;
for (int i=0; i<libPaths.length(); i++)
{
String libPath = libPaths.get(i);

if (defaultInstallOptions_.getLibraryPath().equals(libPath))
selectedIndex = i;

if (libPath.equals(installContext_.getDefaultLibraryPath()))
libPath = libPath + " [Default]";

libraryListBox_.addItem(libPath);

}
libraryListBox_.setSelectedIndex(selectedIndex);
mainPanel.add(libraryListBox_);

// install dependencies check box
installDependenciesCheckBox_ = new CheckBox();
installDependenciesCheckBox_.addStyleName(RESOURCES.styles().installDependenciesCheckBox());
installDependenciesCheckBox_.setText("Install dependencies");
installDependenciesCheckBox_.setValue(
defaultInstallOptions_.getInstallDependencies());
mainPanel.add(installDependenciesCheckBox_);

mainPanel.add(new HTML("<br/>"));

return mainPanel;
}

Expand Down Expand Up @@ -143,7 +189,8 @@ public void onError(ServerError error)
static interface Styles extends CssResource
{
String mainWidget();
String packageNameSuggestBox();
String extraBottomPad();
String installDependenciesCheckBox();
}

static interface Resources extends ClientBundle
Expand All @@ -158,11 +205,13 @@ public static void ensureStylesInjected()
RESOURCES.styles().ensureInjected();
}

@SuppressWarnings("unused")
private final PackageInstallContext installContext_;
private final PackageInstallOptions defaultInstallOptions_;
private final PackagesServerOperations server_;
private final GlobalDisplay globalDisplay_;

private SuggestBox packageNameSuggestBox_ = null;
private ListBox libraryListBox_ = null;
private CheckBox installDependenciesCheckBox_ = null;

}

0 comments on commit 965dd32

Please sign in to comment.