Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dee7f05242e23ea709d301b096c41b78db9da58e (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
/*******************************************************************************
 * Copyright (c) 2018 Angelo ZERR.
 *
 * 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:
 * Angelo Zerr <angelo.zerr@gmail.com> - [minimap] Initialize minimap view - Bug 535450
 *******************************************************************************/
package org.eclipse.ui.internal.views.minimap;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.IPage;
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
import org.eclipse.ui.part.PageSite;

import org.eclipse.ui.texteditor.ITextEditor;

/**
 * Minimap view used to display content of current text editor with scale.
 *
 */
public class MinimapView extends PageBookView {

	private String defaultText;

	public MinimapView() {
		this.defaultText = MinimapMessages.MinimapViewNoMinimap;
	}

	@Override
	protected IPage createDefaultPage(PageBook book) {
		MessagePage page = new MessagePage();
		this.initPage(page);
		page.createControl(book);
		page.setMessage(this.defaultText);
		return page;
	}

	@Override
	protected PageRec doCreatePage(IWorkbenchPart part) {
		Page page = createMinimapPage(part);
		if (page == null) {
			return null;
		}
		PageSite site = new PageSite(this.getViewSite());
		page.init(site);
		page.createControl(this.getPageBook());
		return new PageBookView.PageRec(part, page);
	}

	private Page createMinimapPage(IWorkbenchPart part) {
		if (part instanceof MultiPageEditorPart) {
			return new MultiPageMinimapPage((MultiPageEditorPart) part);
		}
		return MinimapPage.createMinimapPage((ITextEditor) part);
	}

	@Override
	protected void doDestroyPage(IWorkbenchPart part, PageRec rec) {
		IPage page = rec.page;
		page.dispose();
		rec.dispose();
	}

	@Override
	protected IWorkbenchPart getBootstrapPart() {
		IWorkbenchPage page = this.getSite().getPage();
		return page != null ? page.getActiveEditor() : null;
	}

	@Override
	protected boolean isImportant(IWorkbenchPart part) {
		return part instanceof ITextEditor || part instanceof MultiPageEditorPart;
	}
}

Back to the top