java.net member

Rechercher dans ce site

Adding images (or any other resources) to Eclipse cheat sheets

>> 13 April 2011

Sometimes it's useful to use images inside cheat sheets. There is one problem, the editor does not allow including images, or any other resources. This tutor describes how to do such things.

This is an excerpt of my little ebook Steps 2 Eclipse Plug-in. This book describes, how my  plug-in for Eclipse: XML Parsing in Java Kit, was written.

If you are interested in this ebook, and/or you want to help the author, please think to buy it.

Adding images or other resources is done using an ItemExtension, this will use a class that handles drawing the images, for instance. The class must implements : org.eclipse.ui.cheatsheets.AbstractItemExtensionElement. This class is associated with an attribute that can be used with an item in your cheat sheet


Adding an extension
Extension tab -> Click on Add button





Select org.eclipse.ui.cheatsheets.cheatSheetItemExtension from the list.
Finish




This will add an extension-point



Right click on the newly created extension-point -> New -> ItemExtension



1. Give a name of your choice to the attribute ItemAttribut (this attribute will be used within  an Item tag, in a cheat sheet later)

2. Give a name (preferably full qualified name) to the class that will handle this attribute

3. Click on class link will open a New Java Class dialog for creating the class




The New Java Class dialog is opened
The class's name and its super class are entered automatically by Eclipse
Click on Finish


This class in one of its method createControl(Composite) we add a control  (for instance a label with an image, to its Composite argument, like the following:

    //create a Label
    Label msg=new Label(composite, SWT.BORDER);
    msg.setText("This is a label");

ItemExtensionHandler
Must have a constructor with a String (done automatically by eclipse)

public class ItemExtensionHandler extends AbstractItemExtensionElement {
private String attributeValue;
    public ItemExtensionHandler(String attributeName) {
        
        super(attributeName);
       
    }

    @Override
    public void handleAttribute(String attributeValue) {
     
        this.attributeValue=attributeValue;

    }

    @Override
    public void createControl(Composite composite) {

        //get the image from ImageRegistry    
        AbstractUIPlugin plugin=Activator.getDefault();
        ImageRegistry reg=plugin.getImageRegistry();
        Image logo=reg.get(Activator.LOGO_ID);
    
          //add a label to composite
          Label label=new Label(composite,SWT.BORDER);
         //Use the label to display the image
         label.setImage(logo);

    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub

    }

}
plugin.xml
When the extension was added in the plug-in editor, information about this extension was written in this file, with the attribute name and its handler class.

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.editors.templates">
      <include
            file="xml_templates_en_1.5.xml">
      </include>
   </extension>
   <extension
         point="org.eclipse.ui.cheatsheets.cheatSheetContent">
      <category
            id="com.java_javafx.eclipse_plugin.category1"
            name="com.java_javafx.eclipse_plugin.kaesar_cheatsheets">
      </category>
   </extension>
   <extension
         point="org.eclipse.ui.cheatsheets.cheatSheetItemExtension">
      <itemExtension
            class="ItemExtensionHandler"
            itemAttribute="myAtt">
      </itemExtension>
   </extension>

</plugin>



Add the attribute to a cheat sheet
The ItemExtension handler class defined above, is associated with an attribute. Its name was entered in ItemAttribute. We are going to use this item's attribute in a cheat sheet. This attribute will be replaced, by whatever we want to display in createControl(Composite) method of the handler class



Let's create a new cheat sheet to hold the image (you can use the image in any other cheat sheet, alongside a text, using this attribute)

Create a new cheat sheet to hold an image
In composite cheat sheet editor -> click on Add Task
Give the task any Name. Click on Path link to open new simple cheat sheet dialog



Give the new file a name in File name, with .xml extension.
Finish
This will open the simple cheat sheet editor




Give a name to this cheat sheet
Click on item to change its name in Title



Click on Source tab. This will open an editor with the source of the cheat sheet .xml file



Using the item's attribut

Use after any item's title the ItemAttribute's name entered when defining ItemExtension. You can give this attribute any value. This value can be obtained in the handler class


cheatsheet_with_logo.xml

<?xml version="1.0" encoding="UTF-8"?>
<cheatsheet
      title="Cheat sheet with logo">
   <intro>
      <description>
         <b>Body</b>
      </description>
   </intro>
   <item
         title="logo" myAtt="value_of_my_attribute">
      <description>
         
      </description>
   </item>
</cheatsheet>


Give it a try

In MANIFEST.MF editor (click on META-INF/MANIFEST.MF in Package Explorer)
Select Overview tab
Under Testing
Click on Launch an Eclipse application link





A new instance of Eclipse is launched. Click on Workbench


Click on Help menu -> Cheat Sheets


  Enjoy !

Read more...

Analyser et traiter des documents XML en Java avec XML Parsing in Java Kit – Plug-in D'Eclipse

>> 06 April 2011

XML Parsing in Java Kit (English)

XML Parsing in Java Kit v2.0.0.beta_2i est un logiciel gratuit, diffusé sous la licence GPL

Téléchargez le plug-in ici

Le plug-in est compatible avec Eclipse (3.6 ou supérieure). Il est composé de trois parties :



Cheat sheets (feuilles de triche) :

Un petit tutoriel sur le parsing de document XML (analyse et traitement), avec une description du parser DOM, la validation de documents, l'utilisation de XPath, référence de caractères, les entités prédéfinies, etc. Avec un exemple interactif de l'utilisation des expressions XPath



Visual XPath
Un visualiseur d'expression XPath. Chargez un fichier .xml depuis votre disque dur (un exemple est fourni aussi). Entrez une expression XPath, puis un clic sur évaluer. Les parties concernées dans le document XML sont surlignées.



Templates ou modèles XML
Quelques modèles prêts à l'emploi, dans vos programmes Java, quand vous programmez des fonctionnalités de traitement de documents XML



Installation :

Télécharger le plug-in ici. Décompressez le fichier .zip. Ceci donne un dossier plugins.

Dans ce dossier i l ya deux fichier .jar

  1. Fermez Eclipse
  2. Copiez les deux fichier .jar du dossier plugins vers le dossier dropins situé sous le dossier d'installation d'Eclipse
  3. Relancer Eclipse

Utilisation des cheat sheets

Le menu Help dans Eclipse -> Cheat Sheets



Un clic sur "Kaesar ALNIJRES – XML Parsing in Java"
Sélectionnez  Parsing XML in Java -> OK




Expression XPath – exemple interactif

Dans cet exemple quelques expressions sont prédéfinies permettant de visualiser leurs résultats. Sélectionnez une expression dans la liste, les parties concernées sont surlignées.



Utilisation de Visual XPath

Pour ouvrir l'outil -> un clic sur son icône dans la barre d'outils d'Eclipse



L'utilisation de cet outil est hyper simple. In suffit d'entrer une expression XPath, puis un clic sur évaluer. Si l'expression est une bonne expression XPath, les parties concernées sont surlignées. Il est possible de travailler avec n'importe quel fichier .xml sur votre disque dur. Utilisez pour cela choisir un fichier.



Utilisation de modèles Java (templates)

Dans un fichier .java -> entrez xml -> puis CTRL+Espace -> sélectionnez un modèle


Le modèle sélectionné est inséré dans le code.

Read more...

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP