<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog d&#039;AIT YAHIA Idir &#187; Java</title>
	<atom:link href="https://blog.developpez.com/aityahia/pcategory/java/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/aityahia</link>
	<description></description>
	<lastBuildDate>Sat, 20 Jul 2013 20:52:44 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Mise en œuvre d’une barre d’état d’une application RCP Eclipse 4</title>
		<link>https://blog.developpez.com/aityahia/p12132/java/mise-en-oeuvre-dune-barre-detat-dune-application-rcp-eclipse-4</link>
		<comments>https://blog.developpez.com/aityahia/p12132/java/mise-en-oeuvre-dune-barre-detat-dune-application-rcp-eclipse-4#comments</comments>
		<pubDate>Fri, 19 Jul 2013 00:13:28 +0000</pubDate>
		<dc:creator><![CDATA[aityahia]]></dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/aityahia/?p=25</guid>
		<description><![CDATA[Dans cet article nous allons voir comment, utiliser le service IEventBroker dans une application Eclipse 4 RCP pour que vos composants puissent communiquer entre eux. A cet effet nous allons prendre l&#8217;exemple un éditeur de texte doté d’une barre d’état qui affichera la position courante du curseur. Nous allons supposer que vous avez installé Eclipse 4.3 (Kepler) ainsi que e4 tools, si ce n’est pas le cas les procédures d’installations sont décrites dans l’article suivant [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Dans cet article nous allons voir comment, utiliser le service IEventBroker dans une application Eclipse 4 RCP pour que vos composants puissent communiquer entre eux.</p>
<p>A cet effet nous allons prendre l&rsquo;exemple un éditeur de texte doté d’une barre d’état qui affichera la position courante du curseur.<br />
<span id="more-25"></span><br />
Nous allons supposer que vous avez  installé Eclipse 4.3 (Kepler) ainsi que e4 tools, si ce n’est pas le cas les procédures d’installations sont décrites dans l’article suivant :</p>
<p><a href="http://aityahia.developpez.com/tutoriels/java/eclipse/e4-rcp/" title="Tutoriel sur la construction d'applications Eclipse RCP basées sur Eclipse 4" target="_blank">Tutoriel sur la construction d&rsquo;applications Eclipse RCP basées sur Eclipse 4</a></p>
<p>Nous n’allons pas nous pencher sur la création d’application Eclipse 4 ou sur l’ajout de composants au modèle d’application, tout est bien expliqué dans le tutoriel sus-cité.</p>
<p>Créez un nouveau projet Eclipse 4, veuillez consulter l’article ci-dessus  pour  voir les étapes à suivre.<br />
Ajouter un PartStak à votre TrimedWindow et ajouter une Input Part au PartStak, avec les paramètres suivant :</p>
<p><strong>Id :</strong> <em>dz.iaityahia.example.texteditor.inputpart.editor</em><br />
<strong>Label :</strong> <em>Editeur </em></p>
<p>Ajoutez un Window Trim a votre TrimBars avec l’option Side Bottom pour que la barre se positionne en bas de votre fenêtre, ça sera notre barre d&rsquo;état.</p>
<p>Ajoutez une ToolBar a votre WindowTrim et un ToolControl  a la ToolBar que vous venez d’ajouter, avec dz.iaityahia.example.texteditor.toolcontrol.positionstatus comme Id.<br />
En final votre modèle d’application devra ressembler à ce qui suit :<br />
  <a href="http://blog.developpez.com/aityahia/files/2013/07/Application-Model.jpg"><img src="http://blog.developpez.com/aityahia/files/2013/07/Application-Model-243x300.jpg" alt="Application Model" width="243" height="300" class="aligncenter size-medium wp-image-27" /></a></p>
<p>Afin de pouvoir invoquer IEventBroker, ajouter la dépendance au package <em>org.eclipse.e4.core.services.events</em></p>
<p>Créez maintenant les classes suivantes, nous verrons plus loin chaque classe en détail </p>
<p><em>EditorView</em> : Classe de notre Inupt Part<br />
<em>CursorPosition</em> : Modele objet qui va contenir la position du curseur<br />
<em>CursorPositionStatus</em> : Classe du ToolControl de notre barre d’état.</p>
<p>Connectez la Classe EditorView à votre Input Part, en cliquant sur le bouton <strong>find</strong>adjacent au champs Class URI,<br />
Notez que vous pouvez créer directement votre classe en cliquant sur le lien Class URI.<br />
Connectez la classe CursorPositionStatus  a votre ToolControl de la même manière.<br />
Modifiez maintenant le code de vos classes comme suit :</p>
<p><strong>Classe CursorPosition</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">dz.iaityahia.example.texteditor</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.MessageFormat</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* @author iaityahia<br />
&nbsp;* &nbsp;cette classe définie le modèle object de la <br />
&nbsp;* &nbsp;position du curseur<br />
&nbsp;*<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CursorPosition <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> column<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//colonne du curseur</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> line<span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">//ligne du curseur</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a> mf<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ligne : {0} | Colonne : {1}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Constructeur de la classe<br />
&nbsp; &nbsp; &nbsp;* avec l'initialisation de la ligne et la colonne<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> CursorPosition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;column <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;line <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Renvoie la chaine de la position suivant le modèle <br />
&nbsp; &nbsp; &nbsp;* definie dans mf<br />
&nbsp; &nbsp; &nbsp;* @return position sous forme de ligne colonne<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args <span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>line,column<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> mf.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Dans cette classe définissons le l&rsquo;objet qui va contenir les informations de la position du curseur, nous avons aussi redéfini la méthode <em>toString</em>  pour quelle renvoi la position sous fomrme de chaine &laquo;&nbsp;Ligne : 0 | Colonne : 0&Prime;</p>
<p><strong>Classe EditorView</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* @author iaityahia <br />
&nbsp;* <br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">dz.iaityahia.example.texteditor</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PreDestroy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.e4.core.services.events.IEventBroker</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.e4.ui.di.Focus</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.SWT</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.custom.StyledText</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Composite</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Event</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Listener</span><span style="color: #339933;">;</span> <br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EditorView <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Inject IEventBroker eventBroker<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nous injections IEventBroker</span><br />
&nbsp; &nbsp; CursorPosition pos <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; StyledText text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> EditorView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Création du contenu de la part<br />
&nbsp; &nbsp; &nbsp;* @param parent<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> createPartControl<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomposite+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Composite</span></a> parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// création de l'objet qui va contenir la position du curseur &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CursorPosition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// création de l'éditeur de texte</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;text <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StyledText <span style="color: #009900;">&#40;</span>parent, SWT.<span style="color: #006633;">BORDER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// création du gestionaire qui va récupérer la position du curseur</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//et enrgistrer l'évenement </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Listener listener <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Listener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> handleEvent<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Event</span></a> arg0<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> caretOffset <span style="color: #339933;">=</span> text.<span style="color: #006633;">getCaretOffset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #006633;">line</span> <span style="color: #339933;">=</span> text.<span style="color: #006633;">getLineAtOffset</span><span style="color: #009900;">&#40;</span>caretOffset<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #006633;">column</span> <span style="color: #339933;">=</span> &nbsp;caretOffset <span style="color: #339933;">-</span> text.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getOffsetAtLine</span><span style="color: #009900;">&#40;</span>pos.<span style="color: #006633;">line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Incrémenter la ligne et la colonne, l'indexation commence à zéro</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #006633;">line</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #006633;">column</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Enregistrement de la position avec la clé CURSOR_POSITION</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventBroker.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CURSOR_POSITION&quot;</span>, pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Ajout du gestionnaire aux événements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// KeyUp et MouseUp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.<span style="color: #006633;">addListener</span><span style="color: #009900;">&#40;</span>SWT.<span style="color: #006633;">KeyUp</span>, listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.<span style="color: #006633;">addListener</span><span style="color: #009900;">&#40;</span>SWT.<span style="color: #006633;">MouseUp</span>, listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @PreDestroy<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> preDestroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Focus<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onFocus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; text.<span style="color: #006633;">setFocus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Dans cette classe nous Injecton le service IEventBroker et nous définissons le contenu de notre Part (view) via la méthode createPartControl annotée avec l&rsquo;annotation @PostConstruct.</p>
<p>l&rsquo;injection du service IEventBroker récupère l&rsquo;instance existante dans le contexte d&rsquo;application, si elle n’existe une nouvelle instance sera créée.</p>
<p>Dans un éditeur de texte la position du curseur peut être changée lorsque l&rsquo;utilisateur relâche la sourie ou une touche de clavier alors que l&rsquo;éditeur détient le focus, c&rsquo;est pour cette raison que nous avons créée un Listener commun pour les événements KeyUp et MouseUp.</p>
<p>Le service IEventBroker nous offre la possibilité d&rsquo;envoyer les donner de deux manières, synchrone avec la méthode send et asynchrone avec la méthode post, dans notre cas nous optons pour un envoie asynchrone.</p>
<p><strong>Classe CursorPositionStatus</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Cette classe construit le label qui servira pour l'affichage <br />
&nbsp;* de la position du curseur et implément la méthode qui est chargée de recevoir<br />
&nbsp;* les évenements émis depuis l'éditeur &nbsp;<br />
&nbsp;* <br />
&nbsp;* @author iaityahia<br />
&nbsp;*<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">dz.iaityahia.example.texteditor</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.e4.core.di.annotations.Optional</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.e4.ui.di.UIEventTopic</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.SWT</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.layout.GridData</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.layout.GridLayout</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Composite</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Label</span><span style="color: #339933;">;</span><br />
<br />
<br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CursorPosStatus <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alabel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Label</span></a> posLabel<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Création du Label<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* @param parent<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> postConstruct<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomposite+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Composite</span></a> parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agridlayout+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">GridLayout</span></a> layout <span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agridlayout+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">GridLayout</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; layout.<span style="color: #006633;">marginHeight</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span>layout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;posLabel <span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alabel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Label</span></a><span style="color: #009900;">&#40;</span>parent,SWT.<span style="color: #006633;">NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GridData gd <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GridData<span style="color: #009900;">&#40;</span>GridData.<span style="color: #006633;">BEGINNING</span>,GridData.<span style="color: #006633;">CENTER</span>,<span style="color: #000066; font-weight: bold;">true</span>,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gd.<span style="color: #006633;">widthHint</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gd.<span style="color: #006633;">horizontalIndent</span> <span style="color: #339933;">=</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;posLabel.<span style="color: #006633;">setLayoutData</span><span style="color: #009900;">&#40;</span>gd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Méthode qui reçoit les évenements<br />
&nbsp; &nbsp; &nbsp;* @param pos<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; @Inject @Optional<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> eventReceived<span style="color: #009900;">&#40;</span>@UIEventTopic<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;CURSOR_POSITION&quot;</span><span style="color: #009900;">&#41;</span> CursorPosition pos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; posLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>pos.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Dans cette classe nous concevons le Label qui va se charger d&rsquo;afficher la position du curseur, avec la méthode <em>postConstruct</em>, également nous implémentons la méthode qui va nous permettre de recevoir les données émises via le service IEventBroker, la méthode se distingue avec l’annotation @UIEventTopic, notez qu&rsquo;il est très important d&rsquo;annoter votre méthode avec @Optional sinon Eclipse va lever des exceptions.</p>
<p>En final nous aurons quelque chose qui ressemble a capture suivante, si vous essayez de modifier le contenu de l&rsquo;éditeur vous allez remarquer que la position du curseur s&rsquo;affiche dans notre barre d&rsquo;état.</p>
<p><img src="http://blog.developpez.com/aityahia/files/2013/07/TextEditor-1.jpg" alt="TextEditor" class="aligncenter" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MessageFormat mettre les paramètres entre quotes</title>
		<link>https://blog.developpez.com/aityahia/p12121/java/messageformat-mettre-les-parametres-entre-quotes</link>
		<comments>https://blog.developpez.com/aityahia/p12121/java/messageformat-mettre-les-parametres-entre-quotes#comments</comments>
		<pubDate>Mon, 15 Jul 2013 00:08:24 +0000</pubDate>
		<dc:creator><![CDATA[aityahia]]></dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/aityahia/?p=18</guid>
		<description><![CDATA[Même si l’interface PreparedStatement existe pour des besoins particuliers vous pouvez être amené à utiliser la classe MessageFormat pour construire une requête SQL , si par exemple vous voulez mettre entre quotes les paramètres de la chaine résultante avec le code ci-dessous qui semble cohérent MessageFormat str = new MessageFormat&#40;&#34;SELECT * FROM mytable WHERE mydate BETWEEN ‘{0}’ AND ‘{1}’&#34;&#41; ; Object&#91;&#93; args = &#123;&#34;2013-07-01&#34;,&#34;2013-07-31&#34;&#125;; String query = str.format&#40;args&#41; ; Vous allez remarquer que cela ne [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Même si l’interface PreparedStatement existe pour des besoins particuliers vous pouvez être amené  à utiliser la classe MessageFormat pour construire une  requête SQL , si par exemple vous voulez mettre entre quotes  les paramètres de la chaine résultante avec le code ci-dessous qui semble cohérent</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a> str <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM mytable WHERE mydate BETWEEN ‘{0}’ AND ‘{1}’&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;2013-07-01&quot;</span>,<span style="color: #0000ff;">&quot;2013-07-31&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> query <span style="color: #339933;">=</span> str.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span></div></div>
<p>Vous allez remarquer que cela ne fonctionne pas et que la méthode ne reconnait pas les paramètres  en tant que tel, si vous affichez la chaine avec System.out.println vous aurez comme résultat la chaine suivante :</p>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SELECT"><span style="color: #990099; font-weight: bold;">SELECT</span></a> <span style="color: #CC0099;">*</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=FROM"><span style="color: #990099; font-weight: bold;">FROM</span></a> mytable <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=WHERE"><span style="color: #990099; font-weight: bold;">WHERE</span></a> mydate <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">BETWEEN</span></a> ‘<span style="color: #FF00FF;">&#123;</span><span style="color: #008080;">0</span><span style="color: #FF00FF;">&#125;</span>’ <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">AND</span></a> ‘<span style="color: #FF00FF;">&#123;</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#125;</span>’</div></div>
<p>Hors que ce n’est pas le résultat souhaité, pour résoudre le problème,il vous suffit de doubler les quotes comme ceci :</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a> str <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM mytable WHERE mydate BETWEEN ''{0}'' AND ''{1}'' &quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;2013-07-01&quot;</span>,<span style="color: #0000ff;">&quot;2013-07-31&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> query <span style="color: #339933;">=</span> str.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
