/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2019 by Hitachi Vantara : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * 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
 *
 * 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.pentaho.di.plugins.fileopensave.lifecycle;

import org.pentaho.di.plugins.fileopensave.cache.FileCache;
import org.pentaho.di.ui.spoon.SpoonLifecycleListener;
import org.pentaho.di.ui.spoon.SpoonPerspective;
import org.pentaho.di.ui.spoon.SpoonPlugin;
import org.pentaho.di.ui.spoon.SpoonPluginInterface;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.XulException;

/**
 * Listens for spoon lifecycle events
 */
@SpoonPlugin( id = "FileBrowserLifecyclePlugin", image = "" )
public class FileBrowserLifecyclePlugin implements SpoonPluginInterface, SpoonLifecycleListener {

  private final FileCache fileCache;

  public FileBrowserLifecyclePlugin( FileCache fileCache ) {
    this.fileCache = fileCache;
  }

  /**
   * Capture event and clear the file cache when repository is changed
   *
   * @param evt
   */
  @Override public void onEvent( SpoonLifeCycleEvent evt ) {
    if ( evt == SpoonLifeCycleEvent.REPOSITORY_CHANGED ) {
      fileCache.clearAll();
    }
  }

  @Override public void applyToContainer( String category, XulDomContainer container ) throws XulException {
    // No UI elements to attach
  }

  @Override public SpoonLifecycleListener getLifecycleListener() {
    return this;
  }

  @Override public SpoonPerspective getPerspective() {
    return null;
  }
}

@@ -1018,16 +1018,54 @@
 eCache;%0A
+import org.pentaho.di.ui.spoon.Spoon;%0A
 import o
@@ -1341,16 +1341,53 @@
 ption;%0A%0A
+import java.util.function.Supplier;%0A%0A
 /**%0A * L
@@ -1592,39 +1592,167 @@
 %0A  p
-rivate final FileCache fileCach
+ublic static final String VFS_CONNECTIONS = %22VFS Connections%22;%0A  private final FileCache fileCache;%0A  private Supplier%3CSpoon%3E spoonSupplier = Spoon::getInstanc
 e;%0A%0A
@@ -2101,16 +2101,202 @@
 rAll();%0A
+      spoonSupplier.get().refreshTree( VFS_CONNECTIONS );%0A    %7D%0A    if ( evt == SpoonLifeCycleEvent.REPOSITORY_DISCONNECTED ) %7B%0A      spoonSupplier.get().refreshTree( VFS_CONNECTIONS );%0A
     %7D%0A  

Refresh vfs connections on repo connect/disconnect