blob: 41f89200204e1eb3b55a4ddcf1a1fec06e04e59d [file] [log] [blame]
package org.eclipse.epp.installer.core.steps;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.installer.core.InstallOptions;
import org.eclipse.epp.installer.core.Variables;
import org.eclipse.epp.installer.core.model.Context;
import org.eclipse.epp.installer.core.model.InstallStep;
import org.eclipse.epp.installer.core.model.Installer;
/**
* Prompt the user to accept or decline an option.<br>
* First set the text that appears to the user:
*
* <pre>
* step.setTitle(&quot;Delete embedded installations&quot;);
* step.setDescription(&quot;Do you want to delete the embedded installations?&quot;);
* step.setChoiceText(&quot;&quot;);
* step.setAcceptText(&quot;Yes, delete embedded installations&quot;);
* step.setDeclineText(&quot;No, do not delete embedded installations&quot;);
* </pre>
*
* Next set the option that is updated when the user makes a choice:
*
* <pre>
* step.setOptionName(OPTION_DELETE_EMBEDDED);
* </pre>
*
* By default, the option is set to "true" or "false" based upon the user's selection, but
* this can be overridden:
*
* <pre>
* step.setAcceptString(&quot;accepted&quot;);
* step.setDeclineString(&quot;declined&quot;);
* </pre>
*
* By default, the installation process continues regardless of which choice the user
* makes, but you can prevent the installation from continuing if the user does not select
* "accept":
*
* <pre>
* step.setContinueOnDecline(false);
* </pre>
*
* <p>
* Copyright (c) 2003, Instantiations, Inc.<br>
* All Rights Reserved
*/
public class ChoiceStep extends InstallStep
{
public static final String VAR_CHOICE_TEXT = "choiceText";
public static final String VAR_ACCEPT_TEXT = "acceptText";
public static final String VAR_DECLINE_TEXT = "declineText";
public static final String VAR_CONTINUE_ON_DECLINE = "continueOnDecline";
public static final String VAR_DEFAULT_CHOICE = "defaultChoice";
/**
* These parameters must be set before running the step
*/
// private String choiceText;
// private String acceptText;
// private String declineText;
// private boolean continueOnDecline = true;
// private boolean defaultChoice = true;
/**
* Setting these options is not necessary
*/
private String acceptString = InstallOptions.TRUE_VALUE;
private String declineString = InstallOptions.FALSE_VALUE;
private String optionName;
public ChoiceStep(Installer installer) {
super(installer);
}
// getters and setters
public String getChoiceText() {
// return Variables.resolve(choiceText, getOptions());
return Variables.resolve(getProperty(VAR_CHOICE_TEXT), getOptions());
}
public void setChoiceText(String choiceText) {
// this.choiceText = choiceText;
setProperty(VAR_CHOICE_TEXT, choiceText);
}
public String getAcceptText() {
// return Variables.resolve(acceptText, getOptions());
return Variables.resolve(getProperty(VAR_ACCEPT_TEXT), getOptions());
}
public void setAcceptText(String acceptText) {
// this.acceptText = acceptText;
setProperty(VAR_ACCEPT_TEXT, acceptText);
}
public String getDeclineText() {
// return Variables.resolve(declineText, getOptions());
return Variables.resolve(getProperty(VAR_DECLINE_TEXT), getOptions());
}
public void setDeclineText(String declineText) {
// this.declineText = declineText;
setProperty(VAR_DECLINE_TEXT, declineText);
}
public boolean getContinueOnDecline() {
// return continueOnDecline;
String value = Variables.resolve(getProperty(VAR_CONTINUE_ON_DECLINE), getOptions());
return InstallOptions.TRUE_VALUE.equals(value);
}
public void setContinueOnDecline(boolean flag) {
// this.continueOnDecline = flag;
setProperty(VAR_CONTINUE_ON_DECLINE, flag ? InstallOptions.TRUE_VALUE : InstallOptions.FALSE_VALUE);
}
public String getAcceptString() {
return Variables.resolve(acceptString, getOptions());
}
public void setAcceptString(String acceptString) {
this.acceptString = acceptString;
}
public String getDeclineString() {
return Variables.resolve(declineString, getOptions());
}
public void setDeclineString(String declineString) {
this.declineString = declineString;
}
public String getOptionName() {
return Variables.resolve(optionName, getOptions());
}
public void setOptionName(String optionName) {
this.optionName = optionName;
}
public boolean getDefaultChoice() {
// return defaultChoice;
String value = Variables.resolve(getProperty(VAR_DEFAULT_CHOICE), getOptions());
return InstallOptions.TRUE_VALUE.equals(value);
}
public void setDefaultChoice(boolean defaultChoice) {
// this.defaultChoice = defaultChoice;
setProperty(VAR_DEFAULT_CHOICE, defaultChoice ? InstallOptions.TRUE_VALUE : InstallOptions.FALSE_VALUE);
}
public void aboutToStep() {
super.aboutToStep();
if (getOptionName() != null) {
getOptions().set(getOptionName(), /*defaultChoice*/getDefaultChoice() ? getAcceptString() : getDeclineString());
}
}
/**
* Method verifyStep.
*
* @return IStatus
* @see org.eclipse.epp.installer.core.model.IInstallStep#verifyStep()
*/
public IStatus verifyStep() {
if (getOptionName() != null) {
return validateOption(getOptions().getString(getOptionName()), getAcceptString(), getDeclineString());
}
return Status.OK_STATUS;
}
public static IStatus validateOption(String option, String acceptString, String declineString) {
if (option == null || option.length() == 0) {
return new Status(IStatus.ERROR, Context.PLUGIN_ID, 0, "Option does not exist", null);
}
if (!option.equals(acceptString) && !option.equals(declineString)) {
return new Status(IStatus.ERROR, Context.PLUGIN_ID, 0, "Option has wrong value", null);
}
return Status.OK_STATUS;
}
}