Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a4156567371e2ac81f3f2e68f4071e79aa7f512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2008, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Nikolay Botev - bug 240651
 ******************************************************************************/

package org.eclipse.ui.part;

import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.internal.IWorkbenchThemeConstants;
import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.themes.ITheme;

/**
 * A MultiEditor is a composite of editors.
 *
 * This class is intended to be subclassed.
 *
 */
public abstract class MultiEditor extends AbstractMultiEditor {

	/**
     * The colors used to draw the title bar of the inner editors
     */
    public static class Gradient {
        public Color fgColor;

        public Color[] bgColors;

        public int[] bgPercents;
    }

	/**
	 * Updates the gradient in the title bar.
	 * @param editor
	 */
	public void updateGradient(IEditorPart editor) {
	    boolean activeEditor = editor == getSite().getPage().getActiveEditor();
	    boolean activePart = editor == getSite().getPage().getActivePart();

	    ITheme theme = editor.getEditorSite().getWorkbenchWindow()
	            .getWorkbench().getThemeManager().getCurrentTheme();
	    Gradient g = new Gradient();

	    ColorRegistry colorRegistry = theme.getColorRegistry();
	    if (activePart) {
	        g.fgColor = colorRegistry
	                .get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR);
	        g.bgColors = new Color[2];
	        g.bgColors[0] = colorRegistry
	                .get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
	        g.bgColors[1] = colorRegistry
	                .get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
	    } else {
	        if (activeEditor) {
	            g.fgColor = colorRegistry
	                    .get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR);
	            g.bgColors = new Color[2];
	            g.bgColors[0] = colorRegistry
	                    .get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
	            g.bgColors[1] = colorRegistry
	                    .get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
	        } else {
	            g.fgColor = colorRegistry
	                    .get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
	            g.bgColors = new Color[2];
	            g.bgColors[0] = colorRegistry
	                    .get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
	            g.bgColors[1] = colorRegistry
	                    .get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
	        }
	    }
	    g.bgPercents = new int[] { theme
	            .getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT) };

	    drawGradient(editor, g);
	}

	/**
	 * Draw the gradient in the title bar.
	 */
	protected abstract void drawGradient(IEditorPart innerEditor, Gradient g);

    /**
     * Create the control of the inner editor.
     *
     * Must be called by subclass.
     */
    public Composite createInnerPartControl(Composite parent,
            final IEditorPart e) {
        Composite content = new Composite(parent, SWT.NONE);
        content.setLayout(new FillLayout());
        e.createPartControl(content);
        parent.addListener(SWT.Activate, event -> {
		    if (event.type == SWT.Activate) {
				activateEditor(e);
			}
		});
        return content;
    }

    /*
     * @see IWorkbenchPart#setFocus()
     */
    @Override
	public void setFocus() {
    	super.setFocus();
        updateGradient(getActiveEditor());
    }

    /**
     * Activates the given nested editor.
     *
     * @param part the nested editor
     * @since 3.5
     */
    @Override
	public void activateEditor(IEditorPart part) {
        IEditorPart oldEditor = getActiveEditor();
        super.activateEditor(part);
        updateGradient(oldEditor);
    }

    /**
     * Return true if the shell is activated.
     */
    protected boolean getShellActivated() {
        WorkbenchWindow window = (WorkbenchWindow) getSite().getPage()
                .getWorkbenchWindow();
        return window.getShellActivated();
    }

	@Override
	public Composite getInnerEditorContainer(
			IEditorReference innerEditorReference) {
		// This method is not used by MutliEditor
		return null;
	}

	@Override
	protected void innerEditorsCreated() {
		// Nothing to do
	}

}

Back to the top