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.LinkedHashMap;
|
|
20 |
import java.util.Map;
|
|
21 |
|
|
22 |
import org.eclipse.jface.layout.RowDataFactory;
|
|
23 |
import org.eclipse.jface.layout.RowLayoutFactory;
|
1618
|
24 |
import org.eclipse.jface.resource.FontDescriptor;
|
|
25 |
import org.eclipse.jface.resource.JFaceResources;
|
1609
|
26 |
import org.eclipse.swt.SWT;
|
|
27 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
28 |
import org.eclipse.swt.events.SelectionEvent;
|
|
29 |
import org.eclipse.swt.events.SelectionListener;
|
|
30 |
import org.eclipse.swt.graphics.Font;
|
1618
|
31 |
import org.eclipse.swt.graphics.FontData;
|
1609
|
32 |
import org.eclipse.swt.widgets.Button;
|
|
33 |
import org.eclipse.swt.widgets.Composite;
|
|
34 |
|
|
35 |
import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage;
|
|
36 |
|
|
37 |
class NavigationBar extends RoundedCornerComposite {
|
|
38 |
|
|
39 |
private PortalEditor portalEditor;
|
|
40 |
|
|
41 |
|
|
42 |
private final class ButtonListener extends SelectionAdapter {
|
|
43 |
@Override
|
|
44 |
public void widgetSelected(SelectionEvent e) {
|
|
45 |
Button button = (Button) e.getSource();
|
|
46 |
selectNavButton(button);
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|
|
50 |
private Map<Button, IPortalPage> buttonToPageMap;
|
|
51 |
private SelectionListener listener;
|
|
52 |
private Font buttonFont;
|
|
53 |
private Font selectedButtonFont;
|
|
54 |
|
|
55 |
NavigationBar(PortalEditor portalEditor, Composite parent) {
|
|
56 |
super(parent, portalEditor.getBackgroundParent(),
|
|
57 |
parent.getDisplay().getSystemColor(SWT.COLOR_BLACK),
|
|
58 |
parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
|
|
59 |
this.portalEditor = portalEditor;
|
|
60 |
buttonToPageMap = new LinkedHashMap<Button, IPortalPage>();
|
1618
|
61 |
RowLayoutFactory.swtDefaults().margins(3, 3).wrap(false).applyTo(this);
|
1609
|
62 |
listener = new ButtonListener();
|
1618
|
63 |
selectedButtonFont = JFaceResources.getHeaderFont();
|
|
64 |
FontData[] fontData = selectedButtonFont.getFontData();
|
|
65 |
for (FontData fd : fontData) {
|
|
66 |
fd.setStyle(SWT.NORMAL);
|
|
67 |
}
|
|
68 |
FontDescriptor desc = FontDescriptor.createFrom(fontData);
|
|
69 |
buttonFont = portalEditor.createFont(desc);
|
1609
|
70 |
}
|
|
71 |
|
|
72 |
public void initUI() {
|
|
73 |
if (buttonToPageMap.isEmpty())
|
|
74 |
return;
|
|
75 |
selectNavButton(buttonToPageMap.keySet().iterator().next());
|
|
76 |
}
|
|
77 |
|
|
78 |
public void addNavButton(NavigationBar bar, IPortalPage page) {
|
|
79 |
Button b = new Button(bar, SWT.TOGGLE | SWT.FLAT);
|
|
80 |
b.setFont(buttonFont);
|
|
81 |
b.setText(page.getText());
|
1618
|
82 |
b.setImage(portalEditor.createImage(page.getImageDescriptor(), 16, 16));
|
1609
|
83 |
b.addSelectionListener(listener);
|
1618
|
84 |
RowDataFactory.swtDefaults().applyTo(b);
|
1609
|
85 |
buttonToPageMap.put(b, page);
|
|
86 |
}
|
|
87 |
|
|
88 |
|
|
89 |
public void selectNavButton(Button button) {
|
|
90 |
for (Button other : buttonToPageMap.keySet()) {
|
|
91 |
other.setSelection(false);
|
|
92 |
other.setFont(buttonFont);
|
|
93 |
}
|
|
94 |
button.setSelection(true);
|
1618
|
95 |
portalEditor.showPage(buttonToPageMap.get(button));
|
1609
|
96 |
button.setFont(selectedButtonFont);
|
1618
|
97 |
layout();
|
|
98 |
}
|
|
99 |
|
|
100 |
@Override
|
|
101 |
public void layout() {
|
|
102 |
super.layout();
|
|
103 |
pack();
|
1609
|
104 |
}
|
|
105 |
} |