diff options
Diffstat (limited to 'examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java')
-rw-r--r-- | examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java index 491a99db53a..ba7d244e1ff 100644 --- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java +++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/ToolbarThemeProcessor.java @@ -1,14 +1,14 @@ /******************************************************************************* * Copyright (c) 2010, 2012 Siemens AG and others. - * - * All rights reserved. This program and the accompanying materials + * + * 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 - * Lars Vogel <lars.vogel@gmail.com> - Bug https://bugs.eclipse.org/413431 + * Lars Vogel <lars.vogel@gmail.com> - Bug 413431, 416166 ******************************************************************************/ package org.eclipse.e4.demo.contacts.processors; @@ -16,58 +16,80 @@ package org.eclipse.e4.demo.contacts.processors; import java.util.List; import javax.inject.Inject; import javax.inject.Named; +import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.demo.contacts.util.Util; +import org.eclipse.e4.ui.css.swt.theme.ITheme; +import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; +import org.eclipse.e4.ui.css.swt.theme.IThemeManager; 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.e4.ui.model.application.ui.menu.MToolBarSeparator; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.swt.widgets.Display; -public class ToolbarThemeProcessor extends AbstractThemeProcessor { +public class ToolbarThemeProcessor extends Util { @Inject @Named("toolbar:org.eclipse.ui.main.toolbar") private MToolBar toolbar; - private final static String PROCESSOR_ID = "org.eclipse.e4.demo.contacts.processor.toolbar"; + private final static String PROCESSOR_ID = "org.eclipse.e4.demo.contacts.processor.toolbar"; + @SuppressWarnings("restriction") @Execute - public void execute(MApplication app) { + public void execute(MApplication app, EModelService service, + IExtensionRegistry registery, IThemeManager mgr) { if (toolbar == null) { return; } - + List<String> tags = app.getTags(); - for(String tag : tags) { - if (PROCESSOR_ID.equals(tag)) - { + for (String tag : tags) { + if (PROCESSOR_ID.equals(tag)) { return; // already processed } } - if (!check()) { + tags.add(PROCESSOR_ID); + + IThemeEngine engine = mgr.getEngineForDisplay(Display.getCurrent()); + List<ITheme> themes = engine.getThemes(); + + MCommand switchThemeCommand = findCommand(app); + + // no themes or command, stop processing + if (themes.size() <= 0 || switchThemeCommand == null) { return; } - tags.add(PROCESSOR_ID); - super.process(app); - } - @Override - protected boolean check() { - return toolbar != null; - } + if (switchThemeCommand != null) { + + toolbar.getChildren().add( + service.createModelElement(MToolBarSeparator.class)); + + for (ITheme theme : themes) { + MParameter parameter = service + .createModelElement(MParameter.class); + parameter.setName("contacts.commands.switchtheme.themeid"); //$NON-NLS-1$ + parameter.setValue(theme.getId()); + String iconURI = getCSSUri(theme.getId(), registery); + if (iconURI != null) { + iconURI = iconURI.replace(".css", ".png"); + } + processTheme(theme.getLabel(), switchThemeCommand, parameter, + iconURI, service); + } - @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(); + MParameter themeId, String iconURI, EModelService service) { + MHandledToolItem toolItem = service + .createModelElement(MHandledToolItem.class); toolItem.setTooltip(name); toolItem.setCommand(switchCommand); toolItem.getParameters().add(themeId); @@ -77,8 +99,4 @@ public class ToolbarThemeProcessor extends AbstractThemeProcessor { toolbar.getChildren().add(toolItem); } - @Override - protected void postprocess() { - } - } |