Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ui.internal.preferences; |
13 |
|
14 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
15 |
import org.eclipse.e4.ui.css.swt.theme.ITheme; |
16 |
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; |
17 |
import org.eclipse.e4.ui.internal.workbench.swt.E4Application; |
18 |
import org.eclipse.jface.preference.PreferencePage; |
19 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
20 |
import org.eclipse.jface.viewers.ComboViewer; |
21 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
23 |
import org.eclipse.jface.viewers.LabelProvider; |
24 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
25 |
import org.eclipse.jface.viewers.StructuredSelection; |
26 |
import org.eclipse.swt.SWT; |
27 |
import org.eclipse.swt.layout.GridData; |
28 |
import org.eclipse.swt.layout.GridLayout; |
29 |
import org.eclipse.swt.widgets.Composite; |
30 |
import org.eclipse.swt.widgets.Control; |
31 |
import org.eclipse.swt.widgets.Label; |
32 |
import org.eclipse.ui.IWorkbench; |
33 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
34 |
|
35 |
/** |
36 |
* @since 3.5 |
37 |
* |
38 |
*/ |
39 |
public class CSSThemePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { |
40 |
private IThemeEngine engine; |
41 |
private ComboViewer themeIdCombo; |
42 |
private ITheme currentTheme; |
43 |
private String defaultTheme; |
44 |
|
45 |
@Override |
46 |
protected Control createContents(Composite parent) { |
47 |
Composite comp = new Composite(parent, SWT.NONE); |
48 |
comp.setLayout(new GridLayout(2, false)); |
49 |
new Label(comp, SWT.NONE).setText("ThemeId"); //$NON-NLS-1$ |
50 |
|
51 |
themeIdCombo = new ComboViewer(comp, SWT.READ_ONLY); |
52 |
themeIdCombo.setLabelProvider(new LabelProvider() { |
53 |
@Override |
54 |
public String getText(Object element) { |
55 |
return ((ITheme) element).getLabel(); |
56 |
} |
57 |
}); |
58 |
themeIdCombo.setContentProvider(new ArrayContentProvider()); |
59 |
themeIdCombo.setInput(engine.getThemes()); |
60 |
themeIdCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
61 |
this.currentTheme = engine.getActiveTheme(); |
62 |
themeIdCombo.setSelection(new StructuredSelection(currentTheme)); |
63 |
themeIdCombo.addSelectionChangedListener(new ISelectionChangedListener() { |
64 |
|
65 |
public void selectionChanged(SelectionChangedEvent event) { |
66 |
engine.setTheme(getSelection(), |
67 |
false); |
68 |
} |
69 |
}); |
70 |
|
71 |
return comp; |
72 |
} |
73 |
|
74 |
private ITheme getSelection() { |
75 |
return (ITheme) ((IStructuredSelection) themeIdCombo.getSelection()).getFirstElement(); |
76 |
} |
77 |
|
78 |
public void init(IWorkbench workbench) { |
79 |
IEclipseContext context = (IEclipseContext) workbench.getService(IEclipseContext.class); |
80 |
defaultTheme = (String) context.get(E4Application.THEME_ID); |
81 |
engine = context.get(IThemeEngine.class); |
82 |
} |
83 |
|
84 |
/* |
85 |
* (non-Javadoc) |
86 |
* |
87 |
* @see org.eclipse.jface.preference.PreferencePage#performOk() |
88 |
*/ |
89 |
@Override |
90 |
public boolean performOk() { |
91 |
engine.setTheme(getSelection(), true); |
92 |
return super.performOk(); |
93 |
} |
94 |
|
95 |
@Override |
96 |
protected void performDefaults() { |
97 |
engine.setTheme(defaultTheme, true); |
98 |
themeIdCombo.setSelection(new StructuredSelection(engine.getActiveTheme())); |
99 |
super.performDefaults(); |
100 |
} |
101 |
|
102 |
/* |
103 |
* (non-Javadoc) |
104 |
* |
105 |
* @see org.eclipse.jface.preference.PreferencePage#performCancel() |
106 |
*/ |
107 |
@Override |
108 |
public boolean performCancel() { |
109 |
engine.setTheme(currentTheme, false); |
110 |
return super.performCancel(); |
111 |
} |
112 |
} |