This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e5a982  HOP-2197 : Changing variable in project dialog requires 
restart (#398)
9e5a982 is described below

commit 9e5a982e5a3a6ccb6360e6ed5c111c27035cbead
Author: Matt Casters <[email protected]>
AuthorDate: Thu Nov 19 11:16:21 2020 +0100

    HOP-2197 : Changing variable in project dialog requires restart (#398)
---
 .../apache/hop/projects/config/ProjectsConfig.java | 185 +++++++++++----------
 .../apache/hop/projects/gui/ProjectsGuiPlugin.java |  41 +++--
 .../apache/hop/projects/project/ProjectDialog.java |  19 +++
 3 files changed, 142 insertions(+), 103 deletions(-)

diff --git 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfig.java
 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfig.java
index 70f2531..ae39a8c 100644
--- 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfig.java
+++ 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfig.java
@@ -1,27 +1,23 @@
-/*! 
******************************************************************************
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- 
*******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
- 
******************************************************************************/
+ */
 
 package org.apache.hop.projects.config;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hop.projects.environment.LifecycleEnvironment;
 import org.apache.hop.projects.lifecycle.ProjectLifecycle;
 import org.apache.hop.projects.project.ProjectConfig;
@@ -50,18 +46,21 @@ public class ProjectsConfig {
     projectLifecycles = new ArrayList<>();
   }
 
-  public ProjectsConfig( ProjectsConfig config ) {
+  public ProjectsConfig(ProjectsConfig config) {
     this();
     enabled = config.enabled;
     openingLastProjectAtStartup = config.openingLastProjectAtStartup;
-    projectConfigurations = new ArrayList<>( config.projectConfigurations );
-    lifecycleEnvironments = new ArrayList<>( config.lifecycleEnvironments );
-    projectLifecycles = new ArrayList<>( config.projectLifecycles );
+    projectConfigurations = new ArrayList<>(config.projectConfigurations);
+    lifecycleEnvironments = new ArrayList<>(config.lifecycleEnvironments);
+    projectLifecycles = new ArrayList<>(config.projectLifecycles);
   }
 
-  public ProjectConfig findProjectConfig( String projectName ) {
-    for ( ProjectConfig projectConfig : projectConfigurations ) {
-      if ( projectConfig.getProjectName().equalsIgnoreCase( projectName ) ) {
+  public ProjectConfig findProjectConfig(String projectName) {
+    if (StringUtils.isEmpty(projectName)) {
+      return null;
+    }
+    for (ProjectConfig projectConfig : projectConfigurations) {
+      if (projectConfig.getProjectName().equalsIgnoreCase(projectName)) {
         return projectConfig;
       }
     }
@@ -74,31 +73,38 @@ public class ProjectsConfig {
    * @param projectName The name of the environment to look up
    * @return The environments for the project
    */
-  public List<LifecycleEnvironment> findEnvironmentsOfProject( String 
projectName ) {
+  public List<LifecycleEnvironment> findEnvironmentsOfProject(String 
projectName) {
     List<LifecycleEnvironment> list = new ArrayList<>();
-    lifecycleEnvironments.stream().forEach( e -> { if 
(e.getProjectName().equals( projectName )) { list.add(e); } } );
+    lifecycleEnvironments.stream()
+        .forEach(
+            e -> {
+              if (e.getProjectName().equals(projectName)) {
+                list.add(e);
+              }
+            });
     return list;
   }
 
-  public void addProjectConfig( ProjectConfig projectConfig ) {
-    ProjectConfig existing = findProjectConfig( projectConfig.getProjectName() 
);
-    if ( existing == null ) {
-      projectConfigurations.add( projectConfig );
+  public void addProjectConfig(ProjectConfig projectConfig) {
+    ProjectConfig existing = findProjectConfig(projectConfig.getProjectName());
+    if (existing == null) {
+      projectConfigurations.add(projectConfig);
     } else {
-      existing.setProjectName( projectConfig.getProjectName() );
-      existing.setProjectHome( projectConfig.getProjectHome() );
-      existing.setConfigFilename( projectConfig.getConfigFilename() );
+      existing.setProjectName(projectConfig.getProjectName());
+      existing.setProjectHome(projectConfig.getProjectHome());
+      existing.setConfigFilename(projectConfig.getConfigFilename());
     }
   }
 
-  public int indexOfProjectConfig( String projectName ) {
-    return projectConfigurations.indexOf( new ProjectConfig( projectName, 
null, null ) ); // Only considers the name
+  public int indexOfProjectConfig(String projectName) {
+    return projectConfigurations.indexOf(
+        new ProjectConfig(projectName, null, null)); // Only considers the name
   }
 
-  public ProjectConfig removeProjectConfig( String projectName ) {
-    int index = indexOfProjectConfig( projectName );
-    if ( index >= 0 ) {
-      return projectConfigurations.remove( index );
+  public ProjectConfig removeProjectConfig(String projectName) {
+    int index = indexOfProjectConfig(projectName);
+    if (index >= 0) {
+      return projectConfigurations.remove(index);
     } else {
       return null;
     }
@@ -106,88 +112,97 @@ public class ProjectsConfig {
 
   public List<String> listProjectConfigNames() {
     List<String> names = new ArrayList<>();
-    projectConfigurations.stream().forEach( config -> names.add( 
config.getProjectName() ) );
-    Collections.sort( names );
+    projectConfigurations.stream().forEach(config -> 
names.add(config.getProjectName()));
+    Collections.sort(names);
     return names;
   }
 
-
-  public LifecycleEnvironment findEnvironment( String environmentName ) {
-    for ( LifecycleEnvironment environment : lifecycleEnvironments ) {
-      if ( environment.getName().equals( environmentName ) ) {
+  public LifecycleEnvironment findEnvironment(String environmentName) {
+    if (StringUtils.isEmpty(environmentName)) {
+      return null;
+    }
+    for (LifecycleEnvironment environment : lifecycleEnvironments) {
+      if (environment.getName().equals(environmentName)) {
         return environment;
       }
     }
     return null;
   }
 
-  public void addEnvironment( LifecycleEnvironment environment ) {
-    int index = lifecycleEnvironments.indexOf( environment );
-    if ( index < 0 ) {
-      lifecycleEnvironments.add( environment );
+  public void addEnvironment(LifecycleEnvironment environment) {
+    int index = lifecycleEnvironments.indexOf(environment);
+    if (index < 0) {
+      lifecycleEnvironments.add(environment);
     } else {
-      lifecycleEnvironments.set( index, environment );
+      lifecycleEnvironments.set(index, environment);
     }
   }
 
-  public LifecycleEnvironment removeEnvironment( String environmentName ) {
-    LifecycleEnvironment environment = findEnvironment( environmentName );
-    if ( environment != null ) {
-      lifecycleEnvironments.remove( environment );
+  public LifecycleEnvironment removeEnvironment(String environmentName) {
+    LifecycleEnvironment environment = findEnvironment(environmentName);
+    if (environment != null) {
+      lifecycleEnvironments.remove(environment);
     }
     return environment;
   }
 
   public List<String> listEnvironmentNames() {
     List<String> names = new ArrayList<>();
-    lifecycleEnvironments.stream().forEach( env -> names.add( env.getName() ) 
);
-    Collections.sort( names );
+    lifecycleEnvironments.stream().forEach(env -> names.add(env.getName()));
+    Collections.sort(names);
     return names;
   }
 
-  public int indexOfEnvironment( String environmentName ) {
-    return lifecycleEnvironments.indexOf( new LifecycleEnvironment( 
environmentName, null, null, Collections.emptyList() ) ); // Only considers the 
name
+  public int indexOfEnvironment(String environmentName) {
+    return lifecycleEnvironments.indexOf(
+        new LifecycleEnvironment(
+            environmentName, null, null, Collections.emptyList())); // Only 
considers the name
   }
 
-
-  public ProjectLifecycle findLifecycle( String lifecycleName ) {
-    for ( ProjectLifecycle lifecycle : projectLifecycles ) {
-      if ( lifecycle.equals( lifecycleName ) ) {
+  public ProjectLifecycle findLifecycle(String lifecycleName) {
+    if (StringUtils.isEmpty(lifecycleName)) {
+      return null;
+    }
+    for (ProjectLifecycle lifecycle : projectLifecycles) {
+      if (lifecycle.equals(lifecycleName)) {
         return lifecycle;
       }
     }
     return null;
   }
 
-  public void addLifecycle( ProjectLifecycle lifecycle ) {
-    int index = projectLifecycles.indexOf( lifecycle );
-    if ( index < 0 ) {
-      projectLifecycles.add( lifecycle );
+  public void addLifecycle(ProjectLifecycle lifecycle) {
+    int index = projectLifecycles.indexOf(lifecycle);
+    if (index < 0) {
+      projectLifecycles.add(lifecycle);
     } else {
-      projectLifecycles.set( index, lifecycle );
+      projectLifecycles.set(index, lifecycle);
     }
   }
 
-  public ProjectLifecycle removeLifecycle( String lifecycleName ) {
-    ProjectLifecycle lifecycle = findLifecycle( lifecycleName );
-    if ( lifecycle != null ) {
-      lifecycleEnvironments.remove( lifecycle );
+  public ProjectLifecycle removeLifecycle(String lifecycleName) {
+    ProjectLifecycle lifecycle = findLifecycle(lifecycleName);
+    if (lifecycle != null) {
+      lifecycleEnvironments.remove(lifecycle);
     }
     return lifecycle;
   }
 
   public List<String> listLifecycleNames() {
     List<String> names = new ArrayList<>();
-    projectLifecycles.stream().forEach( lifecycle -> names.add( 
lifecycle.getName() ) );
-    Collections.sort( names );
+    projectLifecycles.stream().forEach(lifecycle -> 
names.add(lifecycle.getName()));
+    Collections.sort(names);
     return names;
   }
 
-  public int indexOfLifecycle( String lifecycleName ) {
-    return projectLifecycles.indexOf( new ProjectLifecycle( lifecycleName, 
Collections.emptyList(), Collections.emptyList() ) ); // Only considers the name
+  public int indexOfLifecycle(String lifecycleName) {
+    return projectLifecycles.indexOf(
+        new ProjectLifecycle(
+            lifecycleName,
+            Collections.emptyList(),
+            Collections.emptyList())); // Only considers the name
   }
 
-
   /**
    * Gets enabled
    *
@@ -197,10 +212,8 @@ public class ProjectsConfig {
     return enabled;
   }
 
-  /**
-   * @param enabled The enabled to set
-   */
-  public void setEnabled( boolean enabled ) {
+  /** @param enabled The enabled to set */
+  public void setEnabled(boolean enabled) {
     this.enabled = enabled;
   }
 
@@ -213,10 +226,8 @@ public class ProjectsConfig {
     return openingLastProjectAtStartup;
   }
 
-  /**
-   * @param openingLastProjectAtStartup The openingLastProjectAtStartup to set
-   */
-  public void setOpeningLastProjectAtStartup( boolean 
openingLastProjectAtStartup ) {
+  /** @param openingLastProjectAtStartup The openingLastProjectAtStartup to 
set */
+  public void setOpeningLastProjectAtStartup(boolean 
openingLastProjectAtStartup) {
     this.openingLastProjectAtStartup = openingLastProjectAtStartup;
   }
 
@@ -229,10 +240,8 @@ public class ProjectsConfig {
     return projectConfigurations;
   }
 
-  /**
-   * @param projectConfigurations The projectConfigurations to set
-   */
-  public void setProjectConfigurations( List<ProjectConfig> 
projectConfigurations ) {
+  /** @param projectConfigurations The projectConfigurations to set */
+  public void setProjectConfigurations(List<ProjectConfig> 
projectConfigurations) {
     this.projectConfigurations = projectConfigurations;
   }
 
@@ -245,10 +254,8 @@ public class ProjectsConfig {
     return lifecycleEnvironments;
   }
 
-  /**
-   * @param lifecycleEnvironments The lifecycleEnvironments to set
-   */
-  public void setLifecycleEnvironments( List<LifecycleEnvironment> 
lifecycleEnvironments ) {
+  /** @param lifecycleEnvironments The lifecycleEnvironments to set */
+  public void setLifecycleEnvironments(List<LifecycleEnvironment> 
lifecycleEnvironments) {
     this.lifecycleEnvironments = lifecycleEnvironments;
   }
 }
diff --git 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
index 20fdcd5..136a04e 100644
--- 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
+++ 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
@@ -1,24 +1,19 @@
-/*! 
******************************************************************************
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- 
*******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
- 
******************************************************************************/
+ */
 
 package org.apache.hop.projects.gui;
 
@@ -34,6 +29,7 @@ import org.apache.hop.core.variables.IVariables;
 import org.apache.hop.core.variables.Variables;
 import org.apache.hop.history.AuditEvent;
 import org.apache.hop.history.AuditManager;
+import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.metadata.api.IHopMetadataProvider;
 import org.apache.hop.metadata.api.IHopMetadataSerializer;
 import org.apache.hop.pipeline.config.PipelineRunConfiguration;
@@ -119,6 +115,23 @@ public class ProjectsGuiPlugin {
 
         refreshProjectsList();
         selectProjectInList( projectName );
+
+        if (projectDialog.isVariablesChanged()) {
+          MessageBox box = new MessageBox( hopGui.getShell(), 
SWT.ICON_QUESTION | SWT.YES | SWT.NO );
+          box.setText( "Reload project?");
+          box.setMessage( "Do you want to reload this project to apply changed 
variables?" );
+          int answer = box.open();
+          if ((answer&SWT.YES)!=0) {
+            // Try to stick to the same environment if we have one selected...
+            //
+            LifecycleEnvironment environment = null;
+            Combo environmentsCombo = getEnvironmentsCombo();
+            if (environmentsCombo!=null) {
+              environment = config.findEnvironment( 
environmentsCombo.getText() );
+            }
+            enableHopGuiProject( projectConfig.getProjectName(), project, 
environment );
+          }
+        }
       }
     } catch ( Exception e ) {
       new ErrorDialog( hopGui.getShell(), "Error", "Error editing project '" + 
projectName, e );
diff --git 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ProjectDialog.java
 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ProjectDialog.java
index 6f4ee12..7fa7aef 100644
--- 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ProjectDialog.java
+++ 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ProjectDialog.java
@@ -82,6 +82,8 @@ public class ProjectDialog extends Dialog {
 
   private IVariables variables;
 
+  private boolean variablesChanged;
+
   public ProjectDialog( Shell parent, Project project, ProjectConfig 
projectConfig, IVariables variables ) {
     super( parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE );
 
@@ -328,6 +330,7 @@ public class ProjectDialog extends Dialog {
     fdVariables.top = new FormAttachment( wlVariables, margin );
     fdVariables.bottom = new FormAttachment( wOK, -margin * 2 );
     wVariables.setLayoutData( fdVariables );
+    wVariables.addModifyListener( e-> { variablesChanged=true; } );
     // lastControl = wVariables;
 
     // When enter is hit, close the dialog
@@ -442,4 +445,20 @@ public class ProjectDialog extends Dialog {
     //
     project.setConfigFilename( projectConfig.getActualProjectConfigFilename( 
variables ) );
   }
+
+  /**
+   * Gets variablesChanged
+   *
+   * @return value of variablesChanged
+   */
+  public boolean isVariablesChanged() {
+    return variablesChanged;
+  }
+
+  /**
+   * @param variablesChanged The variablesChanged to set
+   */
+  public void setVariablesChanged( boolean variablesChanged ) {
+    this.variablesChanged = variablesChanged;
+  }
 }

Reply via email to