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