While you certainly can go with a fully manual method like Bennett has suggested, WPILib will take care of most of that for you. This is all that you really need to do for the compressor.
Code:
Compressor compressor = new Compressor(1, 2);
// 1, 2 are locations of your limit switch and compressor relay, respectively
compressor.start();
This will start the compressor and run it until the pressure switch has been hit. It will start back up again once the switch turns off again.
I recommend putting this in your main Robot class, where the compressor is declared as a class variable and you initialize and start in your robotInit() method. You can also create a pneumatics subsystem, and have its default command run the compressor.start() method in the initialize() method.
For operating solenoids, the WPILib documentation has an example, you can find that here:
http://wpilib.screenstepslive.com/s/...ders-solenoids.
If you have any more questions, feel free to ask.