Search in sources :

Example 1 with SurrogateCreationType

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

the class ScdManager method getSurrogateCreationTypeNames.

public String[] getSurrogateCreationTypeNames() {
    List<String> allTypeNames = new ArrayList<String>();
    IElementParameter param = getComponent().getElementParameter(EParameterName.SK_CREATION.getName());
    for (SurrogateCreationType type : SurrogateCreationType.values()) {
        if (param != null) {
            if (ArrayUtils.contains(param.getListItemsDisplayCodeName(), type.name())) {
                allTypeNames.add(type.getName());
            }
        } else {
            allTypeNames.add(type.getName());
        }
    }
    return allTypeNames.toArray(new String[0]);
}
Also used : SurrogateCreationType(org.talend.designer.scd.model.SurrogateCreationType) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 2 with SurrogateCreationType

use of org.talend.designer.scd.model.SurrogateCreationType 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

SurrogateCreationType (org.talend.designer.scd.model.SurrogateCreationType)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 IElementParameter (org.talend.core.model.process.IElementParameter)1 SurrogateKey (org.talend.designer.scd.model.SurrogateKey)1 DragDropManager (org.talend.designer.scd.util.DragDropManager)1