diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ApplicationSourceFromTemplateModel.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ApplicationSourceFromTemplateModel.java index 26ccc18a8e..d4955ffd16 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ApplicationSourceFromTemplateModel.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ApplicationSourceFromTemplateModel.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.CoreException; @@ -141,8 +140,11 @@ private void handleSelectedAppSource(PropertyChangeEvent evt) { if(evt.getNewValue() instanceof IApplicationSource && ResourceKind.TEMPLATE.equals(((IApplicationSource) evt.getNewValue()).getKind())){ IApplicationSource source = (IApplicationSource) evt.getNewValue(); - this.template = (ITemplate) source.getSource(); - updateTemplateParameters(template); + ITemplate newTemplate = (ITemplate) source.getSource(); + if (!Objects.equals(newTemplate, this.template)) { + this.template = newTemplate; + updateTemplateParameters(newTemplate); + } } } private void handleEclipseProject(PropertyChangeEvent evt) { @@ -165,7 +167,7 @@ private void updateTemplateParameters(ITemplate template) { if (template == null) { return; } - setParameters(new ArrayList<>(template.getParameters().values())); + setParameters(template.getParameters().values()); setItems(template.getItems()); setLabels(template.getObjectLabels()); } @@ -181,54 +183,56 @@ public boolean isParameterModified(IParameter param) { } @Override - public void setParameters(List parameters) { + public void setParameters(Collection parameters) { + List oldParameters = new ArrayList<>(this.parameters); + if (parameters == null) { + this.parameters.clear(); + } else { + this.originalValueMap = toMap(parameters); + List newParameters = new ArrayList<>(); + newParameters.addAll(injectProjectParameters(eclipseProject, parameters)); + this.parameters.clear(); + this.parameters.addAll(newParameters); + } + firePropertyChange(PROPERTY_PARAMETERS, oldParameters, this.parameters); + } + + private Map toMap(Collection parameters) { Map paramsMap = new HashMap<>(); if (parameters != null) { parameters.forEach(p -> paramsMap.put(p.getName(), p.getValue())); } - originalValueMap = paramsMap; - firePropertyChange(PROPERTY_PARAMETERS, this.parameters, this.parameters = injectProjectParameters(this.eclipseProject, parameters)); + return paramsMap; } - private static List injectProjectParameters(org.eclipse.core.resources.IProject project, List originalParameters) { + private Collection injectProjectParameters(org.eclipse.core.resources.IProject project, Collection originalParameters) { if (originalParameters == null || originalParameters.isEmpty()) { return originalParameters; } Map projectParams = getProjectParameters(project); - List newParameters = originalParameters.stream().map(p -> { - IParameter clone = p.clone(); - String value = projectParams.get(clone.getName()); + originalParameters.forEach(p -> { + String value = projectParams.get(p.getName()); if (value != null) { - clone.setValue(value); + p.setValue(value); } - return clone; - }).collect(Collectors.toList()); + }); - return newParameters; + return originalParameters; } - private static Map getProjectParameters(org.eclipse.core.resources.IProject project) { + private Map getProjectParameters(org.eclipse.core.resources.IProject project) { if(project == null) { return Collections.emptyMap(); } + Map projectParams = new HashMap<>(); - String gitRepo = null; - try { - gitRepo = StringUtils.defaultString(EGitUtils.getDefaultRemoteRepo(project)); - } catch (CoreException e) { - throw new OpenShiftException(e, NLS.bind("Could not determine the default remote Git repository for \"{0}\"", project.getName())); - } + String gitRepo = getGitRepo(project); if (gitRepo != null) { projectParams.put(PARAMETER_SOURCE_REPOSITORY_URL, gitRepo); projectParams.put(PARAMETER_GIT_URI, gitRepo);//legacy key - String branch; - try { - branch = StringUtils.defaultString(EGitUtils.getCurrentBranch(project)); - } catch (CoreException e) { - throw new OpenShiftException(e, NLS.bind("Could not determine the default Git branch for \"{0}\"", project.getName())); - } + String branch = getGitBranch(project); projectParams.put("SOURCE_REPOSITORY_REF", branch); projectParams.put("GIT_REF", branch);//legacy key @@ -242,6 +246,22 @@ private static Map getProjectParameters(org.eclipse.core.resourc return projectParams; } + private String getGitBranch(org.eclipse.core.resources.IProject project) { + try { + return StringUtils.defaultString(EGitUtils.getCurrentBranch(project)); + } catch (CoreException e) { + throw new OpenShiftException(e, NLS.bind("Could not determine the default Git branch for \"{0}\"", project.getName())); + } + } + + private String getGitRepo(org.eclipse.core.resources.IProject project) { + try { + return StringUtils.defaultString(EGitUtils.getDefaultRemoteRepo(project)); + } catch (CoreException e) { + throw new OpenShiftException(e, NLS.bind("Could not determine the default remote Git repository for \"{0}\"", project.getName())); + } + } + @Override public IParameter getSelectedParameter() { return this.selectedParameter; diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ITemplateParametersPageModel.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ITemplateParametersPageModel.java index edcbb905b6..132206fa5d 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ITemplateParametersPageModel.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/ITemplateParametersPageModel.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate; +import java.util.Collection; import java.util.List; import com.openshift.restclient.model.template.IParameter; @@ -34,7 +35,7 @@ public interface ITemplateParametersPageModel { * Set the list of template parameters * @param parameters */ - void setParameters(List parameters); + void setParameters(Collection parameters); /** * Get the selected parameter diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/TemplateParametersPage.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/TemplateParametersPage.java index 5be0458315..b542c73536 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/TemplateParametersPage.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/wizard/newapp/fromtemplate/TemplateParametersPage.java @@ -99,12 +99,12 @@ protected void doCreateControls(Composite container, DataBindingContext dbc) { this.viewer = createTable(tableContainer, parametersObservable, dbc); GridDataFactory.fillDefaults() .span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).hint(500, 300).applyTo(tableContainer); + viewer.setInput(parametersObservable); IObservableValue selectedParameter = BeanProperties.value(ITemplateParametersPageModel.PROPERTY_SELECTED_PARAMETER).observe(model); ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer)) .to(selectedParameter) .in(dbc); - viewer.setInput(parametersObservable); viewer.addDoubleClickListener(onDoubleClick()); // edit button