@Test
  public void testFilterVariables() throws Exception {

    initByFile("default.csv");

    Variables vars = new Variables();
    vars.setVariable("VAR_TEST", "second");
    data.filterProcessor =
        new TextFileFilterProcessor(
            new TextFileFilter[] {new TextFileFilter(0, "${VAR_TEST}", false, false)}, vars);
    setFields(new BaseFileInputField(), new BaseFileInputField(), new BaseFileInputField());

    process();

    check(new Object[][] {{"first", "1", "1.1"}, {"third", "3", "3.3"}});
  }
  public void getUsedVariables(JobMeta jobMeta) {
    Properties sp = new Properties();
    VariableSpace space = Variables.getADefaultVariableSpace();

    String[] keys = space.listVariables();
    for (int i = 0; i < keys.length; i++) {
      sp.put(keys[i], space.getVariable(keys[i]));
    }

    List<String> vars = jobMeta.getUsedVariables();
    if (vars != null && vars.size() > 0) {
      HashMap<String, String> newVariables = new HashMap<String, String>();

      for (int i = 0; i < vars.size(); i++) {
        String varname = vars.get(i);
        if (!varname.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) {
          newVariables.put(varname, Const.NVL(variables.get(varname), sp.getProperty(varname, "")));
        }
      }
      // variables.clear();
      variables.putAll(newVariables);
    }
  }
  private void show() {
    if (rowDatas.size() == 0) return;

    int nr = wStepList.getSelectionIndex();

    java.util.List<Object[]> buffer = (java.util.List<Object[]>) rowDatas.get(nr);
    RowMetaInterface rowMeta = (RowMetaInterface) rowMetas.get(nr);
    String name = (String) stepNames.get(nr);

    if (rowMeta != null && buffer != null && buffer.size() > 0) {
      PreviewRowsDialog prd =
          new PreviewRowsDialog(
              shell, Variables.getADefaultVariableSpace(), SWT.NONE, name, rowMeta, buffer);
      prd.open();
    } else {
      MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
      mb.setText(
          BaseMessages.getString(PKG, "EnterPreviewRowsDialog.Dialog.NoPreviewRowsFound.Title"));
      mb.setMessage(
          BaseMessages.getString(PKG, "EnterPreviewRowsDialog.Dialog.NoPreviewRowsFound.Message"));
      mb.open();
    }
  }
 @Test
 public void testDefaultSettings() throws Exception {
   // Note - this method should only use native or odbc.
   // The jndi meta is used for mutations of the meta, and it would
   // not be threadsafe in a multi-threaded testing environment
   // (each test run in its own thread).
   assertEquals(-1, nativeMeta.getDefaultDatabasePort());
   assertTrue(nativeMeta.supportsSetCharacterStream());
   assertTrue(nativeMeta.supportsAutoInc());
   assertEquals("", nativeMeta.getLimitClause(5));
   assertEquals(0, nativeMeta.getNotFoundTK(true));
   assertEquals("", nativeMeta.getSQLNextSequenceValue("FOO"));
   assertEquals("", nativeMeta.getSQLCurrentSequenceValue("FOO"));
   assertEquals("", nativeMeta.getSQLSequenceExists("FOO"));
   assertTrue(nativeMeta.isFetchSizeSupported());
   assertFalse(nativeMeta.needsPlaceHolder());
   assertTrue(nativeMeta.supportsSchemas());
   assertTrue(nativeMeta.supportsCatalogs());
   assertTrue(nativeMeta.supportsEmptyTransactions());
   assertEquals("SUM", nativeMeta.getFunctionSum());
   assertEquals("AVG", nativeMeta.getFunctionAverage());
   assertEquals("MIN", nativeMeta.getFunctionMinimum());
   assertEquals("MAX", nativeMeta.getFunctionMaximum());
   assertEquals("COUNT", nativeMeta.getFunctionCount());
   assertEquals("\"", nativeMeta.getStartQuote());
   assertEquals("\"", nativeMeta.getEndQuote());
   assertEquals("FOO.BAR", nativeMeta.getSchemaTableCombination("FOO", "BAR"));
   assertEquals(DatabaseMeta.CLOB_LENGTH, nativeMeta.getMaxTextFieldLength());
   assertEquals(DatabaseMeta.CLOB_LENGTH, nativeMeta.getMaxVARCHARLength());
   assertTrue(nativeMeta.supportsTransactions());
   assertFalse(nativeMeta.supportsSequences());
   assertTrue(nativeMeta.supportsBitmapIndex());
   assertTrue(nativeMeta.supportsSetLong());
   assertArrayEquals(new String[] {}, nativeMeta.getReservedWords());
   assertTrue(nativeMeta.quoteReservedWords());
   assertFalse(nativeMeta.supportsRepository());
   assertArrayEquals(new String[] {"TABLE"}, nativeMeta.getTableTypes());
   assertArrayEquals(new String[] {"VIEW"}, nativeMeta.getViewTypes());
   assertArrayEquals(new String[] {"SYNONYM"}, nativeMeta.getSynonymTypes());
   assertFalse(nativeMeta.useSchemaNameForTableList());
   assertTrue(nativeMeta.supportsViews());
   assertFalse(nativeMeta.supportsSynonyms());
   assertNull(nativeMeta.getSQLListOfProcedures());
   assertNull(nativeMeta.getSQLListOfSequences());
   assertTrue(nativeMeta.supportsFloatRoundingOnUpdate());
   assertNull(nativeMeta.getSQLLockTables(new String[] {"FOO"}));
   assertNull(nativeMeta.getSQLUnlockTables(new String[] {"FOO"}));
   assertTrue(nativeMeta.supportsTimeStampToDateConversion());
   assertTrue(nativeMeta.supportsBatchUpdates());
   assertFalse(nativeMeta.supportsBooleanDataType());
   assertFalse(nativeMeta.supportsTimestampDataType());
   assertTrue(nativeMeta.preserveReservedCase());
   assertTrue(nativeMeta.isDefaultingToUppercase());
   Map<String, String> emptyMap = new HashMap<String, String>();
   assertEquals(emptyMap, nativeMeta.getExtraOptions());
   assertEquals(";", nativeMeta.getExtraOptionSeparator());
   assertEquals("=", nativeMeta.getExtraOptionValueSeparator());
   assertEquals(";", nativeMeta.getExtraOptionIndicator());
   assertTrue(nativeMeta.supportsOptionsInURL());
   assertNull(nativeMeta.getExtraOptionsHelpText());
   assertTrue(nativeMeta.supportsGetBlob());
   assertNull(nativeMeta.getConnectSQL());
   assertTrue(nativeMeta.supportsSetMaxRows());
   assertFalse(nativeMeta.isUsingConnectionPool());
   assertEquals(ConnectionPoolUtil.defaultMaximumNrOfConnections, nativeMeta.getMaximumPoolSize());
   assertEquals(ConnectionPoolUtil.defaultInitialNrOfConnections, nativeMeta.getInitialPoolSize());
   assertFalse(nativeMeta.isPartitioned());
   assertArrayEquals(new PartitionDatabaseMeta[0], nativeMeta.getPartitioningInformation());
   Properties emptyProps = new Properties();
   assertEquals(emptyProps, nativeMeta.getConnectionPoolingProperties());
   assertTrue(nativeMeta.needsToLockAllTables());
   assertTrue(nativeMeta.isStreamingResults());
   assertFalse(nativeMeta.isQuoteAllFields());
   assertFalse(nativeMeta.isForcingIdentifiersToLowerCase());
   assertFalse(nativeMeta.isForcingIdentifiersToUpperCase());
   assertFalse(nativeMeta.isUsingDoubleDecimalAsSchemaTableSeparator());
   assertTrue(nativeMeta.isRequiringTransactionsOnQueries());
   assertEquals(
       "org.pentaho.di.core.database.DatabaseFactory", nativeMeta.getDatabaseFactoryName());
   assertNull(nativeMeta.getPreferredSchemaName());
   assertFalse(nativeMeta.supportsSequenceNoMaxValueOption());
   assertFalse(nativeMeta.requiresCreateTablePrimaryKeyAppend());
   assertFalse(nativeMeta.requiresCastToVariousForIsNull());
   assertFalse(nativeMeta.isDisplaySizeTwiceThePrecision());
   assertTrue(nativeMeta.supportsPreparedStatementMetadataRetrieval());
   assertFalse(nativeMeta.supportsResultSetMetadataRetrievalOnly());
   assertFalse(nativeMeta.isSystemTable("FOO"));
   assertTrue(nativeMeta.supportsNewLinesInSQL());
   assertNull(nativeMeta.getSQLListOfSchemas());
   assertEquals(0, nativeMeta.getMaxColumnsInIndex());
   assertTrue(nativeMeta.supportsErrorHandlingOnBatchUpdates());
   assertTrue(nativeMeta.isExplorable());
   assertNull(nativeMeta.getXulOverlayFile());
   assertTrue(nativeMeta.onlySpaces("   \t   \n  \r   "));
   assertFalse(nativeMeta.isMySQLVariant());
   assertTrue(nativeMeta.canTest());
   assertTrue(nativeMeta.requiresName());
   assertTrue(nativeMeta.releaseSavepoint());
   Variables v = new Variables();
   v.setVariable("FOOVARIABLE", "FOOVALUE");
   DatabaseMeta dm = new DatabaseMeta();
   dm.setDatabaseInterface(nativeMeta);
   assertEquals("", nativeMeta.getDataTablespaceDDL(v, dm));
   assertEquals("", nativeMeta.getIndexTablespaceDDL(v, dm));
   assertFalse(nativeMeta.useSafePoints());
   assertTrue(nativeMeta.supportsErrorHandling());
   assertEquals("'DATA'", nativeMeta.getSQLValue(new ValueMetaString("FOO"), "DATA", null));
   assertEquals("'15'", nativeMeta.getSQLValue(new ValueMetaString("FOO"), "15", null));
   assertEquals("_", nativeMeta.getFieldnameProtector());
   assertEquals("_1ABC_123", nativeMeta.getSafeFieldname("1ABC 123"));
   BaseDatabaseMeta tmpSC =
       new ConcreteBaseDatabaseMeta() {
         @Override
         public String[] getReservedWords() {
           return new String[] {"SELECT"};
         }
       };
   assertEquals("SELECT_", tmpSC.getSafeFieldname("SELECT"));
   assertEquals("NOMAXVALUE", nativeMeta.getSequenceNoMaxValueOption());
   assertTrue(nativeMeta.supportsAutoGeneratedKeys());
   assertNull(nativeMeta.customizeValueFromSQLType(new ValueMetaString("FOO"), null, 0));
   assertTrue(nativeMeta.fullExceptionLog(new RuntimeException("xxxx")));
 }
  @Override
  public String encode(AbstractMeta meta) throws Exception {
    TransMeta transMeta = (TransMeta) meta;

    mxGraph graph = new mxGraph();
    graph.getModel().beginUpdate();
    mxCell parent = (mxCell) graph.getDefaultParent();
    Document doc = mxUtils.createDocument();

    try {
      Element e = super.encodeCommRootAttr(transMeta, doc);
      e.setAttribute("trans_version", transMeta.getTransversion());
      e.setAttribute("trans_type", transMeta.getTransformationType().getCode());
      e.setAttribute("trans_status", String.valueOf(transMeta.getTransstatus()));

      // variables
      Properties sp = new Properties();
      JSONArray jsonArray = new JSONArray();

      String[] keys = Variables.getADefaultVariableSpace().listVariables();
      for (int i = 0; i < keys.length; i++) {
        sp.put(keys[i], Variables.getADefaultVariableSpace().getVariable(keys[i]));
      }

      List<String> vars = transMeta.getUsedVariables();
      for (int i = 0; i < vars.size(); i++) {
        String varname = vars.get(i);
        if (!varname.startsWith(Const.INTERNAL_VARIABLE_PREFIX)
            && Const.indexOfString(varname, transMeta.listParameters()) < 0) {
          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", sp.getProperty(varname, ""));
          jsonArray.add(param);
        }
      }

      for (String varname : Const.INTERNAL_JOB_VARIABLES) {
        String value = transMeta.getVariable(varname);
        if (!Const.isEmpty(value)) {

          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", value);
          jsonArray.add(param);
        }
      }
      e.setAttribute("variables", jsonArray.toString());

      TransLogTable transLogTable = transMeta.getTransLogTable();
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("connection", transLogTable.getConnectionName());
      jsonObject.put("schema", transLogTable.getSchemaName());
      jsonObject.put("table", transLogTable.getTableName());
      jsonObject.put("size_limit_lines", transLogTable.getLogSizeLimit());
      jsonObject.put("interval", transLogTable.getLogInterval());
      jsonObject.put("timeout_days", transLogTable.getTimeoutInDays());
      JSONArray fields = new JSONArray();
      for (LogTableField field : transLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("subjectAllowed", field.isSubjectAllowed());
        if (field.isSubjectAllowed()) {
          jsonField.put("subject", field.getSubject() == null ? "" : field.getSubject().toString());
        } else {
          jsonField.put("subject", "-");
        }
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("transLogTable", jsonObject.toString());

      StepLogTable stepLogTable = transMeta.getStepLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", stepLogTable.getConnectionName());
      jsonObject.put("schema", stepLogTable.getSchemaName());
      jsonObject.put("table", stepLogTable.getTableName());
      jsonObject.put("timeout_days", stepLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : stepLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("stepLogTable", jsonObject.toString());

      PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", performanceLogTable.getConnectionName());
      jsonObject.put("schema", performanceLogTable.getSchemaName());
      jsonObject.put("table", performanceLogTable.getTableName());
      jsonObject.put("interval", performanceLogTable.getLogInterval());
      jsonObject.put("timeout_days", performanceLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : performanceLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("performanceLogTable", jsonObject.toString());

      MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", metricsLogTable.getConnectionName());
      jsonObject.put("schema", metricsLogTable.getSchemaName());
      jsonObject.put("table", metricsLogTable.getTableName());
      jsonObject.put("timeout_days", metricsLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : metricsLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("metricsLogTable", jsonObject.toString());

      jsonObject = new JSONObject();
      jsonObject.put(
          "connection",
          transMeta.getMaxDateConnection() == null
              ? ""
              : transMeta.getMaxDateConnection().getName());
      jsonObject.put("table", transMeta.getMaxDateTable());
      jsonObject.put("field", transMeta.getMaxDateField());
      jsonObject.put("offset", transMeta.getMaxDateOffset());
      jsonObject.put("maxdiff", transMeta.getMaxDateDifference());
      e.setAttribute("maxdate", jsonObject.toString());

      e.setAttribute("size_rowset", String.valueOf(transMeta.getSizeRowset()));
      e.setAttribute("sleep_time_empty", String.valueOf(transMeta.getSleepTimeEmpty()));
      e.setAttribute("sleep_time_full", String.valueOf(transMeta.getSleepTimeFull()));
      e.setAttribute("unique_connections", transMeta.isUsingUniqueConnections() ? "Y" : "N");
      e.setAttribute("feedback_shown", transMeta.isFeedbackShown() ? "Y" : "N");
      e.setAttribute("feedback_size", String.valueOf(transMeta.getFeedbackSize()));
      e.setAttribute(
          "using_thread_priorities", transMeta.isUsingThreadPriorityManagment() ? "Y" : "N");
      e.setAttribute(
          "capture_step_performance", transMeta.isCapturingStepPerformanceSnapShots() ? "Y" : "N");
      e.setAttribute(
          "step_performance_capturing_delay",
          String.valueOf(transMeta.getStepPerformanceCapturingDelay()));
      e.setAttribute(
          "step_performance_capturing_size_limit",
          transMeta.getStepPerformanceCapturingSizeLimit());

      super.encodeSlaveServers(e, transMeta);
      encodeClusterSchema(e, transMeta);
      encodePartitionSchema(e, transMeta);

      try {
        if (transMeta.getKey() != null) {
          e.setAttribute("key_for_session_key", XMLHandler.encodeBinaryData(transMeta.getKey()));
        } else {
          e.setAttribute("key_for_session_key", "");
        }
      } catch (Exception e1) {
        e1.printStackTrace();
        e.setAttribute("key_for_session_key", "");
      }
      e.setAttribute("is_key_private", transMeta.isPrivateKey() ? "Y" : "N");

      super.encodeNote(doc, graph, transMeta);

      super.encodeDatabases(e, transMeta);
      parent.setValue(e);

      // encode steps and hops
      HashMap<StepMeta, Object> cells = new HashMap<StepMeta, Object>();
      List<StepMeta> list = transMeta.getSteps();
      for (int i = 0; i < list.size(); i++) {
        StepMeta step = (StepMeta) list.get(i);
        Point p = step.getLocation();
        StepEncoder stepEncoder = (StepEncoder) PluginFactory.getBean(step.getStepID());

        PluginInterface plugin =
            PluginRegistry.getInstance().getPlugin(StepPluginType.class, step.getStepID());
        Object cell =
            graph.insertVertex(
                parent,
                null,
                stepEncoder.encodeStep(step),
                p.x,
                p.y,
                40,
                40,
                "icon;image=" + SvgImageUrl.getUrl(plugin));
        cells.put(step, cell);
      }

      for (int i = 0; i < transMeta.nrTransHops(); i++) {
        TransHopMeta transHopMeta = transMeta.getTransHop(i);

        Object v1 = cells.get(transHopMeta.getFromStep());
        Object v2 = cells.get(transHopMeta.getToStep());

        graph.insertEdge(parent, null, TransHopMetaCodec.encode(transHopMeta), v1, v2);
      }
    } finally {
      graph.getModel().endUpdate();
    }

    mxCodec codec = new mxCodec();
    return mxUtils.getPrettyXml(codec.encode(graph.getModel()));
  }
public class PartitionsController extends LazilyInitializedController
    implements IUISupportController {

  private static Class<?> PKG =
      RepositoryExplorerDialog.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

  protected BindingFactory bf = null;

  private Shell shell = null;

  private XulTree partitionsTable = null;

  private UIPartitions partitionList = new UIPartitions();

  private VariableSpace variableSpace = Variables.getADefaultVariableSpace();

  @Override
  public String getName() {
    return "partitionsController";
  }

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

  public void createBindings() {
    refreshPartitions();
    try {
      partitionsTable = (XulTree) document.getElementById("partitions-table");
      bf.setBindingType(Binding.Type.ONE_WAY);
      bf.createBinding(partitionList, "children", partitionsTable, "elements").fireSourceChanged();
      bf.createBinding(partitionsTable, "selectedItems", this, "enableButtons");
    } catch (Exception e) {
      // convert to runtime exception so it bubbles up through the UI
      throw new RuntimeException(e);
    }
  }

  protected boolean doLazyInit() {
    // Load the SWT Shell from the explorer dialog
    shell = ((SwtDialog) document.getElementById("repository-explorer-dialog")).getShell();

    enableButtons(true, false, false);
    bf = new SwtBindingFactory();
    bf.setDocument(this.getXulDomContainer().getDocumentRoot());

    if (bf != null) {
      createBindings();
    }
    return true;
  }

  public void setVariableSpace(VariableSpace variableSpace) {
    this.variableSpace = variableSpace;
  }

  public void editPartition() {
    String partitionSchemaName = "";
    try {
      Collection<UIPartition> partitions = partitionsTable.getSelectedItems();

      if (partitions != null && !partitions.isEmpty()) {
        // Grab the first item in the list & send it to the partition schema dialog
        PartitionSchema partitionSchema =
            ((UIPartition) partitions.toArray()[0]).getPartitionSchema();
        partitionSchemaName = partitionSchema.getName();
        // Make sure the partition already exists
        ObjectId partitionId = repository.getPartitionSchemaID(partitionSchema.getName());
        if (partitionId == null) {
          MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
          mb.setMessage(
              BaseMessages.getString(
                  PKG,
                  "RepositoryExplorerDialog.Partition.DoesNotExists.Message",
                  partitionSchemaName));
          mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
          mb.open();
        } else {
          PartitionSchemaDialog partitionDialog =
              new PartitionSchemaDialog(
                  shell, partitionSchema, repository.readDatabases(), variableSpace);
          if (partitionDialog.open()) {
            if (partitionSchema.getName() != null && !partitionSchema.getName().equals("")) {
              repository.insertLogEntry(
                  BaseMessages.getString(
                      RepositoryExplorer.class,
                      "PartitionsController.Message.UpdatingPartition",
                      partitionSchema.getName()));
              repository.save(partitionSchema, Const.VERSION_COMMENT_EDIT_VERSION, null);
            } else {
              MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
              mb.setMessage(
                  BaseMessages.getString(
                      PKG, "RepositoryExplorerDialog.Partition.Edit.InvalidName.Message"));
              mb.setText(
                  BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
              mb.open();
            }
          }
        }
      } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mb.setMessage(
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Partition.NoItemSelected.Message"));
        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
        mb.open();
      }
    } catch (KettleException e) {
      new ErrorDialog(
          shell,
          BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"),
          BaseMessages.getString(
                  PKG, "RepositoryExplorerDialog.Partition.Edit.UnexpectedError.Message")
              + partitionSchemaName
              + "]",
          e);
    } finally {
      refreshPartitions();
    }
  }

  public void createPartition() {
    try {
      PartitionSchema partition = new PartitionSchema();
      PartitionSchemaDialog partitionDialog =
          new PartitionSchemaDialog(shell, partition, repository.readDatabases(), variableSpace);
      if (partitionDialog.open()) {
        // See if this partition already exists...
        ObjectId idPartition = repository.getPartitionSchemaID(partition.getName());
        if (idPartition == null) {
          if (partition.getName() != null && !partition.getName().equals("")) {
            repository.insertLogEntry(
                BaseMessages.getString(
                    RepositoryExplorer.class,
                    "PartitionsController.Message.CreatingPartition",
                    partition.getName()));
            repository.save(partition, Const.VERSION_COMMENT_INITIAL_VERSION, null);
          } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(
                BaseMessages.getString(
                    PKG, "RepositoryExplorerDialog.Partition.Edit.InvalidName.Message"));
            mb.setText(
                BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Create.Title"));
            mb.open();
          }
        } else {
          MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
          mb.setMessage(
              BaseMessages.getString(
                  PKG, "RepositoryExplorerDialog.Partition.Create.AlreadyExists.Message"));
          mb.setText(
              BaseMessages.getString(
                  PKG, "RepositoryExplorerDialog.Partition.Create.AlreadyExists.Title"));
          mb.open();
        }
      }
    } catch (KettleException e) {
      new ErrorDialog(
          shell,
          BaseMessages.getString(
              PKG, "RepositoryExplorerDialog.Partition.Create.UnexpectedError.Title"),
          BaseMessages.getString(
              PKG, "RepositoryExplorerDialog.Partition.Create.UnexpectedError.Message"),
          e);
    } finally {
      refreshPartitions();
    }
  }

  public void removePartition() {
    String partitionSchemaName = "";
    try {
      Collection<UIPartition> partitions = partitionsTable.getSelectedItems();

      if (partitions != null && !partitions.isEmpty()) {
        for (Object obj : partitions) {
          if (obj != null && obj instanceof UIPartition) {
            UIPartition partition = (UIPartition) obj;
            PartitionSchema partitionSchema = partition.getPartitionSchema();
            partitionSchemaName = partitionSchema.getName();
            // Make sure the partition to delete exists in the repository
            ObjectId partitionId = repository.getPartitionSchemaID(partitionSchema.getName());
            if (partitionId == null) {
              MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
              mb.setMessage(
                  BaseMessages.getString(
                      PKG,
                      "RepositoryExplorerDialog.Partition.DoesNotExists.Message",
                      partitionSchemaName));
              mb.setText(
                  BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"));
              mb.open();
            } else {
              repository.deletePartitionSchema(partitionId);
            }
          }
        }
      } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mb.setMessage(
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Partition.NoItemSelected.Message"));
        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"));
        mb.open();
      }
    } catch (KettleException e) {
      new ErrorDialog(
          shell,
          BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"),
          BaseMessages.getString(
                  PKG, "RepositoryExplorerDialog.Partition.Delete.UnexpectedError.Message")
              + partitionSchemaName
              + "]",
          e); //$NON-NLS-3$
    } finally {
      refreshPartitions();
    }
  }

  public void refreshPartitions() {
    if (repository != null) {
      final List<UIPartition> tmpList = new ArrayList<UIPartition>();
      Runnable r =
          new Runnable() {
            public void run() {
              try {
                ObjectId[] partitionIdList = repository.getPartitionSchemaIDs(false);

                for (ObjectId partitionId : partitionIdList) {
                  PartitionSchema partition = repository.loadPartitionSchema(partitionId, null);
                  // Add the partition schema to the list
                  tmpList.add(new UIPartition(partition));
                }
              } catch (KettleException e) {
                // convert to runtime exception so it bubbles up through the UI
                throw new RuntimeException(e);
              }
            }
          };
      doWithBusyIndicator(r);
      partitionList.setChildren(tmpList);
    }
  }

  public void setEnableButtons(List<UIPartition> partitions) {
    boolean enableEdit = false;
    boolean enableRemove = false;
    if (partitions != null && partitions.size() > 0) {
      enableRemove = true;
      if (partitions.size() == 1) {
        enableEdit = true;
      }
    }
    // Convenience - Leave 'new' enabled, modify 'edit' and 'remove'
    enableButtons(true, enableEdit, enableRemove);
  }

  public void enableButtons(boolean enableNew, boolean enableEdit, boolean enableRemove) {
    XulButton bNew = (XulButton) document.getElementById("partitions-new");
    XulButton bEdit = (XulButton) document.getElementById("partitions-edit");
    XulButton bRemove = (XulButton) document.getElementById("partitions-remove");

    bNew.setDisabled(!enableNew);
    bEdit.setDisabled(!enableEdit);
    bRemove.setDisabled(!enableRemove);
  }

  public void tabClicked() {
    lazyInit();
  }
}