Search in sources :

Example 1 with JsonInputMeta

use of org.pentaho.di.trans.steps.jsoninput.JsonInputMeta in project pentaho-kettle by pentaho.

the class JsonInputDialog method open.

public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);
    lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    changed = input.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JsonInputDialog.DialogTitle"));
    middle = props.getMiddlePct();
    margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.top = new FormAttachment(0, margin);
    fdlStepname.right = new FormAttachment(middle, -margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
    addFileTab();
    addContentTab();
    addFieldsTab();
    addAdditionalFieldsTab();
    fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wStepname, margin);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wPreview = new Button(shell, SWT.PUSH);
    wPreview.setText(BaseMessages.getString(PKG, "JsonInputDialog.Button.PreviewRows"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, wTabFolder);
    // Add listeners
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    lsPreview = new Listener() {

        public void handleEvent(Event e) {
            preview();
        }
    };
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wPreview.addListener(SWT.Selection, lsPreview);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wLimit.addSelectionListener(lsDef);
    wInclRownumField.addSelectionListener(lsDef);
    wInclFilenameField.addSelectionListener(lsDef);
    // Add the file to the list of files...
    SelectionAdapter selA = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            wFilenameList.add(new String[] { wFilename.getText(), wFilemask.getText(), wExcludeFilemask.getText(), JsonInputMeta.RequiredFilesCode[0], JsonInputMeta.RequiredFilesCode[0] });
            wFilename.setText("");
            wFilemask.setText("");
            wExcludeFilemask.setText("");
            wFilenameList.removeEmptyRows();
            wFilenameList.setRowNums();
            wFilenameList.optWidth(true);
        }
    };
    wbaFilename.addSelectionListener(selA);
    wFilename.addSelectionListener(selA);
    // Delete files from the list of files...
    wbdFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            int[] idx = wFilenameList.getSelectionIndices();
            wFilenameList.remove(idx);
            wFilenameList.removeEmptyRows();
            wFilenameList.setRowNums();
        }
    });
    // Edit the selected file & remove from the list...
    wbeFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            int idx = wFilenameList.getSelectionIndex();
            if (idx >= 0) {
                String[] string = wFilenameList.getItem(idx);
                wFilename.setText(string[0]);
                wFilemask.setText(string[1]);
                wExcludeFilemask.setText(string[2]);
                wFilenameList.remove(idx);
            }
            wFilenameList.removeEmptyRows();
            wFilenameList.setRowNums();
        }
    });
    // Show the files that are selected at this time...
    wbShowFiles.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            try {
                JsonInputMeta tfii = new JsonInputMeta();
                getInfo(tfii);
                FileInputList fileInputList = tfii.getFiles(transMeta);
                String[] files = fileInputList.getFileStrings();
                if (files != null && files.length > 0) {
                    EnterSelectionDialog esd = new EnterSelectionDialog(shell, files, BaseMessages.getString(PKG, "JsonInputDialog.FilesReadSelection.DialogTitle"), BaseMessages.getString(PKG, "JsonInputDialog.FilesReadSelection.DialogMessage"));
                    esd.setViewOnly();
                    esd.open();
                } else {
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                    mb.setMessage(BaseMessages.getString(PKG, "JsonInputDialog.NoFileFound.DialogMessage"));
                    mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
                    mb.open();
                }
            } catch (KettleException ex) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "JsonInputDialog.ErrorParsingData.DialogTitle"), BaseMessages.getString(PKG, "JsonInputDialog.ErrorParsingData.DialogMessage"), ex);
            }
        }
    });
    // Enable/disable the right fields to allow a filename to be added to each row...
    wInclFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            setIncludeFilename();
        }
    });
    // Enable/disable the right fields to allow a row number to be added to each row...
    wInclRownum.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            setIncludeRownum();
        }
    });
    // Whenever something changes, set the tooltip to the expanded version of the filename:
    wFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wFilename.setToolTipText(wFilename.getText());
        }
    });
    // Listen to the Browse... button
    wbbFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (!Utils.isEmpty(wFilemask.getText()) || !Utils.isEmpty(wExcludeFilemask.getText())) {
                // A mask: a
                // directory!
                DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
                if (wFilename.getText() != null) {
                    String fpath = transMeta.environmentSubstitute(wFilename.getText());
                    dialog.setFilterPath(fpath);
                }
                if (dialog.open() != null) {
                    String str = dialog.getFilterPath();
                    wFilename.setText(str);
                }
            } else {
                FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                dialog.setFilterExtensions(new String[] { "*.js;*.JS;*.json;*.JSON", "*" });
                if (wFilename.getText() != null) {
                    String fname = transMeta.environmentSubstitute(wFilename.getText());
                    dialog.setFileName(fname);
                }
                dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.JsonFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
                if (dialog.open() != null) {
                    String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    wFilename.setText(str);
                }
            }
        }
    });
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wTabFolder.setSelection(0);
    // Set the shell size, based upon previous time...
    setSize();
    getData(input);
    activeStreamField();
    setIncludeFilename();
    setIncludeRownum();
    input.setChanged(changed);
    wFields.optWidth(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) CTabFolder(org.eclipse.swt.custom.CTabFolder) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) JsonInputMeta(org.pentaho.di.trans.steps.jsoninput.JsonInputMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) FileInputList(org.pentaho.di.core.fileinput.FileInputList) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 2 with JsonInputMeta

use of org.pentaho.di.trans.steps.jsoninput.JsonInputMeta in project pentaho-kettle by pentaho.

the class JsonInputAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    mockFactory = new MetaverseObjectFactory();
    when(mockBuilder.getMetaverseObjectFactory()).thenReturn(mockFactory);
    when(mockNamespace.getParentNamespace()).thenReturn(mockNamespace);
    analyzer = new JsonInputAnalyzer() {

        @Override
        public Set<String> getInputStepNames(final JsonInputMeta meta, final String fieldName) {
            Set<String> inputFieldStepNames = new HashSet<>();
            inputFieldStepNames.add("previousStep");
            return inputFieldStepNames;
        }
    };
    analyzer.setMetaverseBuilder(mockBuilder);
    when(mockJsonInput.getStepMetaInterface()).thenReturn(meta);
    when(mockJsonInput.getStepMeta()).thenReturn(mockStepMeta);
    when(mockStepMeta.getStepMetaInterface()).thenReturn(meta);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) JsonInputMeta(org.pentaho.di.trans.steps.jsoninput.JsonInputMeta) Before(org.junit.Before)

Example 3 with JsonInputMeta

use of org.pentaho.di.trans.steps.jsoninput.JsonInputMeta in project pentaho-kettle by pentaho.

the class JsonInputDialog method preview.

// Preview the data
private void preview() {
    try {
        JsonInputMeta oneMeta = new JsonInputMeta();
        getInfo(oneMeta);
        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "JsonInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "JsonInputDialog.NumberRows.DialogMessage"));
        int previewSize = numberDialog.open();
        if (previewSize > 0) {
            TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
            progressDialog.open();
            if (!progressDialog.isCancelled()) {
                Trans trans = progressDialog.getTrans();
                String loggingText = progressDialog.getLoggingText();
                if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                    EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                    etd.setReadOnly();
                    etd.open();
                }
                PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
                prd.open();
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JsonInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "JsonInputDialog.ErrorPreviewingData.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JsonInputMeta(org.pentaho.di.trans.steps.jsoninput.JsonInputMeta) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans)

Aggregations

JsonInputMeta (org.pentaho.di.trans.steps.jsoninput.JsonInputMeta)3 KettleException (org.pentaho.di.core.exception.KettleException)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellAdapter (org.eclipse.swt.events.ShellAdapter)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Button (org.eclipse.swt.widgets.Button)1 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)1 Display (org.eclipse.swt.widgets.Display)1 Event (org.eclipse.swt.widgets.Event)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1