blob: 7da7582d31c57080fc7a09a4bb875a02e8ac7387 (
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
|
/*******************************************************************************
* Copyright (c) 2011 Manumitting Technologies, Inc.
* 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:
* Brian de Alwis (MT) - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.tools.css.spy;
import javax.inject.Inject;
import javax.inject.Provider;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.statusreporter.StatusReporter;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl;
import org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
public class OpenSpyHandler {
@Inject
@Optional
protected Display display;
@Inject
protected IEclipseContext context;
@Inject
protected Provider<StatusReporter> reporter;
@Execute
public void openSpy() {
Control control = display.getCursorControl();
// it may be that only the shell was selected
if (control == null) {
control = display.getActiveShell();
}
CssSpyDialog spy = new CssSpyDialog(control.getShell());
spy.setSpecimen(control);
spy.open();
}
private CSSEngine findCSSEngine() {
if(display != null) {
Object themeEngine = display.getData("org.eclipse.e4.ui.css.swt.theme");
if(themeEngine instanceof ThemeEngine) { return ((ThemeEngine)themeEngine)
.getCSSEngine(); }
}
if(context != null) {
Object themeEngine = context.get(IThemeEngine.class);
if(themeEngine instanceof ThemeEngine) { return ((ThemeEngine)themeEngine)
.getCSSEngine(); }
}
// otherwise just create a copy of the engine.
return new CSSSWTEngineImpl(display, true);
}
}
|