/* * Copyright (c) 2016, Alex Blewitt, Bandlem Ltd * Copyright (c) 2016, Packt Publishing Ltd * * 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 */ package com.packtpub.e4.application.parts; import javax.annotation.PostConstruct; import javax.inject.Inject; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ListViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import com.packtpub.e4.application.IStringService; public class Rainbow { private static final Object[] rainbow = { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" }; @Inject // private ESelectionService selectionService; private IEventBroker broker; @Inject private IStringService stringService; @PostConstruct public void create(Composite parent) { ListViewer lv = new ListViewer(parent, SWT.NONE); lv.setContentProvider(new ArrayContentProvider()); lv.addSelectionChangedListener(event -> { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); Object colour = sel.getFirstElement(); broker.post("rainbow/colour", stringService.process(colour.toString())); }); lv.setInput(rainbow); } }