-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.management;\r
-\r
-import org.eclipse.core.runtime.ListenerList;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SessionContextProvider implements ISessionContextProvider {\r
-\r
- private ListenerList listeners = new ListenerList();\r
- \r
- private Object handle;\r
-\r
- private ISessionContext context;\r
- \r
- public SessionContextProvider(Object handle) {\r
- this.handle = handle;\r
- }\r
- \r
- public Object getHandle() {\r
- return handle;\r
- }\r
-\r
- public void setHandle(Object handle) {\r
- this.handle = handle;\r
- }\r
-\r
- @Override\r
- public void addContextChangedListener(ISessionContextChangedListener listener) {\r
- listeners.add(listener);\r
- }\r
-\r
- @Override\r
- public ISessionContext getSessionContext() {\r
- return context;\r
- }\r
-\r
- @Override\r
- public void removeContextChangedListener(ISessionContextChangedListener listener) {\r
- listeners.remove(listener);\r
- }\r
-\r
- private boolean safeEquals(Object o1, Object o2) {\r
- if (o1 == null)\r
- return o2 == null;\r
- return o1.equals(o2);\r
- }\r
- \r
- @Override\r
- public ISessionContext setSessionContext(ISessionContext context) {\r
- ISessionContext oldContext = this.context;\r
- this.context = context;\r
-\r
- if (!safeEquals(oldContext, context))\r
- fireChanged(oldContext, context);\r
-\r
- return oldContext;\r
- }\r
-\r
- protected void fireChanged(ISessionContext oldValue, ISessionContext newValue) {\r
- SessionContextChangedEvent event = new SessionContextChangedEvent(this, handle, oldValue, newValue);\r
- for (Object o : listeners.getListeners())\r
- ((ISessionContextChangedListener) o).sessionContextChanged(event);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "SessionContextProvider [handle=" + handle + ", context=" + context + "]";\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.management;
+
+import org.eclipse.core.runtime.ListenerList;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SessionContextProvider implements ISessionContextProvider {
+
+ private ListenerList<ISessionContextChangedListener> listeners = new ListenerList<>();
+
+ private Object handle;
+
+ private ISessionContext context;
+
+ public SessionContextProvider(Object handle) {
+ this.handle = handle;
+ }
+
+ public Object getHandle() {
+ return handle;
+ }
+
+ public void setHandle(Object handle) {
+ this.handle = handle;
+ }
+
+ @Override
+ public void addContextChangedListener(ISessionContextChangedListener listener) {
+ listeners.add(listener);
+ }
+
+ @Override
+ public ISessionContext getSessionContext() {
+ return context;
+ }
+
+ @Override
+ public void removeContextChangedListener(ISessionContextChangedListener listener) {
+ listeners.remove(listener);
+ }
+
+ private boolean safeEquals(Object o1, Object o2) {
+ if (o1 == null)
+ return o2 == null;
+ return o1.equals(o2);
+ }
+
+ @Override
+ public ISessionContext setSessionContext(ISessionContext context) {
+ ISessionContext oldContext = this.context;
+ this.context = context;
+
+ if (!safeEquals(oldContext, context))
+ fireChanged(oldContext, context);
+
+ return oldContext;
+ }
+
+ protected void fireChanged(ISessionContext oldValue, ISessionContext newValue) {
+ SessionContextChangedEvent event = new SessionContextChangedEvent(this, handle, oldValue, newValue);
+ for (Object o : listeners.getListeners())
+ ((ISessionContextChangedListener) o).sessionContextChanged(event);
+ }
+
+ @Override
+ public String toString() {
+ return "SessionContextProvider [handle=" + handle + ", context=" + context + "]";
+ }
+
+}