Search in sources :

Example 1 with FixedFileInputField

use of org.pentaho.di.trans.steps.fixedinput.FixedFileInputField in project pentaho-kettle by pentaho.

the class FixedFileImportWizardPage2 method createControl.

public void createControl(Composite parent) {
    shell = parent.getShell();
    int margin = Const.MARGIN;
    int left = props.getMiddlePct() / 2;
    int middle = props.getMiddlePct();
    int right = middle + left;
    // create the composite to hold the widgets
    Composite composite = new Composite(parent, SWT.NONE);
    props.setLook(composite);
    FormLayout compLayout = new FormLayout();
    compLayout.marginHeight = Const.FORM_MARGIN;
    compLayout.marginWidth = Const.FORM_MARGIN;
    composite.setLayout(compLayout);
    wFields = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wFields);
    fdFields = new FormData();
    fdFields.top = new FormAttachment(0, 0);
    fdFields.left = new FormAttachment(0, 0);
    fdFields.right = new FormAttachment(left, 0);
    fdFields.bottom = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);
    refreshFields();
    // Fieldname line
    wlFieldname = new Label(composite, SWT.RIGHT);
    wlFieldname.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Fieldname.Label"));
    props.setLook(wlFieldname);
    fdlFieldname = new FormData();
    fdlFieldname.left = new FormAttachment(wFields, 0);
    fdlFieldname.top = new FormAttachment(0, 0);
    fdlFieldname.right = new FormAttachment(middle, 0);
    wlFieldname.setLayoutData(fdlFieldname);
    wFieldname = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFieldname);
    fdFieldname = new FormData();
    fdFieldname.left = new FormAttachment(middle, margin);
    fdFieldname.right = new FormAttachment(right, 0);
    fdFieldname.top = new FormAttachment(0, 0);
    wFieldname.setLayoutData(fdFieldname);
    // Position line
    wlWidth = new Label(composite, SWT.RIGHT);
    wlWidth.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.FieldWidth.Label"));
    props.setLook(wlWidth);
    fdlWidth = new FormData();
    fdlWidth.left = new FormAttachment(wFields, 0);
    fdlWidth.top = new FormAttachment(wFieldname, margin);
    fdlWidth.right = new FormAttachment(middle, 0);
    wlWidth.setLayoutData(fdlWidth);
    wWidth = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wWidth);
    fdWidth = new FormData();
    fdWidth.left = new FormAttachment(middle, margin);
    fdWidth.top = new FormAttachment(wFieldname, margin);
    fdWidth.right = new FormAttachment(right, 0);
    wWidth.setLayoutData(fdWidth);
    // Topos line
    wlLength = new Label(composite, SWT.RIGHT);
    wlLength.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.FieldLength.Label"));
    props.setLook(wlLength);
    fdlLength = new FormData();
    fdlLength.left = new FormAttachment(wFields, 0);
    fdlLength.top = new FormAttachment(wWidth, margin);
    fdlLength.right = new FormAttachment(middle, 0);
    wlLength.setLayoutData(fdlLength);
    wLength = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wLength);
    fdLength = new FormData();
    fdLength.left = new FormAttachment(middle, margin);
    fdLength.top = new FormAttachment(wWidth, margin);
    fdLength.right = new FormAttachment(right, 0);
    wLength.setLayoutData(fdLength);
    // Fieldtype line
    wlFieldtype = new Label(composite, SWT.RIGHT);
    wlFieldtype.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.FieldType.Label"));
    props.setLook(wlFieldtype);
    fdlFieldtype = new FormData();
    fdlFieldtype.left = new FormAttachment(wFields, 0);
    fdlFieldtype.top = new FormAttachment(wLength, margin);
    fdlFieldtype.right = new FormAttachment(middle, 0);
    wlFieldtype.setLayoutData(fdlFieldtype);
    wFieldtype = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);
    props.setLook(wFieldtype);
    for (int i = 0; i < ValueMetaFactory.getValueMetaNames().length; i++) {
        wFieldtype.add(ValueMetaFactory.getValueMetaNames()[i]);
    }
    fdFieldtype = new FormData();
    fdFieldtype.left = new FormAttachment(middle, margin);
    fdFieldtype.top = new FormAttachment(wLength, margin);
    fdFieldtype.right = new FormAttachment(right, 0);
    wFieldtype.setLayoutData(fdFieldtype);
    // Format line
    wlFormat = new Label(composite, SWT.RIGHT);
    wlFormat.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.FieldFormatter.Label"));
    props.setLook(wlFormat);
    fdlFormat = new FormData();
    fdlFormat.left = new FormAttachment(wFields, 0);
    fdlFormat.top = new FormAttachment(wFieldtype, margin);
    fdlFormat.right = new FormAttachment(middle, 0);
    wlFormat.setLayoutData(fdlFormat);
    wFormat = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFormat);
    fdFormat = new FormData();
    fdFormat.left = new FormAttachment(middle, margin);
    fdFormat.top = new FormAttachment(wFieldtype, margin);
    fdFormat.right = new FormAttachment(right, 0);
    wFormat.setLayoutData(fdFormat);
    /*
     * // Ignore checkbox wlIgnore=new Label(composite, SWT.RIGHT); wlIgnore.setText(BaseMessages.getString(PKG,
     * "FixedFileImportWizardPage2.Ignore.Label")); props.setLook(wlIgnore); fdlIgnore=new FormData(); fdlIgnore.left =
     * new FormAttachment(wFields, 0); fdlIgnore.top = new FormAttachment(wFormat, margin); fdlIgnore.right= new
     * FormAttachment(middle, 0); wlIgnore.setLayoutData(fdlIgnore); wIgnore=new Button(composite, SWT.CHECK);
     * props.setLook(wIgnore); fdIgnore=new FormData(); fdIgnore.left = new FormAttachment(middle, margin); fdIgnore.top
     * = new FormAttachment(wFormat, margin); fdIgnore.right= new FormAttachment(right, 0);
     * wIgnore.setLayoutData(fdIgnore);
     *
     * // Trimtype line wlTrimtype=new Label(composite, SWT.RIGHT); wlTrimtype.setText(BaseMessages.getString(PKG,
     * "FixedFileImportWizardPage2.TrimType.Label")); props.setLook(wlTrimtype); fdlTrimtype=new FormData();
     * fdlTrimtype.left = new FormAttachment(wFields, 0); fdlTrimtype.top = new FormAttachment(wIgnore, margin);
     * fdlTrimtype.right= new FormAttachment(middle, 0); wlTrimtype.setLayoutData(fdlTrimtype); wTrimtype=new
     * CCombo(composite, SWT.BORDER | SWT.READ_ONLY); props.setLook(wTrimtype); for (int i=0;i<
     * TextFileInputMeta.trimTypeDesc.length;i++) { wTrimtype.add( TextFileInputMeta.trimTypeDesc[i] ); } fdTrimtype=new
     * FormData(); fdTrimtype.left = new FormAttachment(middle, margin); fdTrimtype.top = new FormAttachment(wIgnore,
     * margin); fdTrimtype.right= new FormAttachment(right, 0); wTrimtype.setLayoutData(fdTrimtype);
     */
    // Precision line
    wlPrecision = new Label(composite, SWT.RIGHT);
    wlPrecision.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Precision.Label"));
    props.setLook(wlPrecision);
    fdlPrecision = new FormData();
    fdlPrecision.left = new FormAttachment(wFields, 0);
    fdlPrecision.top = new FormAttachment(wFormat, margin);
    fdlPrecision.right = new FormAttachment(middle, 0);
    wlPrecision.setLayoutData(fdlPrecision);
    wPrecision = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPrecision);
    fdPrecision = new FormData();
    fdPrecision.left = new FormAttachment(middle, margin);
    fdPrecision.top = new FormAttachment(wFormat, margin);
    fdPrecision.right = new FormAttachment(right, 0);
    wPrecision.setLayoutData(fdPrecision);
    // Currency line
    wlCurrency = new Label(composite, SWT.RIGHT);
    wlCurrency.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Currency.Label"));
    props.setLook(wlCurrency);
    fdlCurrency = new FormData();
    fdlCurrency.left = new FormAttachment(wFields, 0);
    fdlCurrency.top = new FormAttachment(wPrecision, margin);
    fdlCurrency.right = new FormAttachment(middle, 0);
    wlCurrency.setLayoutData(fdlCurrency);
    wCurrency = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCurrency);
    fdCurrency = new FormData();
    fdCurrency.left = new FormAttachment(middle, margin);
    fdCurrency.top = new FormAttachment(wPrecision, margin);
    fdCurrency.right = new FormAttachment(right, 0);
    wCurrency.setLayoutData(fdCurrency);
    // Decimal line
    wlDecimal = new Label(composite, SWT.RIGHT);
    wlDecimal.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Decimal.Label"));
    props.setLook(wlDecimal);
    fdlDecimal = new FormData();
    fdlDecimal.left = new FormAttachment(wFields, 0);
    fdlDecimal.top = new FormAttachment(wCurrency, margin);
    fdlDecimal.right = new FormAttachment(middle, 0);
    wlDecimal.setLayoutData(fdlDecimal);
    wDecimal = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDecimal);
    fdDecimal = new FormData();
    fdDecimal.left = new FormAttachment(middle, margin);
    fdDecimal.top = new FormAttachment(wCurrency, margin);
    fdDecimal.right = new FormAttachment(right, 0);
    wDecimal.setLayoutData(fdDecimal);
    // Group line
    wlGroup = new Label(composite, SWT.RIGHT);
    wlGroup.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Group.Label"));
    props.setLook(wlGroup);
    fdlGroup = new FormData();
    fdlGroup.left = new FormAttachment(wFields, 0);
    fdlGroup.top = new FormAttachment(wDecimal, margin);
    fdlGroup.right = new FormAttachment(middle, 0);
    wlGroup.setLayoutData(fdlGroup);
    wGroup = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wGroup);
    fdGroup = new FormData();
    fdGroup.left = new FormAttachment(middle, margin);
    fdGroup.top = new FormAttachment(wDecimal, margin);
    fdGroup.right = new FormAttachment(right, 0);
    wGroup.setLayoutData(fdGroup);
    /*
     * // Ignore checkbox wlRepeat=new Label(composite, SWT.RIGHT); wlRepeat.setText(BaseMessages.getString(PKG,
     * "FixedFileImportWizardPage2.Repeat.Label")); props.setLook(wlRepeat); fdlRepeat=new FormData(); fdlRepeat.left =
     * new FormAttachment(wFields, 0); fdlRepeat.top = new FormAttachment(wGroup, margin); fdlRepeat.right= new
     * FormAttachment(middle, 0); wlRepeat.setLayoutData(fdlRepeat); wRepeat=new Button(composite, SWT.CHECK);
     * props.setLook(wRepeat); fdRepeat=new FormData(); fdRepeat.left = new FormAttachment(middle, margin); fdRepeat.top
     * = new FormAttachment(wGroup, margin); fdRepeat.right= new FormAttachment(right, 0);
     * wRepeat.setLayoutData(fdRepeat);
     *
     * // Null line wlNull=new Label(composite, SWT.RIGHT); wlNull.setText(BaseMessages.getString(PKG,
     * "FixedFileImportWizardPage2.Null.Label")); props.setLook(wlNull); fdlNull=new FormData(); fdlNull.left = new
     * FormAttachment(wFields, 0); fdlNull.top = new FormAttachment(wRepeat, margin); fdlNull.right= new
     * FormAttachment(middle, 0); wlNull.setLayoutData(fdlNull); wNull=new Text(composite, SWT.SINGLE | SWT.LEFT |
     * SWT.BORDER); props.setLook(wNull); fdNull=new FormData(); fdNull.left = new FormAttachment(middle, margin);
     * fdNull.top = new FormAttachment(wRepeat, margin); fdNull.right= new FormAttachment(right, 0);
     * wNull.setLayoutData(fdNull);
     */
    // The buttons
    wPrev = new Button(composite, SWT.PUSH);
    wPrev.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Previous.Button"));
    fdPrev = new FormData();
    fdPrev.left = new FormAttachment(left, margin);
    fdPrev.bottom = new FormAttachment(100, 0);
    wPrev.setLayoutData(fdPrev);
    // Guess button
    wGuess = new Button(composite, SWT.PUSH);
    wGuess.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Guess.Button"));
    fdGuess = new FormData();
    fdGuess.left = new FormAttachment(wPrev, margin);
    fdGuess.bottom = new FormAttachment(100, 0);
    wGuess.setLayoutData(fdGuess);
    // GuessAll button
    wGuessAll = new Button(composite, SWT.PUSH);
    wGuessAll.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.GuessAll.Button"));
    fdGuessAll = new FormData();
    fdGuessAll.left = new FormAttachment(wGuess, 0);
    fdGuessAll.bottom = new FormAttachment(100, 0);
    wGuessAll.setLayoutData(fdGuessAll);
    wNext = new Button(composite, SWT.PUSH);
    wNext.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.Next.Button"));
    fdNext = new FormData();
    fdNext.left = new FormAttachment(wGuessAll, 0);
    fdNext.bottom = new FormAttachment(100, 0);
    wNext.setLayoutData(fdNext);
    // Sample list on the right...
    wSamples = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    props.setLook(wSamples, Props.WIDGET_STYLE_FIXED);
    fdSamples = new FormData();
    fdSamples.top = new FormAttachment(0, 0);
    fdSamples.left = new FormAttachment(right, 0);
    fdSamples.right = new FormAttachment(100, 0);
    fdSamples.bottom = new FormAttachment(100, 0);
    wSamples.setLayoutData(fdSamples);
    wFields.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            showInfo();
        }
    });
    if (wFields.getItemCount() > 0) {
        wFields.select(0);
        showInfo();
    }
    wFieldtype.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                int valtype = ValueMetaFactory.getIdForValueMeta(wFieldtype.getText());
                FixedFileInputField field = fields.get(idx);
                field.setType(valtype);
            }
        }
    });
    wFieldname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setName(wFieldname.getText());
                wFields.setItem(idx, wFieldname.getText());
            }
        }
    });
    wFormat.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setFormat(wFormat.getText());
            }
        }
    });
    wNext.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0 && idx < wFields.getItemCount() - 1) {
                wFields.select(idx + 1);
                wFields.showSelection();
                showInfo();
            }
        }
    });
    wPrev.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx > 0) {
                wFields.select(idx - 1);
                wFields.showSelection();
                showInfo();
            }
        }
    });
    /*
     * wIgnore.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int idx =
     * wFields.getSelectionIndex(); if (idx>=0) { FixedFileInputField field = fields.get(idx); field.flipIgnored(); } }
     * } );
     */
    wGuess.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setSamples(wSamples.getItems());
                field.guess();
                showInfo();
            }
        }
    });
    wGuessAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
            mb.setMessage(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.OverwriteTypeSettings.DialogMessage"));
            mb.setText(BaseMessages.getString(PKG, "FixedFileImportWizardPage2.OverwriteTypeSettings.DialogTitle"));
            int answer = mb.open();
            if (answer == SWT.YES) {
                int position = 0;
                for (int i = 0; i < fields.size(); i++) {
                    FixedFileInputField field = fields.get(i);
                    field.setSamples(getRowSamples(position, field.getWidth()));
                    field.guess();
                    wFields.select(i);
                    wFields.showSelection();
                    showInfo();
                    position += field.getWidth();
                }
            }
            if (wFields.getItemCount() > 0) {
                wFields.select(0);
                wFields.showSelection();
            }
            showInfo();
        }
    });
    /*
     * wRepeat.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int idx =
     * wFields.getSelectionIndex(); if (idx>=0) { TextFileInputField field = (TextFileInputField)fields.get(idx);
     * field.flipRepeated(); } } } );
     */
    wCurrency.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setCurrency(wCurrency.getText());
            }
        }
    });
    wGroup.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setGrouping(wGroup.getText());
            }
        }
    });
    wDecimal.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int idx = wFields.getSelectionIndex();
            if (idx >= 0) {
                FixedFileInputField field = fields.get(idx);
                field.setDecimal(wDecimal.getText());
            }
        }
    });
    /*
     * wNull.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { int idx =
     * wFields.getSelectionIndex(); if (idx>=0) { TextFileInputField field = (TextFileInputField)fields.get(idx);
     * field.setNullString(wNull.getText()); } } } );
     *
     * wTrimtype.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int idx =
     * wFields.getSelectionIndex(); if (idx>=0) { int trimType =
     * TextFileInputMeta.getTrimTypeByDesc(wTrimtype.getText()); TextFileInputField field =
     * (TextFileInputField)fields.get(idx); field.setTrimType(trimType); } } } );
     */
    // set the composite as the control for this page
    setControl(composite);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 2 with FixedFileInputField

use of org.pentaho.di.trans.steps.fixedinput.FixedFileInputField in project pentaho-kettle by pentaho.

the class FixedInputDialog method getInfo.

private void getInfo(FixedInputMeta fixedInputMeta) {
    fixedInputMeta.setFilename(wFilename.getText());
    fixedInputMeta.setLineWidth(wLineWidth.getText());
    fixedInputMeta.setBufferSize(wBufferSize.getText());
    fixedInputMeta.setLazyConversionActive(wLazyConversion.getSelection());
    fixedInputMeta.setHeaderPresent(wHeaderPresent.getSelection());
    fixedInputMeta.setLineFeedPresent(wLineFeedPresent.getSelection());
    fixedInputMeta.setRunningInParallel(wRunningInParallel.getSelection());
    fixedInputMeta.setFileType(FixedInputMeta.getFileType(wFileType.getText()));
    fixedInputMeta.setEncoding(wEncoding.getText());
    fixedInputMeta.setAddResultFile(wAddResult.getSelection());
    int nrNonEmptyFields = wFields.nrNonEmpty();
    fixedInputMeta.allocate(nrNonEmptyFields);
    for (int i = 0; i < nrNonEmptyFields; i++) {
        TableItem item = wFields.getNonEmpty(i);
        int colnr = 1;
        FixedFileInputField field = new FixedFileInputField();
        field.setName(item.getText(colnr++));
        field.setType(ValueMetaFactory.getIdForValueMeta(item.getText(colnr++)));
        field.setFormat(item.getText(colnr++));
        field.setWidth(Const.toInt(item.getText(colnr++), -1));
        field.setLength(Const.toInt(item.getText(colnr++), -1));
        field.setPrecision(Const.toInt(item.getText(colnr++), -1));
        field.setCurrency(item.getText(colnr++));
        field.setDecimal(item.getText(colnr++));
        field.setGrouping(item.getText(colnr++));
        field.setTrimType(ValueMetaString.getTrimTypeByDesc(item.getText(colnr++)));
        // CHECKSTYLE:Indentation:OFF
        fixedInputMeta.getFieldDefinition()[i] = field;
    }
    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth(true);
    fixedInputMeta.setChanged();
}
Also used : FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) TableItem(org.eclipse.swt.widgets.TableItem)

Example 3 with FixedFileInputField

use of org.pentaho.di.trans.steps.fixedinput.FixedFileInputField in project pentaho-kettle by pentaho.

the class FixedTableDraw method paintControl.

// Draw the widget.
public void paintControl(PaintEvent e) {
    offset = getOffset();
    if (offset == null) {
        return;
    }
    Point area = getArea();
    Point max = getMaximum();
    Point thumb = getThumb(area, max);
    hori.setThumb(thumb.x);
    vert.setThumb(thumb.y);
    // From where do we need to draw?
    int fromy = -offset.y / (fontheight + 2);
    int toy = fromy + (area.y / (fontheight + 2));
    int fromx = -offset.x / fontwidth;
    int tox = fromx + (area.x / fontwidth);
    Image image = new Image(display, area.x, area.y);
    if (fromx != prev_fromx || fromy != prev_fromy || tox != prev_tox || toy != prev_toy) {
        if (cache_image != null) {
            cache_image.dispose();
            cache_image = null;
        }
        cache_image = new Image(display, area.x, area.y);
        GC gc = new GC(cache_image);
        // We have a cached image: draw onto it!
        int linepos = TOP - 5;
        gc.setBackground(bg);
        gc.fillRectangle(LEFT, TOP, area.x, area.y);
        // We draw in black...
        gc.setForeground(black);
        // 
        for (int i = fromy; i < rows.size() && i < toy; i++) {
            String str = rows.get(i);
            for (int p = fromx; p < str.length() && p < tox; p++) {
                gc.drawText("" + str.charAt(p), LEFT + MARGIN + p * fontwidth + offset.x, TOP + i * (fontheight + 2) + offset.y, true);
            }
            if (str.length() < tox) {
                gc.setForeground(red);
                gc.setBackground(red);
                int x_oval = LEFT + MARGIN + str.length() * fontwidth + offset.x;
                int y_oval = TOP + i * (fontheight + 2) + offset.y;
                gc.drawOval(x_oval, y_oval, fontwidth, fontheight);
                gc.fillOval(x_oval, y_oval, fontwidth, fontheight);
                gc.setForeground(black);
                gc.setBackground(bg);
            }
        }
        // Draw the rulers
        // HORIZONTAL
        gc.setBackground(lgray);
        gc.fillRectangle(LEFT + MARGIN, 0, area.x, linepos + 1);
        gc.setBackground(bg);
        gc.drawLine(LEFT + MARGIN, linepos, area.x, linepos);
        // Little tabs, small ones, every 5 big one, every 10 the number above...
        for (int i = fromx; i < maxlen + 10 && i < tox + 10; i++) {
            String number = "" + i;
            int numsize = number.length() * fontwidth;
            if (i > 0 && (i % 10) == 0) {
                gc.drawText("" + i, LEFT + MARGIN + i * fontwidth - numsize / 2 + offset.x, linepos - 10 - fontheight, true);
            }
            if (i > 0 && (i % 5) == 0) {
                gc.drawLine(LEFT + MARGIN + i * fontwidth + offset.x, linepos, LEFT + MARGIN + i * fontwidth + offset.x, linepos - 5);
            } else {
                gc.drawLine(LEFT + MARGIN + i * fontwidth + offset.x, linepos, LEFT + MARGIN + i * fontwidth + offset.x, linepos - 3);
            }
        }
        // VERTICIAL
        gc.setBackground(lgray);
        gc.fillRectangle(0, TOP, LEFT, area.y);
        gc.drawLine(LEFT, TOP, LEFT, area.y);
        for (int i = fromy; i < rows.size() && i < toy; i++) {
            String number = "" + (i + 1);
            int numsize = number.length() * fontwidth;
            gc.drawText(number, LEFT - 5 - numsize, TOP + i * (fontheight + 2) + offset.y, true);
            gc.drawLine(LEFT, TOP + (i + 1) * (fontheight + 2) + offset.y, LEFT - 5, TOP + (i + 1) * (fontheight + 2) + offset.y);
        }
        gc.dispose();
    }
    GC gc = new GC(image);
    // Draw the cached image onto the canvas image:
    gc.drawImage(cache_image, 0, 0);
    // Also draw the markers...
    gc.setForeground(red);
    gc.setBackground(red);
    int position = 0;
    for (FixedFileInputField field : fields) {
        int x = position;
        if (x >= fromx && x <= tox) {
            drawMarker(gc, x, area.y);
        }
        position += field.getWidth();
    }
    if (potential_click >= 0) {
        gc.setForeground(blue);
        gc.setBackground(blue);
        drawMarker(gc, potential_click, area.y);
    }
    // Draw the image:
    e.gc.drawImage(image, 0, 0);
    gc.dispose();
    image.dispose();
}
Also used : FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 4 with FixedFileInputField

use of org.pentaho.di.trans.steps.fixedinput.FixedFileInputField in project pentaho-kettle by pentaho.

the class FixedTableDraw method setMarker.

private void setMarker(int x) {
    int idx = -1;
    int highest_smaller = -1;
    int position = 0;
    for (int i = 0; i < fields.size() && idx < 0; i++) {
        FixedFileInputField field = fields.get(i);
        int width = field.getWidth();
        if (position == potential_click) {
            idx = i;
        }
        if (highest_smaller < 0 && position + width >= x) {
            // The first time this occurs is OK.
            highest_smaller = i;
        }
        position += width;
    }
    // 
    if (idx < 0) {
        // Position is not yet in the list, the field is not deleted, but added
        if (highest_smaller >= 0) {
            // OK, let's add a new field, but split the length of the previous field
            // We want to keep this list sorted, so add at position lowest_larger.
            // We want to change the previous entry and add another after it.
            FixedFileInputField prevfield = fields.get(highest_smaller);
            int prevPosition = getFieldPosition(prevfield);
            int newlength = prevfield.getWidth() - (x - prevPosition);
            FixedFileInputField field = new FixedFileInputField();
            field.setName(getNewFieldname());
            field.setWidth(newlength);
            fields.add(highest_smaller + 1, field);
            // Don't forget to make the previous field shorter
            prevfield.setWidth(x - prevPosition);
        }
    } else {
        if (highest_smaller >= 0) {
            // Now we need to remove the field with the same starting position
            // The previous field need to receive extra length
            // 
            FixedFileInputField prevfield = fields.get(highest_smaller);
            FixedFileInputField field = fields.get(idx);
            prevfield.setWidth(prevfield.getWidth() + field.getWidth());
            // Remove the field
            fields.remove(idx);
        }
    }
    // Something has changed: change wizard page...
    wPage.setPageComplete(wPage.canFlipToNextPage());
}
Also used : FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) Point(org.eclipse.swt.graphics.Point)

Example 5 with FixedFileInputField

use of org.pentaho.di.trans.steps.fixedinput.FixedFileInputField in project pentaho-kettle by pentaho.

the class FixedTableDraw method getFieldPosition.

private int getFieldPosition(FixedFileInputField look) {
    int position = 0;
    for (FixedFileInputField field : fields) {
        if (field.equals(look)) {
            // Same name:
            return position;
        }
        int width = field.getWidth();
        position += width;
    }
    return -1;
}
Also used : FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) Point(org.eclipse.swt.graphics.Point)

Aggregations

FixedFileInputField (org.pentaho.di.trans.steps.fixedinput.FixedFileInputField)10 Point (org.eclipse.swt.graphics.Point)4 TableItem (org.eclipse.swt.widgets.TableItem)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 FixedInputMeta (org.pentaho.di.trans.steps.fixedinput.FixedInputMeta)2 List (java.util.List)1 Wizard (org.eclipse.jface.wizard.Wizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 CCombo (org.eclipse.swt.custom.CCombo)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1