<commit_before>package org.pentaho.di.ui.repository.repositoryexplorer.controllers;

import java.util.Enumeration;
import java.util.ResourceBundle;

import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException;
import org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorer;
import org.pentaho.ui.xul.XulException;
import org.pentaho.ui.xul.components.XulMessageBox;
import org.pentaho.ui.xul.impl.AbstractXulEventHandler;

public abstract class LazilyInitializedController extends AbstractXulEventHandler {
  protected Repository repository;

  protected boolean initialized;

  private ResourceBundle messages = new ResourceBundle() {

    @Override
    public Enumeration<String> getKeys() {
      return null;
    }

    @Override
    protected Object handleGetObject(String key) {
      return BaseMessages.getString(RepositoryExplorer.class, key);
    }

  };

  public void init(Repository repository) throws ControllerInitializationException {
    this.repository = repository;
  }

  protected synchronized void lazyInit() {
    if (!initialized) {
      boolean succeeded = false;
      try {
        succeeded = doLazyInit();
      } catch (Exception e) {
        e.printStackTrace();
        showErrorDialog(e);
      }
      if (succeeded) {
        initialized = true;
      } else {
        showErrorDialog(null);
      }
    }
  }

  private void showErrorDialog(final Exception e) {
    XulMessageBox messageBox = null;
    try {
      messageBox = (XulMessageBox) document.createElement("messagebox"); //$NON-NLS-1$
    } catch (XulException xe) {
      throw new RuntimeException(xe);
    }
    messageBox.setTitle(messages.getString("Dialog.Error"));//$NON-NLS-1$
    messageBox.setAcceptLabel(messages.getString("Dialog.Ok"));//$NON-NLS-1$
    if (e != null) {
      messageBox.setMessage(BaseMessages.getString(RepositoryExplorer.class,
          "LazilyInitializedController.Message.UnableToInitWithParam", e.getLocalizedMessage()));//$NON-NLS-1$
    } else {
      messageBox.setMessage(BaseMessages.getString(RepositoryExplorer.class,
          "LazilyInitializedController.Message.UnableToInit"));//$NON-NLS-1$
    }
    messageBox.open();
  }<commit_msg>[PDI-4068] lazy init of repository explorer tabs<commit_after>package org.pentaho.di.ui.repository.repositoryexplorer.controllers;

import java.util.Enumeration;
import java.util.ResourceBundle;

import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException;
import org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorer;
import org.pentaho.ui.xul.XulException;
import org.pentaho.ui.xul.components.XulMessageBox;
import org.pentaho.ui.xul.impl.AbstractXulEventHandler;

public abstract class LazilyInitializedController extends AbstractXulEventHandler {
  protected Repository repository;

  protected boolean initialized;

  private ResourceBundle messages = new ResourceBundle() {

    @Override
    public Enumeration<String> getKeys() {
      return null;
    }

    @Override
    protected Object handleGetObject(String key) {
      return BaseMessages.getString(RepositoryExplorer.class, key);
    }

  };

  public void init(Repository repository) throws ControllerInitializationException {
    this.repository = repository;
  }

  protected synchronized void lazyInit() {
    if (!initialized) {
      try {
        boolean succeeded = doLazyInit();
        if (succeeded) {
          initialized = true;
        } else {
          showErrorDialog(null);
        }
      } catch (Exception e) {
        e.printStackTrace();
        showErrorDialog(e);
      }
    }
  }

  private void showErrorDialog(final Exception e) {
    XulMessageBox messageBox = null;
    try {
      messageBox = (XulMessageBox) document.createElement("messagebox"); //$NON-NLS-1$
    } catch (XulException xe) {
      throw new RuntimeException(xe);
    }
    messageBox.setTitle(messages.getString("Dialog.Error"));//$NON-NLS-1$
    messageBox.setAcceptLabel(messages.getString("Dialog.Ok"));//$NON-NLS-1$
    if (e != null) {
      messageBox.setMessage(BaseMessages.getString(RepositoryExplorer.class,
          "LazilyInitializedController.Message.UnableToInitWithParam", e.getLocalizedMessage()));//$NON-NLS-1$
    } else {
      messageBox.setMessage(BaseMessages.getString(RepositoryExplorer.class,
          "LazilyInitializedController.Message.UnableToInit"));//$NON-NLS-1$
    }
    messageBox.open();
  }
{'fraction_non_alphanumeric': 0.10724698042482299, 'fraction_numerical': 0.003748438150770512, 'mean_word_length': 3.8078078078078077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837006', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1379, 'n_words': 238}