Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Temporarily apply stylesheet for document generation
Temporarily apply stylesheet for document generation [message #1745238] Thu, 06 October 2016 19:22 Go to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
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 08:34 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
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 Smile

HTH,
Camille


Camille Letavernier
Re: Temporarily apply stylesheet for document generation [message #1817795 is a reply to message #1745281] Fri, 29 November 2019 09:36 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hello,

Is there any new available settings to manage the CSS style for a 'print' media? I'm also interested in this.

Regards.

Yoann.
Re: Temporarily apply stylesheet for document generation [message #1817796 is a reply to message #1817795] Fri, 29 November 2019 09:42 Go to previous message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Yoann,

Nothing new on this side; Papyrus CSS still don't support the @media rules

Regards,
Camille


Camille Letavernier
Previous Topic:Package with little red rectangle - what does it mean
Next Topic:Tests using EditHelperAdvice classes
Goto Forum:
  


Current Time: Fri Apr 19 02:00:56 GMT 2024

Powered by FUDForum. Page generated in 0.02731 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top