<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="it">
	<id>http://wiki.netsitech.com/index.php?action=history&amp;feed=atom&amp;title=Programmazione%3AJava%2FEclipse_RCP%2FUtilizzo_della_CoolBar</id>
	<title>Programmazione:Java/Eclipse RCP/Utilizzo della CoolBar - Cronologia</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.netsitech.com/index.php?action=history&amp;feed=atom&amp;title=Programmazione%3AJava%2FEclipse_RCP%2FUtilizzo_della_CoolBar"/>
	<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;action=history"/>
	<updated>2026-05-04T15:11:23Z</updated>
	<subtitle>Cronologia della pagina su questo sito</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2763&amp;oldid=prev</id>
		<title>Rimondini il 08:26, 14 apr 2008</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2763&amp;oldid=prev"/>
		<updated>2008-04-14T08:26:16Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;it&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versione meno recente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Versione delle 08:26, 14 apr 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Riga 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Riga 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Programmazione:Java/Eclipse_RCP|&amp;lt;&amp;lt; Back to Eclipse RCP]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=CoolBarManager=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=CoolBarManager=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Questa è una classe di esempio per la gestione della CoolBar.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Questa è una classe di esempio per la gestione della CoolBar.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rimondini</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2654&amp;oldid=prev</id>
		<title>Rimondini: ha spostato Programmazione:Java/Utilizzo della CoolBar a Programmazione:Java/Eclipse RCP/Utilizzo della CoolBar</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2654&amp;oldid=prev"/>
		<updated>2008-04-14T08:04:53Z</updated>

		<summary type="html">&lt;p&gt;ha spostato &lt;a href=&quot;/index.php/Programmazione:Java/Utilizzo_della_CoolBar&quot; class=&quot;mw-redirect&quot; title=&quot;Programmazione:Java/Utilizzo della CoolBar&quot;&gt;Programmazione:Java/Utilizzo della CoolBar&lt;/a&gt; a &lt;a href=&quot;/index.php/Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&quot; title=&quot;Programmazione:Java/Eclipse RCP/Utilizzo della CoolBar&quot;&gt;Programmazione:Java/Eclipse RCP/Utilizzo della CoolBar&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;it&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versione meno recente&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Versione delle 08:04, 14 apr 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;it&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(Nessuna differenza)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Rimondini</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2152&amp;oldid=prev</id>
		<title>Rimondini il 09:53, 12 nov 2007</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/Eclipse_RCP/Utilizzo_della_CoolBar&amp;diff=2152&amp;oldid=prev"/>
		<updated>2007-11-12T09:53:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nuova pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=CoolBarManager=&lt;br /&gt;
Questa è una classe di esempio per la gestione della CoolBar.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;NB: per essere il più sintetico possibile questo esempio non segue le best practice ^^&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Definizione classe==&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
public class CoolBarManager {&lt;br /&gt;
   FormToolkit ft;&lt;br /&gt;
   &lt;br /&gt;
   public CoolBarManager() {&lt;br /&gt;
      ft = new FormToolkit(PlatformUI.getWorkbench().getDisplay());&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   public void create(Composite parent) {&lt;br /&gt;
       // Expanded function after....&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   protected void setCoolItemSize(final CoolItem coolItem) {&lt;br /&gt;
       // Expanded function after....&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   protected String shortenText(String textValue, ToolItem item) {&lt;br /&gt;
       // Expanded function after....&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   protected int getMaxWidth(Image image) {&lt;br /&gt;
      return image.getBounds().width * 5;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Funzione di creazione della CoolBar==&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
public void create(Composite parent) {&lt;br /&gt;
   // Create Coolbar composite container&lt;br /&gt;
   Composite bar = ft.createComposite(parent);&lt;br /&gt;
   bar.setLayout(new FormLayout());&lt;br /&gt;
&lt;br /&gt;
   // Create CoolBar control&lt;br /&gt;
   CoolBar coolbar = new CoolBar(bar, SWT.FLAT);&lt;br /&gt;
   fd = new FormData();&lt;br /&gt;
   fd.top = new FormAttachment(0, 0);&lt;br /&gt;
   fd.left = new FormAttachment(0, 0);&lt;br /&gt;
   fd.right = new FormAttachment(100, 0);&lt;br /&gt;
   coolbar.setLayoutData(fd);&lt;br /&gt;
&lt;br /&gt;
   // Create ToolBar control&lt;br /&gt;
   ToolBar tb = new ToolBar(coolbar, SWT.HORIZONTAL | SWT.RIGHT);&lt;br /&gt;
   tb.setFont(JFaceResources.getFont(&amp;quot;org.eclipse.ui.smallFont&amp;quot;)); // set small eclipse font as toolbar font&lt;br /&gt;
&lt;br /&gt;
   // Create CoolItem control&lt;br /&gt;
   CoolItem ci = new CoolItem(coolbar, SWT.DROP_DOWN);&lt;br /&gt;
   ci.setControl(tb);&lt;br /&gt;
   ci.addSelectionListener(new CoolItemSelectionListener());&lt;br /&gt;
&lt;br /&gt;
   parent.addListener(SWT.Resize, new Listener() {&lt;br /&gt;
      public void handleEvent(Event event) {&lt;br /&gt;
         setCoolItemSize(ci);&lt;br /&gt;
      }&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   setCoolItemSize(ci);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Funzione di calcolo della dimensione del CoolItem==&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
protected void setCoolItemSize(final CoolItem coolItem) {&lt;br /&gt;
   // there is no coolItem when the bar is on the left&lt;br /&gt;
   int rowHeight = 0;&lt;br /&gt;
   ToolItem[] toolItems = tb.getItems();&lt;br /&gt;
   for (int i = 0; i &amp;lt; toolItems.length; i++) {&lt;br /&gt;
      rowHeight = Math.max(rowHeight, toolItems[i].getBounds().height);&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   Rectangle area = coolbar.getClientArea();&lt;br /&gt;
   int rows = rowHeight &amp;lt;= 0 ? 1 : (int) Math.max(1, Math.floor(area.height / rowHeight));&lt;br /&gt;
   if (rows == 1 || (tb.getStyle() &amp;amp; SWT.WRAP) == 0) {&lt;br /&gt;
      Point p = tb.computeSize(SWT.DEFAULT, SWT.DEFAULT);&lt;br /&gt;
      coolItem.setSize(coolItem.computeSize(p.x, p.y));&lt;br /&gt;
      return;&lt;br /&gt;
   }&lt;br /&gt;
   Point offset = coolItem.computeSize(0, 0);&lt;br /&gt;
   Point wrappedSize = tb.computeSize(area.width - offset.x, SWT.DEFAULT);&lt;br /&gt;
   int h = rows * rowHeight;&lt;br /&gt;
   int w = wrappedSize.y &amp;lt;= h ? wrappedSize.x : wrappedSize.x + 1;&lt;br /&gt;
   coolItem.setSize(coolItem.computeSize(w, h));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Funzione di troncamento delle descrizioni troppo lunghe==&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
protected String shortenText(String textValue, ToolItem item) {&lt;br /&gt;
   if (textValue == null || item == null || item.isDisposed()) {&lt;br /&gt;
      return null;&lt;br /&gt;
   }&lt;br /&gt;
   String returnText = textValue;&lt;br /&gt;
   String originalText = textValue;&lt;br /&gt;
   GC gc = new GC(item.getParent());&lt;br /&gt;
   int maxWidth = getMaxWidth(item.getImage());&lt;br /&gt;
   if (gc.textExtent(textValue).x &amp;gt;= maxWidth) {&lt;br /&gt;
      for (int i = textValue.length(); i &amp;gt; 0; i--) {&lt;br /&gt;
         String test = textValue.substring(0, i);&lt;br /&gt;
         test = test + ellipsis;&lt;br /&gt;
         if (gc.textExtent(test).x &amp;lt; maxWidth) {&lt;br /&gt;
            returnText = test;&lt;br /&gt;
            break;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      if (item.getToolTipText() == null) {&lt;br /&gt;
         item.setToolTipText(originalText);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   gc.dispose();&lt;br /&gt;
   return returnText;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Listener di visualizzazione menu contestuale==&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
class CoolItemSelectionListener extends SelectionAdapter {&lt;br /&gt;
   private Menu menu = null;&lt;br /&gt;
&lt;br /&gt;
   public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
      /**&lt;br /&gt;
       * A selection event will be fired when the cool item is selected by&lt;br /&gt;
       * its gripper or if the drop down arrow (or 'chevron') is selected.&lt;br /&gt;
       * Examine the event detail to determine where the widget was&lt;br /&gt;
       * selected.&lt;br /&gt;
       */&lt;br /&gt;
      if (event.detail == SWT.ARROW) {&lt;br /&gt;
         /*&lt;br /&gt;
          * If the popup menu is already up (i.e. user pressed arrow&lt;br /&gt;
          * twice), then dispose it.&lt;br /&gt;
          */&lt;br /&gt;
         if (menu != null) {&lt;br /&gt;
            menu.dispose();&lt;br /&gt;
            menu = null;&lt;br /&gt;
            return;&lt;br /&gt;
         }&lt;br /&gt;
         /*&lt;br /&gt;
          * Get the cool item and convert its bounds to display&lt;br /&gt;
          * coordinates.&lt;br /&gt;
          */&lt;br /&gt;
         CoolItem coolItem = (CoolItem) event.widget;&lt;br /&gt;
         Rectangle itemBounds = coolItem.getBounds();&lt;br /&gt;
         itemBounds.width = event.x - itemBounds.x;&lt;br /&gt;
         Point pt = coolbar.toDisplay(new Point(itemBounds.x, itemBounds.y));&lt;br /&gt;
         itemBounds.x = pt.x;&lt;br /&gt;
         itemBounds.y = pt.y;&lt;br /&gt;
&lt;br /&gt;
         /* Get the toolbar from the cool item. */&lt;br /&gt;
         ToolBar toolBar = (ToolBar) coolItem.getControl();&lt;br /&gt;
         ToolItem[] tools = toolBar.getItems();&lt;br /&gt;
         int toolCount = tools.length;&lt;br /&gt;
&lt;br /&gt;
         /*&lt;br /&gt;
          * Convert the bounds of each tool item to display coordinates,&lt;br /&gt;
          * and determine which ones are past the bounds of the cool&lt;br /&gt;
          * item.&lt;br /&gt;
          */&lt;br /&gt;
         int i = 0;&lt;br /&gt;
         while (i &amp;lt; toolCount) {&lt;br /&gt;
            Rectangle toolBounds = tools[i].getBounds();&lt;br /&gt;
            pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y));&lt;br /&gt;
            toolBounds.x = pt.x;&lt;br /&gt;
            toolBounds.y = pt.y;&lt;br /&gt;
            Rectangle intersection = itemBounds.intersection(toolBounds);&lt;br /&gt;
            if (!intersection.equals(toolBounds)) {&lt;br /&gt;
               break;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
         }&lt;br /&gt;
         /*&lt;br /&gt;
          * Create a pop-up menu with items for each of the hidden&lt;br /&gt;
          * buttons.&lt;br /&gt;
          */&lt;br /&gt;
         menu = new Menu(coolbar);&lt;br /&gt;
         for (int j = i; j &amp;lt; toolCount; j++) {&lt;br /&gt;
            ToolItem tool = tools[j];&lt;br /&gt;
            MenuItem menuItem = new MenuItem(menu, SWT.NONE);&lt;br /&gt;
            menuItem.setImage(tool.getImage());&lt;br /&gt;
            String text = tool.getToolTipText();&lt;br /&gt;
            if (text != null) {&lt;br /&gt;
               menuItem.setText(text);&lt;br /&gt;
            }&lt;br /&gt;
            menuItem.setData(tool.getData());&lt;br /&gt;
            menuItem.addListener(SWT.Selection, new Listener() {&lt;br /&gt;
               public void handleEvent(Event event) {&lt;br /&gt;
                  processButton(event);&lt;br /&gt;
               }&lt;br /&gt;
            });&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
         /*&lt;br /&gt;
          * Display the pop-up menu at the lower left corner of the arrow&lt;br /&gt;
          * button. Dispose the menu when the user is done with it.&lt;br /&gt;
          */&lt;br /&gt;
         pt = coolbar.toDisplay(new Point(event.x, event.y));&lt;br /&gt;
         menu.setLocation(pt.x, pt.y);&lt;br /&gt;
         menu.setVisible(true);&lt;br /&gt;
         while (menu != null &amp;amp;&amp;amp; !menu.isDisposed() &amp;amp;&amp;amp; menu.isVisible()) {&lt;br /&gt;
            if (!PlatformUI.getWorkbench().getDisplay().readAndDispatch()) {&lt;br /&gt;
               PlatformUI.getWorkbench().getDisplay().sleep();&lt;br /&gt;
            }&lt;br /&gt;
         }&lt;br /&gt;
         if (menu != null) {&lt;br /&gt;
            menu.dispose();&lt;br /&gt;
            menu = null;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rimondini</name></author>
		
	</entry>
</feed>