|
Re: Temporarily apply stylesheet for document generation [message #1745281 is a reply to message #1745238] |
Fri, 07 October 2016 08:34 |
Camille Letavernier Messages: 952 Registered: February 2011 |
Senior Member |
|
|
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
Camille Letavernier
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04519 seconds