Search in sources :

Example 41 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class QueryTypeController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createControl(org.eclipse
     * .swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Control lastControlUsed = super.createControl(subComposite, param, numInRow, nbInRow, top, lastControl);
    IElementParameter queryStoreTypeParameter = param.getChildParameters().get(EParameterName.QUERYSTORE_TYPE.getName());
    if (queryStoreTypeParameter != null) {
        String queryStoreType = (String) queryStoreTypeParameter.getValue();
        if (queryStoreType != null && queryStoreType.equals(EmfComponent.BUILTIN)) {
            lastControlUsed = addGuessQueryButton(subComposite, param, lastControlUsed, numInRow, top);
        }
    }
    return lastControlUsed;
}
Also used : Control(org.eclipse.swt.widgets.Control) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 42 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class AbstractJobSettingsPage method save.

protected void save() {
    List<String> checkedObjects = new ArrayList<String>();
    List<IRepositoryViewObject> allProcess = null;
    try {
        allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    }
    for (IRepositoryViewObject object : allProcess) {
        if (isStatUseProjectSetting(object)) {
            if (!checkedObjects.contains(object.getProperty().getId())) {
                checkedObjects.add(object.getProperty().getId());
                if (!checkedNodeObject.contains(object)) {
                    checkedNodeObject.add(object);
                }
            }
        }
    }
    List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
    if (allOpenedProcessList != null) {
        for (int i = 0; i < allOpenedProcessList.size(); i++) {
            if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
                openedProcessList.add(allOpenedProcessList.get(i));
            }
        }
    }
    //
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
            final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
            // must init this
            addContextModel = false;
            if (!contextVars.isEmpty()) {
                // boolean showDialog = false;
                Set<String> contextSet = new HashSet<String>();
                for (String key : contextVars.keySet()) {
                    contextSet = contextVars.get(key);
                    break;
                }
                Connection connection = null;
                IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                if (ptParam != null) {
                    IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
                    Object proValue = propertyElem.getValue();
                    if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
                        IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        String value = (String) repositoryElem.getValue();
                        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
                        connection = connectionItem.getConnection();
                        if (connection != null && connection.isContextMode()) {
                            addContextModel = true;
                        // ContextItem contextItem =
                        // ContextUtils.getContextItemById(connection.getContextId());
                        // for (IProcess process : openedProcessList) {
                        // Set<String> addedContext =
                        // ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                        // contextSet, process.getContextManager(), false);
                        // if (addedContext != null && !addedContext.isEmpty()) {
                        // showDialog = true;
                        // break;
                        // }
                        // }
                        }
                    }
                }
                if (addContextModel) {
                    // if the context is not existed in job, will add or not.
                    Display disp = Display.getCurrent();
                    if (disp == null) {
                        disp = Display.getDefault();
                    }
                    if (disp != null) {
                        disp.syncExec(new Runnable() {

                            @Override
                            public void run() {
                                showContextAndCheck(contextVars);
                            }
                        });
                    } else {
                        showContextAndCheck(contextVars);
                    }
                }
            }
            monitor.worked(10);
            IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    for (IRepositoryViewObject object : checkedNodeObject) {
                        saveProcess(object, addContextModel, contextVars, monitor);
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IElementParameter(org.talend.core.model.process.IElementParameter) HashSet(java.util.HashSet) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Display(org.eclipse.swt.widgets.Display)

Example 43 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ElementParameter2ParameterType method saveElementParameters.

/**
     * save the EMF Model's parameters to Element
     *
     * @param elem
     * @param pType
     */
public static void saveElementParameters(Element elem, ParametersType pType) {
    EList<ElementParameterType> listParamType = pType.getElementParameter();
    listParamType.clear();
    Element defaultElement = getDefaultElement(pType);
    List<? extends IElementParameter> paramList = elem.getElementParametersWithChildrens();
    for (IElementParameter param : paramList) {
        ElementParameterType type = getElemeterParameterType(param);
        IElementParameter defalutParam = defaultElement.getElementParameter(type.getName());
        if (defalutParam != null) {
            listParamType.add(type);
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Element(org.talend.core.model.process.Element) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 44 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class AbstractJobSettingsPage method updateProjectSetting.

public void updateProjectSetting() {
    String[] split = getRepositoryPropertyName().split(":");
    String parentParamName = split[0];
    Element elementParams = elem;
    IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
    if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
        if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
            DatabaseConnection connection = null;
            String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
            if (lastVersion != null && lastVersion.getProperty() != null) {
                Item item = lastVersion.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    connection = (DatabaseConnection) dbItem.getConnection();
                }
            }
            if (connection != null) {
                boolean sameValues = true;
                for (IElementParameter param : elementParams.getElementParameters()) {
                    String repositoryValue = param.getRepositoryValue();
                    if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
                        Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
                        if (repValue == null) {
                            continue;
                        }
                        if (repositoryValue.equals(UpdatesConstants.TYPE)) {
                            // datebase type
                            boolean found = false;
                            String[] list = param.getListRepositoryItems();
                            for (int i = 0; (i < list.length) && (!found); i++) {
                                if (repValue.equals(list[i])) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                sameValues = false;
                                break;
                            }
                        } else {
                            // check the value
                            if (!param.getValue().equals(repValue)) {
                                sameValues = false;
                                break;
                            }
                        }
                    }
                }
                if (!sameValues) {
                    boolean ok = MessageDialog.openQuestion(getShell(), getDisplayName(), "Connection has been changed , do you want to change value from repository ?");
                    if (ok) {
                        ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, getRepositoryPropertyName(), id);
                        changeValuesFromRepository.execute();
                        isConnectionChanged = true;
                    }
                }
            } else {
                MessageDialog.openInformation(getShell(), getDisplayName(), "Connection has been deleted ,change to build in automaticlly");
                ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, getPropertyTypeName(), EmfComponent.BUILTIN);
                changeValuesFromRepository1.execute();
                isConnectionChanged = true;
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) Element(org.talend.core.model.process.Element) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 45 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class JobSettingProjectSettingPage method performOk.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.preference.PreferencePage#performOk()
     */
@Override
public boolean performOk() {
    if (mComposite != null) {
        ImplicitContextSettings implicit = pro.getEmfProject().getImplicitContextSettings();
        if (implicit != null) {
            // save to emf Model
            ElementParameter2ParameterType.setParameterValue(implicit.getParameters(), EParameterName.IMPLICT_DEFAULT_PROJECTSETTING.getName(), Boolean.valueOf(implicitBtn.getSelection()));
            // save to the memory
            IElementParameter elementParameter = pro.getInitialContextLoad().getElementParameter(EParameterName.IMPLICT_DEFAULT_PROJECTSETTING.getName());
            if (elementParameter != null) {
                elementParameter.setValue(Boolean.valueOf(implicitBtn.getSelection()));
            }
        }
        StatAndLogsSettings stat = pro.getEmfProject().getStatAndLogsSettings();
        if (stat != null) {
            ElementParameter2ParameterType.setParameterValue(stat.getParameters(), EParameterName.STATS_DEFAULT_PROJECTSETTING.getName(), Boolean.valueOf(statBtn.getSelection()));
            IElementParameter elementParameter = pro.getStatsAndLog().getElementParameter(EParameterName.STATS_DEFAULT_PROJECTSETTING.getName());
            if (elementParameter != null) {
                elementParameter.setValue(Boolean.valueOf(statBtn.getSelection()));
            }
        }
        ProjectSettingManager.saveProject();
    }
    return super.performOk();
}
Also used : StatAndLogsSettings(org.talend.core.model.properties.StatAndLogsSettings) IElementParameter(org.talend.core.model.process.IElementParameter) ImplicitContextSettings(org.talend.core.model.properties.ImplicitContextSettings)

Aggregations

IElementParameter (org.talend.core.model.process.IElementParameter)426 ArrayList (java.util.ArrayList)161 List (java.util.List)108 Node (org.talend.designer.core.ui.editor.nodes.Node)108 Map (java.util.Map)95 INode (org.talend.core.model.process.INode)92 HashMap (java.util.HashMap)82 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)73 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)69 Point (org.eclipse.swt.graphics.Point)57 ElementParameter (org.talend.designer.core.model.components.ElementParameter)48 ConnectionItem (org.talend.core.model.properties.ConnectionItem)45 IConnection (org.talend.core.model.process.IConnection)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 Item (org.talend.core.model.properties.Item)37 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)37 IComponent (org.talend.core.model.components.IComponent)35 CCombo (org.eclipse.swt.custom.CCombo)33 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)29 Connection (org.talend.core.model.metadata.builder.connection.Connection)28