How to import a resource in Eclipse plugin stylesheet? - css

To create an Eclipse plugin, I need to import/use some resources into a stylesheet.
All the necessary files reside into the plugin package and are correctly build with no errors into the final .jar.
I have this folder/files in plugin package:
> my.plugin.package.name
> META-INF/
> MANIFEST.MF
> resources/
> css/
> base-stylesheet.css
> win-stylesheet.css
> linux-stylesheet.css
> ...
> images/
> mytexture.png
> ...
> plugin.xml
> ...
in win-stylesheet.css I want to import base-stylesheet.css and use mytexture.png, so into the CSS I do:
#import url("base-stylesheet.css");
#elemId {
background-image: url(../images/mytexture.png);
}
unfortunately, these gives a MalformedURLException, I noticed also that:
using character " or ' or nothing to delimit the url string give the same error;
using #import url("/base-stylesheet.css") or #import url("./base-stylesheet.css") works perfecly when running/debugging the plugin into a second Eclipse instance but silently fails with the same error when the plugin jar is installed in Eclipse;
using #import url("platform:/plugin/my.plugin.id/resources/css/base-stylesheet.css") or #import url("platform://plugin/my.plugin.id/resources/css/base-stylesheet.css") where my.plugin.id is the Bundle-SymbolicName assigned in MANIFEST.MF give the same error both when running/debugging the plugin and when using it after installing the jar.
I suspect that the workspace directory is automatically assigned to platform:/plugin/org.eclipse.platform/.
How can I solve it?

The existing Eclipse stylesheets just use
#import url("base-stylesheet.css");
for css in the same directory.
For resources you specify the location in the applicationCSSResources property in the product extension point properties:
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
name="%product.name"
application="org.eclipse.e4.ui.workbench.swt.E4Application">
<property
name="applicationCSSResources"
value="platform:/plugin/my.plugin.package.name/images/">
</property>

The blog post "Import CSS files in Eclipse Luna M6" from Lars Vogel seems to imply that the import now works, meaning you need at least an Eclipse 4.4 Luna M6.
Not only that 4.4 M6 release comes with a dark theme for the IDE, it also lists:
CSS includes
CSS files for Eclipse can now include other CSS files via the #import url("platform:/plugin/Bundle-Symbolic-Name/path/file.extension"); statement.
This allows easy reuse of existing style sheets.
For instance (Vogel's post):
In your RCP application, create a /css/default.css file with only one instruction:
#import url(“platform:/plugin/org.eclipse.ui.themes/css/e4-dark.css”);
Add org.eclipse.ui.themes to your RCP product and add the applicationCSS property pointing to platform:/plugin/test/css/default.css in your product extension point.

Related

PhpStorm File Watcher for SCSS not compiling node_modules

I'm working on a custom theme for my local WordPress site. I've set up a File Watcher in PhpStorm that compiles my scss files in myTheme/scss/ to myTheme/style.css.
This works as intended, the variables which I've declared in _variables.scss are able to be used in style.css or any file imported after it.
My problem now is that the #import '~foundation-sites/dist/css/foundation.min.css'; is being compiled as #import '~foundation-sites/dist/css/foundation.min.css'; instead of the actual css content.
I've tried using #import '../node_modules/foundation-sites/dist/css/foundation.min.css'; instead but this compiles the same way.
What am I doing wrong?
.css extension in import statement tells the compiler to generate plain CSS import instead of pulling the contents in; see https://github.com/sass/sass/issues/556#issuecomment-397771726 for reference.
I'd suggest changing your import to
#import '../node_modules/foundation-sites/dist/css/foundation' - this should help.
Note that ~ prefix is a webpack feature SASS compiler is not aware of. So, when using SASS in your file watcher, you have to either change paths to relative or pass --load-path node_modules/ to compiler
I ran into this issue and this solved it for me. Uncheck Track only root files, which is defaultly checked.

Eclipse 4 themes

I am migrating a 3.x eclipse RCP to e4.
I was able to successfully use eclipse's predefined themes. But I have done it by adding an extension to org.eclipse.e4.ui.css.swt.theme and copying all the css and images folder found in org.eclipse.ui.themes to my application.
I am not going to ever modify those themes I copied. So I was wondering if I can use the themes directly without copying the already made css files and images folder. This is also not future proof, if I ever upgrade eclipse platform where there was an update in the themes I would have to recopy the new theme resources.
What is the right way to do things? What is the e4 way?
Based on greg-449 answer I have added the following:
<property
name="applicationCSS"
value="platform:/plugin/com.example.rcp4/css/default.css">
</property>
Where default.css contains:
#import url("platform:/plugin/org.eclipse.ui.themes/css/e4_default_win7.css");
This works just fine. But now I am facing this look:
You can import existing CSS files in to your CSS using #import so you don't need to copy them.
Something like:
#import url("platform:/plugin/greg.music.e4.rcp/css/helvneue.css");
In this platform:/plugin/greg.music.e4.rcp is selecting the plugin containing the css (a plugin with id greg.music.e4.rcp in this case). /css/helvneue.css is the path to the CSS within the plugin.

Bootstrap 3 and Less together

I wanted to use Bootstrap 3 and Less together. Here is what I did:
installed Node.js
installed Less using npm
downloaded bootstrap source (in a different directory than my project's directory)
copied the entire '/less' subfolder to my project's working directory.
created my custom .less file (e.g. styles.less) and included the following:
#import '../less/bootstrap.less';
#import '../less/utilities.less';
compiled in the Node command prompt using: ' lessc styles.less > styles.css '
My question:
Do I now need to only include the compiled styles.css file with my project or do I have to include all the bootstrap components as well?
Also, is this workflow recommended? (I actually read something similar in a smashingmagazine.com article).
PS: Apologies in advance for this silly (I think) question.
Thanks!
If you used
#import "bootstrap.less";
..inside your main less file, then the bootstrap.less will be included during compiletime and will be inside your compiled styles.css.
After your styles.css has been compiled, you only need to include this file into your project.
PS. Also take a look inside your styles.css file, to see what has been compiled inside there. Or play around yourself/experiment. For example, create 2 different less files, #import them inside your main.less, compile and see what happens.

Importing Sass stylesheets from an external directory

I have the following set up:
d:\modules\base - This is where my CSS framework (Inuit CSS) and site theme lives. The idea is for others to be able to use this as an import into their sites main style.scss and write their own styles on top of this.
d:\sites\my-site - As described above, I will import the module\base into my site.
To do this I use
#import "D:\modules\base\style";
Which works... But for other developers, their module mite be on a different drive, or have a different folder structure. So I was wondering if there was any way to do the following:
#import "$module-path\style";
Then they could set their module path themselves in a config file or something similar.
I appreciate there may be other methods to make this easier, e.g. having it all in the same folder, but would be interested if there was a solution to this method.
Thanks
I managed to get around this by making a directory link in d:\sites\my-site
in CMD, type
mklink /D my-link-name D:\modules\base\stylesheets
this creates a link in the directory your in called "my-link-name" and points it to the module.
Then I just include this in my sites style.scss like so:
#import "my-link-name\style";
Just use a relative path to your import, e.g.:
#import '../../base/style';

How to add css to Vaadin / Maven project?

There exists a question at SO about how to add css to Vaadin project. The tip there was to add css at /WEB-INF/VAADIN/themes/ location.
My problem is that Vaadin projects normally have WEB-INF folder under WebContent and now on Maven the similar folder is under webapp. This seems to be causing that my css changes do not take effect.
Also, is it necessary to have the custom css in same sub-structure as the original css? I want to modify table css and don't know if the css needs to be in a specific path.
So how to add the css for table so that also the table is changed, not just that the code builds correctly? :)
Update 1: I could get the following tempalate out with Firebug, but this is closest thing what I get to browser.
< link rel="stylesheet" type="text/css" href="/html/VAADIN/themes/mytheme/styles.css" >
< html >
< head >
< title > < /title >
< /head >
< body onload="javascript:location.replace('/c')" >
< !--The numbers below are used to fill up space so that this works properly in IE.
See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807 for more
information on why this is necessary.
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
-- >
< /body >
< /html >
< /link >
You will probably put your styles.css file in the src/main/webapp/VAADIN/themes/[yourtheme]/ folder and configure Maven to copy everything in src/main/webapp into your WEB-INF. This way your .css file will end up in WEB-INF/VAADIN/themes/[yourtheme]/.
It is strongly recommended to inherit from a theme rather than trying to override the behavior of a default theme.
Then you need to specify your theme name in the application
public void init()
{
setTheme("simplegae");
...
and make your .css file inherit from a theme's css (runo, reindeer, ...).
#import "../reindeer/styles.css";
I have recently put up a sample Vaadin application using Maven which is accessible at this address. It is aimed to work on GAE, but you can check it out from SVN and have a look at what I have done:
svn co http://code.google.com/p/tinywebgears-samples/source/browse/trunk/simplegae/ simplegae
You will probably put your styles.css file in the src/main/webapp/VAADIN/themes/[yourtheme]/ folder and configure Maven to copy everything in src/main/webapp into your WEB-INF. This way your .css file will end up in WEB-INF/VAADIN/themes/[yourtheme]/.
Just a little change :
put your folder in src/main/resources/VAADIN/themes/ instead of src/main/webapp/VAADIN/themes/
I hope it will work for you as it worked for us
Regards Éric
edit : Here an useful link : Deploying a Maven web project on Jetty

Resources