| package org.eclipse.epp.installer.core.model; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.Map; |
| |
| 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; |
| |
| /** |
| * Concrete implementation of |
| * {@link org.eclipse.epp.installer.core.model.IInstallStep}. Subclasses |
| * should implement the appropriate interfaces listed in InstallCodeStep. |
| */ |
| public class InstallStep implements IInstallStep { |
| |
| public static final String VAR_TITLE = "title"; |
| public static final String VAR_DESCRIPTION = "description"; |
| |
| /** |
| * Associated installer instance. |
| */ |
| private final Installer installer; |
| |
| /** |
| * Cached UI adapter |
| */ |
| private Object adapter; |
| |
| /** |
| * Install Step title. |
| * @see #getTitle() |
| */ |
| // private String title; |
| |
| /** |
| * Install step description. |
| * @see #getDescription() |
| */ |
| // private String description; |
| |
| protected Map properties; |
| |
| private Map aboutToStepProperties; |
| |
| private List aboutToStepProcessors; |
| |
| /** |
| * Construct a new instance with the associated installation context. |
| * |
| * @param installer |
| * Installer |
| */ |
| public InstallStep(Installer installer) { |
| this.installer = installer; |
| this.properties = new HashMap(); |
| this.aboutToStepProperties = new HashMap(); |
| this.aboutToStepProcessors = new ArrayList(); |
| } |
| |
| /** |
| * Return associated installer instance. |
| * |
| * @return Return associated installer instance. |
| */ |
| public Installer getInstaller() { |
| return installer; |
| } |
| |
| /** |
| * Return associated install options. |
| * |
| * @return associated install options. |
| * @see org.eclipse.epp.installer.core.model.IInstallStep#getOptions() |
| */ |
| public InstallOptions getOptions() { |
| return getInstaller().getOptions(); |
| } |
| |
| /** |
| * Return install step title string. |
| * |
| * @return install step title. |
| * @see org.eclipse.epp.installer.core.model.IInstallStep#getTitle() |
| */ |
| public String getTitle() { |
| // return title; |
| return Variables.resolve(getProperty(VAR_TITLE), getOptions()); |
| } |
| |
| /** |
| * Set install step titile string. |
| * |
| * @param title to set. |
| * @see #getTitle() |
| */ |
| public void setTitle(String title) { |
| // this.title = title; |
| setProperty(VAR_TITLE, title); |
| } |
| |
| /** |
| * Return install step description string. |
| * |
| * @return String |
| * @see org.eclipse.epp.installer.core.model.IInstallStep#getDescription() |
| */ |
| public String getDescription() { |
| // return description; |
| return Variables.resolve(getProperty(VAR_DESCRIPTION), getOptions()); |
| } |
| |
| /** |
| * Set install step description string. |
| * |
| * @param description to set. |
| * @see #getDescription() |
| */ |
| public void setDescription(String description) { |
| // this.description = description; |
| setProperty(VAR_DESCRIPTION, description); |
| } |
| |
| /** |
| * Return execution condition. |
| * Used to specefy step execution condition |
| * |
| * Used by installer to ensure step execution. |
| * @return <code>true</code> if step needed to be executed, and <code>false</code>othervise. |
| */ |
| public boolean canExecute() { |
| return true; |
| } |
| |
| /** |
| * Return back condition. |
| * Used to specify step back condition |
| * |
| * Used by installer to ensure what step support back execution. |
| * @return <code>true</code> if step can back, and <code>false</code>othervise. |
| */ |
| public boolean canBack() { |
| return true; |
| } |
| |
| /** |
| * Answer if step complited. |
| * Can execute some actions. See {@link org.eclipse.epp.installer.core.steps.RunOperationsStep } for example. |
| * |
| * @return IStatus step status. |
| * @see org.eclipse.epp.installer.core.model.IInstallStep#verifyStep() |
| */ |
| public IStatus verifyStep() { |
| return Status.OK_STATUS; |
| } |
| |
| /** |
| * Return adapter. |
| * |
| * @param adapterType return adapter for. |
| * @return adapter or null if no adapter found. |
| * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) |
| */ |
| public Object getAdapter(Class adapterType) { |
| if (adapter == null) { |
| if (IInstallStep.class.equals(adapter)) { |
| adapter = this; |
| } else { |
| adapter = installer.getAdapter(this, adapterType); |
| } |
| } |
| return adapter; |
| } |
| |
| /** |
| * Called immediately before the step is to be performed. Typically this is |
| * before a wizard page becomes visible or before the code is installed. |
| * |
| * @see org.eclipse.epp.installer.core.model.IInstallStep#aboutToStep() |
| */ |
| public void aboutToStep() { |
| properties.putAll(aboutToStepProperties); |
| for (Iterator it = aboutToStepProcessors.iterator(); it.hasNext(); ) { |
| IStepProcessor processor = (IStepProcessor) it.next(); |
| processor.process(this); |
| } |
| } |
| |
| public String getProperty(String key) { |
| return (String) properties.get(key); |
| } |
| |
| public void setProperty(String key, String value) { |
| properties.put(key, value); |
| } |
| |
| public void aboutToStepSetProperty(String key, String value) { |
| aboutToStepProperties.put(key, value); |
| } |
| |
| public void aboutToStepAddProcessor(IStepProcessor processor) { |
| aboutToStepProcessors.add(processor); |
| } |
| |
| } |