Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 342771 | Differences between
and this patch

Collapse All | Expand All

(-)html/releases/0.3/index.html (+29 lines)
Lines 33-38 Link Here
33
    <li><a href="#image-el">Image Expressions</a></li>
33
    <li><a href="#image-el">Image Expressions</a></li>
34
    <li><a href="#ancestor-access">Ancestor Access</a></li>
34
    <li><a href="#ancestor-access">Ancestor Access</a></li>
35
    <li><a href="#with">Improved With Directive Presentation</a></li>
35
    <li><a href="#with">Improved With Directive Presentation</a></li>
36
    <li><a href="#action-hints">Presentation Hints for Actions</a></li>
36
  </ol>
37
  </ol>
37
</ol>
38
</ol>
38
 
39
 
Lines 533-538 Link Here
533
534
534
<p style="margin-left: 20px;"><img src="images/with-4.png"/></p>
535
<p style="margin-left: 20px;"><img src="images/with-4.png"/></p>
535
536
537
<h2><a name="action-label-el">Presentation Hints for Actions</a></h2>
538
539
<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>
540
541
<table>
542
<tr><td>image</td><td>Only image is rendered.</td></tr>
543
<tr><td>image+text</td><td>Text will be rendered to the right of the image.</td></tr>
544
<tr><td>image</td><td>Only text is rendered.</td></tr>
545
</table>
546
547
<p style="margin-left: 20px;"><b>Example</b></p>
548
549
<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>
550
551
<pre class="source-code"><code>
552
&lt;action&gt;
553
    &lt;id&gt;Sapphire.Gallery.Open.Homepage&lt;/id&gt;
554
    &lt;label&gt;Sapphire Homepage&lt;/label&gt;
555
    &lt;image&gt;images/web.png&lt;/image&gt;
556
    &lt;description&gt;Open Sapphire project homepage&lt;/description&gt;
557
    &lt;context&gt;Sapphire.EditorPage&lt;/context&gt;
558
    &lt;hint&gt;
559
        &lt;name>style&lt;/name&gt;
560
        &lt;value>image+text&lt;/value&gt;
561
    &lt;/hint&gt;
562
&lt;/action&gt;
563
</code></pre>
564
536
<br/><br/>
565
<br/><br/>
537
566
538
</body>
567
</body>
(-)sdef/GalleryEditor.sdef (+18 lines)
Lines 25-30 Link Here
25
        <bundle>org.eclipse.sapphire.samples</bundle>
25
        <bundle>org.eclipse.sapphire.samples</bundle>
26
        <package>org.eclipse.sapphire.samples.gallery</package>
26
        <package>org.eclipse.sapphire.samples.gallery</package>
27
        <package>org.eclipse.sapphire.samples.gallery.internal</package>
27
        <package>org.eclipse.sapphire.samples.gallery.internal</package>
28
        <package>org.eclipse.sapphire.samples.gallery.ui</package>
28
    </import>
29
    </import>
29
    
30
    
30
    <documentation>
31
    <documentation>
Lines 1427-1432 Link Here
1427
                </node>
1428
                </node>
1428
            </node>
1429
            </node>
1429
        </root-node>
1430
        </root-node>
1431
        <action>
1432
	        <id>Sapphire.Gallery.Open.Homepage</id>
1433
	        <label>Sapphire Homepage</label>
1434
	        <image>images/web.png</image>
1435
	        <description>Open Sapphire project homepage</description>
1436
	        <context>Sapphire.EditorPage</context>
1437
	        <hint>
1438
	            <name>style</name>
1439
	            <value>image+text</value>
1440
	        </hint>
1441
	    </action>
1442
	    <action-handler>
1443
	        <action>Sapphire.Gallery.Open.Homepage</action>
1444
	        <id>Sapphire.Gallery.Open.Homepage</id>
1445
	        <label>Sapphire Homepage</label>
1446
	        <impl>OpenHomepageActionHandler</impl>
1447
	    </action-handler>
1430
    </editor-page>
1448
    </editor-page>
1431
    <import>
1449
    <import>
1432
        <bundle>org.eclipse.sapphire.workspace.ui</bundle>
1450
        <bundle>org.eclipse.sapphire.workspace.ui</bundle>
(-)src/org/eclipse/sapphire/samples/gallery/ui/OpenHomepageActionHandler.java (+59 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2011 Liferay, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Greg Amerson - initial implementation
10
 ******************************************************************************/
11
12
package org.eclipse.sapphire.samples.gallery.ui;
13
14
import java.net.URL;
15
16
import org.eclipse.sapphire.ui.SapphireActionHandler;
17
import org.eclipse.sapphire.ui.SapphireRenderingContext;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.browser.IWebBrowser;
21
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
22
23
/**
24
 * @author <a href="mailto:gregory.amerson@liferay.com">Greg Amerson</a>
25
 */
26
27
public class OpenHomepageActionHandler extends SapphireActionHandler
28
{
29
30
	@Override
31
	protected Object run(SapphireRenderingContext context) 
32
	{
33
34
		Display.getDefault().asyncExec(new Runnable() 
35
		{
36
37
			public void run() 
38
			{
39
				try 
40
				{
41
					IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
42
43
					IWebBrowser browser =
44
						browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR |
45
							IWorkbenchBrowserSupport.NAVIGATION_BAR, null, "Sapphire Project", null);
46
47
					browser.openURL(new URL("http://www.eclipse.org/sapphire/"));
48
				}
49
				catch (Exception e) 
50
				{
51
					// ignore
52
				}
53
			}
54
		});
55
56
		return null;
57
	}
58
59
}
(-)sdef/SapphireEditorCommon.sdef (+13 lines)
Lines 8-13 Link Here
8
 *
8
 *
9
 * Contributors:
9
 * Contributors:
10
 *        Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *        Konstantin Komissarchik - initial implementation and ongoing maintenance
11
 *        Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar
11
 ******************************************************************************
12
 ******************************************************************************
12
-->
13
-->
13
14
Lines 56-61 Link Here
56
                    </content>
57
                    </content>
57
                </section>
58
                </section>
58
                <section>
59
                <section>
60
	                <label>presentation hints</label>
61
	                <content>
62
	                    <property-editor>
63
	                        <property-editor>Hints</property-editor>
64
                        	<hint>
65
	                            <name>show.label</name>
66
	                            <value>false</value>
67
	                        </hint>
68
	                    </property-editor>
69
	                </content>
70
	            </section>
71
                <section>
59
                    <label>applicability</label>
72
                    <label>applicability</label>
60
                    <content>
73
                    <content>
61
                        <property-editor>ConditionClass</property-editor>
74
                        <property-editor>ConditionClass</property-editor>
(-)src/org/eclipse/sapphire/ui/SapphireAction.java (+30 lines)
Lines 7-19 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar           
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui;
13
package org.eclipse.sapphire.ui;
13
14
14
import java.util.ArrayList;
15
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.Collections;
17
import java.util.HashMap;
16
import java.util.List;
18
import java.util.List;
19
import java.util.Map;
17
import java.util.concurrent.CopyOnWriteArrayList;
20
import java.util.concurrent.CopyOnWriteArrayList;
18
21
19
import org.eclipse.sapphire.modeling.el.Function;
22
import org.eclipse.sapphire.modeling.el.Function;
Lines 21-26 Link Here
21
import org.eclipse.sapphire.modeling.el.FunctionResult;
24
import org.eclipse.sapphire.modeling.el.FunctionResult;
22
import org.eclipse.sapphire.modeling.el.Literal;
25
import org.eclipse.sapphire.modeling.el.Literal;
23
import org.eclipse.sapphire.ui.def.ISapphireActionDef;
26
import org.eclipse.sapphire.ui.def.ISapphireActionDef;
27
import org.eclipse.sapphire.ui.def.ISapphireHint;
28
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
24
import org.eclipse.sapphire.ui.def.SapphireActionType;
29
import org.eclipse.sapphire.ui.def.SapphireActionType;
25
import org.eclipse.sapphire.ui.def.SapphireKeySequence;
30
import org.eclipse.sapphire.ui.def.SapphireKeySequence;
26
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
31
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
Lines 48-53 Link Here
48
    private final List<SapphireActionHandler> handlers = new CopyOnWriteArrayList<SapphireActionHandler>();
53
    private final List<SapphireActionHandler> handlers = new CopyOnWriteArrayList<SapphireActionHandler>();
49
    private final List<SapphireActionHandlerFilter> filters = new CopyOnWriteArrayList<SapphireActionHandlerFilter>();
54
    private final List<SapphireActionHandlerFilter> filters = new CopyOnWriteArrayList<SapphireActionHandlerFilter>();
50
    private final Listener handlerListener;
55
    private final Listener handlerListener;
56
    private Map<String,Object> hints;
51
    
57
    
52
    public SapphireAction()
58
    public SapphireAction()
53
    {
59
    {
Lines 103-108 Link Here
103
        }
109
        }
104
        
110
        
105
        setEnabled( false );
111
        setEnabled( false );
112
        
113
        this.hints = new HashMap<String,Object>();
114
        
115
        for( ISapphireHint hint : def.getHints() )
116
        {
117
            final String name = hint.getName().getText();
118
            Object parsedValue = null;
119
            
120
            if( name.equals( ISapphirePartDef.HINT_STYLE ) )
121
            {
122
                parsedValue = hint.getValue().getText();
123
            }
124
           
125
            this.hints.put( name, parsedValue );
126
        }
106
    }
127
    }
107
    
128
    
108
    @Override
129
    @Override
Lines 196-201 Link Here
196
        return this.parent.getContext();
217
        return this.parent.getContext();
197
    }
218
    }
198
    
219
    
220
    @SuppressWarnings( "unchecked" )
221
    
222
    public <T> T getRenderingHint( final String name,
223
                                   final T defaultValue )
224
    {
225
        final Object hintValue = this.hints == null ? null : this.hints.get( name );
226
        return hintValue == null ? defaultValue : (T) hintValue;
227
    }
228
199
    public SapphireActionType getType()
229
    public SapphireActionType getType()
200
    {
230
    {
201
        synchronized( this )
231
        synchronized( this )
(-)src/org/eclipse/sapphire/ui/SapphireSection.java (-2 / +3 lines)
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Ling Hao - [bugzilla 329115] support more details link for long descriptions
10
 *    Ling Hao - [bugzilla 329115] support more details link for long descriptions
11
 *                 [bugzilla 329114] rewrite context help binding feature
11
 *               [bugzilla 329114] rewrite context help binding feature
12
 *    Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar           
12
 ******************************************************************************/
13
 ******************************************************************************/
13
14
14
package org.eclipse.sapphire.ui;
15
package org.eclipse.sapphire.ui;
Lines 108-114 Link Here
108
        final SapphireActionPresentationManager actionPresentationManager = new SapphireActionPresentationManager( context, actions );
109
        final SapphireActionPresentationManager actionPresentationManager = new SapphireActionPresentationManager( context, actions );
109
        final SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation( actionPresentationManager );
110
        final SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation( actionPresentationManager );
110
        
111
        
111
        final ToolBar toolbar = new ToolBar( this.section, SWT.FLAT | SWT.HORIZONTAL );
112
        final ToolBar toolbar = new ToolBar( this.section, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT );
112
        toolBarActionsPresentation.setToolBar( toolbar );
113
        toolBarActionsPresentation.setToolBar( toolbar );
113
        toolBarActionsPresentation.render();
114
        toolBarActionsPresentation.render();
114
        this.section.setTextClient( toolbar );
115
        this.section.setTextClient( toolbar );
(-)src/org/eclipse/sapphire/ui/def/ISapphireActionDef.java (+16 lines)
Lines 7-18 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Greg Amerson [342771] - Support "image+label" hint for when actions are presented in a toolbar
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui.def;
13
package org.eclipse.sapphire.ui.def;
13
14
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.sapphire.modeling.ListProperty;
16
import org.eclipse.sapphire.modeling.ListProperty;
17
import org.eclipse.sapphire.modeling.ModelElementList;
16
import org.eclipse.sapphire.modeling.ModelElementType;
18
import org.eclipse.sapphire.modeling.ModelElementType;
17
import org.eclipse.sapphire.modeling.Value;
19
import org.eclipse.sapphire.modeling.Value;
18
import org.eclipse.sapphire.modeling.ValueProperty;
20
import org.eclipse.sapphire.modeling.ValueProperty;
Lines 25-30 Link Here
25
import org.eclipse.sapphire.modeling.annotations.Type;
27
import org.eclipse.sapphire.modeling.annotations.Type;
26
import org.eclipse.sapphire.modeling.serialization.ValueSerialization;
28
import org.eclipse.sapphire.modeling.serialization.ValueSerialization;
27
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
29
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
30
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
28
import org.eclipse.sapphire.ui.def.internal.KeySequenceValueSerializationService;
31
import org.eclipse.sapphire.ui.def.internal.KeySequenceValueSerializationService;
29
32
30
/**
33
/**
Lines 41-46 Link Here
41
{
44
{
42
    ModelElementType TYPE = new ModelElementType( ISapphireActionDef.class );
45
    ModelElementType TYPE = new ModelElementType( ISapphireActionDef.class );
43
    
46
    
47
	String HINT_VALUE_STYLE_IMAGE = "image";
48
	String HINT_VALUE_STYLE_IMAGE_TEXT = "image+text";
49
	String HINT_VALUE_STYLE_TEXT = "text";
50
44
    // *** Id ***
51
    // *** Id ***
45
52
46
    @Required
53
    @Required
Lines 166-171 Link Here
166
    Value<String> getGroup();
173
    Value<String> getGroup();
167
    void setGroup( String value );
174
    void setGroup( String value );
168
    
175
    
176
	// *** Hints ***
177
178
	@Label(standard = "hints")
179
	@Type(base = ISapphireHint.class)
180
	@XmlListBinding(mappings = @XmlListBinding.Mapping(element = "hint", type = ISapphireHint.class))
181
	ListProperty PROP_HINTS = new ListProperty(TYPE, "Hints");
182
183
	ModelElementList<ISapphireHint> getHints();
184
169
    // *** LocationHints ***
185
    // *** LocationHints ***
170
    
186
    
171
    @Documentation( content = "Location hints are used to arrange actions in relation to each other. " +
187
    @Documentation( content = "Location hints are used to arrange actions in relation to each other. " +
(-)src/org/eclipse/sapphire/ui/def/internal/SapphireHintValuePossibleValuesService.java (-8 / +17 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui.def.internal;
13
package org.eclipse.sapphire.ui.def.internal;
Lines 14-20 Link Here
14
import java.util.SortedSet;
15
import java.util.SortedSet;
15
16
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.sapphire.modeling.IModelParticle;
17
import org.eclipse.sapphire.modeling.PossibleValuesService;
19
import org.eclipse.sapphire.modeling.PossibleValuesService;
20
import org.eclipse.sapphire.ui.def.ISapphireActionDef;
18
import org.eclipse.sapphire.ui.def.ISapphireHint;
21
import org.eclipse.sapphire.ui.def.ISapphireHint;
19
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
22
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
20
import org.eclipse.sapphire.ui.def.ISapphirePropertyEditorDef;
23
import org.eclipse.sapphire.ui.def.ISapphirePropertyEditorDef;
Lines 33-39 Link Here
33
    protected void fillPossibleValues( final SortedSet<String> values )
36
    protected void fillPossibleValues( final SortedSet<String> values )
34
    {
37
    {
35
        final ISapphireHint element = (ISapphireHint) element();
38
        final ISapphireHint element = (ISapphireHint) element();
36
        final ISapphirePartDef partdef = (ISapphirePartDef) element.parent().parent();
39
        final IModelParticle partdef = element.parent().parent();
37
        final String hint = element.getName().getText();
40
        final String hint = element.getName().getText();
38
        
41
        
39
        if( hint != null )
42
        if( hint != null )
Lines 44-57 Link Here
44
                values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL );
47
                values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL );
45
                values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL_INDENTED );
48
                values.add( ISapphirePropertyEditorDef.HINT_VALUE_CHECKBOX_LAYOUT_TRAILING_LABEL_INDENTED );
46
            }
49
            }
47
            else if( hint.equals( ISapphirePropertyEditorDef.HINT_STYLE ) )
50
            else if ( hint.equals( ISapphirePartDef.HINT_STYLE ) ) 
48
            {
51
            {
49
                if( partdef instanceof ISapphireWithDirectiveDef )
52
            	if (partdef instanceof ISapphireWithDirectiveDef)
50
                {
53
            	{
51
                    values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_CHECKBOX );
54
            		values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_CHECKBOX );
52
                    values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_DROP_DOWN_LIST );
55
            		values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_RADIO_BUTTONS );
53
                    values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_RADIO_BUTTONS );
56
            		values.add( ISapphireWithDirectiveDef.HINT_VALUE_STYLE_DROP_DOWN_LIST );
54
                }
57
            	}
58
            	else if (partdef instanceof ISapphireActionDef) 
59
            	{
60
            		values.add( ISapphireActionDef.HINT_VALUE_STYLE_IMAGE );
61
            		values.add( ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT );
62
	            	values.add( ISapphireActionDef.HINT_VALUE_STYLE_TEXT );
63
            	}
55
            }
64
            }
56
        }
65
        }
57
    }
66
    }
(-)src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarActionPresentation.java (-2 / +18 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui.swt.renderer;
13
package org.eclipse.sapphire.ui.swt.renderer;
Lines 22-27 Link Here
22
import org.eclipse.sapphire.ui.SapphireActionGroup;
23
import org.eclipse.sapphire.ui.SapphireActionGroup;
23
import org.eclipse.sapphire.ui.SapphireActionHandler;
24
import org.eclipse.sapphire.ui.SapphireActionHandler;
24
import org.eclipse.sapphire.ui.SapphireRenderingContext;
25
import org.eclipse.sapphire.ui.SapphireRenderingContext;
26
import org.eclipse.sapphire.ui.def.ISapphireActionDef;
27
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
25
import org.eclipse.sapphire.ui.def.SapphireActionType;
28
import org.eclipse.sapphire.ui.def.SapphireActionType;
26
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.accessibility.AccessibleAdapter;
30
import org.eclipse.swt.accessibility.AccessibleAdapter;
Lines 129-136 Link Here
129
            {
132
            {
130
                throw new IllegalStateException();
133
                throw new IllegalStateException();
131
            }
134
            }
132
135
            
133
            toolItem.setImage( context.getImageCache().getImage( action.getImage( 16 ) ) );
136
            String hint = action.getRenderingHint(ISapphirePartDef.HINT_STYLE, ISapphireActionDef.HINT_VALUE_STYLE_IMAGE);
137
            
138
            if (ISapphireActionDef.HINT_VALUE_STYLE_IMAGE.equals(hint) || 
139
            	ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT.equals(hint))
140
            {
141
            	toolItem.setImage( context.getImageCache().getImage( action.getImage( 16 ) ) );
142
            }
143
            
144
            if (ISapphireActionDef.HINT_VALUE_STYLE_IMAGE_TEXT.equals(hint) ||
145
				ISapphireActionDef.HINT_VALUE_STYLE_TEXT.equals(hint))
146
            {
147
            	toolItem.setText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, true ) );
148
            }
149
            
134
            toolItem.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) );
150
            toolItem.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) );
135
            toolItem.setData( action );
151
            toolItem.setData( action );
136
            toolItem.addSelectionListener( toolItemListener );
152
            toolItem.addSelectionListener( toolItemListener );
(-)src/org/eclipse/sapphire/ui/swt/renderer/SapphireToolBarManagerActionPresentation.java (-199 / +60 lines)
Lines 7-41 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Greg Amerson - [342771] Support "image+label" hint for when actions are presented in a toolbar
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui.swt.renderer;
13
package org.eclipse.sapphire.ui.swt.renderer;
13
14
14
import static org.eclipse.sapphire.modeling.util.MiscUtil.equal;
15
import org.eclipse.jface.action.ControlContribution;
15
16
import java.util.List;
17
18
import org.eclipse.jface.action.ActionContributionItem;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.action.IContributionItem;
21
import org.eclipse.jface.action.IToolBarManager;
16
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.action.Separator;
23
import org.eclipse.jface.action.SubContributionItem;
24
import org.eclipse.jface.action.SubToolBarManager;
17
import org.eclipse.jface.action.SubToolBarManager;
25
import org.eclipse.jface.action.ToolBarManager;
18
import org.eclipse.jface.action.ToolBarManager;
26
import org.eclipse.sapphire.modeling.CapitalizationType;
27
import org.eclipse.sapphire.modeling.localization.LabelTransformer;
28
import org.eclipse.sapphire.ui.ISapphirePart;
19
import org.eclipse.sapphire.ui.ISapphirePart;
29
import org.eclipse.sapphire.ui.SapphireAction;
30
import org.eclipse.sapphire.ui.SapphireActionGroup;
20
import org.eclipse.sapphire.ui.SapphireActionGroup;
31
import org.eclipse.sapphire.ui.SapphireActionHandler;
32
import org.eclipse.sapphire.ui.SapphireRenderingContext;
21
import org.eclipse.sapphire.ui.SapphireRenderingContext;
33
import org.eclipse.sapphire.ui.def.SapphireActionType;
22
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.graphics.Cursor;
23
import org.eclipse.swt.graphics.Cursor;
35
import org.eclipse.swt.graphics.Rectangle;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Shell;
37
import org.eclipse.swt.widgets.ToolBar;
27
import org.eclipse.swt.widgets.ToolBar;
38
import org.eclipse.swt.widgets.ToolItem;
39
28
40
/**
29
/**
41
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
30
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
Lines 47-56 Link Here
47
    
36
    
48
{
37
{
49
    private IToolBarManager toolbar;
38
    private IToolBarManager toolbar;
39
    private SapphireToolBarContribution sapphireToolbar;
40
    private SapphireToolBarActionPresentation delegate;
50
    
41
    
51
    public SapphireToolBarManagerActionPresentation( final SapphireActionPresentationManager manager )
42
    public SapphireToolBarManagerActionPresentation( final SapphireActionPresentationManager manager )
52
    {
43
    {
53
        super( manager );
44
        super( manager );
45
        
46
        this.delegate = new SapphireToolBarActionPresentation( manager );
54
    }
47
    }
55
48
56
    public SapphireToolBarManagerActionPresentation( final ISapphirePart part,
49
    public SapphireToolBarManagerActionPresentation( final ISapphirePart part,
Lines 68-259 Link Here
68
    public void setToolBarManager( final IToolBarManager toolbar )
61
    public void setToolBarManager( final IToolBarManager toolbar )
69
    {
62
    {
70
        this.toolbar = toolbar;
63
        this.toolbar = toolbar;
71
    }
72
    
73
    public void render()
74
    {
75
        setCursor( this.toolbar, null );
76
        
77
        final SapphireRenderingContext context = getManager().getContext();
78
        
79
        boolean first = true;
80
        String lastGroup = null;
81
        
82
        for( final SapphireAction action : getActions() )
83
        {
84
            final String group = action.getGroup();
85
            
86
            if( ! first && ! equal( lastGroup, group ) )
87
            {
88
                this.toolbar.add( new Separator() );
89
            }
90
            
91
            first = false;
92
            lastGroup = group;
93
            
94
            final List<SapphireActionHandler> handlers = action.getActiveHandlers();
95
            final org.eclipse.jface.action.Action a;
96
            
97
            if( action.getType() == SapphireActionType.PUSH )
98
            {
99
                a = new org.eclipse.jface.action.Action( null, org.eclipse.jface.action.Action.AS_PUSH_BUTTON )
100
                {
101
                    @Override
102
                    public void run()
103
                    {
104
                        if( handlers.size() == 1 )
105
                        {
106
                            handlers.get( 0 ).execute( context );
107
                        }
108
                        else
109
                        {
110
                            displayActionHandlerChoice( action );
111
                        }
112
                    }
113
                };
114
                
115
                registerHotSpot( action, new JFaceActionHotSpot( a ) );
116
            }
117
            else if( action.getType() == SapphireActionType.TOGGLE )
118
            {
119
                a = new org.eclipse.jface.action.Action( null, org.eclipse.jface.action.Action.AS_CHECK_BOX )
120
                {
121
                    @Override
122
                    public void run()
123
                    {
124
                        handlers.get( 0 ).execute( context );
125
                    }
126
                };
127
            }
128
            else
129
            {
130
                throw new IllegalStateException();
131
            }
132
            
133
            a.setImageDescriptor( action.getImage( 16 ) );
134
            a.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) );
135
            
136
            this.toolbar.add( a );
137
            
138
            final Runnable updateActionEnablementStateOp = new Runnable()
139
            {
140
                public void run()
141
                {
142
                    a.setEnabled( action.isEnabled() );
143
                }
144
            };
145
            
146
            final Runnable updateActionCheckedStateOp = new Runnable()
147
            {
148
                public void run()
149
                {
150
                    a.setChecked( action.isChecked() );
151
                }
152
            };
153
            
154
            action.addListener
155
            (
156
                new SapphireAction.Listener()
157
                {
158
                    @Override
159
                    public void handleEvent( final SapphireAction.Event event )
160
                    {
161
                        final String type = event.getType();
162
                        
163
                        if( type.equals( SapphireAction.EVENT_ENABLEMENT_STATE_CHANGED ) )
164
                        {
165
                            updateActionEnablementStateOp.run();
166
                        }
167
                        else if( type.equals( SapphireAction.EVENT_CHECKED_STATE_CHANGED ) )
168
                        {
169
                            updateActionCheckedStateOp.run();
170
                        }
171
                    }
172
                }
173
            );
174
            
175
            updateActionEnablementStateOp.run();
176
            updateActionCheckedStateOp.run();
177
        }
178
        
64
        
179
        this.toolbar.update( true );
65
        this.sapphireToolbar = new SapphireToolBarContribution("sapphire");
180
    }
66
    }
181
    
67
    
182
    private static void setCursor( final IToolBarManager toolBarManager,
68
    public void render()
183
                                   final Cursor cursor )
184
    {
185
        if( toolBarManager instanceof ToolBarManager )
186
        {
187
            ( (ToolBarManager) toolBarManager ).getControl().setCursor( null );
188
        }
189
        else if( toolBarManager instanceof SubToolBarManager )
190
        {
191
            setCursor( (IToolBarManager) ( (SubToolBarManager) toolBarManager ).getParent(), cursor );
192
        }
193
    }
194
    
195
    private final class JFaceActionHotSpot
196
    
197
        extends HotSpot
198
        
199
    {
69
    {
200
        private final org.eclipse.jface.action.Action action;
70
    	setCursor ( this.toolbar, null );
201
        
71
    	
202
        public JFaceActionHotSpot( final org.eclipse.jface.action.Action item )
72
    	this.toolbar.add(this.sapphireToolbar);        
203
        {
73
        
204
            this.action = item;
74
        this.toolbar.update( true ); // call update so our embedded toolbar will get created
205
        }
75
    }
206
    
76
    
207
        @Override
77
	private static void setCursor(final IToolBarManager toolBarManager,
208
        public Rectangle getBounds()
78
								  final Cursor cursor)
209
        {
79
	{
210
            ToolItem actionToolItem = null;
80
		if (toolBarManager instanceof ToolBarManager)
211
            
81
		{
212
            for( ToolItem toolItem : getToolBar( getToolBarManager() ).getItems() )
82
			((ToolBarManager) toolBarManager).getControl().setCursor(null);
213
            {
83
		}
214
                final Object data = toolItem.getData();
84
		else if (toolBarManager instanceof SubToolBarManager)
215
                
85
		{
216
                if( data instanceof IContributionItem && getJFaceAction( ( (IContributionItem) data ) ) == this.action )
86
			setCursor((IToolBarManager) ((SubToolBarManager) toolBarManager).getParent(), cursor);
217
                {
87
		}
218
                    actionToolItem = toolItem;
88
	}
219
                    break;
89
    
220
                }
90
    private final class SapphireToolBarContribution extends ControlContribution
221
            }
91
    {
222
            
92
		private ToolBar embeddedToolbar;
223
            return toDisplay( actionToolItem.getParent(), actionToolItem.getBounds() );
93
		
224
        }
94
		protected SapphireToolBarContribution(String id)
225
        
95
		{
226
        private IAction getJFaceAction( final IContributionItem item )
96
			super(id);
227
        {
97
		}
228
            if( item instanceof ActionContributionItem )
98
		
229
            {
99
		@Override
230
                return ( (ActionContributionItem) item ).getAction();
100
		public boolean isDynamic() 
231
            }
101
		{
232
            else if( item instanceof SubContributionItem )
102
			return true;
233
            {
103
		}
234
                return getJFaceAction( ( (SubContributionItem) item ).getInnerItem() );
104
		
235
            }
105
		@Override
236
            else
106
		protected Control createControl(Composite parent)
237
            {
107
		{
238
                return null;
108
			this.embeddedToolbar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
239
            }
109
			this.embeddedToolbar.setBackground(null);
240
        }
110
			this.embeddedToolbar.setForeground(parent.getForeground());
241
        
111
			
242
        private ToolBar getToolBar( final IToolBarManager manager )
112
	        SapphireToolBarManagerActionPresentation.this.delegate.setToolBar(this.embeddedToolbar);
243
        {
113
        
244
            if( manager instanceof ToolBarManager )
114
	        SapphireToolBarManagerActionPresentation.this.delegate.render();
245
            {
115
			
246
                return ( (ToolBarManager) manager ).getControl();
116
			return this.embeddedToolbar;
247
            }
117
		}
248
            else if( manager instanceof SubToolBarManager )
118
	
249
            {
250
                return getToolBar( (IToolBarManager) ( (SubToolBarManager) manager ).getParent() );
251
            }
252
            else
253
            {
254
                throw new IllegalStateException( manager.getClass().getName() );
255
            }
256
        }
257
    }
119
    }
258
    
259
}
120
}

Return to bug 342771