Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 93806 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativePresentationFactory.java (-4 / +3 lines)
Lines 30-36 Link Here
30
     */
30
     */
31
    public StackPresentation createEditorPresentation(Composite parent,
31
    public StackPresentation createEditorPresentation(Composite parent,
32
            IStackPresentationSite site) {        
32
            IStackPresentationSite site) {        
33
        return new TabbedStackPresentation(site, new NativeTabFolder(parent), new StandardEditorSystemMenu(site));
33
        return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardEditorSystemMenu(site));
34
    }
34
    }
35
35
36
    /*
36
    /*
Lines 40-46 Link Here
40
     */
40
     */
41
    public StackPresentation createViewPresentation(Composite parent,
41
    public StackPresentation createViewPresentation(Composite parent,
42
            IStackPresentationSite site) {
42
            IStackPresentationSite site) {
43
        return new TabbedStackPresentation(site, new NativeTabFolder(parent), new StandardViewSystemMenu(site));
43
        return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardViewSystemMenu(site));
44
    }
44
    }
45
45
46
    /*
46
    /*
Lines 51-58 Link Here
51
    public StackPresentation createStandaloneViewPresentation(Composite parent,
51
    public StackPresentation createStandaloneViewPresentation(Composite parent,
52
            IStackPresentationSite site, boolean showTitle) {
52
            IStackPresentationSite site, boolean showTitle) {
53
        // TODO honour showTitle
53
        // TODO honour showTitle
54
        return new TabbedStackPresentation(site, new NativeTabFolder(parent), 
54
        return new TabbedStackPresentation(site, new NativeTabFolder(parent, site), new StandardViewSystemMenu(site));
55
                new StandardViewSystemMenu(site));
56
    }
55
    }
57
56
58
}
57
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabFolder.java (-65 / +126 lines)
Lines 1-4 Link Here
1
/*******************************************************************************
1
 /*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
Lines 10-52 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations.defaultpresentation;
11
package org.eclipse.ui.internal.presentations.defaultpresentation;
12
12
13
import org.eclipse.jface.preference.IPreferenceStore;
13
import org.eclipse.jface.util.Geometry;
14
import org.eclipse.jface.util.Geometry;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.custom.CLabel;
16
import org.eclipse.swt.custom.CLabel;
16
import org.eclipse.swt.custom.ViewForm;
17
import org.eclipse.swt.custom.ViewForm;
18
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Point;
19
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.*;
21
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.ui.internal.*;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.swt.widgets.Listener;
24
import org.eclipse.swt.widgets.TabFolder;
25
import org.eclipse.swt.widgets.TabItem;
26
import org.eclipse.swt.widgets.Widget;
27
import org.eclipse.ui.IPropertyListener;
28
import org.eclipse.ui.internal.dnd.DragUtil;
24
import org.eclipse.ui.internal.dnd.DragUtil;
29
import org.eclipse.ui.internal.layout.SizeCache;
25
import org.eclipse.ui.internal.layout.SizeCache;
30
import org.eclipse.ui.internal.presentations.util.AbstractTabFolder;
26
import org.eclipse.ui.internal.presentations.util.*;
31
import org.eclipse.ui.internal.presentations.util.AbstractTabItem;
32
import org.eclipse.ui.internal.presentations.util.PartInfo;
33
import org.eclipse.ui.internal.presentations.util.ProxyControl;
34
import org.eclipse.ui.internal.presentations.util.StandardSystemToolbar;
35
import org.eclipse.ui.internal.presentations.util.TabFolderEvent;
36
import org.eclipse.ui.internal.util.Util;
27
import org.eclipse.ui.internal.util.Util;
28
import org.eclipse.ui.presentations.*;
37
29
38
/**
30
/**
39
 * @since 3.1
31
 * @since 3.1
40
 */
32
 */
41
public class NativeTabFolder extends AbstractTabFolder {
33
public class NativeTabFolder extends AbstractTabFolder {
42
34
43
    private TabFolder control;
35
    private IStackPresentationSite site;
36
    private TabFolder tabFolder;
44
    private ViewForm viewForm;
37
    private ViewForm viewForm;
45
    private StandardSystemToolbar systemToolbar;
46
    private CLabel title;
38
    private CLabel title;
39
    
40
    private ToolBar viewToolBar;
41
    private ToolItem menuButton;
42
    private ToolItem closeButton;
43
    
47
    private ProxyControl topCenter;
44
    private ProxyControl topCenter;
48
    private SizeCache topCenterCache;
45
    private SizeCache topCenterCache;
49
    
46
    
47
    private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore();
48
    
50
    private static final String FULL_TITLE = "part_title"; //$NON-NLS-1$
49
    private static final String FULL_TITLE = "part_title"; //$NON-NLS-1$
51
    
50
    
52
    private Listener selectionListener = new Listener() {
51
    private Listener selectionListener = new Listener() {
Lines 55-86 Link Here
55
        }
54
        }
56
    };
55
    };
57
    
56
    
58
    private IPropertyListener systemToolbarListener = new IPropertyListener() {
57
    /*private Listener dragListener = new Listener() {
58
        public void handleEvent(Event event) {
59
60
            Point localPos = new Point(event.x, event.y);
61
            TabItem tabUnderPointer = tabFolder.getItem(localPos);
62
63
            // Drags on the title area drag the selected part only
64
            if (tabUnderPointer == null) {
65
                if ((tabFolder.getStyle()&SWT.BOTTOM)!=0
66
                        && localPos.y < paneFolder.getControl().getBounds().height
67
                                - paneFolder.getTabHeight())
68
                    tabUnderPointer = paneFolder.getSelection();
69
                else if ((tabFolder.getStyle()&SWT.TOP)!=0
70
                        && localPos.y > paneFolder.getTabHeight())
71
                    tabUnderPointer = paneFolder.getSelection();
72
            }
73
74
            // Not in a tab, not in a title area, must be dragging the whole stack
75
            if (tabUnderPointer == null) {
76
                site.dragStart(tabFolder.getControl().toDisplay(localPos), false);
77
                return;
78
            }
59
79
60
        public void propertyChanged(Object source, int propId) {
80
            IPresentablePart part = getPartForTab(tabUnderPointer);
61
            Point location;
81
62
            
82
            if (site.isPartMoveable(part)) {
63
            if (propId == TabFolderEvent.EVENT_PANE_MENU) {
83
                site.dragStart(part, tabFolder.getControl().toDisplay(localPos), false);
64
                location = getPaneMenuLocation();
65
            } else {
66
                location = new Point(0,0);
67
            }
84
            }
68
            
69
            fireEvent(propId, getSelection(), location);
70
        }
85
        }
71
        
86
    };*/
72
    };
73
    
87
    
74
    public NativeTabFolder(Composite parent) {
88
    public NativeTabFolder(Composite parent, final IStackPresentationSite site) {
75
        control = new TabFolder(parent, SWT.BOTTOM);
89
        
76
        control.addListener(SWT.Selection, selectionListener);
90
        this.site = site;
77
        attachListeners(control, false);
78
        
91
        
79
        viewForm = new ViewForm(control, SWT.FLAT);
92
        int tabPos = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION);
93
        
94
        tabFolder = new TabFolder(parent, tabPos);
95
        tabFolder.addListener(SWT.Selection, selectionListener);
96
        attachListeners(tabFolder, false);
97
        
98
        viewForm = new ViewForm(tabFolder, SWT.FLAT);
99
        viewForm.setVisible(false);
80
        attachListeners(viewForm, false);
100
        attachListeners(viewForm, false);
81
        systemToolbar = new StandardSystemToolbar(viewForm, true, false, true, true, true);
101
        
82
        systemToolbar.addListener(systemToolbarListener);
102
        addListener(new TabFolderListener() {
83
        viewForm.setTopRight(systemToolbar.getControl());
103
            public void handleEvent(TabFolderEvent e) {
104
                viewForm.setVisible(site.getPartList().length>0);
105
            }
106
        });
107
        
108
        viewToolBar = new ToolBar(viewForm, SWT.HORIZONTAL|SWT.FLAT);
109
        viewForm.setTopRight(viewToolBar);
110
        
111
        menuButton = new ToolItem(viewToolBar, SWT.PUSH);
112
        menuButton.setDisabledImage(null); // TODO: comment this out?
113
        // PR#1GE56QT - Avoid creation of unnecessary image.
114
        menuButton.setImage(WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU));
115
        menuButton.setToolTipText("Menu"); //$NON-NLS-1$
116
        menuButton.addSelectionListener(new SelectionAdapter() {
117
            public void widgetSelected(SelectionEvent e) {
118
                IPresentablePart part = site.getSelectedPart();
119
                if (part == null) 
120
                    return;
121
122
                IPartMenu menu = part.getMenu();
123
124
                if (menu != null) {
125
                    menu.showMenu(getPaneMenuLocation());
126
                }
127
            }
128
        });
129
        
130
        closeButton = new ToolItem(viewToolBar, SWT.PUSH);
131
        closeButton.setDisabledImage(null); // TODO: comment this out?
132
        // PR#1GE56QT - Avoid creation of unnecessary image.
133
        closeButton.setImage(WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW));
134
        closeButton.setToolTipText("Close"); //$NON-NLS-1$
135
        closeButton.addSelectionListener(new SelectionAdapter() {
136
            public void widgetSelected(SelectionEvent e) {
137
                IPresentablePart part = site.getSelectedPart();
138
                if (part == null) 
139
                    return;
140
                
141
                //fireEvent(TabFolderEvent.EVENT_CLOSE);
142
                if (part != null) {
143
                    site.close(new IPresentablePart[] { part });
144
                }
145
            }
146
        });
84
        
147
        
85
        topCenter = new ProxyControl(viewForm);
148
        topCenter = new ProxyControl(viewForm);
86
        topCenterCache = new SizeCache();
149
        topCenterCache = new SizeCache();
Lines 114-120 Link Here
114
        super.layout(flushCache);
177
        super.layout(flushCache);
115
        
178
        
116
        Rectangle oldBounds = viewForm.getBounds();
179
        Rectangle oldBounds = viewForm.getBounds();
117
        Rectangle newBounds = control.getClientArea();
180
        Rectangle newBounds = tabFolder.getClientArea();
118
        
181
        
119
        viewForm.setBounds(newBounds);
182
        viewForm.setBounds(newBounds);
120
        
183
        
Lines 127-142 Link Here
127
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getPaneMenuLocation()
190
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getPaneMenuLocation()
128
     */
191
     */
129
    public Point getPaneMenuLocation() {
192
    public Point getPaneMenuLocation() {
130
        return systemToolbar.getPaneMenuLocation();
193
        Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar);
131
    }
194
        return new Point(bounds.x, bounds.y + bounds.height);
132
    
133
    /* (non-Javadoc)
134
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setState(int)
135
     */
136
    public void setState(int state) {
137
        super.setState(state);
138
        
139
        systemToolbar.setState(state);
140
    }
195
    }
141
    
196
    
142
    /* (non-Javadoc)
197
    /* (non-Javadoc)
Lines 149-162 Link Here
149
            return new Rectangle(0,0,0,0);
204
            return new Rectangle(0,0,0,0);
150
        }
205
        }
151
        
206
        
152
        return Geometry.toControl(control, DragUtil.getDisplayBounds(content));
207
        return Geometry.toControl(tabFolder, DragUtil.getDisplayBounds(content));
153
    }
208
    }
154
209
155
    /* (non-Javadoc)
210
    /* (non-Javadoc)
156
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getItems()
211
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getItems()
157
     */
212
     */
158
    public AbstractTabItem[] getItems() {
213
    public AbstractTabItem[] getItems() {
159
        TabItem[] items = control.getItems();
214
        TabItem[] items = tabFolder.getItems();
160
        
215
        
161
        AbstractTabItem[] result = new AbstractTabItem[items.length];
216
        AbstractTabItem[] result = new AbstractTabItem[items.length];
162
        
217
        
Lines 185-202 Link Here
185
        }
240
        }
186
        
241
        
187
        NativeTabItem tab = (NativeTabItem) toSelect;
242
        NativeTabItem tab = (NativeTabItem) toSelect;
188
        control.setSelection(new TabItem[] {(TabItem)tab.getWidget()});
243
        tabFolder.setSelection(new TabItem[] {(TabItem)tab.getWidget()});
189
    }
244
    }
190
245
191
    /* (non-Javadoc)
246
    /* (non-Javadoc)
192
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelectedInfo(org.eclipse.ui.internal.presentations.util.PartInfo)
247
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelectedInfo(org.eclipse.ui.internal.presentations.util.PartInfo)
193
     */
248
     */
194
    public void setSelectedInfo(PartInfo info) {
249
    public void setSelectedInfo(PartInfo info) {
195
        if (!Util.equals(title.getText(), info.title)) {
250
        if (!Util.equals(title.getText(), info.contentDescription)) {
196
            title.setText(info.title);
251
            title.setText(info.contentDescription);
197
        }
198
        if (title.getImage() != info.image) {
199
            title.setImage(info.image);
200
        }
252
        }
201
    }
253
    }
202
    /* (non-Javadoc)
254
    /* (non-Javadoc)
Lines 211-225 Link Here
211
     */
263
     */
212
    public Rectangle getTabArea() {
264
    public Rectangle getTabArea() {
213
265
214
        Rectangle bounds = control.getBounds();
266
        Rectangle bounds = tabFolder.getBounds();
215
        
267
        
216
        Rectangle clientArea = control.getClientArea();
268
        Rectangle clientArea = tabFolder.getClientArea();
217
        
269
        
218
        bounds.x = 0;
270
        bounds.x = 0;
219
        bounds.y = 0;
271
        bounds.y = 0;
220
        Geometry.expand(bounds, 0, 0, - (clientArea.height + clientArea.y), 0);
272
        Geometry.expand(bounds, 0, 0, - (clientArea.height + clientArea.y), 0);
221
        
273
        
222
        return Geometry.toDisplay(control.getParent(), bounds);
274
        return Geometry.toDisplay(tabFolder.getParent(), bounds);
223
    }
275
    }
224
    
276
    
225
    /* (non-Javadoc)
277
    /* (non-Javadoc)
Lines 241-247 Link Here
241
    }
293
    }
242
    
294
    
243
    public Control getControl() {
295
    public Control getControl() {
244
        return control;
296
        return tabFolder;
245
    }
297
    }
246
    
298
    
247
    /* (non-Javadoc)
299
    /* (non-Javadoc)
Lines 255-261 Link Here
255
    }
307
    }
256
    
308
    
257
    public AbstractTabItem getSelection() {
309
    public AbstractTabItem getSelection() {
258
        TabItem[] sel = control.getSelection();
310
        TabItem[] sel = tabFolder.getSelection();
259
        
311
        
260
        if (sel.length == 0) {
312
        if (sel.length == 0) {
261
            return null;
313
            return null;
Lines 264-269 Link Here
264
        return getTab(sel[0]);
316
        return getTab(sel[0]);
265
    }
317
    }
266
    
318
    
319
    private TabItem getSelectedTabItem() {
320
        WidgetTabItem selection = (WidgetTabItem)getSelection();
321
        
322
        if (selection==null)
323
            return null;
324
        
325
        return (TabItem)selection.getWidget();
326
    }
327
    
267
    /* (non-Javadoc)
328
    /* (non-Javadoc)
268
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getContentParent()
329
     * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getContentParent()
269
     */
330
     */
Lines 283-289 Link Here
283
     * @since 3.1
344
     * @since 3.1
284
     */
345
     */
285
    public TabFolder getTabFolder() {
346
    public TabFolder getTabFolder() {
286
        return control;
347
        return tabFolder;
287
    }
348
    }
288
349
289
    /**
350
    /**
Lines 292-298 Link Here
292
     * @since 3.1
353
     * @since 3.1
293
     */
354
     */
294
    /* protected */ void setSelectedTitle(String newTitle) {
355
    /* protected */ void setSelectedTitle(String newTitle) {
295
        title.setText(newTitle);
356
        getSelectedTabItem().setText(newTitle);
296
    }
357
    }
297
358
298
    /**
359
    /**
Lines 300-306 Link Here
300
     * @since 3.1
361
     * @since 3.1
301
     */
362
     */
302
    /* protected */ void setSelectedImage(Image image) {
363
    /* protected */ void setSelectedImage(Image image) {
303
        title.setImage(image);
364
        getSelectedTabItem().setImage(image);
304
    }
365
    }
305
366
306
    /* (non-Javadoc)
367
    /* (non-Javadoc)
Lines 315-320 Link Here
315
     * @since 3.1
376
     * @since 3.1
316
     */
377
     */
317
    public void enablePaneMenu(boolean enabled) {
378
    public void enablePaneMenu(boolean enabled) {
318
        systemToolbar.enablePaneMenu(enabled);
379
        menuButton.setEnabled(enabled);
319
    }
380
    }
320
}
381
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/defaultpresentation/NativeTabItem.java (-3 / +52 lines)
Lines 32-44 Link Here
32
    public Rectangle getBounds() {
32
    public Rectangle getBounds() {
33
        return new Rectangle(0,0,0,0);
33
        return new Rectangle(0,0,0,0);
34
    }
34
    }
35
35
    
36
    public void setInfo(PartInfo info) {
36
    public void setInfo(PartInfo info) {
37
        TabItem widget = (TabItem) getWidget();
37
        TabItem widget = (TabItem) getWidget();
38
        
38
        
39
        if (!Util.equals(widget.getText(), info.name)) {
39
        String name = getLabelText(info, false, false);
40
            widget.setText(info.name);
40
        if (!Util.equals(widget.getText(), name)) {
41
            widget.setText(name);
42
        }
43
        
44
        if (!Util.equals(widget.getImage(), info.image)) {
45
            widget.setImage(info.image);
41
        }
46
        }
47
        
42
        String oldToolTip = Util.safeString(widget.getToolTipText());
48
        String oldToolTip = Util.safeString(widget.getToolTipText());
43
        
49
        
44
        if (!Util.equals(info.toolTip, oldToolTip)) {
50
        if (!Util.equals(info.toolTip, oldToolTip)) {
Lines 48-52 Link Here
48
            }
54
            }
49
            widget.setToolTipText(toolTip);
55
            widget.setToolTipText(toolTip);
50
        }
56
        }
57
    }  
58
    
59
    /**
60
     * Returns the label text that should be used for the tab item for the
61
     * specified part
62
     * 
63
     * @param presentablePart
64
     * @param dirtyLeft
65
     * @param includePath
66
     * @return a formated label text
67
     */
68
    private static String getLabelText(PartInfo info, boolean dirtyLeft,
69
            boolean includePath) {
70
        String title = info.name.trim();
71
        String text = title;
72
73
        if (includePath) {
74
            String titleTooltip = info.toolTip.trim();
75
76
            if (titleTooltip.endsWith(title))
77
                titleTooltip = titleTooltip.substring(0,
78
                        titleTooltip.lastIndexOf(title)).trim();
79
80
            if (titleTooltip.endsWith("\\")) //$NON-NLS-1$
81
                titleTooltip = titleTooltip.substring(0,
82
                        titleTooltip.lastIndexOf("\\")).trim(); //$NON-NLS-1$
83
84
            if (titleTooltip.endsWith("/")) //$NON-NLS-1$
85
                titleTooltip = titleTooltip.substring(0,
86
                        titleTooltip.lastIndexOf("/")).trim(); //$NON-NLS-1$
87
88
            if (titleTooltip.length() >= 1)
89
                text += " - " + titleTooltip; //$NON-NLS-1$
90
        }
91
92
        if (info.dirty) {
93
            if (dirtyLeft)
94
                text = "* " + text; //$NON-NLS-1$
95
            else
96
                text = text + " *"; //$NON-NLS-1$
97
        }
98
99
        return text;
51
    }    
100
    }    
52
}
101
}

Return to bug 93806