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 24347 Details for
Bug 93806
[PresentationAPI] Improve the presentation examples
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]
Improved patch for the native tabs presentation
org.eclipse.ui.workbench-patch.diff (text/plain), 17.24 KB, created by
Stephan Michels
on 2005-07-05 10:37:08 EDT
(
hide
)
Description:
Improved patch for the native tabs presentation
Filename:
MIME Type:
Creator:
Stephan Michels
Created:
2005-07-05 10:37:08 EDT
Size:
17.24 KB
patch
obsolete
>Index: Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativePresentationFactory.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativePresentationFactory.java,v >retrieving revision 1.4 >diff -u -r1.4 NativePresentationFactory.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativePresentationFactory.java 15 Jun 2005 18:41:21 -0000 1.4 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativePresentationFactory.java 5 Jul 2005 14:34:08 -0000 >@@ -30,7 +30,7 @@ > */ > public StackPresentation createEditorPresentation(Composite parent, > IStackPresentationSite site) { >- return new TabbedStackPresentation(site, new NativeTabFolder(parent), new StandardEditorSystemMenu(site)); >+ return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardEditorSystemMenu(site)); > } > > /* >@@ -40,7 +40,7 @@ > */ > public StackPresentation createViewPresentation(Composite parent, > IStackPresentationSite site) { >- return new TabbedStackPresentation(site, new NativeTabFolder(parent), new StandardViewSystemMenu(site)); >+ return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardViewSystemMenu(site)); > } > > /* >@@ -51,8 +51,7 @@ > public StackPresentation createStandaloneViewPresentation(Composite parent, > IStackPresentationSite site, boolean showTitle) { > // TODO honour showTitle >- return new TabbedStackPresentation(site, new NativeTabFolder(parent), >- new StandardViewSystemMenu(site)); >+ return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardViewSystemMenu(site)); > } > > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabFolder.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabFolder.java,v >retrieving revision 1.7 >diff -u -r1.7 NativeTabFolder.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabFolder.java 15 Jun 2005 18:41:21 -0000 1.7 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabFolder.java 5 Jul 2005 14:34:08 -0000 >@@ -1,4 +1,4 @@ >-/******************************************************************************* >+ /******************************************************************************* > * Copyright (c) 2004, 2005 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 >@@ -10,43 +10,42 @@ > *******************************************************************************/ > package org.eclipse.ui.internal.presentations.defaultpresentation; > >+import org.eclipse.jface.preference.IPreferenceStore; > import org.eclipse.jface.util.Geometry; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CLabel; > import org.eclipse.swt.custom.ViewForm; >+import org.eclipse.swt.events.*; > import org.eclipse.swt.graphics.Image; > 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.Event; >-import org.eclipse.swt.widgets.Listener; >-import org.eclipse.swt.widgets.TabFolder; >-import org.eclipse.swt.widgets.TabItem; >-import org.eclipse.swt.widgets.Widget; >-import org.eclipse.ui.IPropertyListener; >+import org.eclipse.swt.widgets.*; >+import org.eclipse.ui.internal.*; > import org.eclipse.ui.internal.dnd.DragUtil; > import org.eclipse.ui.internal.layout.SizeCache; >-import org.eclipse.ui.internal.presentations.util.AbstractTabFolder; >-import org.eclipse.ui.internal.presentations.util.AbstractTabItem; >-import org.eclipse.ui.internal.presentations.util.PartInfo; >-import org.eclipse.ui.internal.presentations.util.ProxyControl; >-import org.eclipse.ui.internal.presentations.util.StandardSystemToolbar; >-import org.eclipse.ui.internal.presentations.util.TabFolderEvent; >+import org.eclipse.ui.internal.presentations.util.*; > import org.eclipse.ui.internal.util.Util; >+import org.eclipse.ui.presentations.*; > > /** > * @since 3.1 > */ > public class NativeTabFolder extends AbstractTabFolder { > >- private TabFolder control; >+ private IStackPresentationSite site; >+ private TabFolder tabFolder; > private ViewForm viewForm; >- private StandardSystemToolbar systemToolbar; > private CLabel title; >+ >+ private ToolBar viewToolBar; >+ private ToolItem menuButton; >+ private ToolItem closeButton; >+ > private ProxyControl topCenter; > private SizeCache topCenterCache; > >+ private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore(); >+ > private static final String FULL_TITLE = "part_title"; //$NON-NLS-1$ > > private Listener selectionListener = new Listener() { >@@ -55,32 +54,96 @@ > } > }; > >- private IPropertyListener systemToolbarListener = new IPropertyListener() { >+ /*private Listener dragListener = new Listener() { >+ public void handleEvent(Event event) { >+ >+ Point localPos = new Point(event.x, event.y); >+ TabItem tabUnderPointer = tabFolder.getItem(localPos); >+ >+ // Drags on the title area drag the selected part only >+ if (tabUnderPointer == null) { >+ if ((tabFolder.getStyle()&SWT.BOTTOM)!=0 >+ && localPos.y < paneFolder.getControl().getBounds().height >+ - paneFolder.getTabHeight()) >+ tabUnderPointer = paneFolder.getSelection(); >+ else if ((tabFolder.getStyle()&SWT.TOP)!=0 >+ && localPos.y > paneFolder.getTabHeight()) >+ tabUnderPointer = paneFolder.getSelection(); >+ } >+ >+ // Not in a tab, not in a title area, must be dragging the whole stack >+ if (tabUnderPointer == null) { >+ site.dragStart(tabFolder.getControl().toDisplay(localPos), false); >+ return; >+ } > >- public void propertyChanged(Object source, int propId) { >- Point location; >- >- if (propId == TabFolderEvent.EVENT_PANE_MENU) { >- location = getPaneMenuLocation(); >- } else { >- location = new Point(0,0); >+ IPresentablePart part = getPartForTab(tabUnderPointer); >+ >+ if (site.isPartMoveable(part)) { >+ site.dragStart(part, tabFolder.getControl().toDisplay(localPos), false); > } >- >- fireEvent(propId, getSelection(), location); > } >- >- }; >+ };*/ > >- public NativeTabFolder(Composite parent) { >- control = new TabFolder(parent, SWT.BOTTOM); >- control.addListener(SWT.Selection, selectionListener); >- attachListeners(control, false); >+ public NativeTabFolder(Composite parent, final IStackPresentationSite site) { >+ >+ this.site = site; > >- viewForm = new ViewForm(control, SWT.FLAT); >+ int tabPos = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); >+ >+ tabFolder = new TabFolder(parent, tabPos); >+ tabFolder.addListener(SWT.Selection, selectionListener); >+ attachListeners(tabFolder, false); >+ >+ viewForm = new ViewForm(tabFolder, SWT.FLAT); >+ viewForm.setVisible(false); > attachListeners(viewForm, false); >- systemToolbar = new StandardSystemToolbar(viewForm, true, false, true, true, true); >- systemToolbar.addListener(systemToolbarListener); >- viewForm.setTopRight(systemToolbar.getControl()); >+ >+ addListener(new TabFolderListener() { >+ public void handleEvent(TabFolderEvent e) { >+ viewForm.setVisible(site.getPartList().length>0); >+ } >+ }); >+ >+ viewToolBar = new ToolBar(viewForm, SWT.HORIZONTAL|SWT.FLAT); >+ viewForm.setTopRight(viewToolBar); >+ >+ menuButton = new ToolItem(viewToolBar, SWT.PUSH); >+ menuButton.setDisabledImage(null); // TODO: comment this out? >+ // PR#1GE56QT - Avoid creation of unnecessary image. >+ menuButton.setImage(WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU)); >+ menuButton.setToolTipText("Menu"); //$NON-NLS-1$ >+ menuButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ IPresentablePart part = site.getSelectedPart(); >+ if (part == null) >+ return; >+ >+ IPartMenu menu = part.getMenu(); >+ >+ if (menu != null) { >+ menu.showMenu(getPaneMenuLocation()); >+ } >+ } >+ }); >+ >+ closeButton = new ToolItem(viewToolBar, SWT.PUSH); >+ closeButton.setDisabledImage(null); // TODO: comment this out? >+ // PR#1GE56QT - Avoid creation of unnecessary image. >+ closeButton.setImage(WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW)); >+ closeButton.setToolTipText("Close"); //$NON-NLS-1$ >+ closeButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ IPresentablePart part = site.getSelectedPart(); >+ if (part == null) >+ return; >+ >+ //fireEvent(TabFolderEvent.EVENT_CLOSE); >+ if (part != null) { >+ site.close(new IPresentablePart[] { part }); >+ } >+ } >+ }); > > topCenter = new ProxyControl(viewForm); > topCenterCache = new SizeCache(); >@@ -114,7 +177,7 @@ > super.layout(flushCache); > > Rectangle oldBounds = viewForm.getBounds(); >- Rectangle newBounds = control.getClientArea(); >+ Rectangle newBounds = tabFolder.getClientArea(); > > viewForm.setBounds(newBounds); > >@@ -127,16 +190,8 @@ > * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getPaneMenuLocation() > */ > public Point getPaneMenuLocation() { >- return systemToolbar.getPaneMenuLocation(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setState(int) >- */ >- public void setState(int state) { >- super.setState(state); >- >- systemToolbar.setState(state); >+ Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar); >+ return new Point(bounds.x, bounds.y + bounds.height); > } > > /* (non-Javadoc) >@@ -149,14 +204,14 @@ > return new Rectangle(0,0,0,0); > } > >- return Geometry.toControl(control, DragUtil.getDisplayBounds(content)); >+ return Geometry.toControl(tabFolder, DragUtil.getDisplayBounds(content)); > } > > /* (non-Javadoc) > * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getItems() > */ > public AbstractTabItem[] getItems() { >- TabItem[] items = control.getItems(); >+ TabItem[] items = tabFolder.getItems(); > > AbstractTabItem[] result = new AbstractTabItem[items.length]; > >@@ -185,18 +240,15 @@ > } > > NativeTabItem tab = (NativeTabItem) toSelect; >- control.setSelection(new TabItem[] {(TabItem)tab.getWidget()}); >+ tabFolder.setSelection(new TabItem[] {(TabItem)tab.getWidget()}); > } > > /* (non-Javadoc) > * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelectedInfo(org.eclipse.ui.internal.presentations.util.PartInfo) > */ > public void setSelectedInfo(PartInfo info) { >- if (!Util.equals(title.getText(), info.title)) { >- title.setText(info.title); >- } >- if (title.getImage() != info.image) { >- title.setImage(info.image); >+ if (!Util.equals(title.getText(), info.contentDescription)) { >+ title.setText(info.contentDescription); > } > } > /* (non-Javadoc) >@@ -211,15 +263,15 @@ > */ > public Rectangle getTabArea() { > >- Rectangle bounds = control.getBounds(); >+ Rectangle bounds = tabFolder.getBounds(); > >- Rectangle clientArea = control.getClientArea(); >+ Rectangle clientArea = tabFolder.getClientArea(); > > bounds.x = 0; > bounds.y = 0; > Geometry.expand(bounds, 0, 0, - (clientArea.height + clientArea.y), 0); > >- return Geometry.toDisplay(control.getParent(), bounds); >+ return Geometry.toDisplay(tabFolder.getParent(), bounds); > } > > /* (non-Javadoc) >@@ -241,7 +293,7 @@ > } > > public Control getControl() { >- return control; >+ return tabFolder; > } > > /* (non-Javadoc) >@@ -255,7 +307,7 @@ > } > > public AbstractTabItem getSelection() { >- TabItem[] sel = control.getSelection(); >+ TabItem[] sel = tabFolder.getSelection(); > > if (sel.length == 0) { > return null; >@@ -264,6 +316,15 @@ > return getTab(sel[0]); > } > >+ private TabItem getSelectedTabItem() { >+ WidgetTabItem selection = (WidgetTabItem)getSelection(); >+ >+ if (selection==null) >+ return null; >+ >+ return (TabItem)selection.getWidget(); >+ } >+ > /* (non-Javadoc) > * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getContentParent() > */ >@@ -283,7 +344,7 @@ > * @since 3.1 > */ > public TabFolder getTabFolder() { >- return control; >+ return tabFolder; > } > > /** >@@ -292,7 +353,7 @@ > * @since 3.1 > */ > /* protected */ void setSelectedTitle(String newTitle) { >- title.setText(newTitle); >+ getSelectedTabItem().setText(newTitle); > } > > /** >@@ -300,7 +361,7 @@ > * @since 3.1 > */ > /* protected */ void setSelectedImage(Image image) { >- title.setImage(image); >+ getSelectedTabItem().setImage(image); > } > > /* (non-Javadoc) >@@ -315,6 +376,6 @@ > * @since 3.1 > */ > public void enablePaneMenu(boolean enabled) { >- systemToolbar.enablePaneMenu(enabled); >+ menuButton.setEnabled(enabled); > } > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabItem.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabItem.java,v >retrieving revision 1.5 >diff -u -r1.5 NativeTabItem.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabItem.java 15 Jun 2005 18:41:21 -0000 1.5 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabItem.java 5 Jul 2005 14:34:08 -0000 >@@ -32,13 +32,19 @@ > public Rectangle getBounds() { > return new Rectangle(0,0,0,0); > } >- >+ > public void setInfo(PartInfo info) { > TabItem widget = (TabItem) getWidget(); > >- if (!Util.equals(widget.getText(), info.name)) { >- widget.setText(info.name); >+ String name = getLabelText(info, false, false); >+ if (!Util.equals(widget.getText(), name)) { >+ widget.setText(name); >+ } >+ >+ if (!Util.equals(widget.getImage(), info.image)) { >+ widget.setImage(info.image); > } >+ > String oldToolTip = Util.safeString(widget.getToolTipText()); > > if (!Util.equals(info.toolTip, oldToolTip)) { >@@ -48,5 +54,48 @@ > } > widget.setToolTipText(toolTip); > } >+ } >+ >+ /** >+ * Returns the label text that should be used for the tab item for the >+ * specified part >+ * >+ * @param presentablePart >+ * @param dirtyLeft >+ * @param includePath >+ * @return a formated label text >+ */ >+ private static String getLabelText(PartInfo info, boolean dirtyLeft, >+ boolean includePath) { >+ String title = info.name.trim(); >+ String text = title; >+ >+ if (includePath) { >+ String titleTooltip = info.toolTip.trim(); >+ >+ if (titleTooltip.endsWith(title)) >+ titleTooltip = titleTooltip.substring(0, >+ titleTooltip.lastIndexOf(title)).trim(); >+ >+ if (titleTooltip.endsWith("\\")) //$NON-NLS-1$ >+ titleTooltip = titleTooltip.substring(0, >+ titleTooltip.lastIndexOf("\\")).trim(); //$NON-NLS-1$ >+ >+ if (titleTooltip.endsWith("/")) //$NON-NLS-1$ >+ titleTooltip = titleTooltip.substring(0, >+ titleTooltip.lastIndexOf("/")).trim(); //$NON-NLS-1$ >+ >+ if (titleTooltip.length() >= 1) >+ text += " - " + titleTooltip; //$NON-NLS-1$ >+ } >+ >+ if (info.dirty) { >+ if (dirtyLeft) >+ text = "* " + text; //$NON-NLS-1$ >+ else >+ text = text + " *"; //$NON-NLS-1$ >+ } >+ >+ return text; > } > }
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 93806
:
24274
|
24275
| 24347