1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.management;
14 import org.eclipse.core.runtime.ListenerList;
17 * @author Tuukka Lehtonen
19 public class SessionContextProvider implements ISessionContextProvider {
21 private ListenerList<ISessionContextChangedListener> listeners = new ListenerList<>();
23 private Object handle;
25 private ISessionContext context;
27 public SessionContextProvider(Object handle) {
31 public Object getHandle() {
35 public void setHandle(Object handle) {
40 public void addContextChangedListener(ISessionContextChangedListener listener) {
41 listeners.add(listener);
45 public ISessionContext getSessionContext() {
50 public void removeContextChangedListener(ISessionContextChangedListener listener) {
51 listeners.remove(listener);
54 private boolean safeEquals(Object o1, Object o2) {
61 public ISessionContext setSessionContext(ISessionContext context) {
62 ISessionContext oldContext = this.context;
63 this.context = context;
65 if (!safeEquals(oldContext, context))
66 fireChanged(oldContext, context);
71 protected void fireChanged(ISessionContext oldValue, ISessionContext newValue) {
72 SessionContextChangedEvent event = new SessionContextChangedEvent(this, handle, oldValue, newValue);
73 for (Object o : listeners.getListeners())
74 ((ISessionContextChangedListener) o).sessionContextChanged(event);
78 public String toString() {
79 return "SessionContextProvider [handle=" + handle + ", context=" + context + "]";