diff options
7 files changed, 150 insertions, 180 deletions
diff --git a/examples/org.eclipse.e4.demo.contacts/plugin.xml b/examples/org.eclipse.e4.demo.contacts/plugin.xml index 8e1877f8c2e..f307c9adcbc 100644 --- a/examples/org.eclipse.e4.demo.contacts/plugin.xml +++ b/examples/org.eclipse.e4.demo.contacts/plugin.xml @@ -17,7 +17,7 @@ </property> <property name="cssTheme" - value="org.eclipse.e4.demo.contacts.themes.darkgradient"> + value="org.eclipse.e4.demo.contacts.themes.blue"> </property> <property name="startupForegroundColor" diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/model/internal/VCardContactsRepository.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/model/internal/VCardContactsRepository.java index 58373dd5781..1e54a6b122a 100644 --- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/model/internal/VCardContactsRepository.java +++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/model/internal/VCardContactsRepository.java @@ -35,9 +35,7 @@ import org.eclipse.e4.demo.contacts.BundleActivatorImpl; import org.eclipse.e4.demo.contacts.model.Contact; import org.eclipse.e4.demo.contacts.model.IContactsRepository; import org.eclipse.osgi.internal.signedcontent.Base64; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.widgets.Display; import org.osgi.framework.Bundle; @SuppressWarnings("restriction") diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/AbstractThemeProcessor.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/AbstractThemeProcessor.java deleted file mode 100644 index d5fc7db694f..00000000000 --- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/AbstractThemeProcessor.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 BestSolution.at, 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: - * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Kai Tödter - Adoption to contacts demo - * Lars Vogel <lars.vogel@gmail.com> - Bug https://bugs.eclipse.org/413431 - ******************************************************************************/ -package org.eclipse.e4.demo.contacts.processors; - -import java.util.List; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.RegistryFactory; -import org.eclipse.e4.core.di.annotations.Execute; -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.MCommandsFactory; -import org.eclipse.e4.ui.model.application.commands.MParameter; -import org.eclipse.swt.widgets.Display; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; - -public abstract class AbstractThemeProcessor { - - public void process(MApplication app) { - if (!check()) { - return; - } - - // FIXME Remove once bug 314091 is resolved - Bundle bundle = FrameworkUtil.getBundle(getClass()); - BundleContext context = bundle.getBundleContext(); - - ServiceReference reference = context - .getServiceReference(IThemeManager.class.getName()); - IThemeManager mgr = (IThemeManager) context.getService(reference); - IThemeEngine engine = mgr.getEngineForDisplay(Display.getCurrent()); - - List<ITheme> themes = engine.getThemes(); - if (themes.size() > 0) { - - MCommand switchThemeCommand = null; - for (MCommand cmd : app.getCommands()) { - if ("contacts.switchTheme".equals(cmd.getElementId())) { //$NON-NLS-1$ - switchThemeCommand = cmd; - break; - } - } - - if (switchThemeCommand != null) { - - preprocess(); - - for (ITheme theme : themes) { - MParameter parameter = MCommandsFactory.INSTANCE - .createParameter(); - parameter.setName("contacts.commands.switchtheme.themeid"); //$NON-NLS-1$ - parameter.setValue(theme.getId()); - String iconURI = getCSSUri(theme.getId()); - if (iconURI != null) { - iconURI = iconURI.replace(".css", ".png"); - } - processTheme(theme.getLabel(), switchThemeCommand, parameter, - iconURI); - } - - postprocess(); - } - } - } - - abstract protected boolean check(); - - abstract protected void preprocess(); - - abstract protected void processTheme(String name, MCommand switchCommand, - MParameter themeId, String iconURI); - - abstract protected void postprocess(); - - private String getCSSUri(String themeId) { - IExtensionRegistry registry = RegistryFactory.getRegistry(); - IExtensionPoint extPoint = registry - .getExtensionPoint("org.eclipse.e4.ui.css.swt.theme"); - - for (IExtension e : extPoint.getExtensions()) { - for (IConfigurationElement ce : e.getConfigurationElements()) { - if (ce.getName().equals("theme") - && ce.getAttribute("id").equals(themeId)) { - return "platform:/plugin/" + ce.getContributor().getName() - + "/" + ce.getAttribute("basestylesheeturi"); - } - } - } - return null; - } -} diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/MenuThemeProcessor.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/MenuThemeProcessor.java index 58508d4c859..f59362a6b92 100644 --- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/MenuThemeProcessor.java +++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/processors/MenuThemeProcessor.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2010, 2012 BestSolution.at, 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 @@ -9,68 +9,89 @@ * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Kai Tödter - Adoption to contacts demo - * 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; 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.MHandledMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenu; -import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.swt.widgets.Display; -public class MenuThemeProcessor extends AbstractThemeProcessor { +public class MenuThemeProcessor extends Util { private static final String BUNDLE_ID = "platform:/plugin/org.eclipse.e4.demo.contacts"; //$NON-NLS-1$ - + @Inject @Named("menu:org.eclipse.ui.main.menu") private MMenu menu; private MMenu themesMenu; - - private final static String PROCESSOR_ID = "org.eclipse.e4.demo.contacts.processor.menu"; + private final static String PROCESSOR_ID = "org.eclipse.e4.demo.contacts.processor.menu"; + + @SuppressWarnings("restriction") @Execute - public void execute(MApplication app) { + public void execute(MApplication app, EModelService service, + IExtensionRegistry registery, IThemeManager mgr) { + + // sanity check if (menu == 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()) { - return; - } + tags.add(PROCESSOR_ID); - super.process(app); - } - @Override - protected boolean check() { - return menu != null; - } + IThemeEngine engine = mgr.getEngineForDisplay(Display.getCurrent()); + + List<ITheme> themes = engine.getThemes(); - @Override - protected void preprocess() { - themesMenu = MMenuFactory.INSTANCE.createMenu(); + MCommand switchThemeCommand = findCommand(app); + + // no themes or command, stop processing + if (themes.size() <= 0 || switchThemeCommand == null) { + return; + } + + themesMenu = service.createModelElement(MMenu.class); themesMenu.setLabel("%switchThemeMenu"); //$NON-NLS-1$ themesMenu.setContributorURI(BUNDLE_ID); + + 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 = Util.getCSSUri(theme.getId(), registery); + if (iconURI != null) { + iconURI = iconURI.replace(".css", ".png"); + } + processTheme(theme.getLabel(), switchThemeCommand, parameter, + iconURI, service); + } + menu.getChildren().add(themesMenu); } - @Override protected void processTheme(String name, MCommand switchCommand, - MParameter themeId, String iconURI) { - MHandledMenuItem menuItem = MMenuFactory.INSTANCE - .createHandledMenuItem(); + MParameter themeId, String iconURI, EModelService service) { + MHandledMenuItem menuItem = service + .createModelElement(MHandledMenuItem.class); menuItem.setLabel(name); menuItem.setCommand(switchCommand); menuItem.getParameters().add(themeId); @@ -82,9 +103,4 @@ public class MenuThemeProcessor extends AbstractThemeProcessor { } - @Override - protected void postprocess() { - menu.getChildren().add(themesMenu); - } - } 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() { - } - } diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/util/Util.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/util/Util.java new file mode 100644 index 00000000000..761c605b40c --- /dev/null +++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/util/Util.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at, 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: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Kai Tödter - Adoption to contacts demo + * Lars Vogel <lars.vogel@gmail.com> - Bug 413431, 416166 + ******************************************************************************/ +package org.eclipse.e4.demo.contacts.util; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; + +public class Util { + public static String getCSSUri(String themeId, IExtensionRegistry registry) { + IExtensionPoint extPoint = registry + .getExtensionPoint("org.eclipse.e4.ui.css.swt.theme"); + + for (IExtension e : extPoint.getExtensions()) { + for (IConfigurationElement ce : e.getConfigurationElements()) { + if (ce.getName().equals("theme") + && ce.getAttribute("id").equals(themeId)) { + return "platform:/plugin/" + ce.getContributor().getName() + + "/" + ce.getAttribute("basestylesheeturi"); + } + } + } + return null; + } + + public static MCommand findCommand(MApplication app) { + MCommand switchThemeCommand = null; + for (MCommand cmd : app.getCommands()) { + if ("contacts.switchTheme".equals(cmd.getElementId())) { //$NON-NLS-1$ + switchThemeCommand = cmd; + break; + } + } + return switchThemeCommand; + } +} diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java index 6814e439d4b..37d3216d00d 100644 --- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java +++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java @@ -14,7 +14,6 @@ package org.eclipse.e4.demo.contacts.views; import org.eclipse.e4.ui.workbench.swt.modeling.EMenuService; -import javax.annotation.PreDestroy; import javax.inject.Inject; import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.core.databinding.observable.map.IObservableMap; @@ -33,7 +32,6 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; |