X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.management%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fmanagement%2FSessionContextProvider.java;h=7b76b24bbf62e2c24b98c1340ba5f437bdc652ae;hp=421c911da053a77e83624d9906aebac4750ee83d;hb=627664d06302d454ea3b3fe14d13bb5ab739d666;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContextProvider.java b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContextProvider.java index 421c911da..7b76b24bb 100644 --- a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContextProvider.java +++ b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContextProvider.java @@ -1,82 +1,82 @@ -/******************************************************************************* - * 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 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 + "]"; - } - -} +/******************************************************************************* + * 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 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 + "]"; + } + +}