Search in sources :

Example 1 with ITransformerFactory

use of org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory in project webtools.sourceediting by eclipse.

the class ProcessorTypeRegistry method getProcessorTypes.

public IProcessorType[] getProcessorTypes() {
    if (installTypes == null) {
        List<ProcessorType> types = new ArrayList<ProcessorType>();
        String featureXMLString = JAXPLaunchingPlugin.getDefault().getPluginPreferences().getString(JAXPRuntime.PREF_FEATURE_XML);
        // If the preference was found, load VMs from it into memory
        FeaturePreferences prefs = null;
        if (featureXMLString.length() > 0) {
            try {
                ByteArrayInputStream inputStream = new ByteArrayInputStream(featureXMLString.getBytes());
                prefs = FeaturePreferences.fromXML(inputStream);
            } catch (CoreException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
        String propXMLString = JAXPLaunchingPlugin.getDefault().getPluginPreferences().getString(JAXPRuntime.PREF_OUTPUT_PROPERTIES_XML);
        // If the preference was found, load VMs from it into memory
        OutputPropertyPreferences outputprefs = null;
        if (propXMLString.length() > 0) {
            try {
                ByteArrayInputStream inputStream = new ByteArrayInputStream(propXMLString.getBytes());
                outputprefs = OutputPropertyPreferences.fromXML(inputStream);
            } catch (CoreException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
        for (Iterator<IConfigurationElement> iter = elements.iterator(); iter.hasNext(); ) {
            IConfigurationElement element = iter.next();
            String id = element.getAttribute(ProcessorTypeRegistryReader.ATT_ID);
            String label = element.getAttribute(ProcessorTypeRegistryReader.ATT_LABEL);
            Map<String, String> featureValues = new HashMap<String, String>();
            Map<String, String> propertyValues = new HashMap<String, String>();
            if (prefs != null && prefs.getFeaturesValues(id) != null)
                featureValues.putAll(prefs.getFeaturesValues(id));
            if (outputprefs != null && outputprefs.getOutputPropertyValues(id) != null)
                propertyValues.putAll(outputprefs.getOutputPropertyValues(id));
            String outputProperties = element.getAttribute(ProcessorTypeRegistryReader.ATT_OUTPUT_PROPERTIES);
            URL outputPropertiesURL = FileLocator.find(Platform.getBundle(element.getContributor().getName()), new Path(outputProperties), null);
            String featureProperties = element.getAttribute(ProcessorTypeRegistryReader.ATT_ATTRIBUTE_PROPERTIES);
            URL featurePropertiesURL = FileLocator.find(Platform.getBundle(element.getContributor().getName()), new Path(featureProperties), null);
            List<ITransformerFactory> transFactoryList = new ArrayList<ITransformerFactory>();
            IConfigurationElement[] transFactEls = element.getChildren(ProcessorTypeRegistryReader.EL_TRANSFORMER_FACTORY);
            for (IConfigurationElement transFactEl : transFactEls) {
                String transFactoryName = transFactEl.getAttribute(ProcessorTypeRegistryReader.ATT_TRANSFORMER_FACTORY_NAME);
                String transFactoryClass = transFactEl.getAttribute(ProcessorTypeRegistryReader.ATT_TRANSFORMER_FACTORY_CLASS);
                transFactoryList.add(new TransformerFactory(transFactoryName, transFactoryClass));
            }
            types.add(new ProcessorType(id, label, featurePropertiesURL, outputPropertiesURL, featureValues, propertyValues, transFactoryList.toArray(new ITransformerFactory[0])));
        }
        installTypes = types.toArray(new IProcessorType[0]);
    }
    return installTypes;
}
Also used : Path(org.eclipse.core.runtime.Path) ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) TransformerFactory(org.eclipse.wst.xsl.jaxp.launching.internal.TransformerFactory) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) ProcessorType(org.eclipse.wst.xsl.jaxp.launching.internal.ProcessorType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeaturePreferences(org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) OutputPropertyPreferences(org.eclipse.wst.xsl.jaxp.launching.internal.OutputPropertyPreferences) ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with ITransformerFactory

use of org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory in project webtools.sourceediting by eclipse.

the class ProcessorBlock method initializeFrom.

public void initializeFrom(ILaunchConfiguration configuration) {
    try {
        boolean useDefaultProcessor = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_USE_DEFAULT_PROCESSOR, true);
        if (useDefaultProcessor) {
            usePreferencesRadio.setSelection(true);
            overridePreferencesRadio.setSelection(false);
            preferencesSelected();
        } else {
            usePreferencesRadio.setSelection(false);
            overridePreferencesRadio.setSelection(true);
            overrideSelected();
            IProcessorInstall runInstall = null;
            String runId = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_PROCESSOR, (String) null);
            if (runId != null)
                runInstall = JAXPRuntime.getProcessor(runId);
            if (runInstall == null)
                runInstall = getRunProcessorPreference();
            runComboViewer.setSelection(new StructuredSelection(runInstall));
            String factoryId = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_TRANSFORMER_FACTORY, (String) null);
            if (factoryId == null) {
                currentFactory = runInstall.getProcessorType().getDefaultTransformerFactory();
            } else {
                for (ITransformerFactory tf : runInstall.getProcessorType().getTransformerFactories()) {
                    if (tf.getFactoryClass().equals(factoryId)) {
                        currentFactory = tf;
                        break;
                    }
                }
            }
            if (currentFactory == null) {
                currentFactory = runInstall.getProcessorType().getDefaultTransformerFactory();
            }
            if (currentFactory != null) {
                factoryComboViewer.setSelection(new StructuredSelection(currentFactory), true);
            }
        }
    } catch (CoreException e) {
        XSLDebugUIPlugin.log(e);
    }
}
Also used : ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) CoreException(org.eclipse.core.runtime.CoreException) IProcessorInstall(org.eclipse.wst.xsl.jaxp.launching.IProcessorInstall) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ITransformerFactory

use of org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory in project webtools.sourceediting by eclipse.

the class ProcessorBlock method createControl.

public void createControl(Composite parent) {
    Font font = parent.getFont();
    Composite group = new Composite(parent, SWT.NULL);
    setControl(group);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    group.setFont(font);
    // group.setText(ProcessorMessages.ProcessorBlock_0);
    usePreferencesRadio = new Button(group, SWT.RADIO);
    usePreferencesRadio.setText(ProcessorMessages.ProcessorBlock_1);
    usePreferencesRadio.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            preferencesSelected();
            updateLaunchConfigurationDialog();
        }
    });
    alterPreferencesButton = new Button(group, SWT.PUSH);
    alterPreferencesButton.setText(ProcessorMessages.ProcessorBlock_2);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gd.widthHint = 150;
    alterPreferencesButton.setLayoutData(gd);
    alterPreferencesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferencePage page = new ProcessorsPreferencePage();
            // $NON-NLS-1$
            showPrefPage("org.eclipse.wst.xslt.launching.ui.preferences.ProcessorPreferencePage", page);
        }
    });
    overridePreferencesRadio = new Button(group, SWT.RADIO);
    overridePreferencesRadio.setText(ProcessorMessages.ProcessorBlock_4);
    overridePreferencesRadio.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            overrideSelected();
            updateLaunchConfigurationDialog();
        }
    });
    installedProcessorsButton = new Button(group, SWT.PUSH);
    installedProcessorsButton.setText(ProcessorMessages.ProcessorsComboBlock_1);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gd.widthHint = 150;
    installedProcessorsButton.setLayoutData(gd);
    installedProcessorsButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferencePage page = new ProcessorsPreferencePage();
            // $NON-NLS-1$
            showPrefPage("org.eclipse.wst.xslt.launching.ui.preferences.ProcessorPreferencePage", page);
        }
    });
    Composite settingsComp = new Composite(group, SWT.NONE);
    GridLayout gl = new GridLayout(3, false);
    gl.marginHeight = 2;
    settingsComp.setLayout(gl);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 15;
    gd.horizontalSpan = 2;
    settingsComp.setLayoutData(gd);
    settingsComp.setFont(font);
    Label label = new Label(settingsComp, SWT.NONE);
    label.setText(ProcessorMessages.ProcessorBlock_6);
    runCombo = new Combo(settingsComp, SWT.READ_ONLY | SWT.SINGLE);
    runCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    runComboViewer = new ComboViewer(runCombo);
    runComboViewer.setContentProvider(new ComboContentProvider());
    runComboViewer.setLabelProvider(new ComboLabelProvider());
    runComboViewer.setInput(JAXPRuntime.getProcessors());
    runComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (!sel.isEmpty()) {
                IProcessorInstall processor = (IProcessorInstall) sel.getFirstElement();
                if (processor.getProcessorType().getTransformerFactories().length > 1)
                    factoryComboViewer.getCombo().setVisible(true);
                else
                    factoryComboViewer.getCombo().setVisible(false);
                factoryComboViewer.setInput(processor.getProcessorType());
                boolean found = false;
                for (ITransformerFactory tf : processor.getProcessorType().getTransformerFactories()) {
                    if (tf.equals(currentFactory)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    currentFactory = processor.getProcessorType().getDefaultTransformerFactory();
                    if (currentFactory != null)
                        factoryComboViewer.setSelection(new StructuredSelection(currentFactory));
                }
            }
            updateLaunchConfigurationDialog();
        }
    });
    Combo factoryCombo = new Combo(settingsComp, SWT.READ_ONLY | SWT.SINGLE);
    factoryCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
    factoryComboViewer = new ComboViewer(factoryCombo);
    factoryComboViewer.setContentProvider(new IStructuredContentProvider() {

        private IProcessorType type;

        public Object[] getElements(Object inputElement) {
            return type.getTransformerFactories();
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            this.type = (IProcessorType) newInput;
        }
    });
    factoryComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            ITransformerFactory f = (ITransformerFactory) element;
            // + " - " + f.getFactoryClass();
            return f.getName();
        }
    });
    factoryComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            currentFactory = (ITransformerFactory) ((IStructuredSelection) event.getSelection()).getFirstElement();
            updateLaunchConfigurationDialog();
        }
    });
// overridePreferencesButton = new Button(group,SWT.CHECK);
// overridePreferencesButton.setText("Override preferences");
// gd = new GridData(SWT.NONE,SWT.NONE,false,false);
// overridePreferencesButton.setLayoutData(gd);
// overridePreferencesButton.addSelectionListener(new SelectionListener(){
// public void widgetDefaultSelected(SelectionEvent e)
// {}
// 
// public void widgetSelected(SelectionEvent e)
// {
// firePreferenceProcessorChanged(overridePreferencesButton.getSelection());
// }
// });
}
Also used : Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ProcessorsPreferencePage(org.eclipse.wst.xsl.jaxp.debug.ui.internal.preferences.ProcessorsPreferencePage) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IProcessorInstall(org.eclipse.wst.xsl.jaxp.launching.IProcessorInstall) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 4 with ITransformerFactory

use of org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory in project webtools.sourceediting by eclipse.

the class LaunchHelper method hydrateTransformerFactory.

private static ITransformerFactory hydrateTransformerFactory(ILaunchConfiguration configuration) throws CoreException {
    IProcessorType type = getProcessorInstall(configuration).getProcessorType();
    boolean useDefaultFactory = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_USE_DEFAULT_PROCESSOR, true);
    if (useDefaultFactory)
        return type.getDefaultTransformerFactory();
    String factoryId = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_TRANSFORMER_FACTORY, (String) null);
    if (factoryId == null)
        return null;
    for (ITransformerFactory factory : type.getTransformerFactories()) {
        if (factory.getFactoryClass().equals(factoryId))
            return factory;
    }
    return null;
}
Also used : ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType)

Aggregations

ITransformerFactory (org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory)4 IProcessorType (org.eclipse.wst.xsl.jaxp.launching.IProcessorType)3 CoreException (org.eclipse.core.runtime.CoreException)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IProcessorInstall (org.eclipse.wst.xsl.jaxp.launching.IProcessorInstall)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Path (org.eclipse.core.runtime.Path)1 IPreferencePage (org.eclipse.jface.preference.IPreferencePage)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1