Search in sources :

Example 6 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class NameAndLabelsTreeController method createControl.

@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    Composite parentComp = new Composite(subComposite, SWT.NONE);
    parentComp.setLayoutData(data);
    parentComp.setLayout(new GridLayout());
    ElementsSelectionComposite<NamedThing> selectionComposite = new ElementsSelectionComposite<NamedThing>(parentComp) {

        @Override
        protected IBaseLabelProvider getLabelProvider() {
            return new LabelProvider() {

                @Override
                public String getText(Object obj) {
                    NamedThing nal = (NamedThing) obj;
                    return nal.getDisplayName();
                }

                @Override
                public Image getImage(Object obj) {
                    return null;
                }
            };
        }

        ;

        @Override
        protected void doSelectionChanged() {
            param.setValue(getSelectedElements());
        }

        @Override
        protected List<String> getSelectedElementLabels() {
            List<String> labels = new ArrayList<>();
            Object value = param.getValue();
            if (value instanceof List) {
                List<?> values = (List<?>) value;
                for (Object valueObj : values) {
                    if (valueObj instanceof NamedThing) {
                        labels.add(((NamedThing) valueObj).getName());
                    }
                }
                return labels;
            }
            return null;
        }

        @Override
        protected List<NamedThing> getInitSelectedElements(List<String> selectedElementLabels) {
            List<NamedThing> selectedElements = new ArrayList<>();
            List<NamedThing> viewerDatas = getViewerData();
            for (NamedThing viewerData : viewerDatas) {
                if (selectedElementLabels.contains(viewerData.getName())) {
                    selectedElements.add(viewerData);
                }
            }
            return selectedElements;
        }
    }.setShowToolbar(true).create();
    selectionComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (param instanceof GenericElementParameter) {
        selectionComposite.setViewerData(ComponentsUtils.getFormalPossibleValues((GenericElementParameter) param));
    }
    selectionComposite.setCheckedState();
    return parentComp;
}
Also used : FormData(org.eclipse.swt.layout.FormData) ElementsSelectionComposite(org.talend.core.ui.composite.ElementsSelectionComposite) ElementsSelectionComposite(org.talend.core.ui.composite.ElementsSelectionComposite) Composite(org.eclipse.swt.widgets.Composite) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 7 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class NameAndLabelsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite comp = new Composite(composite, SWT.NONE);
    comp.setLayoutData(new GridData(GridData.FILL_BOTH));
    comp.setLayout(new GridLayout());
    selectionComposite = new ElementsSelectionComposite<NamedThing>(comp) {

        @Override
        protected IBaseLabelProvider getLabelProvider() {
            return new LabelProvider() {

                @Override
                public String getText(Object obj) {
                    NamedThing nal = (NamedThing) obj;
                    return nal.getDisplayName();
                }

                @Override
                public Image getImage(Object obj) {
                    return null;
                }
            };
        }

        ;
    }.setMultipleSelection(false).create();
    selectionComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    selectionComposite.setViewerData(nameAndLabels);
    Composite customComposite = new Composite(comp, SWT.NONE);
    customComposite.setLayout(new GridLayout());
    customComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button useCustomBtn = new Button(customComposite, SWT.CHECK);
    //$NON-NLS-1$
    useCustomBtn.setText(Messages.getString("NameAndLabelsDialog.custom.button"));
    useCustomBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFieldsStatus(useCustomBtn.getSelection());
        }
    });
    //$NON-NLS-1$
    customObjNameText = new LabelledText(customComposite, Messages.getString("NameAndLabelsDialog.custom.text"));
    updateFieldsStatus(useCustomBtn.getSelection());
    if (!isInWizard) {
        // set empty quotes to show the user he should fill the name between quotes
        //$NON-NLS-1$
        customObjNameText.setText("\"\"");
    }
    return composite;
}
Also used : LabelledText(org.talend.commons.ui.swt.formtools.LabelledText) ElementsSelectionComposite(org.talend.core.ui.composite.ElementsSelectionComposite) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) NamedThing(org.talend.daikon.NamedThing) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 8 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class MarketoSourceOrSinkTest method getCustomObjects.

public List<NamedThing> getCustomObjects() {
    List<NamedThing> co = new ArrayList<>();
    SimpleNamedThing snt = new SimpleNamedThing("car_c", "car_c");
    co.add(snt);
    snt = new SimpleNamedThing("smartphone_c", "smartphone_c");
    co.add(snt);
    return co;
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 9 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SalesforceComponentTestIT method testWizard.

@Test
public void testWizard() throws Throwable {
    final List<RepoProps> repoProps = new ArrayList<>();
    Repository repo = new TestRepository(repoProps);
    getComponentService().setRepository(repo);
    Set<ComponentWizardDefinition> wizards = getComponentService().getTopLevelComponentWizards();
    int connectionWizardDefinitionNumber = 0;
    ComponentWizardDefinition wizardDef = null;
    for (ComponentWizardDefinition wizardDefinition : wizards) {
        if (wizardDefinition instanceof SalesforceConnectionWizardDefinition) {
            wizardDef = wizardDefinition;
            connectionWizardDefinitionNumber++;
        }
    }
    assertEquals(1, connectionWizardDefinitionNumber);
    assertEquals("Salesforce Connection", wizardDef.getMenuItemName());
    ComponentWizard connectionWizard = getComponentService().getComponentWizard(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeSalesforce");
    assertNotNull(connectionWizard);
    assertEquals("nodeSalesforce", connectionWizard.getRepositoryLocation());
    List<Form> forms = connectionWizard.getForms();
    Form connFormWizard = forms.get(0);
    assertEquals("Wizard", connFormWizard.getName());
    assertFalse(connFormWizard.isAllowBack());
    assertFalse(connFormWizard.isAllowForward());
    assertFalse(connFormWizard.isAllowFinish());
    // Main from SalesforceModuleListProperties
    assertEquals("Main", forms.get(1).getName());
    assertEquals("Salesforce Connection Settings", connFormWizard.getTitle());
    assertEquals("Complete these fields in order to connect to your Salesforce account.", connFormWizard.getSubtitle());
    SalesforceConnectionProperties connProps = (SalesforceConnectionProperties) connFormWizard.getProperties();
    Form advancedForm = connProps.getForm(Form.ADVANCED);
    assertTrue(((PresentationItem) connFormWizard.getWidget("advanced").getContent()).getFormtoShow() + " should be == to " + advancedForm, ((PresentationItem) connFormWizard.getWidget("advanced").getContent()).getFormtoShow() == advancedForm);
    Object image = getComponentService().getWizardPngImage(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.TREE_ICON_16X16);
    assertNotNull(image);
    image = getComponentService().getWizardPngImage(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.WIZARD_BANNER_75X66);
    assertNotNull(image);
    // Check the non-top-level wizard
    // check password i18n
    assertEquals("Name", connProps.getProperty("name").getDisplayName());
    connProps.name.setValue("connName");
    setupProps(connProps, !ADD_QUOTES);
    Form userPassword = (Form) connFormWizard.getWidget("userPassword").getContent();
    Property passwordSe = (Property) userPassword.getWidget("password").getContent();
    assertEquals("Password", passwordSe.getDisplayName());
    // check name i18n
    // $NON-NLS-1$
    NamedThing nameProp = connFormWizard.getWidget("name").getContent();
    assertEquals("Name", nameProp.getDisplayName());
    connProps = (SalesforceConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), connFormWizard, "testConnection", connProps);
    assertTrue(connFormWizard.isAllowForward());
    Form modForm = forms.get(1);
    SalesforceModuleListProperties mlProps = (SalesforceModuleListProperties) modForm.getProperties();
    assertFalse(modForm.isCallAfterFormBack());
    assertFalse(modForm.isCallAfterFormNext());
    assertTrue(modForm.isCallAfterFormFinish());
    assertTrue(modForm.isCallBeforeFormPresent());
    assertFalse(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertFalse(modForm.isAllowFinish());
    mlProps = (SalesforceModuleListProperties) getComponentService().beforeFormPresent(modForm.getName(), mlProps);
    assertTrue(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertTrue(modForm.isAllowFinish());
    @SuppressWarnings("unchecked") List<NamedThing> all = mlProps.selectedModuleNames.getValue();
    assertNull(all);
    // TCOMP-9 Change the module list to use getPossibleValues() for SalesforceModuleListProperties
    List<NamedThing> possibleValues = (List<NamedThing>) mlProps.selectedModuleNames.getPossibleValues();
    assertTrue(possibleValues.size() > 50);
    List<NamedThing> selected = new ArrayList<>();
    selected.add(possibleValues.get(0));
    selected.add(possibleValues.get(2));
    selected.add(possibleValues.get(3));
    mlProps.selectedModuleNames.setValue(selected);
    getComponentService().afterFormFinish(modForm.getName(), mlProps);
    LOGGER.debug(repoProps.toString());
    assertEquals(4, repoProps.size());
    int i = 0;
    for (RepoProps rp : repoProps) {
        if (i == 0) {
            assertEquals("connName", rp.name);
            SalesforceConnectionProperties storedConnProps = (SalesforceConnectionProperties) rp.props;
            assertEquals(userId, storedConnProps.userPassword.userId.getValue());
            assertEquals(password, storedConnProps.userPassword.password.getValue());
        } else {
            SalesforceModuleProperties storedModule = (SalesforceModuleProperties) rp.props;
            assertEquals(selected.get(i - 1).getName(), storedModule.moduleName.getValue());
            assertTrue(rp.schema.getFields().size() > 10);
            assertThat(storedModule.main.schema.getStringValue(), is(rp.schema.toString()));
        }
        i++;
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) PresentationItem(org.talend.daikon.properties.PresentationItem) Form(org.talend.daikon.properties.presentation.Form) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SalesforceConnectionWizardDefinition(org.talend.components.salesforce.SalesforceConnectionWizardDefinition) SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) Repository(org.talend.daikon.properties.service.Repository) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) SalesforceModuleListProperties(org.talend.components.salesforce.SalesforceModuleListProperties) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Example 10 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SalesforceRuntimeCommon method getSchemaNames.

public static List<NamedThing> getSchemaNames(PartnerConnection connection) throws IOException {
    List<NamedThing> returnList = new ArrayList<>();
    DescribeGlobalResult result = null;
    try {
        result = connection.describeGlobal();
    } catch (ConnectionException e) {
        throw new ComponentException(e);
    }
    DescribeGlobalSObjectResult[] objects = result.getSobjects();
    for (DescribeGlobalSObjectResult obj : objects) {
        LOG.debug("module label: " + obj.getLabel() + " name: " + obj.getName());
        returnList.add(new SimpleNamedThing(obj.getName(), obj.getLabel()));
    }
    return returnList;
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

NamedThing (org.talend.daikon.NamedThing)71 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)34 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)21 Property (org.talend.daikon.properties.property.Property)17 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 ComponentException (org.talend.components.api.exception.ComponentException)14 Schema (org.apache.avro.Schema)11 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)9 ValidationResult (org.talend.daikon.properties.ValidationResult)8 Form (org.talend.daikon.properties.presentation.Form)8 List (java.util.List)7 IOException (java.io.IOException)6 PresentationItem (org.talend.daikon.properties.PresentationItem)6 Properties (org.talend.daikon.properties.Properties)6 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)5 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)5 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)4 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4