diff -r 231c47d08fe4 -r 085da1889c59 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/TaskBar.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/TaskBar.java Tue Jul 13 15:27:30 2010 -0500 @@ -0,0 +1,122 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.editor; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.RowDataFactory; +import org.eclipse.jface.layout.RowLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.events.IHyperlinkListener; +import org.eclipse.ui.forms.widgets.Hyperlink; + +import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage.IActionBar; + +class TaskBar extends RoundedCornerComposite { + + private final class ActionListener implements IHyperlinkListener { + @Override + public void linkActivated(HyperlinkEvent e) { + Hyperlink link = (Hyperlink) e.getSource(); + runAction(link); + } + + @Override + public void linkEntered(HyperlinkEvent e) { + Hyperlink link = (Hyperlink) e.getSource(); + link.setUnderlined(true); + } + + @Override + public void linkExited(HyperlinkEvent e) { + Hyperlink link = (Hyperlink) e.getSource(); + link.setUnderlined(false); + } + } + + private PortalEditor portalEditor; + private Map linkToActionMap; + private ActionListener listener; + + public TaskBar(Composite parent, PortalEditor portalEditor, IActionBar actionBar) { + super(parent, portalEditor.getBackgroundParent(), + parent.getDisplay().getSystemColor(SWT.COLOR_BLACK), + parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + this.portalEditor = portalEditor; + createTitle(actionBar); + createActions(actionBar); + setLayoutData(GridDataFactory.swtDefaults().grab(true, true).align(SWT.CENTER, SWT.BEGINNING).create()); + setLayout(RowLayoutFactory.swtDefaults().type(SWT.VERTICAL).margins(10, 10).extendedMargins(5, 5, 5, 10).fill(true).wrap(false).create()); + } + + private void createTitle(IActionBar actionBar) { + String title = actionBar.getTitle(); + if (title != null) { + Label l = new Label(this, SWT.LEFT); + l.setFont(portalEditor.createFont("Arial", 10, SWT.BOLD)); + l.setBackground(l.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + l.setText(title); + l.setLayoutData(RowDataFactory.swtDefaults().create()); + l = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR); + l.setLayoutData(RowDataFactory.swtDefaults().create()); + } + } + + private void createActions(IActionBar actionBar) { + listener = new ActionListener(); + linkToActionMap = new HashMap(); + for (IAction action : actionBar.getActions()) { + Hyperlink link = new Hyperlink(this, SWT.NONE); + link.setText(action.getText()); + String toolTipText = action.getToolTipText(); + if (toolTipText != null) + link.setToolTipText(toolTipText); + link.setBackground(link.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + linkToActionMap.put(link, action); + link.addHyperlinkListener(listener); + } +// updateAllActionsUI(); + } + + public void runAction(Hyperlink link) { + IAction action = linkToActionMap.get(link); + action.run(); + } + + public void updateActionUI(String actionId) { + for (Entry entry : linkToActionMap.entrySet()) { + IAction action = entry.getValue(); + if (actionId.equals(action.getId())) { + entry.getKey().setEnabled(action.isEnabled()); + } + } + } + + public void updateAllActionsUI() { + for (Entry entry : linkToActionMap.entrySet()) { + entry.getKey().setEnabled(entry.getValue().isEnabled()); + } + } + +} \ No newline at end of file