Search in sources :

Example 6 with ImportRules

use of org.pentaho.di.imp.ImportRules in project pentaho-kettle by pentaho.

the class ImportRulesDialog method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    KettleEnvironment.init();
    PropsUI.init(display, PropsUI.TYPE_PROPERTIES_SPOON);
    Shell shell = new Shell(display);
    ImportRules importRules = new ImportRules();
    importRules.loadXML(XMLHandler.getSubNode(XMLHandler.loadXMLFile("bin/import-rules.xml"), ImportRules.XML_TAG));
    ImportRulesDialog dialog = new ImportRulesDialog(shell, importRules);
    if (dialog.open()) {
        for (ImportRuleInterface rule : importRules.getRules()) {
            System.out.println(" - " + rule.toString());
        }
    }
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) Shell(org.eclipse.swt.widgets.Shell) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) Display(org.eclipse.swt.widgets.Display)

Example 7 with ImportRules

use of org.pentaho.di.imp.ImportRules in project pentaho-kettle by pentaho.

the class Spoon method importDirectoryToRepository.

public void importDirectoryToRepository() {
    FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
    dialog.setText(BaseMessages.getString(PKG, "Spoon.SelectAnXMLFileToImportFrom.Message"));
    if (dialog.open() == null) {
        return;
    }
    // Ask for a set of import rules
    // 
    MessageBox box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.YES | SWT.NO | SWT.CANCEL);
    box.setText(BaseMessages.getString(PKG, "Spoon.QuestionApplyImportRules.Title"));
    box.setMessage(BaseMessages.getString(PKG, "Spoon.QuestionApplyImportRules.Message"));
    int answer = box.open();
    if (answer == SWT.CANCEL) {
        return;
    }
    // Get the import rules
    // 
    ImportRules importRules = new ImportRules();
    if (answer == SWT.YES) {
        ImportRulesDialog importRulesDialog = new ImportRulesDialog(shell, importRules);
        if (!importRulesDialog.open()) {
            return;
        }
    }
    // Ask for a destination in the repository...
    // 
    SelectDirectoryDialog sdd = new SelectDirectoryDialog(shell, SWT.NONE, rep);
    RepositoryDirectoryInterface baseDirectory = sdd.open();
    if (baseDirectory == null) {
        return;
    }
    // Finally before importing, ask for a version comment (if applicable)
    // 
    String fullPath = baseDirectory.getPath() + "/foo.ktr";
    String versionComment = null;
    boolean versionOk = false;
    while (!versionOk) {
        versionComment = RepositorySecurityUI.getVersionComment(shell, rep, "Import of files into [" + baseDirectory.getPath() + "]", fullPath, true);
        // if the version comment is null, the user hit cancel, exit.
        if (versionComment == null) {
            return;
        }
        if (Utils.isEmpty(versionComment) && rep.getSecurityProvider().isVersionCommentMandatory()) {
            if (!RepositorySecurityUI.showVersionCommentMandatoryDialog(shell)) {
                versionOk = true;
            }
        } else {
            versionOk = true;
        }
    }
    String[] filenames = dialog.getFileNames();
    if (filenames.length > 0) {
        RepositoryImportProgressDialog ripd = new RepositoryImportProgressDialog(shell, SWT.NONE, rep, dialog.getFilterPath(), filenames, baseDirectory, versionComment, importRules);
        ripd.open();
        refreshTree();
    }
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ImportRulesDialog(org.pentaho.di.ui.imp.ImportRulesDialog) RepositoryImportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryImportProgressDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectDirectoryDialog(org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with ImportRules

use of org.pentaho.di.imp.ImportRules in project pentaho-kettle by pentaho.

the class Spoon method exportRepositoryDirectory.

/**
 * @param directoryToExport
 *          set to null to export the complete repository
 * @return false if we want to stop processing. true if we need to continue.
 */
public boolean exportRepositoryDirectory(RepositoryDirectory directoryToExport) {
    FileDialog dialog = this.getExportFileDialog();
    if (dialog.open() == null) {
        return false;
    }
    String filename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
    log.logBasic(BaseMessages.getString(PKG, "Spoon.Log.Exporting"), BaseMessages.getString(PKG, "Spoon.Log.ExportObjectsToFile", filename));
    // check if file is exists
    MessageBox box = RepositoryExportProgressDialog.checkIsFileIsAcceptable(shell, log, filename);
    int answer = (box == null) ? SWT.OK : box.open();
    if (answer != SWT.OK) {
        // seems user don't want to overwrite file...
        return false;
    }
    // ok, let's show one more modal dialog, users like modal dialogs.
    // They feel that their opinion are important to us.
    box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.YES | SWT.NO | SWT.CANCEL);
    box.setText(BaseMessages.getString(PKG, "Spoon.QuestionApplyImportRulesToExport.Title"));
    box.setMessage(BaseMessages.getString(PKG, "Spoon.QuestionApplyImportRulesToExport.Message"));
    answer = box.open();
    if (answer == SWT.CANCEL) {
        return false;
    }
    // Get the import rules
    // 
    ImportRules importRules = new ImportRules();
    if (answer == SWT.YES) {
        ImportRulesDialog importRulesDialog = new ImportRulesDialog(shell, importRules);
        if (!importRulesDialog.open()) {
            return false;
        }
    }
    RepositoryExportProgressDialog repd = new RepositoryExportProgressDialog(shell, rep, directoryToExport, filename, importRules);
    repd.open();
    return true;
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) ImportRulesDialog(org.pentaho.di.ui.imp.ImportRulesDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryExportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryExportProgressDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

ImportRules (org.pentaho.di.imp.ImportRules)8 ImportRuleInterface (org.pentaho.di.imp.rule.ImportRuleInterface)4 FileDialog (org.eclipse.swt.widgets.FileDialog)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 Point (org.pentaho.di.core.gui.Point)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 KettlePropertiesFileDialog (org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog)2 ImportRulesDialog (org.pentaho.di.ui.imp.ImportRulesDialog)2 File (java.io.File)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 FileObject (org.apache.commons.vfs2.FileObject)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1