Java tutorial
/** SpagoBI, the Open Source Business Intelligence suite Copyright (C) 2012 Engineering Ingegneria Informatica S.p.A. - SpagoBI Competency Center This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. **/ package it.eng.spagobi.meta.editor.business; import java.util.ArrayList; import java.util.Collection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; /** * @author Andrea Gioia (andrea.gioia@eng.it) * */ public class BusinessModelEditorSelectionProvider implements ISelectionProvider { BusinessModelEditor editor; /** * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s * that are listening to this editor. */ protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); /** * This keeps track of the selection of the editor as a whole. */ protected ISelection editorSelection = StructuredSelection.EMPTY; public BusinessModelEditorSelectionProvider(BusinessModelEditor editor) { this.editor = editor; } public ISelection getEditorSelection() { return editorSelection; } public void setEditorSelection(ISelection editorSelection) { this.editorSelection = editorSelection; } /** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void addSelectionChangedListener(ISelectionChangedListener listener) { selectionChangedListeners.add(listener); } /** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void removeSelectionChangedListener(ISelectionChangedListener listener) { selectionChangedListeners.remove(listener); } /** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to return this editor's overall selection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public ISelection getSelection() { return editorSelection; } /** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection. * Calling this result will notify the listeners. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setSelection(ISelection selection) { editorSelection = selection; for (ISelectionChangedListener listener : selectionChangedListeners) { listener.selectionChanged(new SelectionChangedEvent(this, selection)); } editor.setStatusLineManager(selection); } }