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();
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations