blob: 9b4f6a5ca6d8f9d5dd39d693249d7faebcc60b26 (
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
|
/*******************************************************************************
* Copyright (c) 2010, 2012 Siemens AG and others.
*
* 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:
* Kai Tödter - initial implementation
******************************************************************************/
package org.eclipse.e4.demo.contacts.processors;
import java.util.List;
import org.eclipse.e4.core.di.annotations.Execute;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MParameter;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
import org.eclipse.emf.ecore.EObject;
public class ToolbarThemeProcessor extends AbstractThemeProcessor {
@Inject
@Named("toolbar:org.eclipse.ui.main.toolbar")
private MToolBar toolbar;
private final static String PROCESSOR_ID = "org.eclipse.e4.demo.contacts.processor.toolbar";
@Execute
public void process() {
MApplication theApp = getApplication();
List<String> tags = theApp.getTags();
for(String tag : tags) {
if (PROCESSOR_ID.equals(tag))
return; // already processed
}
if (!check())
return;
tags.add(PROCESSOR_ID);
super.process();
}
@Override
protected boolean check() {
return toolbar != null;
}
@Override
protected void preprocess() {
toolbar.getChildren().add(
MMenuFactory.INSTANCE.createToolBarSeparator());
}
@Override
protected void processTheme(String name, MCommand switchCommand,
MParameter themeId, String iconURI) {
MHandledToolItem toolItem = MMenuFactory.INSTANCE
.createHandledToolItem();
toolItem.setTooltip(name);
toolItem.setCommand(switchCommand);
toolItem.getParameters().add(themeId);
if (iconURI != null) {
toolItem.setIconURI(iconURI);
}
toolbar.getChildren().add(toolItem);
}
@Override
protected void postprocess() {
}
@Override
protected MApplication getApplication() {
return (MApplication) (((EObject) toolbar).eContainer()).eContainer().eContainer();
}
}
|