Search in sources :

Example 6 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class MultipleSurrogateSection method addButtonClick.

/**
     * DOC hcw Comment method "addButtonClick".
     */
protected void addButtonClick() {
    SurrogateKey key = surrogateManager.createSurrogateKey();
    createNewItem(key);
}
Also used : SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 7 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class SurrogateSection method setTableInput.

public void setTableInput(List<SurrogateKey> input) {
    if (input == null || input.isEmpty()) {
        key = new SurrogateKey();
    } else {
        key = input.get(0);
    }
    nameText.setText(key.getColumn());
    if (key.getCreation() == SurrogateCreationType.INPUT_FIELD) {
        inputFieldLabel.setText(key.getComplement());
    } else if (key.getCreation() == SurrogateCreationType.ROUTINE) {
        routineText.setText(key.getComplement());
    } else if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE) {
        dbSequenceText.setText(key.getComplement());
    }
    creationCombo.select(getIndexByCreationType(key.getCreation()));
    // activate event to switch component in stack layout
    creationSwitch.run();
}
Also used : SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 8 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class SurrogateSection method createContents.

@Override
protected void createContents(Composite parent) {
    dragDropManager = new DragDropManager();
    key = new SurrogateKey();
    final Color white = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    parent.setBackground(white);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setBackground(white);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    // row 1
    Label nameLabel = new Label(composite, SWT.NONE);
    //$NON-NLS-1$
    nameLabel.setText("name");
    nameLabel.setBackground(white);
    GridDataFactory.swtDefaults().applyTo(nameLabel);
    nameText = new Text(composite, SWT.BORDER);
    GridDataFactory.swtDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(nameText);
    nameText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (StringUtils.isEmpty(nameText.getText())) {
                nameText.setBackground(ERROR_COLOR);
            } else {
                nameText.setBackground(white);
            }
            // update model value
            key.setColumn(nameText.getText());
        }
    });
    // row 2
    Label creationLabel = new Label(composite, SWT.NONE);
    //$NON-NLS-1$
    creationLabel.setText("creation");
    creationLabel.setBackground(white);
    GridDataFactory.swtDefaults().applyTo(creationLabel);
    creationCombo = new CCombo(composite, SWT.READ_ONLY | SWT.BORDER);
    creationCombo.setItems(getScdManager().getSurrogateCreationTypeNames());
    GridDataFactory.swtDefaults().hint(SURROGATE_FIELD_WIDTH + 3, SWT.DEFAULT).applyTo(creationCombo);
    // row 3
    Label complementLabel = new Label(composite, SWT.NONE);
    //$NON-NLS-1$
    complementLabel.setText("complement");
    complementLabel.setBackground(white);
    GridDataFactory.swtDefaults().applyTo(complementLabel);
    final Composite complementComp = new Composite(composite, SWT.NONE);
    GridDataFactory.swtDefaults().applyTo(complementComp);
    final StackLayout stack = new StackLayout();
    complementComp.setLayout(stack);
    final Composite inputFieldComp = new Composite(complementComp, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(inputFieldComp);
    inputFieldLabel = new Label(inputFieldComp, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, true).hint(100, SWT.DEFAULT).applyTo(inputFieldLabel);
    // add drag and drop support for input field
    IDragDropDelegate delegate = createDragDropDelegate(inputFieldLabel);
    dragDropManager.addDragSupport(inputFieldLabel, delegate);
    dragDropManager.addDropSupport(inputFieldLabel, delegate);
    // show DB_SEQUENCE in OraleSCD
    // final boolean enableOracle = getScdManager().enableOracle();
    // if (enableOracle) {
    dbSequenceComp = new Composite(complementComp, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(dbSequenceComp);
    dbSequenceText = new Text(dbSequenceComp, SWT.BORDER);
    dbSequenceText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (StringUtils.isEmpty(dbSequenceText.getText())) {
                dbSequenceText.setBackground(ERROR_COLOR);
            } else {
                dbSequenceText.setBackground(white);
            }
            if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE) {
                key.setComplement(dbSequenceText.getText());
            }
        }
    });
    GridDataFactory.fillDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(dbSequenceText);
    TalendProposalUtils.installOn(dbSequenceText, null);
    // }
    final Composite routineFieldComp = new Composite(complementComp, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(routineFieldComp);
    routineText = new Text(routineFieldComp, SWT.BORDER);
    routineText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (StringUtils.isEmpty(routineText.getText())) {
                routineText.setBackground(ERROR_COLOR);
            } else {
                routineText.setBackground(white);
            }
            if (key.getCreation() == SurrogateCreationType.ROUTINE) {
                // update model value
                key.setComplement(routineText.getText());
            }
        }
    });
    GridDataFactory.fillDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(routineText);
    // add content proposal for routine
    TalendProposalUtils.installOn(routineText, null);
    final Label emptyLabel = new Label(complementComp, SWT.NONE);
    emptyLabel.setBackground(white);
    stack.topControl = emptyLabel;
    // when combo is changed, also change the control in complement
    creationSwitch = new Runnable() {

        public void run() {
            String diaplayName = creationCombo.getText();
            // SurrogateCreationType type = SurrogateCreationType.getTypeByIndex(index + 1);
            SurrogateCreationType type = SurrogateCreationType.getTypeByName(diaplayName);
            key.setCreation(type);
            if (type == SurrogateCreationType.ROUTINE) {
                // routineText;
                stack.topControl = routineFieldComp;
                if (StringUtils.isEmpty(routineText.getText())) {
                    routineText.setBackground(ERROR_COLOR);
                    //$NON-NLS-1$
                    key.setComplement("");
                } else {
                    routineText.setBackground(white);
                }
                //$NON-NLS-1$
                inputFieldLabel.setText("");
                // if (enableOracle) {
                //$NON-NLS-1$
                dbSequenceText.setText("");
            // }
            } else if (type == SurrogateCreationType.INPUT_FIELD) {
                // inputFieldLabel;
                stack.topControl = inputFieldComp;
                if (StringUtils.isEmpty(inputFieldLabel.getText())) {
                    inputFieldLabel.setBackground(ERROR_COLOR);
                    //$NON-NLS-1$
                    key.setComplement("");
                } else {
                    inputFieldLabel.setBackground(null);
                }
                //$NON-NLS-1$
                routineText.setText("");
                // if (enableOracle) {
                //$NON-NLS-1$
                dbSequenceText.setText("");
            // }
            } else if (type == SurrogateCreationType.DB_SEQUENCE) {
                // else if (type == SurrogateCreationType.DB_SEQUENCE && enableOracle) {
                // dbSequenceText;
                stack.topControl = dbSequenceComp;
                if (StringUtils.isEmpty(dbSequenceText.getText())) {
                    dbSequenceText.setBackground(ERROR_COLOR);
                    //$NON-NLS-1$
                    key.setComplement("");
                } else {
                    dbSequenceText.setBackground(white);
                }
                //$NON-NLS-1$
                inputFieldLabel.setText("");
                routineText.setText("");
            } else {
                stack.topControl = emptyLabel;
                //$NON-NLS-1$
                routineText.setText("");
                //$NON-NLS-1$
                inputFieldLabel.setText("");
                // if (enableOracle) {
                //$NON-NLS-1$     
                dbSequenceText.setText("");
                // }
                //$NON-NLS-1$
                key.setComplement("");
            }
            scdManager.fireFieldChange();
            complementComp.layout();
        }
    };
    creationCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            creationSwitch.run();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) SurrogateKey(org.talend.designer.scd.model.SurrogateKey) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) SurrogateCreationType(org.talend.designer.scd.model.SurrogateCreationType) StackLayout(org.eclipse.swt.custom.StackLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DragDropManager(org.talend.designer.scd.util.DragDropManager)

Aggregations

SurrogateKey (org.talend.designer.scd.model.SurrogateKey)8 HashMap (java.util.HashMap)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 ArrayList (java.util.ArrayList)1 CCombo (org.eclipse.swt.custom.CCombo)1 StackLayout (org.eclipse.swt.custom.StackLayout)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 Color (org.eclipse.swt.graphics.Color)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 SurrogateCreationType (org.talend.designer.scd.model.SurrogateCreationType)1 DragDropManager (org.talend.designer.scd.util.DragDropManager)1