Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0c6d3f63d1082caac63970816aa6af29634bb359 (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
/***********************************************************************
 * Copyright (c) 2007, 2008, 2009 Anyware Technologies, Obeo
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Anyware Technologies - initial API and implementation
 *    Obeo
 *    
 **********************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.outline.overview;

import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.parts.ScrollableThumbnail;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * This class is an outline control showing an overview of a graphical editor. <br>
 * 
 * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a>
 * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
 */
public class OverviewComposite extends Composite {

	/** the control of the overview */
	private Canvas overview;

	/** the root edit part */
	private ScalableFreeformRootEditPart rootEditPart;

	/** the thumbnail */
	private ScrollableThumbnail thumbnail;

	/**
	 * Creates a new OverviewOutlinePage instance.
	 * 
	 * @param parent
	 *        the parent composite
	 * @param rootEditPart
	 *        the root edit part
	 */
	public OverviewComposite(Composite parent, ScalableFreeformRootEditPart rootEditPart) {
		super(parent, SWT.BORDER);
		this.rootEditPart = rootEditPart;

		GridLayout layout = new GridLayout();
		layout.horizontalSpacing = 0;
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.verticalSpacing = 0;
		setLayout(layout);
		setLayoutData(new GridData(GridData.FILL_BOTH));
		createControl(this);
	}

	/**
	 * Creates the inner controls
	 * 
	 * @param parent
	 *        the parent composite
	 */
	public void createControl(Composite parent) {
		// An swt canvas and lws drawing the figure.
		overview = new Canvas(parent, SWT.NONE);
		overview.setLayoutData(new GridData(GridData.FILL_BOTH));
		// A draw2d object linking swt and draw2d
		LightweightSystem lightweightSystem = new LightweightSystem(overview);

		// create the thumbnail
		thumbnail = new ScrollableThumbnail((Viewport)rootEditPart.getFigure());
		thumbnail.setBorder(new MarginBorder(3));
		thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS/* SCALABLE_LAYERS */));
		lightweightSystem.setContents(thumbnail);

	}

	/**
	 * {@inheritDoc}
	 */
	public void dispose() {
		if(null != thumbnail) {
			thumbnail.deactivate();
			thumbnail = null;
		}

		super.dispose();
	}

	/**
	 * {@inheritDoc}
	 */
	public void setVisible(boolean state) {
		thumbnail.setVisible(state);
		super.setVisible(state);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @return the main control
	 */
	public Control getControl() {
		return overview;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @return <code>true</code> if the focus succeed
	 */
	public boolean setFocus() {
		if(getControl() != null) {
			return getControl().setFocus();
		}
		return false;
	}

}

Back to the top