Search in sources :

Example 6 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class CodeView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    parent.setLayout(new FillLayout());
    ECodeLanguage language = LanguageManager.getCurrentLanguage();
    ISourceViewer viewer = null;
    final StyledText text;
    int styles = SWT.H_SCROLL | SWT.V_SCROLL;
    document = new Document();
    switch(language) {
        case JAVA:
            IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
            viewer = new JavaSourceViewer(parent, null, null, false, styles, store);
            viewer.setDocument(document);
            JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
            tools.setupJavaDocumentPartitioner(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING);
            SimpleJavaSourceViewerConfiguration config = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true);
            viewer.configure(config);
            viewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
            document = viewer.getDocument();
            break;
        // empty since only have java
        default:
    }
    viewer.setEditable(false);
    text = viewer.getTextWidget();
    // getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    IAction wrapAction = new Action() {

        @Override
        public void run() {
            text.setWordWrap(isChecked());
        }
    };
    //$NON-NLS-1$
    wrapAction.setToolTipText("wrap");
    wrapAction.setChecked(false);
    //$NON-NLS-1$
    wrapAction.setImageDescriptor(ImageDescriptor.createFromFile(DesignerPlugin.class, "/icons/wrap.gif"));
    tbm.add(wrapAction);
    createMenu();
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) StyledText(org.eclipse.swt.custom.StyledText) SimpleJavaSourceViewerConfiguration(org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration) IAction(org.eclipse.jface.action.IAction) JavaTextTools(org.eclipse.jdt.ui.text.JavaTextTools) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DesignerPlugin(org.talend.designer.core.DesignerPlugin) JavaSourceViewer(org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 7 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class TestComponentsAction method initialize.

public void initialize() {
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    "Component Test") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                // IProgressMonitor monitorWrap = new CodeGeneratorProgressMonitor(monitor);
                //$NON-NLS-1$
                monitor.beginTask("Component Test Running", 1100);
                IComponentsFactory componentsFactory = ComponentsFactoryProvider.getInstance();
                Set<IComponent> components = componentsFactory.getComponents();
                monitor.worked(100);
                RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
                ECodeLanguage codeLanguage = repositoryContext.getProject().getLanguage();
                String path = getPath();
                // TODO
                int taskTotal = components.size();
                for (IComponent component : components) {
                    String templateURI = path + File.separatorChar + component.getName() + File.separatorChar + TestParameter.GENERATE_TEST;
                    File templateFile = new File(templateURI);
                    // System.out.println(templateFile + " " + templateFile.exists());
                    if (templateFile.exists()) {
                        File[] fileArray = getFile(templateFile, codeLanguage);
                        //$NON-NLS-1$ //$NON-NLS-2$
                        generateCode(fileArray, templateURI.replace("\\", "/"));
                    }
                    monitor.worked(1 * 1000 / taskTotal);
                }
            } catch (Exception e) {
                //$NON-NLS-1$
                log.error("Exception during test Initialization", e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) IComponentsFactory(org.talend.core.model.components.IComponentsFactory) IComponent(org.talend.core.model.components.IComponent) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 8 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class ContextParameterExtractor method buildParameterFrom.

private static IContextParameter buildParameterFrom(final Control text, final IContextManager manager, final String parameterName) {
    //$NON-NLS-1$
    String nameProposal = "";
    if (text instanceof Text) {
        nameProposal = ((Text) text).getSelectionText();
        if (nameProposal.length() == 0) {
            nameProposal = ((Text) text).getText();
        }
    } else {
        if (text instanceof StyledText) {
            nameProposal = ((StyledText) text).getSelectionText();
            if (nameProposal.length() == 0) {
                nameProposal = ((StyledText) text).getText();
            }
        }
    }
    if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
        nameProposal = TalendTextUtils.removeQuotes(nameProposal);
    }
    String value = nameProposal;
    if (ContextParameterUtils.containContextVariables(value)) {
        //$NON-NLS-1$
        MessageDialog.openError(//$NON-NLS-1$
        new Shell(), //$NON-NLS-1$
        Messages.getString("ContextParameterExtractor.ExistedTitle"), //$NON-NLS-1$
        Messages.getString("ContextParameterExtractor.ExistedMessages"));
        return null;
    }
    //$NON-NLS-1$ //$NON-NLS-2$
    nameProposal = nameProposal.replace(" ", "_");
    IContextParameter parameter = new JobContextParameter();
    if (manager.checkValidParameterName(null, parameterName)) {
        parameter.setName(parameterName);
    } else if (manager.checkValidParameterName(null, nameProposal)) {
        parameter.setName(nameProposal);
    } else {
        //$NON-NLS-1$
        parameter.setName("");
    }
    ECodeLanguage curLanguage = LanguageManager.getCurrentLanguage();
    if (curLanguage == ECodeLanguage.PERL) {
        parameter.setType(MetadataTalendType.getDefaultTalendType());
    } else {
        parameter.setType(JavaTypesManager.getDefaultJavaType().getId());
    }
    //$NON-NLS-1$
    parameter.setPrompt(parameterName + "?");
    //$NON-NLS-1$
    parameter.setComment("");
    parameter.setValue(value);
    return parameter;
}
Also used : JobContextParameter(org.talend.core.model.context.JobContextParameter) Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) IContextParameter(org.talend.core.model.process.IContextParameter) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 9 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class SynchronizeSchemaOnlyForPerlDemoMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.
     * ProcessItem)
     */
@Override
public ExecutionResult execute(Item item) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        boolean modified = false;
        ECodeLanguage language = LanguageManager.getCurrentLanguage();
        if (language == ECodeLanguage.PERL) {
            Project project = ProjectManager.getInstance().getProject(item);
            if (project != null && project.getTechnicalLabel().equalsIgnoreCase("TALENDDEMOSPERL")) {
                //$NON-NLS-1$
                IProcess2 process = (IProcess2) RepositoryPlugin.getDefault().getDesignerCoreService().getProcessFromItem(item);
                modified = synchronizeSchema(process);
                if (modified) {
                    ProcessType processType = process.saveXmlFile();
                    if (item instanceof ProcessItem) {
                        ((ProcessItem) item).setProcess(processType);
                    } else if (item instanceof JobletProcessItem) {
                        ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                    }
                    factory.save(item, true);
                    return ExecutionResult.SUCCESS_NO_ALERT;
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Project(org.talend.core.model.properties.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) JobletProcess(org.talend.designer.joblet.model.JobletProcess) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 10 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class LanguageProvider method getCurrentLanguage.

public static ILanguage getCurrentLanguage() {
    ECodeLanguage codeLanguage = null;
    if (!MapperMain.isStandAloneMode()) {
        RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
        codeLanguage = repositoryContext.getProject().getLanguage();
    } else {
        codeLanguage = ECodeLanguage.PERL;
    }
    switch(codeLanguage) {
        case JAVA:
            if (!(language instanceof JavaLanguage) || LanguageProvider.language == null) {
                LanguageProvider.language = getJavaLanguage();
            }
            break;
        default:
            if (!(language instanceof PerlLanguage) || LanguageProvider.language == null) {
                LanguageProvider.language = getPerlLanguage();
            }
    }
    return LanguageProvider.language;
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) PerlLanguage(org.talend.designer.mapper.language.perl.PerlLanguage) JavaLanguage(org.talend.designer.mapper.language.java.JavaLanguage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

ECodeLanguage (org.talend.core.language.ECodeLanguage)29 RepositoryContext (org.talend.core.context.RepositoryContext)5 HashMap (java.util.HashMap)4 StyledText (org.eclipse.swt.custom.StyledText)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)4 IFile (org.eclipse.core.resources.IFile)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 IEditorReference (org.eclipse.ui.IEditorReference)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 EList (org.eclipse.emf.common.util.EList)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)2 Item (org.talend.core.model.properties.Item)2