|
Lines 13-23
Link Here
|
| 13 |
|
13 |
|
| 14 |
import static org.eclipse.sapphire.modeling.util.MiscUtil.equal; |
14 |
import static org.eclipse.sapphire.modeling.util.MiscUtil.equal; |
| 15 |
|
15 |
|
|
|
16 |
import java.util.ArrayList; |
| 16 |
import java.util.List; |
17 |
import java.util.List; |
| 17 |
|
18 |
|
| 18 |
import org.eclipse.jface.action.ActionContributionItem; |
19 |
import org.eclipse.jface.action.ActionContributionItem; |
|
|
20 |
import org.eclipse.jface.action.ContributionItem; |
| 21 |
import org.eclipse.jface.action.ControlContribution; |
| 19 |
import org.eclipse.jface.action.IAction; |
22 |
import org.eclipse.jface.action.IAction; |
| 20 |
import org.eclipse.jface.action.IContributionItem; |
23 |
import org.eclipse.jface.action.IContributionItem; |
|
|
24 |
import org.eclipse.jface.action.IContributionManager; |
| 21 |
import org.eclipse.jface.action.IToolBarManager; |
25 |
import org.eclipse.jface.action.IToolBarManager; |
| 22 |
import org.eclipse.jface.action.Separator; |
26 |
import org.eclipse.jface.action.Separator; |
| 23 |
import org.eclipse.jface.action.SubContributionItem; |
27 |
import org.eclipse.jface.action.SubContributionItem; |
|
Lines 30-41
Link Here
|
| 30 |
import org.eclipse.sapphire.ui.SapphireActionGroup; |
34 |
import org.eclipse.sapphire.ui.SapphireActionGroup; |
| 31 |
import org.eclipse.sapphire.ui.SapphireActionHandler; |
35 |
import org.eclipse.sapphire.ui.SapphireActionHandler; |
| 32 |
import org.eclipse.sapphire.ui.SapphireRenderingContext; |
36 |
import org.eclipse.sapphire.ui.SapphireRenderingContext; |
|
|
37 |
import org.eclipse.sapphire.ui.def.ISapphireActionDef; |
| 33 |
import org.eclipse.sapphire.ui.def.SapphireActionType; |
38 |
import org.eclipse.sapphire.ui.def.SapphireActionType; |
|
|
39 |
import org.eclipse.swt.SWT; |
| 40 |
import org.eclipse.swt.events.DisposeEvent; |
| 41 |
import org.eclipse.swt.events.DisposeListener; |
| 34 |
import org.eclipse.swt.graphics.Cursor; |
42 |
import org.eclipse.swt.graphics.Cursor; |
| 35 |
import org.eclipse.swt.graphics.Rectangle; |
43 |
import org.eclipse.swt.graphics.Rectangle; |
|
|
44 |
import org.eclipse.swt.widgets.Button; |
| 45 |
import org.eclipse.swt.widgets.Composite; |
| 46 |
import org.eclipse.swt.widgets.Control; |
| 47 |
import org.eclipse.swt.widgets.CoolBar; |
| 48 |
import org.eclipse.swt.widgets.Menu; |
| 36 |
import org.eclipse.swt.widgets.Shell; |
49 |
import org.eclipse.swt.widgets.Shell; |
| 37 |
import org.eclipse.swt.widgets.ToolBar; |
50 |
import org.eclipse.swt.widgets.ToolBar; |
| 38 |
import org.eclipse.swt.widgets.ToolItem; |
51 |
import org.eclipse.swt.widgets.ToolItem; |
|
|
52 |
import org.eclipse.ui.internal.forms.widgets.FormsResources; |
| 39 |
|
53 |
|
| 40 |
/** |
54 |
/** |
| 41 |
* @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> |
55 |
* @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> |
|
Lines 47-52
Link Here
|
| 47 |
|
61 |
|
| 48 |
{ |
62 |
{ |
| 49 |
private IToolBarManager toolbar; |
63 |
private IToolBarManager toolbar; |
|
|
64 |
private SapphireToolbarContribution sapphireToolbar; |
| 50 |
|
65 |
|
| 51 |
public SapphireToolBarManagerActionPresentation( final SapphireActionPresentationManager manager ) |
66 |
public SapphireToolBarManagerActionPresentation( final SapphireActionPresentationManager manager ) |
| 52 |
{ |
67 |
{ |
|
Lines 68-73
Link Here
|
| 68 |
public void setToolBarManager( final IToolBarManager toolbar ) |
83 |
public void setToolBarManager( final IToolBarManager toolbar ) |
| 69 |
{ |
84 |
{ |
| 70 |
this.toolbar = toolbar; |
85 |
this.toolbar = toolbar; |
|
|
86 |
|
| 87 |
this.sapphireToolbar = new SapphireToolbarContribution("sapphire"); |
| 71 |
} |
88 |
} |
| 72 |
|
89 |
|
| 73 |
public void render() |
90 |
public void render() |
|
Lines 79-91
Link Here
|
| 79 |
boolean first = true; |
96 |
boolean first = true; |
| 80 |
String lastGroup = null; |
97 |
String lastGroup = null; |
| 81 |
|
98 |
|
|
|
99 |
this.toolbar.add(this.sapphireToolbar); |
| 100 |
|
| 82 |
for( final SapphireAction action : getActions() ) |
101 |
for( final SapphireAction action : getActions() ) |
| 83 |
{ |
102 |
{ |
| 84 |
final String group = action.getGroup(); |
103 |
final String group = action.getGroup(); |
| 85 |
|
104 |
|
| 86 |
if( ! first && ! equal( lastGroup, group ) ) |
105 |
if( ! first && ! equal( lastGroup, group ) ) |
| 87 |
{ |
106 |
{ |
| 88 |
this.toolbar.add( new Separator() ); |
107 |
this.sapphireToolbar.add( new Separator() ); |
| 89 |
} |
108 |
} |
| 90 |
|
109 |
|
| 91 |
first = false; |
110 |
first = false; |
|
Lines 130-139
Link Here
|
| 130 |
throw new IllegalStateException(); |
149 |
throw new IllegalStateException(); |
| 131 |
} |
150 |
} |
| 132 |
|
151 |
|
| 133 |
a.setImageDescriptor( action.getImage( 16 ) ); |
152 |
String hint = action.getRenderingHint(ISapphireActionDef.HINT_ACTION_STYLE, ISapphireActionDef.HINT_VALUE_ACTION_STYLE_IMAGE); |
|
|
153 |
|
| 154 |
if (ISapphireActionDef.HINT_VALUE_ACTION_STYLE_IMAGE.equals(hint) || |
| 155 |
ISapphireActionDef.HINT_VALUE_ACTION_STYLE_IMAGE_LABEL.equals(hint)) |
| 156 |
{ |
| 157 |
a.setImageDescriptor( action.getImage( 16 ) ); |
| 158 |
} |
| 159 |
|
| 160 |
if (ISapphireActionDef.HINT_VALUE_ACTION_STYLE_IMAGE_LABEL.equals(hint) || |
| 161 |
ISapphireActionDef.HINT_VALUE_ACTION_STYLE_LABEL_ONLY.equals(hint)) |
| 162 |
{ |
| 163 |
a.setText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, true ) ); |
| 164 |
} |
| 165 |
|
| 134 |
a.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) ); |
166 |
a.setToolTipText( LabelTransformer.transform( action.getLabel(), CapitalizationType.TITLE_STYLE, false ) ); |
| 135 |
|
167 |
|
| 136 |
this.toolbar.add( a ); |
168 |
ActionContributionItem item = new ActionContributionItem(a); |
|
|
169 |
|
| 170 |
if (ISapphireActionDef.HINT_VALUE_ACTION_STYLE_IMAGE_LABEL.equals(hint)) |
| 171 |
{ |
| 172 |
item.setMode(ActionContributionItem.MODE_FORCE_TEXT); |
| 173 |
} |
| 174 |
|
| 175 |
this.sapphireToolbar.add( item ); |
| 137 |
|
176 |
|
| 138 |
final Runnable updateActionEnablementStateOp = new Runnable() |
177 |
final Runnable updateActionEnablementStateOp = new Runnable() |
| 139 |
{ |
178 |
{ |
|
Lines 256-259
Link Here
|
| 256 |
} |
295 |
} |
| 257 |
} |
296 |
} |
| 258 |
|
297 |
|
|
|
298 |
private final class SapphireToolbarContribution extends ControlContribution |
| 299 |
{ |
| 300 |
private ToolBarManager embeddedToolbarManager; |
| 301 |
private List<IContributionItem> items = new ArrayList<IContributionItem>(); |
| 302 |
|
| 303 |
protected SapphireToolbarContribution(String id) |
| 304 |
{ |
| 305 |
super(id); |
| 306 |
} |
| 307 |
|
| 308 |
public void add(IContributionItem item) |
| 309 |
{ |
| 310 |
items.add(item); |
| 311 |
} |
| 312 |
|
| 313 |
@Override |
| 314 |
protected Control createControl(Composite parent) |
| 315 |
{ |
| 316 |
this.embeddedToolbarManager = new ToolBarManager(SWT.FLAT | SWT.RIGHT); |
| 317 |
ToolBar embeddedToolbar = this.embeddedToolbarManager.createControl(parent); |
| 318 |
embeddedToolbar.setBackground(null); |
| 319 |
embeddedToolbar.setForeground(parent.getForeground()); |
| 320 |
embeddedToolbar.setCursor(FormsResources.getHandCursor()); |
| 321 |
updateToolbar(); |
| 322 |
return embeddedToolbar; |
| 323 |
} |
| 324 |
|
| 325 |
private void updateToolbar() |
| 326 |
{ |
| 327 |
this.embeddedToolbarManager.removeAll(); |
| 328 |
|
| 329 |
for (IContributionItem item : items) { |
| 330 |
this.embeddedToolbarManager.add(item); |
| 331 |
} |
| 332 |
|
| 333 |
this.embeddedToolbarManager.update(true); |
| 334 |
} |
| 335 |
|
| 336 |
} |
| 259 |
} |
337 |
} |