1609
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.carbide.internal.discovery.ui.editor;
|
|
18 |
|
|
19 |
import java.util.HashMap;
|
|
20 |
import java.util.Map;
|
|
21 |
import java.util.Map.Entry;
|
|
22 |
|
|
23 |
import org.eclipse.jface.action.IAction;
|
|
24 |
import org.eclipse.jface.layout.RowDataFactory;
|
|
25 |
import org.eclipse.jface.layout.RowLayoutFactory;
|
1618
|
26 |
import org.eclipse.jface.resource.JFaceResources;
|
1609
|
27 |
import org.eclipse.swt.SWT;
|
|
28 |
import org.eclipse.swt.widgets.Composite;
|
|
29 |
import org.eclipse.swt.widgets.Label;
|
|
30 |
import org.eclipse.ui.forms.events.HyperlinkEvent;
|
|
31 |
import org.eclipse.ui.forms.events.IHyperlinkListener;
|
|
32 |
import org.eclipse.ui.forms.widgets.Hyperlink;
|
|
33 |
|
1734
|
34 |
import com.nokia.carbide.internal.discovery.ui.extension.IActionBar;
|
1609
|
35 |
|
|
36 |
class TaskBar extends RoundedCornerComposite {
|
|
37 |
|
|
38 |
private final class ActionListener implements IHyperlinkListener {
|
|
39 |
@Override
|
|
40 |
public void linkActivated(HyperlinkEvent e) {
|
|
41 |
Hyperlink link = (Hyperlink) e.getSource();
|
|
42 |
runAction(link);
|
|
43 |
}
|
|
44 |
|
|
45 |
@Override
|
|
46 |
public void linkEntered(HyperlinkEvent e) {
|
|
47 |
Hyperlink link = (Hyperlink) e.getSource();
|
|
48 |
link.setUnderlined(true);
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
|
52 |
public void linkExited(HyperlinkEvent e) {
|
|
53 |
Hyperlink link = (Hyperlink) e.getSource();
|
|
54 |
link.setUnderlined(false);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
private Map<Hyperlink, IAction> linkToActionMap;
|
|
59 |
private ActionListener listener;
|
|
60 |
|
1705
|
61 |
public TaskBar(Composite parent, Composite backgroundParent, IActionBar actionBar) {
|
|
62 |
super(parent, backgroundParent,
|
1609
|
63 |
parent.getDisplay().getSystemColor(SWT.COLOR_BLACK),
|
|
64 |
parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
|
|
65 |
createTitle(actionBar);
|
|
66 |
createActions(actionBar);
|
1831
|
67 |
RowLayoutFactory.swtDefaults().type(SWT.VERTICAL).margins(5, 5).extendedMargins(7, 7, 7, 7).fill(true).wrap(false).applyTo(this);
|
1609
|
68 |
}
|
|
69 |
|
|
70 |
private void createTitle(IActionBar actionBar) {
|
1615
|
71 |
Label l = new Label(this, SWT.LEFT);
|
1618
|
72 |
l.setFont(JFaceResources.getBannerFont());
|
1615
|
73 |
l.setBackground(l.getDisplay().getSystemColor(SWT.COLOR_WHITE));
|
|
74 |
l.setText(actionBar.getTitle());
|
|
75 |
RowDataFactory.swtDefaults().applyTo(l);
|
|
76 |
l = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
|
|
77 |
RowDataFactory.swtDefaults().applyTo(l);
|
1609
|
78 |
}
|
|
79 |
|
|
80 |
private void createActions(IActionBar actionBar) {
|
|
81 |
listener = new ActionListener();
|
|
82 |
linkToActionMap = new HashMap<Hyperlink, IAction>();
|
|
83 |
for (IAction action : actionBar.getActions()) {
|
|
84 |
Hyperlink link = new Hyperlink(this, SWT.NONE);
|
|
85 |
link.setText(action.getText());
|
|
86 |
String toolTipText = action.getToolTipText();
|
|
87 |
if (toolTipText != null)
|
|
88 |
link.setToolTipText(toolTipText);
|
1653
|
89 |
link.setForeground(link.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
|
1609
|
90 |
link.setBackground(link.getDisplay().getSystemColor(SWT.COLOR_WHITE));
|
1661
|
91 |
String actionId = action.getId();
|
|
92 |
String[] highlightedActionIds = actionBar.getHighlightedActionIds();
|
|
93 |
if (actionId != null && highlightedActionIds != null) {
|
|
94 |
for (String highlightedId : highlightedActionIds) {
|
|
95 |
if (highlightedId.equals(actionId)) {
|
|
96 |
link.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
|
|
97 |
break;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
1609
|
101 |
linkToActionMap.put(link, action);
|
|
102 |
link.addHyperlinkListener(listener);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
public void runAction(Hyperlink link) {
|
|
107 |
IAction action = linkToActionMap.get(link);
|
|
108 |
action.run();
|
|
109 |
}
|
|
110 |
|
|
111 |
public void updateActionUI(String actionId) {
|
|
112 |
for (Entry<Hyperlink, IAction> entry : linkToActionMap.entrySet()) {
|
|
113 |
IAction action = entry.getValue();
|
|
114 |
if (actionId.equals(action.getId())) {
|
1734
|
115 |
Hyperlink link = entry.getKey();
|
|
116 |
if (link != null && !link.isDisposed())
|
|
117 |
link.setEnabled(entry.getValue().isEnabled());
|
1609
|
118 |
}
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
public void updateAllActionsUI() {
|
|
123 |
for (Entry<Hyperlink, IAction> entry : linkToActionMap.entrySet()) {
|
1734
|
124 |
Hyperlink link = entry.getKey();
|
|
125 |
if (link != null && !link.isDisposed())
|
|
126 |
link.setEnabled(entry.getValue().isEnabled());
|
1609
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
} |