Search in sources :

Example 21 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class ScriptDialog method treeDblClick.

/*
   * private void rebuildInputFieldsTree(){ try{ String itemName = BaseMessages.getString(PKG,
   * "ScriptDialog.InputFields.Label");
   *
   * RowMetaInterface r = transMeta.getPrevStepFields(stepname); if (r!=null){ TreeItem item = null; for (TreeItem look
   * : wTree.getItems()) { if (look.getText().equals(itemName)) { // This is the rebuild part! for (TreeItem child :
   * look.getItems()) child.dispose(); // clear the children. item=look; break; } } if (item==null) item = new
   * TreeItem(wTree, SWT.NULL); item.setText(itemName); String strItemToAdd=""; for (int i=0;i<r.size();i++){
   * ValueMetaInterface v = r.getValueMeta(i); if (wCompatible.getSelection()) { switch(v.getType()){ case
   * ValueMetaInterface.TYPE_STRING : strItemToAdd=v.getName()+".getString()"; break; case
   * ValueMetaInterface.TYPE_NUMBER : strItemToAdd=v.getName()+".getNumber()"; break; case
   * ValueMetaInterface.TYPE_INTEGER: strItemToAdd=v.getName()+".getInteger()"; break; case ValueMetaInterface.TYPE_DATE
   * : strItemToAdd=v.getName()+".getDate()"; break; case ValueMetaInterface.TYPE_BOOLEAN:
   * strItemToAdd=v.getName()+".getBoolean()"; break; case ValueMetaInterface.TYPE_BIGNUMBER:
   * strItemToAdd=v.getName()+".getBigNumber()"; break; case ValueMetaInterface.TYPE_BINARY:
   * strItemToAdd=v.getName()+".getBytes()"; break; case ValueMetaInterface.TYPE_SERIALIZABLE:
   * strItemToAdd=v.getName()+".getSerializable()"; break; default: strItemToAdd=v.getName(); break; } } else {
   * strItemToAdd=v.getName(); } TreeItem itemInputFields = new TreeItem(item, SWT.NULL);
   * itemInputFields.setText(strItemToAdd); itemInputFields.setData(strItemToAdd); } } }catch(KettleException ke){ new
   * ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptDialog.FailedToGetFields.DialogTitle"),
   * BaseMessages.getString(PKG, "ScriptDialog.FailedToGetFields.DialogMessage"), ke); } }
   */
// Adds the Current item to the current Position
private void treeDblClick(Event event) {
    StyledTextComp wScript = getStyledTextComp();
    Point point = new Point(event.x, event.y);
    TreeItem item = wTree.getItem(point);
    // Qualifikation where the Click comes from
    if (item != null && item.getParentItem() != null) {
        if (item.getParentItem().equals(wTreeScriptsItem)) {
            setActiveCtab(item.getText());
        } else if (!item.getData().equals("Function")) {
            int iStart = wScript.getCaretOffset();
            // this selection will be replaced by wScript.insert
            int selCount = wScript.getSelectionCount();
            // when a selection is already there we need to subtract the position
            iStart = iStart - selCount;
            if (iStart < 0) {
                // just safety
                iStart = 0;
            }
            String strInsert = (String) item.getData();
            if (strInsert.equals("jsFunction")) {
                strInsert = item.getText();
            }
            wScript.insert(strInsert);
            wScript.setSelection(iStart, iStart + strInsert.length());
        }
    }
/*
     * if (item != null && item.getParentItem()!=null && !item.getData().equals("Function")) { int iStart =
     * wScript.getCaretOffset(); String strInsert =(String)item.getData(); if(strInsert.equals("jsFunction")) strInsert
     * = (String)item.getText(); wScript.insert(strInsert); wScript.setSelection(iStart,iStart+strInsert.length()); }
     */
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point)

Example 22 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class ScriptDialog method buildingFolderMenu.

private void buildingFolderMenu() {
    // styledTextPopupmenu = new Menu(, SWT.POP_UP);
    MenuItem addNewItem = new MenuItem(cMenu, SWT.PUSH);
    addNewItem.setText(BaseMessages.getString(PKG, "ScriptDialog.AddNewTab"));
    addNewItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            addCtab("", "", ADD_BLANK);
        }
    });
    MenuItem copyItem = new MenuItem(cMenu, SWT.PUSH);
    copyItem.setText(BaseMessages.getString(PKG, "ScriptDialog.AddCopy"));
    copyItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            CTabItem item = folder.getSelection();
            StyledTextComp st = (StyledTextComp) item.getControl();
            addCtab(item.getText(), st.getText(), ADD_COPY);
        }
    });
    new MenuItem(cMenu, SWT.SEPARATOR);
    MenuItem setActiveScriptItem = new MenuItem(cMenu, SWT.PUSH);
    setActiveScriptItem.setText(BaseMessages.getString(PKG, "ScriptDialog.SetTransformScript"));
    setActiveScriptItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            CTabItem item = folder.getSelection();
            for (int i = 0; i < folder.getItemCount(); i++) {
                if (folder.getItem(i).equals(item)) {
                    if (item.getImage().equals(imageActiveScript)) {
                        strActiveScript = "";
                    } else if (item.getImage().equals(imageActiveStartScript)) {
                        strActiveStartScript = "";
                    } else if (item.getImage().equals(imageActiveEndScript)) {
                        strActiveEndScript = "";
                    }
                    item.setImage(imageActiveScript);
                    strActiveScript = item.getText();
                } else if (folder.getItem(i).getImage().equals(imageActiveScript)) {
                    folder.getItem(i).setImage(imageInactiveScript);
                }
            }
            modifyScriptTree(item, SET_ACTIVE_ITEM);
        }
    });
    MenuItem setStartScriptItem = new MenuItem(cMenu, SWT.PUSH);
    setStartScriptItem.setText(BaseMessages.getString(PKG, "ScriptDialog.SetStartScript"));
    setStartScriptItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            CTabItem item = folder.getSelection();
            for (int i = 0; i < folder.getItemCount(); i++) {
                if (folder.getItem(i).equals(item)) {
                    if (item.getImage().equals(imageActiveScript)) {
                        strActiveScript = "";
                    } else if (item.getImage().equals(imageActiveStartScript)) {
                        strActiveStartScript = "";
                    } else if (item.getImage().equals(imageActiveEndScript)) {
                        strActiveEndScript = "";
                    }
                    item.setImage(imageActiveStartScript);
                    strActiveStartScript = item.getText();
                } else if (folder.getItem(i).getImage().equals(imageActiveStartScript)) {
                    folder.getItem(i).setImage(imageInactiveScript);
                }
            }
            modifyScriptTree(item, SET_ACTIVE_ITEM);
        }
    });
    MenuItem setEndScriptItem = new MenuItem(cMenu, SWT.PUSH);
    setEndScriptItem.setText(BaseMessages.getString(PKG, "ScriptDialog.SetEndScript"));
    setEndScriptItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            CTabItem item = folder.getSelection();
            for (int i = 0; i < folder.getItemCount(); i++) {
                if (folder.getItem(i).equals(item)) {
                    if (item.getImage().equals(imageActiveScript)) {
                        strActiveScript = "";
                    } else if (item.getImage().equals(imageActiveStartScript)) {
                        strActiveStartScript = "";
                    } else if (item.getImage().equals(imageActiveEndScript)) {
                        strActiveEndScript = "";
                    }
                    item.setImage(imageActiveEndScript);
                    strActiveEndScript = item.getText();
                } else if (folder.getItem(i).getImage().equals(imageActiveEndScript)) {
                    folder.getItem(i).setImage(imageInactiveScript);
                }
            }
            modifyScriptTree(item, SET_ACTIVE_ITEM);
        }
    });
    new MenuItem(cMenu, SWT.SEPARATOR);
    MenuItem setRemoveScriptItem = new MenuItem(cMenu, SWT.PUSH);
    setRemoveScriptItem.setText(BaseMessages.getString(PKG, "ScriptDialog.RemoveScriptType"));
    setRemoveScriptItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            CTabItem item = folder.getSelection();
            input.setChanged(true);
            if (item.getImage().equals(imageActiveScript)) {
                strActiveScript = "";
            } else if (item.getImage().equals(imageActiveStartScript)) {
                strActiveStartScript = "";
            } else if (item.getImage().equals(imageActiveEndScript)) {
                strActiveEndScript = "";
            }
            item.setImage(imageInactiveScript);
        }
    });
    folder.setMenu(cMenu);
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CTabFolderEvent(org.eclipse.swt.custom.CTabFolderEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 23 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class MondrianInputDialog 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();
        }
    };
    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, "MondrianInputDialog.MondrianInput"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    // 
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "MondrianInputDialog.StepName"));
    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.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Some buttons
    // 
    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, "System.Button.Preview"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, null);
    // Mondrian Role
    Label wlRole = new Label(shell, SWT.RIGHT);
    wlRole.setText(BaseMessages.getString(PKG, "MondrianInputDialog.Role"));
    props.setLook(wlRole);
    FormData fdlRole = new FormData();
    fdlRole.left = new FormAttachment(0, 0);
    fdlRole.right = new FormAttachment(middle, -margin);
    fdlRole.bottom = new FormAttachment(wOK, -2 * margin);
    wlRole.setLayoutData(fdlRole);
    wRole = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wRole);
    wRole.addModifyListener(lsMod);
    wRole.setToolTipText(BaseMessages.getString(PKG, "MondrianInputDialog.Role.Tooltip"));
    FormData fdRole = new FormData();
    fdRole.left = new FormAttachment(middle, 0);
    fdRole.right = new FormAttachment(100, -margin);
    fdRole.bottom = new FormAttachment(wOK, -2 * margin);
    wRole.setLayoutData(fdRole);
    // Catalog location...
    // 
    wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbbFilename);
    wbbFilename.setText(BaseMessages.getString("System.Button.Browse"));
    wbbFilename.setToolTipText(BaseMessages.getString("System.Tooltip.BrowseForFileOrDirAndAdd"));
    FormData fdbFilename = new FormData();
    fdbFilename.right = new FormAttachment(100, 0);
    fdbFilename.bottom = new FormAttachment(wRole, -2 * margin);
    wbbFilename.setLayoutData(fdbFilename);
    wlCatalog = new Label(shell, SWT.RIGHT);
    wlCatalog.setText(BaseMessages.getString(PKG, "MondrianInputDialog.Catalog"));
    props.setLook(wlCatalog);
    fdlCatalog = new FormData();
    fdlCatalog.left = new FormAttachment(0, 0);
    fdlCatalog.right = new FormAttachment(middle, -margin);
    fdlCatalog.bottom = new FormAttachment(wRole, -2 * margin);
    wlCatalog.setLayoutData(fdlCatalog);
    wCatalog = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCatalog);
    wCatalog.addModifyListener(lsMod);
    fdCatalog = new FormData();
    fdCatalog.left = new FormAttachment(middle, 0);
    fdCatalog.right = new FormAttachment(wbbFilename, -margin);
    fdCatalog.bottom = new FormAttachment(wRole, -2 * margin);
    wCatalog.setLayoutData(fdCatalog);
    // Replace variables in MDX?
    // 
    wlVariables = new Label(shell, SWT.RIGHT);
    wlVariables.setText(BaseMessages.getString(PKG, "MondrianInputDialog.ReplaceVariables"));
    props.setLook(wlVariables);
    fdlVariables = new FormData();
    fdlVariables.left = new FormAttachment(0, 0);
    fdlVariables.right = new FormAttachment(middle, -margin);
    fdlVariables.bottom = new FormAttachment(wCatalog, -margin);
    wlVariables.setLayoutData(fdlVariables);
    wVariables = new Button(shell, SWT.CHECK);
    props.setLook(wVariables);
    wVariables.setToolTipText(BaseMessages.getString(PKG, "MondrianInputDialog.ReplaceVariables.Tooltip"));
    fdVariables = new FormData();
    fdVariables.left = new FormAttachment(middle, 0);
    fdVariables.right = new FormAttachment(100, 0);
    fdVariables.bottom = new FormAttachment(wCatalog, -margin);
    wVariables.setLayoutData(fdVariables);
    wVariables.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setSQLToolTip();
            input.setChanged();
        }
    });
    wlPosition = new Label(shell, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    fdlPosition.bottom = new FormAttachment(wVariables, -margin);
    wlPosition.setLayoutData(fdlPosition);
    // Table line...
    // 
    wlSQL = new Label(shell, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "MondrianInputDialog.SQL"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wConnection, margin * 2);
    wlSQL.setLayoutData(fdlSQL);
    wSQL = new StyledTextComp(transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wSQL, Props.WIDGET_STYLE_FIXED);
    wSQL.addModifyListener(lsMod);
    fdSQL = new FormData();
    fdSQL.left = new FormAttachment(0, 0);
    fdSQL.top = new FormAttachment(wlSQL, margin);
    fdSQL.right = new FormAttachment(100, -2 * margin);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);
    wSQL.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setSQLToolTip();
            setPosition();
        }
    });
    wSQL.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wSQL.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wSQL.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // Text Higlighting
    wSQL.addLineStyleListener(new MDXValuesHighlight());
    // Add listeners
    lsCancel = new Listener() {

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

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

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

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wCatalog.addSelectionListener(lsDef);
    if (wbbFilename != null) {
        // Listen to the browse button next to the file name
        wbbFilename.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                dialog.setFilterExtensions(new String[] { "*.xml", "*" });
                if (wCatalog.getText() != null) {
                    String fname = transMeta.environmentSubstitute(wCatalog.getText());
                    dialog.setFileName(fname);
                }
                dialog.setFilterNames(new String[] { BaseMessages.getString("System.FileType.XMLFiles"), BaseMessages.getString("System.FileType.AllFiles") });
                if (dialog.open() != null) {
                    String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    wCatalog.setText(str);
                }
            }
        });
    }
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    getData();
    input.setChanged(changed);
    // Set the shell size, based upon previous time...
    setSize();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) TextVar(org.pentaho.di.ui.core.widget.TextVar) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 24 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class LucidDBStreamingLoaderDialog 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();
        }
    };
    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, "LucidDBStreamingLoaderDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.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.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Schema line...
    wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.TargetSchema.Label"));
    props.setLook(wlSchema);
    fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);
    wSchema = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchema);
    wSchema.addModifyListener(lsMod);
    fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(100, 0);
    wSchema.setLayoutData(fdSchema);
    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.TargetTable.Label"));
    props.setLook(wlTable);
    fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wSchema, margin);
    wlTable.setLayoutData(fdlTable);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Browse.Button"));
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wSchema, margin);
    wbTable.setLayoutData(fdbTable);
    wTable = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTable);
    wTable.addModifyListener(lsMod);
    fdTable = new FormData();
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.top = new FormAttachment(wSchema, margin);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);
    // Auto create table check.
    lAutoCreateTable = new Label(shell, SWT.RIGHT);
    props.setLook(lAutoCreateTable);
    fdlAutoCreateTable = new FormData();
    fdlAutoCreateTable.left = new FormAttachment(0, 0);
    fdlAutoCreateTable.top = new FormAttachment(wTable, margin);
    fdlAutoCreateTable.right = new FormAttachment(middle, -margin);
    lAutoCreateTable.setLayoutData(fdlAutoCreateTable);
    fdbAutoCreateTable = new FormData();
    fdbAutoCreateTable.left = new FormAttachment(lAutoCreateTable, 10);
    fdbAutoCreateTable.top = new FormAttachment(wTable, margin);
    // Host
    wlHost = new Label(shell, SWT.RIGHT);
    wlHost.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Host.Label"));
    props.setLook(wlHost);
    fdlHost = new FormData();
    fdlHost.left = new FormAttachment(0, 0);
    fdlHost.top = new FormAttachment(lAutoCreateTable, margin);
    fdlHost.right = new FormAttachment(middle, -margin);
    wlHost.setLayoutData(fdlHost);
    wHost = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wHost);
    wHost.addModifyListener(lsMod);
    fdHost = new FormData();
    fdHost.left = new FormAttachment(middle, 0);
    fdHost.top = new FormAttachment(lAutoCreateTable, margin);
    fdHost.right = new FormAttachment(100, 0);
    wHost.setLayoutData(fdHost);
    // Port line
    wlPort = new Label(shell, SWT.RIGHT);
    wlPort.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Port.Label"));
    props.setLook(wlPort);
    fdlPort = new FormData();
    fdlPort.left = new FormAttachment(0, 0);
    fdlPort.top = new FormAttachment(wHost, margin);
    fdlPort.right = new FormAttachment(middle, -margin);
    wlPort.setLayoutData(fdlPort);
    wPort = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPort);
    wPort.addModifyListener(lsMod);
    fdPort = new FormData();
    fdPort.left = new FormAttachment(middle, 0);
    fdPort.top = new FormAttachment(wHost, margin);
    fdPort.right = new FormAttachment(100, 0);
    wPort.setLayoutData(fdPort);
    // Operation line:
    wlOperation = new Label(shell, SWT.RIGHT);
    wlOperation.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.Label"));
    props.setLook(wlOperation);
    fdlOperation = new FormData();
    fdlOperation.left = new FormAttachment(0, 0);
    fdlOperation.top = new FormAttachment(wPort, margin);
    fdlOperation.right = new FormAttachment(middle, -margin);
    wlOperation.setLayoutData(fdlOperation);
    wOperation = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wOperation);
    wOperation.addModifyListener(lsMod);
    fdOperation = new FormData();
    fdOperation.top = new FormAttachment(wPort, margin);
    fdOperation.left = new FormAttachment(middle, 0);
    fdOperation.right = new FormAttachment(100, 0);
    wOperation.setLayoutData(fdOperation);
    final String[] operations = new String[] { BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item1"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item2"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item3"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item4") };
    wOperation.setItems(operations);
    wOperation.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            CCombo mycc = (CCombo) event.widget;
            // MERGE
            if (operations[0].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                wFieldsTb.table.getColumn(3).setWidth(80);
            // INSERT
            } else if (operations[1].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wFieldsTab);
                wKeysTab.getControl().setEnabled(false);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                wFieldsTb.table.getColumn(3).setWidth(0);
            // UPDATE
            } else if (operations[2].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                // grey out update field in Field TabelView
                wFieldsTb.table.getColumn(3).setWidth(80);
            // CUSTOM
            } else if (operations[3].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(true);
                wFieldsTb.table.getColumn(3).setWidth(80);
            }
        }
    });
    // TabFolder
    wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
    wTabFolder.setSimple(false);
    fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wlOperation, margin);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);
    wKeysTab = new CTabItem(wTabFolder, SWT.NONE);
    wKeysTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.TabTitle"));
    FormLayout fieldsLayout = new FormLayout();
    fieldsLayout.marginWidth = Const.FORM_MARGIN;
    fieldsLayout.marginHeight = Const.FORM_MARGIN;
    // TabItem: Keys
    wKeysComp = new Composite(wTabFolder, SWT.NONE);
    wKeysComp.setLayout(fieldsLayout);
    props.setLook(wKeysComp);
    wlKeysTb = new Label(wKeysComp, SWT.LEFT);
    wlKeysTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.Label"));
    fdlKeysTb = new FormData();
    fdlKeysTb.left = new FormAttachment(0, 0);
    fdlKeysTb.top = new FormAttachment(0, 0);
    fdlKeysTb.right = new FormAttachment(100, 0);
    wlKeysTb.setLayoutData(fdlKeysTb);
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Key.Column1"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Key.Column2"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
    wKeysTb = new TableView(transMeta, wKeysComp, SWT.FULL_SELECTION | SWT.MULTI, colinf, 0, lsMod, props);
    fdKeysTb = new FormData();
    fdKeysTb.left = new FormAttachment(0, 0);
    fdKeysTb.top = new FormAttachment(wlKeysTb, margin);
    fdKeysTb.right = new FormAttachment(100, 0);
    fdKeysTb.bottom = new FormAttachment(95, -margin);
    wKeysTb.setLayoutData(fdKeysTb);
    fdKeysComp = new FormData();
    fdKeysComp.left = new FormAttachment(0, 0);
    fdKeysComp.top = new FormAttachment(0, 0);
    fdKeysComp.right = new FormAttachment(100, 0);
    fdKeysComp.bottom = new FormAttachment(100, 0);
    wKeysComp.setLayoutData(fdKeysComp);
    wGetFieldsForKeys = new Button(wKeysComp, SWT.PUSH);
    wGetFieldsForKeys.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.GetFields.Label"));
    fdGetFieldsForKeys = new FormData();
    fdGetFieldsForKeys.top = new FormAttachment(wKeysTb, margin);
    fdGetFieldsForKeys.left = new FormAttachment(0, margin);
    wGetFieldsForKeys.setLayoutData(fdGetFieldsForKeys);
    wGetFieldsForKeys.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getFields(wKeysTab.getText());
        }
    });
    wDoMappingForKeys = new Button(wKeysComp, SWT.PUSH);
    wDoMappingForKeys.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.EditMapping.Label"));
    fdDoMappingForKeys = new FormData();
    fdDoMappingForKeys.top = new FormAttachment(wKeysTb, margin);
    fdDoMappingForKeys.left = new FormAttachment(wGetFieldsForKeys, margin);
    wDoMappingForKeys.setLayoutData(fdDoMappingForKeys);
    wDoMappingForKeys.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            generateMappings(wKeysTab.getText());
        }
    });
    wKeysComp.layout();
    wKeysTab.setControl(wKeysComp);
    // TabItem: Fields
    wFieldsTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldsTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldsTab.TabTitle"));
    wFieldsComp = new Composite(wTabFolder, SWT.NONE);
    wFieldsComp.setLayout(fieldsLayout);
    props.setLook(wFieldsComp);
    wlFieldsTb = new Label(wFieldsComp, SWT.LEFT);
    wlFieldsTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldTab.Label"));
    fdlFieldsTb = new FormData();
    fdlFieldsTb.left = new FormAttachment(0, 0);
    fdlFieldsTb.top = new FormAttachment(0, 0);
    fdlFieldsTb.right = new FormAttachment(100, 0);
    wlFieldsTb.setLayoutData(fdlFieldsTb);
    ColumnInfo[] colinf1 = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column1"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column2"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column3"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "Y", "N" }, true) };
    wFieldsTb = new TableView(transMeta, wFieldsComp, SWT.FULL_SELECTION | SWT.MULTI, colinf1, 0, lsMod, props);
    fdFieldsTb = new FormData();
    fdFieldsTb.left = new FormAttachment(0, 0);
    fdFieldsTb.top = new FormAttachment(wlFieldsTb, margin);
    fdFieldsTb.right = new FormAttachment(100, 0);
    fdFieldsTb.bottom = new FormAttachment(95, -margin);
    wFieldsTb.setLayoutData(fdFieldsTb);
    fdFieldsComp = new FormData();
    fdFieldsComp.left = new FormAttachment(0, 0);
    fdFieldsComp.top = new FormAttachment(0, 0);
    fdFieldsComp.right = new FormAttachment(100, 0);
    fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldsComp.setLayoutData(fdFieldsComp);
    wGetFieldsForFields = new Button(wFieldsComp, SWT.PUSH);
    wGetFieldsForFields.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.GetFields.Label"));
    fdGetFieldsForFields = new FormData();
    fdGetFieldsForFields.top = new FormAttachment(wFieldsTb, margin);
    fdGetFieldsForFields.left = new FormAttachment(0, margin);
    wGetFieldsForFields.setLayoutData(fdGetFieldsForFields);
    wGetFieldsForFields.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getFields(wFieldsTab.getText());
        }
    });
    wDoMappingForFields = new Button(wFieldsComp, SWT.PUSH);
    wDoMappingForFields.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.EditMapping.Label"));
    fdDoMappingForFields = new FormData();
    fdDoMappingForFields.top = new FormAttachment(wFieldsTb, margin);
    fdDoMappingForFields.left = new FormAttachment(wGetFieldsForFields, margin);
    wDoMappingForFields.setLayoutData(fdDoMappingForFields);
    wDoMappingForFields.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            generateMappings(wFieldsTab.getText());
        }
    });
    wFieldsComp.layout();
    wFieldsTab.setControl(wFieldsComp);
    // TabItem: Custom disable Custom tab
    wCustomTab = new CTabItem(wTabFolder, SWT.NONE);
    wCustomTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CustomTab.TabTitle"));
    wCustomComp = new Composite(wTabFolder, SWT.NONE);
    wCustomComp.setLayout(fieldsLayout);
    props.setLook(wCustomComp);
    wlCustomTb = new Label(wCustomComp, SWT.LEFT);
    wlCustomTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CustomTab.Label"));
    fdlCustomTb = new FormData();
    fdlCustomTb.left = new FormAttachment(0, 0);
    fdlCustomTb.top = new FormAttachment(0, 0);
    fdlCustomTb.right = new FormAttachment(100, 0);
    wlCustomTb.setLayoutData(fdlCustomTb);
    wCustomTb = new StyledTextComp(transMeta, wCustomComp, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wCustomTb, Props.WIDGET_STYLE_FIXED);
    wCustomTb.addModifyListener(lsMod);
    fdCustomTb = new FormData();
    fdCustomTb.left = new FormAttachment(0, 0);
    fdCustomTb.top = new FormAttachment(wlCustomTb, margin);
    fdCustomTb.right = new FormAttachment(100, -2 * margin);
    fdCustomTb.bottom = new FormAttachment(100, -margin);
    wCustomTb.setLayoutData(fdCustomTb);
    // Text Higlighting
    SQLValuesHighlight lineStyler = new SQLValuesHighlight();
    wCustomTb.addLineStyleListener(lineStyler);
    fdCustomComp = new FormData();
    fdCustomComp.left = new FormAttachment(0, 0);
    fdCustomComp.top = new FormAttachment(0, 0);
    fdCustomComp.right = new FormAttachment(100, 0);
    fdCustomComp.bottom = new FormAttachment(100, 0);
    wCustomComp.setLayoutData(fdCustomComp);
    wCustomComp.layout();
    wCustomTab.setControl(wCustomComp);
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString("System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString("System.Button.Cancel"));
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(BaseMessages.getString("System.Button.SQL"));
    setButtonPositions(new Button[] { wOK, wSQL, wCancel }, margin, null);
    // Add listeners
    lsOK = new Listener() {

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

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

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

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

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wbTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getTableName();
        }
    });
    // 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 : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) CTabFolder(org.eclipse.swt.custom.CTabFolder) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) CTabItem(org.eclipse.swt.custom.CTabItem) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) 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) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) TextVar(org.pentaho.di.ui.core.widget.TextVar) CCombo(org.eclipse.swt.custom.CCombo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) Display(org.eclipse.swt.widgets.Display) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 25 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class SQLEditor method open.

public void open() {
    shell = new Shell(parentShell, style);
    props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageConnection());
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "SQLEditor.Title"));
    int margin = Const.MARGIN;
    // Script line
    wlScript = new Label(shell, SWT.NONE);
    wlScript.setText(BaseMessages.getString(PKG, "SQLEditor.Editor.Label"));
    props.setLook(wlScript);
    fdlScript = new FormData();
    fdlScript.left = new FormAttachment(0, 0);
    fdlScript.top = new FormAttachment(0, 0);
    wlScript.setLayoutData(fdlScript);
    wScript = new StyledTextComp(this.variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    wScript.setText("");
    props.setLook(wScript, Props.WIDGET_STYLE_FIXED);
    fdScript = new FormData();
    fdScript.left = new FormAttachment(0, 0);
    fdScript.top = new FormAttachment(wlScript, margin);
    fdScript.right = new FormAttachment(100, -10);
    fdScript.bottom = new FormAttachment(100, -70);
    wScript.setLayoutData(fdScript);
    wScript.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setPosition();
        }
    });
    wScript.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wScript.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wScript.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // SQL Higlighting
    highlight = new SQLValuesHighlight();
    highlight.addKeyWords(connection.getReservedWords());
    wScript.addLineStyleListener(highlight);
    wlPosition = new Label(shell, SWT.NONE);
    wlPosition.setText(BaseMessages.getString(PKG, "SQLEditor.LineNr.Label", "0"));
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.top = new FormAttachment(wScript, margin);
    fdlPosition.right = new FormAttachment(100, 0);
    wlPosition.setLayoutData(fdlPosition);
    wExec = new Button(shell, SWT.PUSH);
    wExec.setText(BaseMessages.getString(PKG, "SQLEditor.Button.Execute"));
    wClear = new Button(shell, SWT.PUSH);
    wClear.setText(BaseMessages.getString(PKG, "SQLEditor.Button.ClearCache"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Close"));
    wClear.setToolTipText(BaseMessages.getString(PKG, "SQLEditor.Button.ClearCache.Tooltip"));
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wExec, wClear, wCancel }, margin, null);
    // Add listeners
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsClear = new Listener() {

        public void handleEvent(Event e) {
            clearCache();
        }
    };
    lsExec = new Listener() {

        public void handleEvent(Event e) {
            try {
                exec();
            } catch (Exception ge) {
            // Ignore errors
            }
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wClear.addListener(SWT.Selection, lsClear);
    wExec.addListener(SWT.Selection, lsExec);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    BaseStepDialog.setSize(shell);
    getData();
    shell.open();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ShellAdapter(org.eclipse.swt.events.ShellAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

StyledTextComp (org.pentaho.di.ui.core.widget.StyledTextComp)41 Event (org.eclipse.swt.widgets.Event)28 Listener (org.eclipse.swt.widgets.Listener)28 ModifyEvent (org.eclipse.swt.events.ModifyEvent)27 ModifyListener (org.eclipse.swt.events.ModifyListener)27 ShellEvent (org.eclipse.swt.events.ShellEvent)27 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 FormAttachment (org.eclipse.swt.layout.FormAttachment)25 FormData (org.eclipse.swt.layout.FormData)25 FormLayout (org.eclipse.swt.layout.FormLayout)25 Button (org.eclipse.swt.widgets.Button)25 Label (org.eclipse.swt.widgets.Label)25 Shell (org.eclipse.swt.widgets.Shell)25 ShellAdapter (org.eclipse.swt.events.ShellAdapter)24 Display (org.eclipse.swt.widgets.Display)24 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 FocusEvent (org.eclipse.swt.events.FocusEvent)19 KeyEvent (org.eclipse.swt.events.KeyEvent)19 MouseEvent (org.eclipse.swt.events.MouseEvent)19 Text (org.eclipse.swt.widgets.Text)19