Search in sources :

Example 56 with EnterSelectionDialog

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

the class DatabaseLookupDialog method getSchemaNames.

private void getSchemaNames() {
    DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
    if (databaseMeta != null) {
        Database database = new Database(loggingObject, databaseMeta);
        try {
            database.connect();
            String[] schemas = database.getSchemas();
            if (null != schemas && schemas.length > 0) {
                schemas = Const.sortStrings(schemas);
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "DatabaseLookupDialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "DatabaseLookupDialog.AvailableSchemas.Message", wConnection.getText()));
                String d = dialog.open();
                if (d != null) {
                    wSchema.setText(Const.NVL(d, ""));
                    setTableFieldCombo();
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "DatabaseLookupDialog.NoSchema.Error"));
                mb.setText(BaseMessages.getString(PKG, "DatabaseLookupDialog.GetSchemas.Error"));
                mb.open();
            }
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "DatabaseLookupDialog.ErrorGettingSchemas"), e);
        } finally {
            database.disconnect();
        }
    }
}
Also used : Database(org.pentaho.di.core.database.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 57 with EnterSelectionDialog

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

the class DBProcDialog 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);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    SelectionAdapter lsSelMod = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            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, "DBProcDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "DBProcDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, 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);
    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabase() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // ProcName line...
    // add button to get list of procedures on selected connection...
    wbProcName = new Button(shell, SWT.PUSH);
    wbProcName.setText(BaseMessages.getString(PKG, "DBProcDialog.Finding.Button"));
    fdbProcName = new FormData();
    fdbProcName.right = new FormAttachment(100, 0);
    fdbProcName.top = new FormAttachment(wConnection, margin * 2);
    wbProcName.setLayoutData(fdbProcName);
    wbProcName.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            DatabaseMeta dbInfo = transMeta.findDatabase(wConnection.getText());
            if (dbInfo != null) {
                Database db = new Database(loggingObject, dbInfo);
                try {
                    db.connect();
                    String[] procs = db.getProcedures();
                    if (procs != null && procs.length > 0) {
                        EnterSelectionDialog esd = new EnterSelectionDialog(shell, procs, BaseMessages.getString(PKG, "DBProcDialog.EnterSelection.DialogTitle"), BaseMessages.getString(PKG, "DBProcDialog.EnterSelection.DialogMessage"));
                        String proc = esd.open();
                        if (proc != null) {
                            wProcName.setText(proc);
                        }
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                        mb.setMessage(BaseMessages.getString(PKG, "DBProcDialog.NoProceduresFound.DialogMessage"));
                        mb.setText(BaseMessages.getString(PKG, "DBProcDialog.NoProceduresFound.DialogTitle"));
                        mb.open();
                    }
                } catch (KettleDatabaseException dbe) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "DBProcDialog.ErrorGettingProceduresList.DialogTitle"), BaseMessages.getString(PKG, "DBProcDialog.ErrorGettingProceduresList.DialogMessage"), dbe);
                } finally {
                    db.disconnect();
                }
            }
        }
    });
    wlProcName = new Label(shell, SWT.RIGHT);
    wlProcName.setText(BaseMessages.getString(PKG, "DBProcDialog.ProcedureName.Label"));
    props.setLook(wlProcName);
    fdlProcName = new FormData();
    fdlProcName.left = new FormAttachment(0, 0);
    fdlProcName.right = new FormAttachment(middle, -margin);
    fdlProcName.top = new FormAttachment(wConnection, margin * 2);
    wlProcName.setLayoutData(fdlProcName);
    wProcName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wProcName);
    wProcName.addModifyListener(lsMod);
    fdProcName = new FormData();
    fdProcName.left = new FormAttachment(middle, 0);
    fdProcName.top = new FormAttachment(wConnection, margin * 2);
    fdProcName.right = new FormAttachment(wbProcName, -margin);
    wProcName.setLayoutData(fdProcName);
    // AutoCommit line
    wlAutoCommit = new Label(shell, SWT.RIGHT);
    wlAutoCommit.setText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Label"));
    wlAutoCommit.setToolTipText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Tooltip"));
    props.setLook(wlAutoCommit);
    fdlAutoCommit = new FormData();
    fdlAutoCommit.left = new FormAttachment(0, 0);
    fdlAutoCommit.top = new FormAttachment(wProcName, margin);
    fdlAutoCommit.right = new FormAttachment(middle, -margin);
    wlAutoCommit.setLayoutData(fdlAutoCommit);
    wAutoCommit = new Button(shell, SWT.CHECK);
    wAutoCommit.setToolTipText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Tooltip"));
    props.setLook(wAutoCommit);
    fdAutoCommit = new FormData();
    fdAutoCommit.left = new FormAttachment(middle, 0);
    fdAutoCommit.top = new FormAttachment(wProcName, margin);
    fdAutoCommit.right = new FormAttachment(100, 0);
    wAutoCommit.setLayoutData(fdAutoCommit);
    wAutoCommit.addSelectionListener(lsSelMod);
    // Result line...
    wlResult = new Label(shell, SWT.RIGHT);
    wlResult.setText(BaseMessages.getString(PKG, "DBProcDialog.Result.Label"));
    props.setLook(wlResult);
    fdlResult = new FormData();
    fdlResult.left = new FormAttachment(0, 0);
    fdlResult.right = new FormAttachment(middle, -margin);
    fdlResult.top = new FormAttachment(wAutoCommit, margin * 2);
    wlResult.setLayoutData(fdlResult);
    wResult = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wResult);
    wResult.addModifyListener(lsMod);
    fdResult = new FormData();
    fdResult.left = new FormAttachment(middle, 0);
    fdResult.top = new FormAttachment(wAutoCommit, margin * 2);
    fdResult.right = new FormAttachment(100, 0);
    wResult.setLayoutData(fdResult);
    // ResultType line
    wlResultType = new Label(shell, SWT.RIGHT);
    wlResultType.setText(BaseMessages.getString(PKG, "DBProcDialog.ResultType.Label"));
    props.setLook(wlResultType);
    fdlResultType = new FormData();
    fdlResultType.left = new FormAttachment(0, 0);
    fdlResultType.right = new FormAttachment(middle, -margin);
    fdlResultType.top = new FormAttachment(wResult, margin);
    wlResultType.setLayoutData(fdlResultType);
    wResultType = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    props.setLook(wResultType);
    String[] types = ValueMetaFactory.getValueMetaNames();
    for (int x = 0; x < types.length; x++) {
        wResultType.add(types[x]);
    }
    wResultType.select(0);
    wResultType.addModifyListener(lsMod);
    fdResultType = new FormData();
    fdResultType.left = new FormAttachment(middle, 0);
    fdResultType.top = new FormAttachment(wResult, margin);
    fdResultType.right = new FormAttachment(100, 0);
    wResultType.setLayoutData(fdResultType);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "DBProcDialog.Parameters.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wResultType, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsCols = 3;
    final int FieldsRows = input.getArgument().length;
    colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Name"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Direction"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "IN", "OUT", "INOUT" });
    colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames());
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, -50);
    wFields.setLayoutData(fdFields);
    // 
    // Search the fields in the background
    final Runnable runnable = new Runnable() {

        public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
                try {
                    RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
                    // Remember these fields...
                    for (int i = 0; i < row.size(); i++) {
                        inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "DBProcDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, wFields);
    // Add listeners
    lsOK = new Listener() {

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

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

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

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    lsResize = new Listener() {

        public void handleEvent(Event event) {
            Point size = shell.getSize();
            wFields.setSize(size.x - 10, size.y - 50);
            wFields.table.setSize(size.x - 10, size.y - 50);
            wFields.redraw();
        }
    };
    shell.addListener(SWT.Resize, lsResize);
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Database(org.pentaho.di.core.database.Database) FormAttachment(org.eclipse.swt.layout.FormAttachment) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) TableView(org.pentaho.di.ui.core.widget.TableView) 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) Point(org.eclipse.swt.graphics.Point) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Point(org.eclipse.swt.graphics.Point) MessageBox(org.eclipse.swt.widgets.MessageBox) TextVar(org.pentaho.di.ui.core.widget.TextVar) CCombo(org.eclipse.swt.custom.CCombo) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Example 58 with EnterSelectionDialog

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

the class DimensionLookupDialog method getSchemaNames.

private void getSchemaNames() {
    DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
    if (databaseMeta != null) {
        Database database = new Database(loggingObject, databaseMeta);
        try {
            database.connect();
            String[] schemas = database.getSchemas();
            if (null != schemas && schemas.length > 0) {
                schemas = Const.sortStrings(schemas);
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "DimensionLookupDialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "DimensionLookupDialog.AvailableSchemas.Message", wConnection.getText()));
                String d = dialog.open();
                if (d != null) {
                    wSchema.setText(Const.NVL(d, ""));
                    setTableFieldCombo();
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSchema.Error"));
                mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.GetSchemas.Error"));
                mb.open();
            }
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "DimensionLookupDialog.ErrorGettingSchemas"), e);
        } finally {
            database.disconnect();
        }
    }
}
Also used : Database(org.pentaho.di.core.database.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 59 with EnterSelectionDialog

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

the class MetaInjectDialog method addInjectTab.

private void addInjectTab() {
    // ////////////////////////
    // START OF INJECT TAB ///
    // ////////////////////////
    wInjectTab = new CTabItem(wTabFolder, SWT.NONE);
    wInjectTab.setText(BaseMessages.getString(PKG, "MetaInjectDialog.InjectTab.TabTitle"));
    wInjectSComp = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wInjectSComp.setLayout(new FillLayout());
    wInjectComp = new Composite(wInjectSComp, SWT.NONE);
    props.setLook(wInjectComp);
    FormLayout fileLayout = new FormLayout();
    fileLayout.marginWidth = 15;
    fileLayout.marginHeight = 15;
    wInjectComp.setLayout(fileLayout);
    wTree = new Tree(wInjectComp, SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    FormData fdTree = new FormData();
    fdTree.left = new FormAttachment(0, 0);
    fdTree.top = new FormAttachment(0, 0);
    fdTree.right = new FormAttachment(100, 0);
    fdTree.bottom = new FormAttachment(100, 0);
    wTree.setLayoutData(fdTree);
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.TargetStep"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.TargetDescription"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.SourceStep"), ColumnInfo.COLUMN_TYPE_CCOMBO, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.SourceField"), ColumnInfo.COLUMN_TYPE_CCOMBO, false, true) };
    wTree.setHeaderVisible(true);
    for (int i = 0; i < colinf.length; i++) {
        ColumnInfo columnInfo = colinf[i];
        TreeColumn treeColumn = new TreeColumn(wTree, columnInfo.getAllignement());
        treeColumn.setText(columnInfo.getName());
        treeColumn.setWidth(200);
    }
    wTree.addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            try {
                Point point = new Point(event.x, event.y);
                TreeItem item = wTree.getItem(point);
                if (item != null) {
                    TargetStepAttribute target = treeItemTargetMap.get(item);
                    if (target != null) {
                        SourceStepField source = targetSourceMapping.get(target);
                        String[] prevStepNames = transMeta.getPrevStepNames(stepMeta);
                        Arrays.sort(prevStepNames);
                        Map<String, SourceStepField> fieldMap = new HashMap<>();
                        for (String prevStepName : prevStepNames) {
                            RowMetaInterface fields = transMeta.getStepFields(prevStepName);
                            for (ValueMetaInterface field : fields.getValueMetaList()) {
                                String key = buildStepFieldKey(prevStepName, field.getName());
                                fieldMap.put(key, new SourceStepField(prevStepName, field.getName()));
                            }
                        }
                        String[] sourceFields = fieldMap.keySet().toArray(new String[fieldMap.size()]);
                        Arrays.sort(sourceFields);
                        String constant = source != null && source.getStepname() == null ? source.getField() : "";
                        EnterSelectionDialog selectSourceField = new EnterSelectionDialog(shell, sourceFields, BaseMessages.getString(PKG, "MetaInjectDialog.SourceFieldDialog.Title"), BaseMessages.getString(PKG, "MetaInjectDialog.SourceFieldDialog.Label"), constant, transMeta);
                        if (source != null && source.getStepname() != null && !Utils.isEmpty(source.getStepname())) {
                            String key = buildStepFieldKey(source.getStepname(), source.getField());
                            selectSourceField.setCurrentValue(key);
                            int index = Const.indexOfString(key, sourceFields);
                            if (index >= 0) {
                                selectSourceField.setSelectedNrs(new int[] { index });
                            }
                        }
                        String selectedStepField = selectSourceField.open();
                        if (selectedStepField != null) {
                            SourceStepField newSource = fieldMap.get(selectedStepField);
                            if (newSource == null) {
                                newSource = new SourceStepField(null, selectedStepField);
                                item.setText(2, CONST_VALUE);
                                item.setText(3, selectedStepField);
                            } else {
                                item.setText(2, newSource.getStepname());
                                item.setText(3, newSource.getField());
                            }
                            targetSourceMapping.put(target, newSource);
                        } else {
                            item.setText(2, "");
                            item.setText(3, "");
                            targetSourceMapping.remove(target);
                        }
                    /*
               * EnterSelectionDialog selectStep = new EnterSelectionDialog(shell, prevStepNames, "Select source step",
               * "Select the source step"); if (source!=null && !Utils.isEmpty(source.getStepname())) { int index =
               * Const.indexOfString(source.getStepname(), prevStepNames); if (index>=0) { selectStep.setSelectedNrs(new
               * int[] {index,}); } } String prevStep = selectStep.open(); if (prevStep!=null) { // OK, now we list the
               * fields from that step... // RowMetaInterface fields = transMeta.getStepFields(prevStep); String[]
               * fieldNames = fields.getFieldNames(); Arrays.sort(fieldNames); EnterSelectionDialog selectField = new
               * EnterSelectionDialog(shell, fieldNames, "Select field", "Select the source field"); if (source!=null &&
               * !Utils.isEmpty(source.getField())) { int index = Const.indexOfString(source.getField(), fieldNames); if
               * (index>=0) { selectField.setSelectedNrs(new int[] {index,}); } } String fieldName = selectField.open();
               * if (fieldName!=null) { // Store the selection, update the UI... // item.setText(2, prevStep);
               * item.setText(3, fieldName); source = new SourceStepField(prevStep, fieldName);
               * targetSourceMapping.put(target, source); } } else { item.setText(2, ""); item.setText(3, "");
               * targetSourceMapping.remove(target); }
               */
                    }
                }
            } catch (Exception e) {
                new ErrorDialog(shell, "Oops", "Unexpected Error", e);
            }
        }
    });
    FormData fdInjectComp = new FormData();
    fdInjectComp.left = new FormAttachment(0, 0);
    fdInjectComp.top = new FormAttachment(0, 0);
    fdInjectComp.right = new FormAttachment(100, 0);
    fdInjectComp.bottom = new FormAttachment(100, 0);
    wInjectComp.setLayoutData(fdInjectComp);
    wInjectComp.pack();
    Rectangle bounds = wInjectComp.getBounds();
    wInjectSComp.setContent(wInjectComp);
    wInjectSComp.setExpandHorizontal(true);
    wInjectSComp.setExpandVertical(true);
    wInjectSComp.setMinWidth(bounds.width);
    wInjectSComp.setMinHeight(bounds.height);
    wInjectTab.setControl(wInjectSComp);
// ///////////////////////////////////////////////////////////
// / END OF INJECT TAB
// ///////////////////////////////////////////////////////////
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) CTabItem(org.eclipse.swt.custom.CTabItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Tree(org.eclipse.swt.widgets.Tree) TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) FormAttachment(org.eclipse.swt.layout.FormAttachment) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with EnterSelectionDialog

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

the class AccessOutputDialog method getTableName.

private void getTableName() {
    AccessOutputMeta meta = new AccessOutputMeta();
    getInfo(meta);
    Database database = null;
    // New class: SelectTableDialog
    try {
        String realFilename = transMeta.environmentSubstitute(meta.getFilename());
        FileObject fileObject = KettleVFS.getFileObject(realFilename, transMeta);
        File file = FileUtils.toFile(fileObject.getURL());
        if (!file.exists() || !file.isFile()) {
            throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.FileDoesNotExist", realFilename));
        }
        database = Database.open(file);
        Set<String> set = database.getTableNames();
        String[] tablenames = set.toArray(new String[set.size()]);
        EnterSelectionDialog dialog = new EnterSelectionDialog(shell, tablenames, BaseMessages.getString(PKG, "AccessOutputDialog.Dialog.SelectATable.Title"), BaseMessages.getString(PKG, "AccessOutputDialog.Dialog.SelectATable.Message"));
        String tablename = dialog.open();
        if (tablename != null) {
            wTablename.setText(tablename);
        }
    } catch (Throwable e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "AccessOutputDialog.UnableToGetListOfTables.Title"), BaseMessages.getString(PKG, "AccessOutputDialog.UnableToGetListOfTables.Message"), e);
    } finally {
        // Don't forget to close the bugger.
        try {
            if (database != null) {
                database.close();
            }
        } catch (Exception e) {
        // Ignore close errors
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(com.healthmarketscience.jackcess.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) AccessOutputMeta(org.pentaho.di.trans.steps.accessoutput.AccessOutputMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)75 MessageBox (org.eclipse.swt.widgets.MessageBox)42 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)42 KettleException (org.pentaho.di.core.exception.KettleException)41 SelectionEvent (org.eclipse.swt.events.SelectionEvent)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)29 ModifyEvent (org.eclipse.swt.events.ModifyEvent)28 ModifyListener (org.eclipse.swt.events.ModifyListener)28 ShellEvent (org.eclipse.swt.events.ShellEvent)28 FormAttachment (org.eclipse.swt.layout.FormAttachment)28 FormData (org.eclipse.swt.layout.FormData)28 FormLayout (org.eclipse.swt.layout.FormLayout)28 Event (org.eclipse.swt.widgets.Event)28 Listener (org.eclipse.swt.widgets.Listener)28 Shell (org.eclipse.swt.widgets.Shell)28 ShellAdapter (org.eclipse.swt.events.ShellAdapter)27 Button (org.eclipse.swt.widgets.Button)27 Display (org.eclipse.swt.widgets.Display)27 Label (org.eclipse.swt.widgets.Label)27 Text (org.eclipse.swt.widgets.Text)27