Temporarily apply stylesheet for document generation [message #1745238] |
Thu, 06 October 2016 15:22  |
Eclipse User |
|
|
|
Hi,
We are using GenDoc for code generation.
In our case, we would like to set some special CSS stylesheet to optimize the diagrams for the documents to be generated.
How would it be possible to programmatically add (and remove again) such a stylesheet ?
For now, I have this "partial" code, but it doesn't feel optimal (I don't even know that it works yet):
StylesheetsFactory styleSheetsFactory = StylesheetsFactory.eINSTANCE;
Path path = new Path(stylePath);
IFile cssFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
StyleSheetReference styleSheetsReference = styleSheetsFactory.createStyleSheetReference();
styleSheetsReference.setPath(cssFile.getFullPath().toString());
CSSDiagramImpl cssDiagram = (CSSDiagramImpl) diagram;
// Now add it to the css diagram's css style sheets
for (Object styleObject : diagram.getStyles()) {
if (styleObject instanceof NamedStyle) {
NamedStyle style = (NamedStyle) styleObject;
if (CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY.equals(style.getName())) {
if (style instanceof EObjectListValueStyle) {
EObjectListValueStyle stylesheetsStyle = (EObjectListValueStyle) style;
EList<StyleSheet> list = (EList<StyleSheet>) stylesheetsStyle.getEObjectListValue();
list.add(styleSheetsReference);
}
}
}
}
Has anybody experience with an optimal way to temporarily assign a css stylesheet?
Thanks,
Johan
|
|
|
Re: Temporarily apply stylesheet for document generation [message #1745281 is a reply to message #1745238] |
Fri, 07 October 2016 04:34   |
Eclipse User |
|
|
|
Hi Johan,
The preferred way with CSS would be to use 'media' rules (With a 'print' media containing your specific rules), but they are not supported in Papyrus, so...
You can reuse the ObservableList from the CSS Properties view plug-in: DiagramStyleSheetObservableList
StylesheetsFactory styleSheetsFactory = StylesheetsFactory.eINSTANCE;
Path path = new Path(stylePath);
IFile cssFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
StyleSheetReference styleSheetsReference = styleSheetsFactory.createStyleSheetReference();
styleSheetsReference.setPath(cssFile.getFullPath().toString());
DiagramStyleSheetObservableList styleSheets = new DiagramStyleSheetObservableList(diagram, editingDomain, CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY);
styleSheets.add(styleSheetReference);
styleSheets.commit(null);
//After printing...
styleSheets.remove(styleSheetReference);
styleSheets.commit(null);
To remove the stylesheet, you may also call editingDomain.getCommandStack().undo(), assuming no other operation modified the model after you added the stylesheet (In any case, this will affect your user's undo/redo history)
I've not tested this code, so adjustements may be required. I don't think you need to go through all these conversions to get the stylesheet path. If your stylesheet is deployed in a plug-in, get the path from: URI.createPlatformPluginURI(pluginId+"/path/in/the/plugin/print.css", true).toString()
If the print style sheet is relative to your model, the stylePath is all you need. If the stylePath is relative to your workspace, then "/"+stylePath should work (Or URI.createPlatformResourceURI(stylePath, true).toString())
I hope I didn't do too many mistakes 
HTH,
Camille
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03676 seconds