Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 194109 Details for
Bug 342771
Support "image+label" hint for when actions are presented in a toolbar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch update #3
bug342771_patch_3.txt (text/plain), 31.24 KB, created by
Greg Amerson
on 2011-04-26 17:13:09 EDT
(
hide
)
Description:
Patch update #3
Filename:
MIME Type:
Creator:
Greg Amerson
Created:
2011-04-26 17:13:09 EDT
Size:
31.24 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.sapphire.doc >Index: html/releases/0.3/index.html >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.doc/html/releases/0.3/index.html,v >retrieving revision 1.15 >diff -u -r1.15 index.html >--- html/releases/0.3/index.html 26 Apr 2011 04:31:38 -0000 1.15 >+++ html/releases/0.3/index.html 26 Apr 2011 21:09:46 -0000 >@@ -33,6 +33,7 @@ > <li><a href="#image-el">Image Expressions</a></li> > <li><a href="#ancestor-access">Ancestor Access</a></li> > <li><a href="#with">Improved With Directive Presentation</a></li> >+ <li><a href="#action-hints">Presentation Hints for Actions</a></li> > </ol> > </ol> > >@@ -533,6 +534,34 @@ > > <p style="margin-left: 20px;"><img src="images/with-4.png"/></p> > >+<h2><a name="action-label-el">Presentation Hints for Actions</a></h2> >+ >+<p>Presentation hints for Actions can now be specified in the sapphire UI definition files. For actions use the "style" hint and provide one of 3 possible style hint values:</p> >+ >+<table> >+<tr><td>image</td><td>Only image is rendered.</td></tr> >+<tr><td>image+text</td><td>Text will be rendered to the right of the image.</td></tr> >+<tr><td>image</td><td>Only text is rendered.</td></tr> >+</table> >+ >+<p style="margin-left: 20px;"><b>Example</b></p> >+ >+<p style="margin-left: 20px;">This following is the actual action definition for a new action added to the Sapphire.EditorPage context of a form editor. </p> >+ >+<pre class="source-code"><code> >+<action> >+ <id>Sapphire.Gallery.Open.Homepage</id> >+ <label>Sapphire Homepage</label> >+ <image>images/web.png</image> >+ <description>Open Sapphire project homepage</description> >+ <context>Sapphire.EditorPage</context> >+ <hint> >+ <name>style</name> >+ <value>image+text</value> >+ </hint> >+</action> >+</code></pre> >+ > <br/><br/> > > </body> >#P org.eclipse.sapphire.samples >Index: sdef/GalleryEditor.sdef >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.samples/sdef/GalleryEditor.sdef,v >retrieving revision 1.27 >diff -u -r1.27 GalleryEditor.sdef >--- sdef/GalleryEditor.sdef 21 Apr 2011 19:09:41 -0000 1.27 >+++ sdef/GalleryEditor.sdef 26 Apr 2011 21:09:47 -0000 >@@ -25,6 +25,7 @@ > <bundle>org.eclipse.sapphire.samples</bundle> > <package>org.eclipse.sapphire.samples.gallery</package> > <package>org.eclipse.sapphire.samples.gallery.internal</package> >+ <package>org.eclipse.sapphire.samples.gallery.ui</package> > </import> > > <documentation> >@@ -1427,6 +1428,23 @@ > </node> > </node> > </root-node> >+ <action> >+ <id>Sapphire.Gallery.Open.Homepage</id> >+ <label>Sapphire Homepage</label> >+ <image>images/web.png</image> >+ <description>Open Sapphire project homepage</description> >+ <context>Sapphire.EditorPage</context> >+ <hint> >+ <name>style</name> >+ <value>image+text</value> >+ </hint> >+ </action> >+ <action-handler> >+ <action>Sapphire.Gallery.Open.Homepage</action> >+ <id>Sapphire.Gallery.Open.Homepage</id> >+ <label>Sapphire Homepage</label> >+ <impl>OpenHomepageActionHandler</impl> >+ </action-handler> > </editor-page> > <import> > <bundle>org.eclipse.sapphire.workspace.ui</bundle> >Index: src/org/eclipse/sapphire/samples/gallery/ui/OpenHomepageActionHandler.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/gallery/ui/OpenHomepageActionHandler.java >diff -N src/org/eclipse/sapphire/samples/gallery/ui/OpenHomepageActionHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/gallery/ui/OpenHomepageActionHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,59 @@ >+/****************************************************************************** >+ * Copyright (c) 2011 Liferay, Inc. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Greg Amerson - initial implementation >+ ******************************************************************************/ >+ >+package org.eclipse.sapphire.samples.gallery.ui; >+ >+import java.net.URL; >+ >+import org.eclipse.sapphire.ui.SapphireActionHandler; >+import org.eclipse.sapphire.ui.SapphireRenderingContext; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.browser.IWebBrowser; >+import org.eclipse.ui.browser.IWorkbenchBrowserSupport; >+ >+/** >+ * @author <a href="mailto:gregory.amerson@liferay.com">Greg Amerson</a> >+ */ >+ >+public class OpenHomepageActionHandler extends SapphireActionHandler >+{ >+ >+ @Override >+ protected Object run(SapphireRenderingContext context) >+ { >+ >+ Display.getDefault().asyncExec(new Runnable() >+ { >+ >+ public void run() >+ { >+ try >+ { >+ IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); >+ >+ IWebBrowser browser = >+ browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | >+ IWorkbenchBrowserSupport.NAVIGATION_BAR, null, "Sapphire Project", null); >+ >+ browser.openURL(new URL("http://www.eclipse.org/sapphire/")); >+ } >+ catch (Exception e) >+ { >+ // ignore >+ } >+ } >+ }); >+ >+ return null; >+ } >+ >+} >#P org.eclipse.sapphire.sdk >Index: sdef/SapphireEditorCommon.sdef >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.sdk/sdef/SapphireEditorCommon.sdef,v >retrieving revision 1.2 >diff -u -r1.2 SapphireEditorCommon.sdef >--- sdef/SapphireEditorCommon.sdef 16 Mar 2011 04:31:20 -0000 1.2 >+++ sdef/SapphireEditorCommon.sdef 26 Apr 2011 21:09:48 -0000 >@@ -8,6 +8,7 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ****************************************************************************** > --> > >@@ -56,6 +57,18 @@ > </content> > </section> > <section> >+ <label>presentation hints</label> >+ <content> >+ <property-editor> >+ <property-editor>Hints</property-editor> >+ <hint> >+ <name>show.label</name> >+ <value>false</value> >+ </hint> >+ </property-editor> >+ </content> >+ </section> >+ <section> > <label>applicability</label> > <content> > <property-editor>ConditionClass</property-editor> >#P org.eclipse.sapphire.ui >Index: src/org/eclipse/sapphire/ui/SapphireAction.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/SapphireAction.java,v >retrieving revision 1.4 >diff -u -r1.4 SapphireAction.java >--- src/org/eclipse/sapphire/ui/SapphireAction.java 20 Apr 2011 05:40:24 -0000 1.4 >+++ src/org/eclipse/sapphire/ui/SapphireAction.java 26 Apr 2011 21:09:49 -0000 >@@ -7,13 +7,16 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui; > > import java.util.ArrayList; > import java.util.Collections; >+import java.util.HashMap; > import java.util.List; >+import java.util.Map; > import java.util.concurrent.CopyOnWriteArrayList; > > import org.eclipse.sapphire.modeling.el.Function; >@@ -21,6 +24,8 @@ > import org.eclipse.sapphire.modeling.el.FunctionResult; > import org.eclipse.sapphire.modeling.el.Literal; > import org.eclipse.sapphire.ui.def.ISapphireActionDef; >+import org.eclipse.sapphire.ui.def.ISapphireHint; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; > import org.eclipse.sapphire.ui.def.SapphireActionType; > import org.eclipse.sapphire.ui.def.SapphireKeySequence; > import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >@@ -48,6 +53,7 @@ > private final List<SapphireActionHandler> handlers = new CopyOnWriteArrayList<SapphireActionHandler>(); > private final List<SapphireActionHandlerFilter> filters = new CopyOnWriteArrayList<SapphireActionHandlerFilter>(); > private final Listener handlerListener; >+ private Map<String,Object> hints; > > public SapphireAction() > { >@@ -103,6 +109,21 @@ > } > > setEnabled( false ); >+ >+ this.hints = new HashMap<String,Object>(); >+ >+ for( ISapphireHint hint : def.getHints() ) >+ { >+ final String name = hint.getName().getText(); >+ Object parsedValue = null; >+ >+ if( name.equals( ISapphirePartDef.HINT_STYLE ) ) >+ { >+ parsedValue = hint.getValue().getText(); >+ } >+ >+ this.hints.put( name, parsedValue ); >+ } > } > > @Override >@@ -196,6 +217,15 @@ > return this.parent.getContext(); > } > >+ @SuppressWarnings( "unchecked" ) >+ >+ public <T> T getRenderingHint( final String name, >+ final T defaultValue ) >+ { >+ final Object hintValue = this.hints == null ? null : this.hints.get( name ); >+ return hintValue == null ? defaultValue : (T) hintValue; >+ } >+ > public SapphireActionType getType() > { > synchronized( this ) >Index: src/org/eclipse/sapphire/ui/SapphireSection.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/SapphireSection.java,v >retrieving revision 1.15 >diff -u -r1.15 SapphireSection.java >--- src/org/eclipse/sapphire/ui/SapphireSection.java 21 Apr 2011 19:26:33 -0000 1.15 >+++ src/org/eclipse/sapphire/ui/SapphireSection.java 26 Apr 2011 21:09:49 -0000 >@@ -8,7 +8,8 @@ > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance > * Ling Hao - [bugzilla 329115] support more details link for long descriptions >- * [bugzilla 329114] rewrite context help binding feature >+ * [bugzilla 329114] rewrite context help binding feature >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui; >@@ -108,7 +109,7 @@ > final SapphireActionPresentationManager actionPresentationManager = new SapphireActionPresentationManager( context, actions ); > final SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation( actionPresentationManager ); > >- final ToolBar toolbar = new ToolBar( this.section, SWT.FLAT | SWT.HORIZONTAL ); >+ final ToolBar toolbar = new ToolBar( this.section, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT ); > toolBarActionsPresentation.setToolBar( toolbar ); > toolBarActionsPresentation.render(); > this.section.setTextClient( toolbar ); >Index: src/org/eclipse/sapphire/ui/def/ISapphireActionDef.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/def/ISapphireActionDef.java,v >retrieving revision 1.5 >diff -u -r1.5 ISapphireActionDef.java >--- src/org/eclipse/sapphire/ui/def/ISapphireActionDef.java 26 Apr 2011 04:31:36 -0000 1.5 >+++ src/org/eclipse/sapphire/ui/def/ISapphireActionDef.java 26 Apr 2011 21:09:49 -0000 >@@ -7,12 +7,14 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson [342771] - Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui.def; > > import org.eclipse.core.runtime.IStatus; > import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; > import org.eclipse.sapphire.modeling.ModelElementType; > import org.eclipse.sapphire.modeling.Value; > import org.eclipse.sapphire.modeling.ValueProperty; >@@ -25,6 +27,7 @@ > import org.eclipse.sapphire.modeling.annotations.Type; > import org.eclipse.sapphire.modeling.serialization.ValueSerialization; > import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; > import org.eclipse.sapphire.ui.def.internal.KeySequenceValueSerializationService; > > /** >@@ -41,6 +44,10 @@ > { > ModelElementType TYPE = new ModelElementType( ISapphireActionDef.class ); > >+ String HINT_VALUE_STYLE_IMAGE = "image"; >+ String HINT_VALUE_STYLE_IMAGE_TEXT = "image+text"; >+ String HINT_VALUE_STYLE_TEXT = "text"; >+ > // *** Id *** > > @Required >@@ -166,6 +173,15 @@ > Value<String> getGroup(); > void setGroup( String value ); > >+ // *** Hints *** >+ >+ @Label(standard = "hints") >+ @Type(base = ISapphireHint.class) >+ @XmlListBinding(mappings = @XmlListBinding.Mapping(element = "hint", type = ISapphireHint.class)) >+ ListProperty PROP_HINTS = new ListProperty(TYPE, "Hints"); >+ >+ ModelElementList<ISapphireHint> getHints(); >+ > // *** LocationHints *** > > @Documentation( content = "Location hints are used to arrange actions in relation to each other. " + >Index: src/org/eclipse/sapphire/ui/def/internal/SapphireHintValuePossibleValuesService.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/def/internal/SapphireHintValuePossibleValuesService.java,v >retrieving revision 1.3 >diff -u -r1.3 SapphireHintValuePossibleValuesService.java >--- src/org/eclipse/sapphire/ui/def/internal/SapphireHintValuePossibleValuesService.java 25 Apr 2011 22:15:05 -0000 1.3 >+++ src/org/eclipse/sapphire/ui/def/internal/SapphireHintValuePossibleValuesService.java 26 Apr 2011 21:09:49 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui.def.internal; >@@ -14,7 +15,9 @@ > import java.util.SortedSet; > > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.sapphire.modeling.IModelParticle; > import org.eclipse.sapphire.modeling.PossibleValuesService; >+import org.eclipse.sapphire.ui.def.ISapphireActionDef; > import org.eclipse.sapphire.ui.def.ISapphireHint; > import org.eclipse.sapphire.ui.def.ISapphirePartDef; > import org.eclipse.sapphire.ui.def.ISapphirePropertyEditorDef; >@@ -33,7 +36,7 @@ > protected void fillPossibleValues( final SortedSet<String> values ) > { > final ISapphireHint element = (ISapphireHint) element(); >- final ISapphirePartDef partdef = (ISapphirePartDef) element.parent().parent(); >+ final IModelParticle partdef = element.parent().parent(); > final String hint = element.getName().getText(); > > if( hint != null ) >@@ -44,14 +47,20 @@ > values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL ); > values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL_INDENTED ); > } >- else if( hint.equals( ISapphirePropertyEditorDef.HINT_STYLE ) ) >+ else if ( hint.equals( ISapphirePartDef.HINT_STYLE ) ) > { >- if( partdef instanceof ISapphireWithDirectiveDef ) >- { >- values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_CHECKBOX ); >- values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_DROP_DOWN_LIST ); >- values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_RADIO_BUTTONS ); >- } >+ if (partdef instanceof ISapphireWithDirectiveDef) >+ { >+ values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_CHECKBOX ); >+ values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_RADIO_BUTTONS ); >+ values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_DROP_DOWN_LIST ); >+ } >+ else if (partdef instanceof ISapphireActionDef) >+ { >+ values.add( ISapphireActionDef.HINT_VALUE_STYLE_IMAGE ); >+ values.add( ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT ); >+ values.add( ISapphireActionDef.HINT_VALUE_STYLE_TEXT ); >+ } > } > } > } >Index: src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarActionPresentation.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarActionPresentation.java,v >retrieving revision 1.4 >diff -u -r1.4 SapphireToolBarActionPresentation.java >--- src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarActionPresentation.java 29 Mar 2011 02:49:46 -0000 1.4 >+++ src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarActionPresentation.java 26 Apr 2011 21:09:49 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui.swt.renderer; >@@ -22,6 +23,8 @@ > import org.eclipse.sapphire.ui.SapphireActionGroup; > import org.eclipse.sapphire.ui.SapphireActionHandler; > import org.eclipse.sapphire.ui.SapphireRenderingContext; >+import org.eclipse.sapphire.ui.def.ISapphireActionDef; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; > import org.eclipse.sapphire.ui.def.SapphireActionType; > import org.eclipse.swt.SWT; > import org.eclipse.swt.accessibility.AccessibleAdapter; >@@ -129,8 +132,21 @@ > { > throw new IllegalStateException(); > } >- >- toolItem.setImage( context.getImageCache().getImage( action.getImage( 16 ) ) ); >+ >+ String hint = action.getRenderingHint(ISapphirePartDef.HINT_STYLE, ISapphireActionDef.HINT_VALUE_STYLE_IMAGE); >+ >+ if (ISapphireActionDef.HINT_VALUE_STYLE_IMAGE.equals(hint) || >+ ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT.equals(hint)) >+ { >+ toolItem.setImage( context.getImageCache().getImage( action.getImage( 16 ) ) ); >+ } >+ >+ if (ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT.equals(hint) || >+ ISapphireActionDef.HINT_VALUE_STYLE_TEXT.equals(hint)) >+ { >+ toolItem.setText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, true ) ); >+ } >+ > toolItem.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) ); > toolItem.setData( action ); > toolItem.addSelectionListener( toolItemListener ); >Index: src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarManagerActionPresentation.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarManagerActionPresentation.java,v >retrieving revision 1.4 >diff -u -r1.4 SapphireToolBarManagerActionPresentation.java >--- src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarManagerActionPresentation.java 29 Mar 2011 02:49:46 -0000 1.4 >+++ src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarManagerActionPresentation.java 26 Apr 2011 21:09:49 -0000 >@@ -7,35 +7,24 @@ > * > * Contributors: > * Konstantin Komissarchik - initial implementation and ongoing maintenance >+ * Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar > ******************************************************************************/ > > package org.eclipse.sapphire.ui.swt.renderer; > >-import static org.eclipse.sapphire.modeling.util.MiscUtil.equal; >- >-import java.util.List; >- >-import org.eclipse.jface.action.ActionContributionItem; >-import org.eclipse.jface.action.IAction; >-import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.ControlContribution; > import org.eclipse.jface.action.IToolBarManager; >-import org.eclipse.jface.action.Separator; >-import org.eclipse.jface.action.SubContributionItem; > import org.eclipse.jface.action.SubToolBarManager; > import org.eclipse.jface.action.ToolBarManager; >-import org.eclipse.sapphire.modeling.CapitalizationType; >-import org.eclipse.sapphire.modeling.localization.LabelTransformer; > import org.eclipse.sapphire.ui.ISapphirePart; >-import org.eclipse.sapphire.ui.SapphireAction; > import org.eclipse.sapphire.ui.SapphireActionGroup; >-import org.eclipse.sapphire.ui.SapphireActionHandler; > import org.eclipse.sapphire.ui.SapphireRenderingContext; >-import org.eclipse.sapphire.ui.def.SapphireActionType; >+import org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Cursor; >-import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.ToolBar; >-import org.eclipse.swt.widgets.ToolItem; > > /** > * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> >@@ -47,10 +36,14 @@ > > { > private IToolBarManager toolbar; >+ private SapphireToolBarContribution sapphireToolbar; >+ private SapphireToolBarActionPresentation delegate; > > public SapphireToolBarManagerActionPresentation( final SapphireActionPresentationManager manager ) > { > super( manager ); >+ >+ this.delegate = new SapphireToolBarActionPresentation( manager ); > } > > public SapphireToolBarManagerActionPresentation( final ISapphirePart part, >@@ -68,192 +61,60 @@ > public void setToolBarManager( final IToolBarManager toolbar ) > { > this.toolbar = toolbar; >- } >- >- public void render() >- { >- setCursor( this.toolbar, null ); >- >- final SapphireRenderingContext context = getManager().getContext(); >- >- boolean first = true; >- String lastGroup = null; >- >- for( final SapphireAction action : getActions() ) >- { >- final String group = action.getGroup(); >- >- if( ! first && ! equal( lastGroup, group ) ) >- { >- this.toolbar.add( new Separator() ); >- } >- >- first = false; >- lastGroup = group; >- >- final List<SapphireActionHandler> handlers = action.getActiveHandlers(); >- final org.eclipse.jface.action.Action a; >- >- if( action.getType() == SapphireActionType.PUSH ) >- { >- a = new org.eclipse.jface.action.Action( null, org.eclipse.jface.action.Action.AS_PUSH_BUTTON ) >- { >- @Override >- public void run() >- { >- if( handlers.size() == 1 ) >- { >- handlers.get( 0 ).execute( context ); >- } >- else >- { >- displayActionHandlerChoice( action ); >- } >- } >- }; >- >- registerHotSpot( action, new JFaceActionHotSpot( a ) ); >- } >- else if( action.getType() == SapphireActionType.TOGGLE ) >- { >- a = new org.eclipse.jface.action.Action( null, org.eclipse.jface.action.Action.AS_CHECK_BOX ) >- { >- @Override >- public void run() >- { >- handlers.get( 0 ).execute( context ); >- } >- }; >- } >- else >- { >- throw new IllegalStateException(); >- } >- >- a.setImageDescriptor( action.getImage( 16 ) ); >- a.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) ); >- >- this.toolbar.add( a ); >- >- final Runnable updateActionEnablementStateOp = new Runnable() >- { >- public void run() >- { >- a.setEnabled( action.isEnabled() ); >- } >- }; >- >- final Runnable updateActionCheckedStateOp = new Runnable() >- { >- public void run() >- { >- a.setChecked( action.isChecked() ); >- } >- }; >- >- action.addListener >- ( >- new SapphireAction.Listener() >- { >- @Override >- public void handleEvent( final SapphireAction.Event event ) >- { >- final String type = event.getType(); >- >- if( type.equals( SapphireAction.EVENT_ENABLEMENT_STATE_CHANGED ) ) >- { >- updateActionEnablementStateOp.run(); >- } >- else if( type.equals( SapphireAction.EVENT_CHECKED_STATE_CHANGED ) ) >- { >- updateActionCheckedStateOp.run(); >- } >- } >- } >- ); >- >- updateActionEnablementStateOp.run(); >- updateActionCheckedStateOp.run(); >- } > >- this.toolbar.update( true ); >+ this.sapphireToolbar = new SapphireToolBarContribution("sapphire"); > } > >- private static void setCursor( final IToolBarManager toolBarManager, >- final Cursor cursor ) >- { >- if( toolBarManager instanceof ToolBarManager ) >- { >- ( (ToolBarManager) toolBarManager ).getControl().setCursor( null ); >- } >- else if( toolBarManager instanceof SubToolBarManager ) >- { >- setCursor( (IToolBarManager) ( (SubToolBarManager) toolBarManager ).getParent(), cursor ); >- } >- } >- >- private final class JFaceActionHotSpot >- >- extends HotSpot >- >+ public void render() > { >- private final org.eclipse.jface.action.Action action; >- >- public JFaceActionHotSpot( final org.eclipse.jface.action.Action item ) >- { >- this.action = item; >- } >- >- @Override >- public Rectangle getBounds() >- { >- ToolItem actionToolItem = null; >- >- for( ToolItem toolItem : getToolBar( getToolBarManager() ).getItems() ) >- { >- final Object data = toolItem.getData(); >- >- if( data instanceof IContributionItem && getJFaceAction( ( (IContributionItem) data ) ) == this.action ) >- { >- actionToolItem = toolItem; >- break; >- } >- } >- >- return toDisplay( actionToolItem.getParent(), actionToolItem.getBounds() ); >- } >- >- private IAction getJFaceAction( final IContributionItem item ) >- { >- if( item instanceof ActionContributionItem ) >- { >- return ( (ActionContributionItem) item ).getAction(); >- } >- else if( item instanceof SubContributionItem ) >- { >- return getJFaceAction( ( (SubContributionItem) item ).getInnerItem() ); >- } >- else >- { >- return null; >- } >- } >- >- private ToolBar getToolBar( final IToolBarManager manager ) >- { >- if( manager instanceof ToolBarManager ) >- { >- return ( (ToolBarManager) manager ).getControl(); >- } >- else if( manager instanceof SubToolBarManager ) >- { >- return getToolBar( (IToolBarManager) ( (SubToolBarManager) manager ).getParent() ); >- } >- else >- { >- throw new IllegalStateException( manager.getClass().getName() ); >- } >- } >+ setCursor ( this.toolbar, null ); >+ >+ this.toolbar.add(this.sapphireToolbar); >+ >+ this.toolbar.update( true ); // call update so our embedded toolbar will get created >+ } >+ >+ private static void setCursor(final IToolBarManager toolBarManager, >+ final Cursor cursor) >+ { >+ if (toolBarManager instanceof ToolBarManager) >+ { >+ ((ToolBarManager) toolBarManager).getControl().setCursor(null); >+ } >+ else if (toolBarManager instanceof SubToolBarManager) >+ { >+ setCursor((IToolBarManager) ((SubToolBarManager) toolBarManager).getParent(), cursor); >+ } >+ } >+ >+ private final class SapphireToolBarContribution extends ControlContribution >+ { >+ private ToolBar embeddedToolbar; >+ >+ protected SapphireToolBarContribution(String id) >+ { >+ super(id); >+ } >+ >+ @Override >+ public boolean isDynamic() >+ { >+ return true; >+ } >+ >+ @Override >+ protected Control createControl(Composite parent) >+ { >+ this.embeddedToolbar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT); >+ this.embeddedToolbar.setBackground(null); >+ this.embeddedToolbar.setForeground(parent.getForeground()); >+ >+ SapphireToolBarManagerActionPresentation.this.delegate.setToolBar(this.embeddedToolbar); >+ >+ SapphireToolBarManagerActionPresentation.this.delegate.render(); >+ >+ return this.embeddedToolbar; >+ } >+ > } >- > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
konstantin
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 342771
:
193955
|
193956
|
194106
| 194109