Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 180514 Details for
Bug 325392
Render menu contributions using the ContributionManagers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fixing the toolbar Renderer v02
toolbarRendering-v02.txt (text/plain), 29.91 KB, created by
Paul Webster
on 2010-10-08 15:04:21 EDT
(
hide
)
Description:
Fixing the toolbar Renderer v02
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2010-10-08 15:04:21 EDT
Size:
29.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.ui.workbench.addons.swt >Index: src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java,v >retrieving revision 1.27 >diff -u -r1.27 CleanupAddon.java >--- src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java 17 Sep 2010 20:20:26 -0000 1.27 >+++ src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java 8 Oct 2010 19:03:14 -0000 >@@ -29,7 +29,7 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.EModelService; > import org.eclipse.emf.ecore.impl.EObjectImpl; >@@ -61,7 +61,7 @@ > // Determine the elements that should *not* ever be auto-destroyed > if (container instanceof MApplication || container instanceof MPerspectiveStack > || container instanceof MMenuElement || container instanceof MTrimBar >- || container instanceof MRenderedToolBar) { >+ || container instanceof MToolBar) { > return; > } > >#P org.eclipse.e4.ui.workbench.renderers.swt >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java,v >retrieving revision 1.17 >diff -u -r1.17 LazyStackRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java 28 Sep 2010 20:18:45 -0000 1.17 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java 8 Oct 2010 19:03:15 -0000 >@@ -27,7 +27,6 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; > import org.eclipse.e4.ui.widgets.CTabFolder; >@@ -169,7 +168,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MRenderedToolBar) >+ if (tbME instanceof MToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -262,7 +261,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MRenderedToolBar) >+ if (tbME instanceof MToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java,v >retrieving revision 1.8 >diff -u -r1.8 MenuRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 8 Oct 2010 14:27:52 -0000 1.8 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 8 Oct 2010 19:03:15 -0000 >@@ -11,6 +11,7 @@ > package org.eclipse.e4.ui.workbench.renderers.swt; > > import java.util.ArrayList; >+import java.util.Collection; > import java.util.HashMap; > import java.util.HashSet; > import java.util.List; >@@ -54,6 +55,8 @@ > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.action.Separator; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Decorations; > import org.eclipse.swt.widgets.Menu; >@@ -264,17 +267,23 @@ > MUIElement container = (MUIElement) ((EObject) element) > .eContainer(); > if (container instanceof MWindow) { >- MenuManager menuBarManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, menuBarManager); >+ MenuManager menuBarManager = getManager(menuModel); >+ if (menuBarManager == null) { >+ menuBarManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, menuBarManager); >+ } > newMenu = menuBarManager.createMenuBar((Decorations) parent); > ((Decorations) parent).setMenuBar(newMenu); > newMenu.setData(menuBarManager); > menuBar = true; > } else { >- MenuManager popupManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >+ MenuManager popupManager = getManager(menuModel); >+ if (popupManager == null) { >+ popupManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, popupManager); >+ } > newMenu = popupManager.createContextMenu((Control) parent); > ((Control) parent).setMenu(newMenu); > newMenu.setData(popupManager); >@@ -285,19 +294,62 @@ > + menuModel + "\n\t" + parent); //$NON-NLS-1$ > > } else if (parent instanceof Control) { >- MenuManager popupManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >+ MenuManager popupManager = getManager(menuModel); >+ if (popupManager == null) { >+ popupManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, popupManager); >+ } > newMenu = popupManager.createContextMenu((Control) parent); > ((Control) parent).setMenu(newMenu); > newMenu.setData(popupManager); > } > processContributions(menuModel, menuBar); >+ if (newMenu != null) { >+ newMenu.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp(menuModel); >+ } >+ }); >+ } > return newMenu; > } > > /** > * @param menuModel >+ */ >+ protected void cleanUp(MMenu menuModel) { >+ Collection<ContributionRecord> vals = modelContributionToRecord >+ .values(); >+ for (ContributionRecord record : vals >+ .toArray(new ContributionRecord[vals.size()])) { >+ if (record.menuModel == menuModel) { >+ record.dispose(); >+ for (MMenuElement copy : record.generatedElements) { >+ modelContributionToRecord.remove(copy); >+ if (copy instanceof MMenu) { >+ MMenu menuCopy = (MMenu) copy; >+ cleanUp(menuCopy); >+ MenuManager copyManager = getManager(menuCopy); >+ clearModelToManager(menuCopy, copyManager); >+ if (copyManager != null) { >+ copyManager.dispose(); >+ } >+ } else { >+ IContributionItem ici = modelToContribution >+ .remove(copy); >+ if (ici != null) { >+ record.manager.remove(ici); >+ } >+ } >+ } >+ record.generatedElements.clear(); >+ } >+ } >+ } >+ >+ /** >+ * @param menuModel > * @param menuBar > */ > private void processContributions(MMenu menuModel, boolean menuBar) { >@@ -390,7 +442,7 @@ > parentContext.runAndTrack(new RunAndTrack() { > @Override > public boolean changed(IEclipseContext context) { >- record.updateVisibility(parentContext); >+ record.updateVisibility(parentContext.getActiveLeaf()); > manager.update(true); > return true; > } >@@ -460,6 +512,12 @@ > generatedElements.add(copy); > } > } >+ >+ public void dispose() { >+ for (MMenuElement copy : generatedElements) { >+ menuModel.getChildren().remove(copy); >+ } >+ } > } > > void removeMenuContributions(final MMenu menuModel, >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java,v >retrieving revision 1.22 >diff -u -r1.22 StackRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java 4 Oct 2010 13:25:03 -0000 1.22 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java 8 Oct 2010 19:03:15 -0000 >@@ -30,7 +30,6 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MStackElement; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; > import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.services.IStylingEngine; >@@ -41,7 +40,6 @@ > import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.EPartService; >-import org.eclipse.jface.action.ToolBarManager; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.MenuDetectEvent; > import org.eclipse.swt.events.MenuDetectListener; >@@ -405,7 +403,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MRenderedToolBar) >+ if (tbME instanceof MToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -524,7 +522,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MRenderedToolBar) >+ if (tbME instanceof MToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -538,15 +536,9 @@ > MToolBar toolbar = part.getToolbar(); > if (toolbar == null) { > if (viewMenu != null) { >- MRenderedToolBar rtb = MenuFactoryImpl.eINSTANCE >- .createRenderedToolBar(); >- rtb.setContributionManager(new ToolBarManager()); >- part.setToolbar(rtb); >- } >- } else if (toolbar instanceof MRenderedToolBar) { >- MRenderedToolBar rtb = (MRenderedToolBar) toolbar; >- if (rtb.getContributionManager() == null) { >- rtb.setContributionManager(new ToolBarManager()); >+ toolbar = MenuFactoryImpl.eINSTANCE.createToolBar(); >+ toolbar.setElementId(part.getElementId()); >+ part.setToolbar(toolbar); > } > } > >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java,v >retrieving revision 1.9 >diff -u -r1.9 ToolBarRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java 8 Oct 2010 14:27:51 -0000 1.9 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java 8 Oct 2010 19:03:16 -0000 >@@ -23,18 +23,22 @@ > import org.eclipse.e4.core.contexts.RunAndTrack; > import org.eclipse.e4.core.services.events.IEventBroker; > import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; >+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; > import org.eclipse.e4.ui.model.application.MApplication; > import org.eclipse.e4.ui.model.application.ui.MElementContainer; > import org.eclipse.e4.ui.model.application.ui.MUIElement; > import org.eclipse.e4.ui.model.application.ui.SideValue; >+import org.eclipse.e4.ui.model.application.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; > import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; > import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; > import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; >+import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.EModelService; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >@@ -44,15 +48,26 @@ > import org.eclipse.jface.action.ContributionItem; > import org.eclipse.jface.action.GroupMarker; > import org.eclipse.jface.action.IContributionItem; >-import org.eclipse.jface.action.IContributionManager; > import org.eclipse.jface.action.Separator; > import org.eclipse.jface.action.ToolBarManager; >-import org.eclipse.jface.layout.RowLayoutFactory; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.ToolBar; > import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Widget; > import org.osgi.service.event.Event; > import org.osgi.service.event.EventHandler; > >@@ -66,10 +81,14 @@ > > private Map<MToolBarElement, IContributionItem> modelToContribution = new HashMap<MToolBarElement, IContributionItem>(); > >+ private ArrayList<ContributionRecord> contributionRecords = new ArrayList<ContributionRecord>(); >+ > // @Inject > // private Logger logger; > > @Inject >+ IPresentationEngine renderer; >+ @Inject > private MApplication application; > @Inject > private EModelService modelService; >@@ -121,6 +140,12 @@ > if (itemModel.isToBeRendered()) { > if (parent != null) { > modelProcessSwitch(parent, itemModel); >+ parent.update(true); >+ ToolBar tb = parent.getControl(); >+ if (tb != null && !tb.isDisposed()) { >+ tb.getShell().layout(new Control[] { tb }, >+ SWT.DEFER); >+ } > } > } else { > IContributionItem ici = modelToContribution >@@ -138,10 +163,14 @@ > return; > } > ici.setVisible(itemModel.isVisible()); >- IContributionManager parent = ((ContributionItem) ici) >+ ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici) > .getParent(); > if (parent != null) { > parent.markDirty(); >+ ToolBar tb = parent.getControl(); >+ if (tb != null && !tb.isDisposed()) { >+ tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ } > } > } > } >@@ -176,6 +205,7 @@ > } > } > }; >+ private Image viewMenuImage; > > @PostConstruct > public void init() { >@@ -212,11 +242,11 @@ > return null; > > // HACK!! This should be done using a separate renderer >- Composite intermediate = new Composite((Composite) parent, SWT.NONE); >- createToolbar(element, intermediate); >+ // Composite intermediate = new Composite((Composite) parent, SWT.NONE); >+ ToolBar bar = createToolbar(element, (Composite) parent); > processContribution((MToolBar) element); > >- return intermediate; >+ return bar; > } > > /** >@@ -295,6 +325,12 @@ > } > manager.markDirty(); > } >+ >+ public void dispose() { >+ for (MToolBarElement copy : generatedElements) { >+ toolbarModel.getChildren().remove(copy); >+ } >+ } > } > > /** >@@ -313,6 +349,7 @@ > } > final ContributionRecord record = new ContributionRecord(toolbarModel, > contribution, manager); >+ contributionRecords.add(record); > record.generate(); > for (MToolBarElement copy : record.generatedElements) { > if (copy instanceof MToolBarSeparator >@@ -332,8 +369,8 @@ > parentContext.runAndTrack(new RunAndTrack() { > @Override > public boolean changed(IEclipseContext context) { >- record.updateVisibility(parentContext); >- manager.update(true); >+ record.updateVisibility(parentContext.getActiveLeaf()); >+ manager.update(false); > return true; > } > }); >@@ -369,27 +406,47 @@ > return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ > } > >- ToolBar createToolbar(final MUIElement element, Composite intermediate) { >+ private ToolBar createToolbar(final MUIElement element, >+ Composite intermediate) { > int orientation = getOrientation(element); >- RowLayout layout = RowLayoutFactory.fillDefaults().wrap(false) >- .spacing(0).type(orientation).create(); >- layout.marginLeft = 3; >- layout.center = true; >- intermediate.setLayout(layout); >- // new Label(intermediate, (orientation == SWT.HORIZONTAL ? SWT.VERTICAL >- // : SWT.HORIZONTAL) | SWT.SEPARATOR); >- >- ToolBar separatorToolBar = new ToolBar(intermediate, orientation >- | SWT.WRAP | SWT.FLAT | SWT.RIGHT); >- new ToolItem(separatorToolBar, SWT.SEPARATOR); >- ToolBarManager manager = new ToolBarManager(orientation | SWT.WRAP >- | SWT.FLAT | SWT.RIGHT); >- modelToManager.put((MToolBar) element, manager); >+ >+ ToolBarManager manager = getManager((MToolBar) element); >+ if (manager == null) { >+ manager = new ToolBarManager(orientation | SWT.WRAP | SWT.FLAT >+ | SWT.RIGHT); >+ linkModelToManager((MToolBar) element, manager); >+ } > ToolBar bar = manager.createControl(intermediate); > bar.setData(manager); >+ bar.getShell().layout(new Control[] { bar }, SWT.DEFER); >+ bar.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp((MToolBar) element); >+ } >+ }); > return bar; > } > >+ /** >+ * @param element >+ */ >+ protected void cleanUp(MToolBar toolbarModel) { >+ for (ContributionRecord record : contributionRecords >+ .toArray(new ContributionRecord[contributionRecords.size()])) { >+ if (record.toolbarModel == toolbarModel) { >+ record.dispose(); >+ contributionRecords.remove(record); >+ for (MToolBarElement copy : record.generatedElements) { >+ IContributionItem ici = modelToContribution.remove(copy); >+ if (ici != null) { >+ record.manager.remove(ici); >+ } >+ } >+ record.generatedElements.clear(); >+ } >+ } >+ } >+ > int getOrientation(final MUIElement element) { > MUIElement theParent = element.getParent(); > if (theParent instanceof MTrimBar) { >@@ -417,7 +474,8 @@ > if (container == null) > return; > >- ToolBarManager parentManager = modelToManager.get(container); >+ Object obj = container; >+ ToolBarManager parentManager = getManager((MToolBar) obj); > if (parentManager == null) { > return; > } >@@ -431,6 +489,216 @@ > } > } > parentManager.update(false); >+ >+ ToolBar tb = (ToolBar) container.getWidget(); >+ if (((EObject) container).eContainer() instanceof MPart) { >+ MPart part = (MPart) ((EObject) container).eContainer(); >+ MMenu viewMenu = getViewMenu(part); >+ >+ // View menu (if any) >+ if (viewMenu != null) { >+ addMenuButton(part, tb, viewMenu); >+ } >+ } >+ tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ } >+ >+ /** >+ * @param tb >+ */ >+ private void addMenuButton(MPart part, ToolBar tb, MMenu menu) { >+ ToolItem ti = new ToolItem(tb, SWT.PUSH); >+ ti.setImage(getViewMenuImage()); >+ ti.setHotImage(null); >+ ti.setToolTipText("View Menu"); //$NON-NLS-1$ >+ ti.setData("theMenu", menu); //$NON-NLS-1$ >+ ti.setData("thePart", part); //$NON-NLS-1$ >+ >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ }); >+ } >+ >+ /** >+ * @param item >+ */ >+ protected void showMenu(ToolItem item) { >+ // Create the UI for the menu >+ final MMenu menuModel = (MMenu) item.getData("theMenu"); //$NON-NLS-1$ >+ MPart part = (MPart) item.getData("thePart"); //$NON-NLS-1$ >+ Control ctrl = (Control) part.getWidget(); >+ Menu menu = (Menu) renderer.createGui(menuModel, ctrl.getShell(), >+ part.getContext()); >+ >+ // ...and Show it... >+ Rectangle ib = item.getBounds(); >+ Point displayAt = item.getParent().toDisplay(ib.x, ib.y + ib.height); >+ menu.setLocation(displayAt); >+ menu.setVisible(true); >+ >+ Display display = Display.getCurrent(); >+ while (!menu.isDisposed() && menu.isVisible()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ menu.dispose(); >+ } >+ >+ private Image getViewMenuImage() { >+ if (viewMenuImage == null) { >+ Display d = Display.getCurrent(); >+ >+ Image viewMenu = new Image(d, 16, 16); >+ Image viewMenuMask = new Image(d, 16, 16); >+ >+ Display display = Display.getCurrent(); >+ GC gc = new GC(viewMenu); >+ GC maskgc = new GC(viewMenuMask); >+ gc.setForeground(display >+ .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >+ gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); >+ >+ int[] shapeArray = new int[] { 6, 1, 15, 1, 11, 5, 10, 5 }; >+ gc.fillPolygon(shapeArray); >+ gc.drawPolygon(shapeArray); >+ >+ Color black = display.getSystemColor(SWT.COLOR_BLACK); >+ Color white = display.getSystemColor(SWT.COLOR_WHITE); >+ >+ maskgc.setBackground(black); >+ maskgc.fillRectangle(0, 0, 16, 16); >+ >+ maskgc.setBackground(white); >+ maskgc.setForeground(white); >+ maskgc.fillPolygon(shapeArray); >+ maskgc.drawPolygon(shapeArray); >+ gc.dispose(); >+ maskgc.dispose(); >+ >+ ImageData data = viewMenu.getImageData(); >+ data.transparentPixel = data.getPixel(0, 0); >+ >+ viewMenuImage = new Image(d, viewMenu.getImageData(), >+ viewMenuMask.getImageData()); >+ viewMenu.dispose(); >+ viewMenuMask.dispose(); >+ } >+ return viewMenuImage; >+ } >+ >+ private MMenu getViewMenu(MPart part) { >+ if (part.getMenus() == null) { >+ return null; >+ } >+ for (MMenu menu : part.getMenus()) { >+ if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >+ return menu; >+ } >+ } >+ return null; >+ } >+ >+ boolean hasOnlySeparators(ToolBar toolbar) { >+ ToolItem[] children = toolbar.getItems(); >+ for (ToolItem toolItem : children) { >+ if ((toolItem.getStyle() & SWT.SEPARATOR) == 0) { >+ return false; >+ } else if (toolItem.getControl() != null >+ && toolItem.getControl().getData(OWNING_ME) instanceof MToolControl) { >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ ToolBar findToolbar(Composite intermediate) { >+ if (!intermediate.isDisposed()) { >+ Control[] children = intermediate.getChildren(); >+ int length = children.length; >+ if (length > 0 && children[length - 1] instanceof ToolBar) { >+ return (ToolBar) children[length - 1]; >+ } >+ } >+ return null; >+ } >+ >+ @Override >+ public void postProcess(MUIElement element) { >+ super.postProcess(element); >+ // disposeToolbarIfNecessary(element); >+ if (element.getWidget() instanceof ToolBar) { >+ ToolBar toolbar = (ToolBar) element.getWidget(); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } >+ toolbar.setVisible(true); >+ } >+ } >+ >+ public Object getUIContainer(MUIElement childElement) { >+ if (childElement.getWidget() instanceof ToolBar) { >+ return childElement.getWidget(); >+ } >+ >+ Object obj = super.getUIContainer(childElement); >+ if (obj instanceof ToolBar) { >+ return obj; >+ } >+ >+ if (obj instanceof Composite) { >+ Composite intermediate = (Composite) obj; >+ if (intermediate == null || intermediate.isDisposed()) { >+ return null; >+ } >+ ToolBar toolbar = findToolbar(intermediate); >+ if (toolbar == null) { >+ toolbar = createToolbar(childElement.getParent(), intermediate); >+ } >+ return toolbar; >+ } >+ return null; >+ } >+ >+ @Override >+ public void disposeWidget(MUIElement element) { >+ ToolBar tb = (ToolBar) element.getWidget(); >+ tb.setVisible(false); >+ unbindWidget(element); >+ tb.setData(AbstractPartRenderer.OWNING_ME, element); >+ } >+ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) { >+ widget.dispose(); >+ } >+ ToolBar toolbar = (ToolBar) getUIContainer(child); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } >+ // disposeToolbarIfNecessary(parentElement); >+ } >+ >+ @Override >+ public void childRendered(MElementContainer<MUIElement> parentElement, >+ MUIElement element) { >+ super.childRendered(parentElement, element); >+ ToolBar toolbar = (ToolBar) getUIContainer(element); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } > } > > /** >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java,v >retrieving revision 1.18 >diff -u -r1.18 ActionBars.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java 24 Sep 2010 12:52:29 -0000 1.18 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java 8 Oct 2010 19:03:17 -0000 >@@ -17,7 +17,7 @@ > import org.eclipse.e4.ui.model.application.ui.MUIElement; > import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; > import org.eclipse.e4.ui.model.application.ui.basic.MPart; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.IToolBarManager; >@@ -84,17 +84,18 @@ > if (tbCtrl != null && !tbCtrl.isDisposed()) { > MUIElement tbModel = (MUIElement) tbCtrl > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbModel instanceof MRenderedToolBar) { >+ if (tbModel instanceof MToolBar) { > // only force a rerender if the toolbar can be seen > if (isSelected(part)) { >+ Object tbParent = tbCtrl.getParent(); > if (part.getContext() != null) { > IPresentationEngine renderer = part.getContext().get( > IPresentationEngine.class); > if (renderer != null) { > renderer.removeGui(tbModel); >- renderer.createGui(tbModel, tbCtrl.getParent(), >+ renderer.createGui(tbModel, tbParent, > part.getContext()); >- tbCtrl.getParent().layout(); >+ ((Control) tbModel.getWidget()).getParent().layout(); > } > } > } >Index: Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java,v >retrieving revision 1.32 >diff -u -r1.32 CompatibilityView.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 4 Aug 2010 15:49:00 -0000 1.32 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 8 Oct 2010 19:03:17 -0000 >@@ -12,14 +12,17 @@ > package org.eclipse.ui.internal.e4.compatibility; > > import javax.inject.Inject; >+import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; >+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; > import org.eclipse.e4.ui.model.application.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu; >-import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; >+import org.eclipse.e4.ui.workbench.renderers.swt.MenuRenderer; > import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; >+import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarRenderer; >+import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.action.ToolBarManager; > import org.eclipse.swt.widgets.Composite; >@@ -75,16 +78,19 @@ > // dispose the tb, it will be re-created when the tab is shown > tb.dispose(); > >+ IEclipseContext context = getModel().getContext(); >+ IRendererFactory rendererFactory = context.get(IRendererFactory.class); >+ > MenuManager mm = (MenuManager) actionBars.getMenuManager(); >- MRenderedMenu menu = null; >+ MMenu menu = null; > for (MMenu me : part.getMenus()) { >- if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU) && (me instanceof MRenderedMenu)) { >- menu = (MRenderedMenu) me; >+ if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >+ menu = me; > break; > } > } > if (menu == null) { >- menu = MenuFactoryImpl.eINSTANCE.createRenderedMenu(); >+ menu = MenuFactoryImpl.eINSTANCE.createMenu(); > menu.setElementId(part.getElementId()); > > menu.getTags().add(StackRenderer.TAG_VIEW_MENU); >@@ -92,17 +98,21 @@ > part.getMenus().add(menu); > > } >- menu.setContributionManager(mm); >+ AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent); >+ if (apr instanceof MenuRenderer) { >+ ((MenuRenderer) apr).linkModelToManager(menu, mm); >+ } > > // Construct the toolbar (if necessary) > MToolBar toolbar = part.getToolbar(); > if (toolbar == null) { >- toolbar = MenuFactoryImpl.eINSTANCE.createRenderedToolBar(); >+ toolbar = MenuFactoryImpl.eINSTANCE.createToolBar(); > toolbar.setElementId(part.getElementId()); > part.setToolbar(toolbar); > } >- if (toolbar instanceof MRenderedToolBar) { >- ((MRenderedToolBar) toolbar).setContributionManager(tbm); >+ apr = rendererFactory.getRenderer(toolbar, parent); >+ if (apr instanceof ToolBarRenderer) { >+ ((ToolBarRenderer) apr).linkModelToManager(toolbar, tbm); > } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 325392
:
179140
|
180268
| 180514 |
180901
|
181172
|
181191
|
181226
|
182202
|
182509
|
182904
|
183010