| package org.eclipse.ui.internal; |
| |
| /* |
| * Copyright (c) 2002 IBM Corp. All rights reserved. |
| * This file is made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| */ |
| |
| import org.eclipse.jface.action.IContributionItem; |
| import org.eclipse.jface.action.ToolBarManager; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.graphics.Point; |
| import org.eclipse.swt.widgets.*; |
| |
| /** |
| * CoolItemToolBarManager class |
| */ |
| public class CoolItemToolBarManager extends ToolBarManager { |
| CoolBarManager parentManager; |
| CoolBarContributionItem coolBarItem; |
| |
| public CoolItemToolBarManager(int style) { |
| super(style); |
| } |
| public ToolBar createControl(Composite parent) { |
| ToolBar tBar = super.createControl(parent); |
| tBar.setMenu(parentManager.getCoolBarMenu()); |
| return tBar; |
| } |
| public void dispose() { |
| // the toolbar menu is shared by all coolitems, so clear the |
| // reference to the menu so that it does not get disposed of |
| getControl().setMenu(null); |
| super.dispose(); |
| } |
| protected CoolBarContributionItem getCoolBarItem() { |
| return coolBarItem; |
| } |
| protected CoolBarManager getParentManager() { |
| return parentManager; |
| } |
| protected boolean isVisible() { |
| if (coolBarItem == null) { |
| return false; |
| } |
| return coolBarItem.isVisible(); |
| } |
| protected void itemAdded(IContributionItem item) { |
| super.itemAdded(item); |
| update(true); |
| parentManager.updateSizeFor(coolBarItem); |
| } |
| protected void itemRemoved(IContributionItem item) { |
| super.itemRemoved(item); |
| update(true); |
| parentManager.updateSizeFor(coolBarItem); |
| } |
| protected void relayout(ToolBar toolBar, int oldCount, int newCount) { |
| if (oldCount == newCount) return; |
| CoolBar coolBar = (CoolBar)toolBar.getParent(); |
| CoolItem[] coolItems = coolBar.getItems(); |
| CoolItem coolItem = null; |
| for (int i = 0; i < coolItems.length; i++) { |
| CoolItem item = coolItems[i]; |
| if (item.getControl() == toolBar) { |
| coolItem = item; |
| break; |
| } |
| } |
| // recompute preferred size so chevron will work correctly when |
| // items are added/removed from the toolbar, don't set the size of |
| // the coolItem since that would affect the position of other |
| // coolItems on the toolbar |
| if (coolItem != null) { |
| Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); |
| Point coolSize = coolItem.computeSize (size.x, size.y); |
| coolItem.setPreferredSize(coolSize); |
| } |
| coolBar.layout(); |
| } |
| protected void setCoolBarItem(CoolBarContributionItem coolBarItem) { |
| this.coolBarItem = coolBarItem; |
| } |
| protected void setParentMgr(CoolBarManager parentManager) { |
| this.parentManager = parentManager; |
| } |
| |
| protected void setVisible(boolean set) { |
| if (coolBarItem != null) { |
| coolBarItem.setVisible(set); |
| } |
| } |
| protected void setVisible(boolean set, boolean forceVisibility) { |
| if (coolBarItem != null) { |
| coolBarItem.setVisible(set, forceVisibility); |
| } |
| } |
| } |