Search in sources :

Example 6 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform in project webtools.sourceediting by eclipse.

the class StylesheetLabelProvider method getText.

@Override
public String getText(Object element) {
    LaunchTransform lt = (LaunchTransform) element;
    int index = lt.getPipeline().getTransformDefs().indexOf(lt);
    IPath path;
    try {
        path = lt.getPath();
    } catch (CoreException e) {
        return MessageFormat.format(Messages.StylesheetEntryLabelProvider_Invalid_path, // $NON-NLS-1$
        new Object[] { "null" });
    }
    if (path == null) {
        return MessageFormat.format(Messages.StylesheetEntryLabelProvider_Invalid_path, // $NON-NLS-1$
        new Object[] { "null" });
    } else if (!path.isAbsolute() || !path.isValidPath(path.toString())) {
        return MessageFormat.format(Messages.StylesheetEntryLabelProvider_Invalid_path, new Object[] { path.toString() });
    }
    String[] segments = path.segments();
    StringBuffer displayPath = new StringBuffer();
    if (segments.length > 0) {
        displayPath.append(segments[segments.length - 1]);
        // $NON-NLS-1$
        displayPath.append(" - ");
        String device = path.getDevice();
        if (device != null) {
            displayPath.append(device);
        }
        displayPath.append(File.separator);
        for (int i = 0; i < segments.length - 1; i++) {
            displayPath.append(segments[i]).append(File.separator);
        }
    } else {
        displayPath.append(path.toString());
    }
    // $NON-NLS-1$
    return (index + 1) + ") " + displayPath.toString();
}
Also used : LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException)

Example 7 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform in project webtools.sourceediting by eclipse.

the class XSLLaunchShortcut method findOrCreateLaunchConfiguration.

private ILaunchConfiguration findOrCreateLaunchConfiguration() throws CoreException {
    ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(getConfigurationType());
    List<ILaunchConfiguration> candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length);
    for (ILaunchConfiguration config : configs) {
        String inputFile = config.getAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, (String) null);
        try {
            inputFile = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(inputFile);
        } catch (CoreException e) {
            // just ignore this one
            continue;
        }
        Path path = new Path(inputFile);
        // the source xml file must be the same
        if (path.equals(xmlFilePath)) {
            BaseLaunchHelper lh = new BaseLaunchHelper(config);
            // all the selected stylesheets must be in the pipeline
            boolean found = false;
            for (IFile stylesheet : xslFiles) {
                found = false;
                for (Iterator<LaunchTransform> iter = lh.getPipeline().getTransformDefs().iterator(); iter.hasNext(); ) {
                    LaunchTransform lt = iter.next();
                    if (lt.getLocation().equals(stylesheet.getLocation())) {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    break;
            }
            if (found)
                candidateConfigs.add(config);
        }
    }
    ILaunchConfiguration config = null;
    int candidateCount = candidateConfigs.size();
    if (candidateCount == 1)
        config = candidateConfigs.get(0);
    else if (candidateCount > 1)
        config = chooseConfiguration(candidateConfigs);
    else
        config = createConfiguration();
    return config;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) BaseLaunchHelper(org.eclipse.wst.xsl.launching.config.BaseLaunchHelper)

Example 8 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform in project webtools.sourceediting by eclipse.

the class XSLLaunchShortcut method createConfiguration.

private ILaunchConfiguration createConfiguration() {
    ILaunchConfiguration config = null;
    try {
        ILaunchConfigurationType configType = getConfigurationType();
        // $NON-NLS-1$
        String lastSegment = xmlFile != null ? xmlFile.getName() : xmlFilePath != null ? xmlFilePath.lastSegment() : "XSLTransformation";
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(lastSegment));
        if (xmlFile != null)
            wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, // $NON-NLS-1$ //$NON-NLS-2$
            "${workspace_loc:" + xmlFile.getFullPath().toPortableString() + "}");
        else
            wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, xmlFilePath.toPortableString());
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_USE_DEFAULT_OUTPUT_FILE, true);
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_OPEN_FILE, true);
        if (pipeline == null)
            pipeline = new LaunchPipeline();
        for (IFile element : xslFiles) {
            pipeline.addTransformDef(new LaunchTransform(element.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE));
        }
        if (xslFilePath != null) {
            pipeline.addTransformDef(new LaunchTransform(xslFilePath, LaunchTransform.EXTERNAL_TYPE));
        }
        if (!pipeline.getTransformDefs().isEmpty()) {
            LaunchTransform lastDef = pipeline.getTransformDefs().get(pipeline.getTransformDefs().size() - 1);
            String outputFormat = guessOutputMethod(lastDef);
            if (outputFormat != null) {
                wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_DEFAULT_OUTPUT_METHOD, outputFormat);
            }
        }
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_PIPELINE, pipeline.toXML());
        if (xmlFile != null)
            wc.setMappedResources(new IResource[] { xmlFile.getProject() });
        config = wc.doSave();
    } catch (CoreException exception) {
        MessageDialog.openError(getShell(), Messages.XSLLaunchShortcut_6, exception.getStatus().getMessage());
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) LaunchPipeline(org.eclipse.wst.xsl.launching.config.LaunchPipeline) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IResource(org.eclipse.core.resources.IResource)

Example 9 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform in project webtools.sourceediting by eclipse.

the class AddExternalFileAction method run.

@Override
public void run() {
    String lastUsedPath = getDialogSetting(LAST_PATH_SETTING);
    if (lastUsedPath == null) {
        // $NON-NLS-1$
        lastUsedPath = "";
    }
    FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
    dialog.setText(Messages.AddExternalFileAction_Selection_3);
    dialog.setFilterPath(lastUsedPath);
    IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
    IContentType contentType = contentTypeManager.getContentType(XSLCore.XSL_CONTENT_TYPE);
    String[] xslContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
    // add *. to front
    for (int i = 0; i < xslContentTypes.length; i++) {
        String string = xslContentTypes[i];
        // $NON-NLS-1$
        xslContentTypes[i] = "*." + string;
    }
    dialog.setFilterExtensions(xslContentTypes);
    String res = dialog.open();
    if (res == null) {
        return;
    }
    IPath filterPath = new Path(dialog.getFilterPath());
    LaunchTransform[] lts = new LaunchTransform[1];
    IPath path = new Path(res).makeAbsolute();
    lts[0] = new LaunchTransform(path.toPortableString(), LaunchTransform.EXTERNAL_TYPE);
    setDialogSetting(LAST_PATH_SETTING, filterPath.toOSString());
    addTransforms(lts);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IPath(org.eclipse.core.runtime.IPath) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentType(org.eclipse.core.runtime.content.IContentType) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 10 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform in project webtools.sourceediting by eclipse.

the class AddWorkspaceFileAction method run.

@Override
public void run() {
    // ViewerFilter filter= new StylesheetFilter(getSelectedJars());
    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setValidator(validator);
    dialog.setTitle(Messages.AddWorkspaceFileAction_DialogTitle);
    dialog.setMessage(Messages.AddWorkspaceFileAction_DialogMessage);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (!(element instanceof IResource))
                return false;
            IResource resource = (IResource) element;
            if (resource.getType() == IResource.FILE) {
                if (!XSLCore.isXSLFile((IFile) resource))
                    return false;
            }
            return true;
        }
    });
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        LaunchTransform[] res = new LaunchTransform[elements.length];
        for (int i = 0; i < res.length; i++) {
            IResource elem = (IResource) elements[i];
            res[i] = new LaunchTransform(elem.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE);
        }
        addTransforms(res);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) StylesheetViewer(org.eclipse.wst.xsl.internal.debug.ui.tabs.main.StylesheetViewer) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IResource(org.eclipse.core.resources.IResource)

Aggregations

LaunchTransform (org.eclipse.wst.xsl.launching.config.LaunchTransform)11 IResource (org.eclipse.core.resources.IResource)4 CoreException (org.eclipse.core.runtime.CoreException)4 IPath (org.eclipse.core.runtime.IPath)4 LaunchPipeline (org.eclipse.wst.xsl.launching.config.LaunchPipeline)4 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 IContainer (org.eclipse.core.resources.IContainer)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1