1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.action.ContributionItem; 14 import org.eclipse.jface.action.IContributionItem; 15 import org.eclipse.jface.action.IMenuListener; 16 import org.eclipse.jface.action.IMenuManager; 17 import org.eclipse.jface.action.MenuManager; 18 import org.eclipse.jface.action.ToolBarManager; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.events.SelectionAdapter; 21 import org.eclipse.swt.events.SelectionEvent; 22 import org.eclipse.swt.events.SelectionListener; 23 import org.eclipse.swt.graphics.Image; 24 import org.eclipse.swt.widgets.Menu; 25 import org.eclipse.swt.widgets.MenuItem; 26 import org.eclipse.swt.widgets.ToolBar; 27 import org.eclipse.swt.widgets.ToolItem; 28 import org.eclipse.ui.IViewReference; 29 import org.eclipse.ui.internal.layout.TrimToolBarBase; 30 31 35 public class ViewStackTrimToolBar extends TrimToolBarBase { 36 private boolean restoreOnUnzoom = false; 37 38 private int paneOrientation; 40 41 private String selectedTabId; 43 44 public ViewStackTrimToolBar(String id, int curSide, int paneOrientation, WorkbenchWindow wbw) { 45 super(id, curSide, wbw); 46 47 this.paneOrientation = paneOrientation; 48 dock(curSide); 49 } 50 51 54 protected void restoreToPresentation() { 55 Perspective persp = wbw.getActiveWorkbenchPage().getActivePerspective(); 56 58 LayoutPart part = persp.getPresentation().findPart(getId(), null); 59 if (part instanceof ContainerPlaceholder) { 60 ViewStack stack = (ViewStack) ((ContainerPlaceholder)part).getRealContainer(); 61 stack.setMinimized(false); 62 } 63 } 65 66 public void initToolBarManager(final ToolBarManager mgr) { 67 IContributionItem restoreContrib = new ContributionItem() { 69 public void fill(ToolBar parent, int index) { 70 ToolItem restoreItem = new ToolItem(mgr.getControl(), SWT.PUSH, index); 71 Image tbImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_ETOOL_RESTORE_TRIMPART); 72 restoreItem.setImage(tbImage); 73 String menuTip = WorkbenchMessages.StandardSystemToolbar_Restore; 74 restoreItem.setToolTipText(menuTip); 75 restoreItem.addSelectionListener(new SelectionListener() { 76 public void widgetDefaultSelected(SelectionEvent e) { 77 restoreToPresentation(); 78 } 79 public void widgetSelected(SelectionEvent e) { 80 restoreToPresentation(); 81 } 82 }); 83 } 84 }; 85 mgr.add(restoreContrib); 86 87 ShowFastViewContribution sfvc = new ShowFastViewContribution(wbw, getId()); 88 mgr.add(sfvc); 89 90 mgr.setContextMenuManager(new MenuManager()); 92 MenuManager menuMgr = mgr.getContextMenuManager(); 93 94 final IContributionItem closeContrib = new ContributionItem() { 95 public void fill(Menu parent, int index) { 96 MenuItem closeItem = new MenuItem(parent, SWT.NONE, index++); 97 closeItem.setText(WorkbenchMessages.WorkbenchWindow_close); 98 closeItem.addSelectionListener(new SelectionAdapter() { 99 public void widgetSelected(SelectionEvent e) { 100 IViewReference selectedView = null; 101 if (contextToolItem != null) { 102 selectedView = (IViewReference) contextToolItem.getData(ShowFastViewContribution.FAST_VIEW); 103 } 104 105 if (selectedView != null) { 106 WorkbenchPage page = wbw.getActiveWorkbenchPage(); 107 if (page != null) { 108 page.hideView(selectedView); 109 } 110 } 111 } 112 }); 113 } 114 }; 115 116 menuMgr.addMenuListener(new IMenuListener() { 118 public void menuAboutToShow(IMenuManager manager) { 119 IViewReference selectedView = null; 120 if (contextToolItem != null) { 121 selectedView = (IViewReference) contextToolItem.getData(ShowFastViewContribution.FAST_VIEW); 122 } 123 124 Perspective persp = wbw.getActiveWorkbenchPage().getActivePerspective(); 126 closeContrib.setVisible(selectedView != null && persp.isCloseable(selectedView)); 127 manager.update(true); 128 } 129 }); 130 131 menuMgr.add(closeContrib); 132 } 133 134 137 public void hookControl(ToolBarManager mgr) { 138 new FastViewDnDHandler(id, mgr, wbw); 142 } 143 144 150 public void setRestoreOnUnzoom(boolean restoreOnUnzoom) { 151 this.restoreOnUnzoom = restoreOnUnzoom; 152 } 153 154 public boolean restoreOnUnzoom() { 155 return restoreOnUnzoom; 156 } 157 158 162 public void setIconSelection(IViewReference ref, boolean selected) { 163 ToolItem item = ShowFastViewContribution.getItem(tbMgr.getControl(), ref); 164 if (item != null) { 165 item.setSelection(selected); 166 167 if (selected) { 168 selectedTabId = ref.getId(); 169 170 if (ref.getSecondaryId() != null) 172 selectedTabId = selectedTabId + ':' + ref.getSecondaryId(); 173 } 174 } 175 } 176 177 180 public int getPaneOrientation() { 181 return paneOrientation; 182 } 183 184 188 public void setSelectedTabId(String id) { 189 selectedTabId = id; 190 } 191 192 195 public String getSelectedTabId() { 196 return selectedTabId; 197 } 198 199 203 public void setOrientation(int newOrientation, WorkbenchWindow wbw) { 204 if (newOrientation == paneOrientation) 205 return; 206 207 paneOrientation = newOrientation; 208 209 if (wbw.getActivePage() instanceof WorkbenchPage) { 211 WorkbenchPage wbp = (WorkbenchPage) wbw.getActivePage(); 212 Perspective persp = wbp.getActivePerspective(); 213 if (persp != null) { 214 IViewReference curRef = persp.getActiveFastView(); 215 if (curRef != null) { 216 persp.setActiveFastView(null); 217 persp.setActiveFastView(curRef); 218 } 219 } 220 221 } 222 223 } 224 } 225 | Popular Tags |