Search in sources :

Example 16 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.

the class JsonInputDialog method setSourceStreamField.

private void setSourceStreamField() {
    try {
        String value = wFieldValue.getText();
        wFieldValue.removeAll();
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null) {
            wFieldValue.setItems(r.getFieldNames());
        }
        if (value != null) {
            wFieldValue.setText(value);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JsonInputDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "JsonInputDialog.FailedToGetFields.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 17 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog 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 = 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();
    FormData 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 = e -> ok();
    lsGet = e -> get();
    lsPreview = e -> preview();
    lsCancel = e -> cancel();
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    wPreview.addListener(SWT.Selection, lsPreview);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

        @Override
        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() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            String[] items = new String[] { wFilename.getText(), wFilemask.getText(), wExcludeFilemask.getText(), JsonInputMeta.RequiredFilesCode[0], JsonInputMeta.RequiredFilesCode[0] };
            wFilenameList.add(items);
            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() {

        @Override
        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() {

        @Override
        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() {

        @Override
        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() {

        @Override
        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() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setIncludeRownum();
        }
    });
    // Whenever something changes, set the tooltip to the expanded version of the filename:
    wFilename.addModifyListener(e -> wFilename.setToolTipText(wFilename.getText()));
    // Listen to the Browse... button
    wbbFilename.addSelectionListener(new SelectionAdapterFileDialogTextVar(log, wFilename, transMeta, new SelectionAdapterOptions(SelectionOperation.FILE_OR_FOLDER, new FilterType[] { FilterType.JSON, FilterType.JS, FilterType.ALL }, FilterType.JSON)));
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        @Override
        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 : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) KettleException(org.pentaho.di.core.exception.KettleException) ShellAdapter(org.eclipse.swt.events.ShellAdapter) CTabFolder(org.eclipse.swt.custom.CTabFolder) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SelectionAdapterOptions(org.pentaho.di.ui.core.events.dialog.SelectionAdapterOptions) ShellEvent(org.eclipse.swt.events.ShellEvent) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) JsonInputMeta(org.pentaho.di.trans.steps.jsoninput.JsonInputMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionAdapterFileDialogTextVar(org.pentaho.di.ui.core.events.dialog.SelectionAdapterFileDialogTextVar) FormAttachment(org.eclipse.swt.layout.FormAttachment) FileInputList(org.pentaho.di.core.fileinput.FileInputList) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) Display(org.eclipse.swt.widgets.Display)

Example 18 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.

the class XulDatabaseDialog method createDialog.

@SuppressWarnings("deprecation")
private void createDialog() {
    XulDomContainer container = null;
    try {
        databaseDialogInstance = new DatabaseConnectionDialog();
        if (((Shell) this.parentShell).getText().contains("Metadata Editor")) {
            databaseDialogInstance.registerClass(EXTENDED_WIDGET_ID, PMD_WIDGET_CLASSNAME);
            databaseDialogInstance.registerClass(EXTENDED_MENULIST_WIDGET_ID, PMD_MENULIST_WIDGET_CLASSNAME);
        } else {
            databaseDialogInstance.registerClass(EXTENDED_WIDGET_ID, EXTENDED_WIDGET_CLASSNAME);
            databaseDialogInstance.registerClass(EXTENDED_MENULIST_WIDGET_ID, EXTENDED_MENULIST_WIDGET_CLASSNAME);
        }
        /*
       * Attention: onload: loadConnectionData() is called here the first time, see below for second time
       */
        container = databaseDialogInstance.getSwtInstance(new KettleXulLoader(), parentShell);
        container.addEventHandler(EVENT_ID, DataOverrideHandler.class.getName());
        SpoonPluginManager.getInstance().applyPluginsForContainer("connection_dialog", container);
        dataHandler = (DataOverrideHandler) container.getEventHandler(EVENT_ID);
        if (databaseMeta != null) {
            dataHandler.setData(databaseMeta);
        }
        dataHandler.setDatabases(databases);
        dataHandler.getControls();
    } catch (XulException e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.HandleXul"), e);
        return;
    }
    try {
        // Inject the button panel that contains the "Feature List" and "Explore" buttons
        XulComponent boxElement = container.getDocumentRoot().getElementById(FRAGMENT_ID);
        XulComponent parentElement = boxElement.getParent();
        ResourceBundle res = null;
        try {
            res = GlobalMessages.getBundle(MESSAGES);
        } catch (MissingResourceException e) {
            log.logError(BaseMessages.getString(PKG, "XulDatabaseDialog.Error.ResourcesNotFound.Title"), e.getMessage(), e);
        }
        XulDomContainer fragmentContainer = null;
        String pkg = getClass().getPackage().getName().replace('.', '/');
        // to check for it here.
        if (res != null) {
            fragmentContainer = container.loadFragment(pkg.concat(DIALOG_FRAGMENT_FILE), res);
        } else {
            fragmentContainer = container.loadFragment(pkg.concat(DIALOG_FRAGMENT_FILE));
        }
        XulComponent newBox = fragmentContainer.getDocumentRoot().getFirstChild();
        parentElement.replaceChild(boxElement, newBox);
    } catch (Exception e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.HandleXul"), e);
        return;
    }
    try {
        xulDialogComponent = (XulDialog) container.getDocumentRoot().getRootElement();
        parentShell.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent arg0) {
                xulDialogComponent.hide();
            }
        });
    } catch (Exception e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Dialog"), e);
        return;
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MissingResourceException(java.util.MissingResourceException) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseConnectionDialog(org.pentaho.ui.database.DatabaseConnectionDialog) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) XulException(org.pentaho.ui.xul.XulException) MissingResourceException(java.util.MissingResourceException) XulException(org.pentaho.ui.xul.XulException) ResourceBundle(java.util.ResourceBundle) XulComponent(org.pentaho.ui.xul.XulComponent)

Example 19 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.

the class XulDatabaseExplorerController method dataProfile.

public void dataProfile() {
    if (model.getTable() == null) {
        return;
    }
    Shell dbShell = (Shell) dbExplorerDialog.getRootObject();
    try {
        TransProfileFactory profileFactory = new TransProfileFactory(this.model.getDatabaseMeta(), getSchemaAndTable(this.model));
        TransMeta transMeta = profileFactory.generateTransformation(new LoggingObject(model.getTable()));
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(dbShell, transMeta, new String[] { TransProfileFactory.RESULT_STEP_NAME }, new int[] { 25000 });
        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(dbShell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            }
            PreviewRowsDialog prd = new PreviewRowsDialog(dbShell, transMeta, SWT.NONE, TransProfileFactory.RESULT_STEP_NAME, progressDialog.getPreviewRowsMeta(TransProfileFactory.RESULT_STEP_NAME), progressDialog.getPreviewRows(TransProfileFactory.RESULT_STEP_NAME), loggingText);
            prd.open();
        }
    } catch (Exception e) {
        new ErrorDialog(this.dbExplorerDialog.getShell(), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Title"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Message"), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) TransProfileFactory(org.pentaho.di.trans.TransProfileFactory) LoggingObject(org.pentaho.di.core.logging.LoggingObject) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) Trans(org.pentaho.di.trans.Trans) XulException(org.pentaho.ui.xul.XulException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 20 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.

the class XulDatabaseExplorerController method getDDLForOther.

public void getDDLForOther() {
    if (databases != null) {
        try {
            // Now select the other connection...
            // Only take non-SAP ERP connections....
            List<DatabaseMeta> dbs = new ArrayList<DatabaseMeta>();
            for (int i = 0; i < databases.size(); i++) {
                if (((databases.get(i)).getDatabaseInterface().isExplorable())) {
                    dbs.add(databases.get(i));
                }
            }
            String[] conn = new String[dbs.size()];
            for (int i = 0; i < conn.length; i++) {
                conn[i] = (dbs.get(i)).getName();
            }
            EnterSelectionDialog esd = new EnterSelectionDialog(this.dbExplorerDialog.getShell(), conn, BaseMessages.getString(PKG, "DatabaseExplorerDialog.TargetDatabase.Title"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.TargetDatabase.Message"));
            String target = esd.open();
            if (target != null) {
                DatabaseMeta targetdbi = DatabaseMeta.findDatabase(dbs, target);
                Database targetdb = new Database(null, targetdbi);
                try {
                    targetdb.connect();
                    String tableName = getSchemaAndTable(model);
                    RowMetaInterface r = targetdb.getTableFields(tableName);
                    String sql = targetdb.getCreateTableStatement(tableName, r, null, false, null, true);
                    SQLEditor se = new SQLEditor(this.getDatabaseMeta(), this.dbExplorerDialog.getShell(), SWT.NONE, this.model.getDatabaseMeta(), this.dbcache, sql);
                    se.open();
                } finally {
                    targetdb.disconnect();
                }
            }
        } catch (KettleDatabaseException dbe) {
            new ErrorDialog(this.dbExplorerDialog.getShell(), BaseMessages.getString(PKG, "Dialog.Error.Header"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.Error.GenDDL"), dbe);
        }
    } else {
        MessageBox mb = new MessageBox(this.dbExplorerDialog.getShell(), SWT.NONE | SWT.ICON_INFORMATION);
        mb.setMessage(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Message"));
        mb.setText(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Title"));
        mb.open();
    }
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) MessageBox(org.eclipse.swt.widgets.MessageBox) Database(org.pentaho.di.core.database.Database) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog)

Aggregations

ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)527 KettleException (org.pentaho.di.core.exception.KettleException)440 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)178 MessageBox (org.eclipse.swt.widgets.MessageBox)118 TableItem (org.eclipse.swt.widgets.TableItem)97 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)76 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)63 TransMeta (org.pentaho.di.trans.TransMeta)48 Shell (org.eclipse.swt.widgets.Shell)46 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)44 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)44 ArrayList (java.util.ArrayList)43 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)40 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)39 StepMeta (org.pentaho.di.trans.step.StepMeta)38 FormData (org.eclipse.swt.layout.FormData)37 FormLayout (org.eclipse.swt.layout.FormLayout)37