1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.ui.workbench.editor;
14 import java.lang.ref.WeakReference;
15 import java.util.WeakHashMap;
18 * A class for holding a set of (Object, ResourceEditorAdapter) bindings. These
19 * bindings are used to store the latest editor opened for input objects. This
20 * is used by the default UI double click actions.
22 * @author Tuukka Lehtonen
24 public class EditorMappingImpl implements EditorMapping {
27 * Prevent the map from holding on to resource editor adapters.
29 WeakHashMap<Object, WeakReference<EditorAdapter>> resourceToAdapter = new WeakHashMap<Object, WeakReference<EditorAdapter>>();
32 public synchronized void put(Object o, EditorAdapter adapter) {
34 if (adapter != null) {
35 resourceToAdapter.put(o, new WeakReference<EditorAdapter>(adapter));
37 resourceToAdapter.remove(o);
42 public synchronized EditorAdapter get(Object o) {
43 //System.out.println("EditorMapping.get(" + o + "): key set=" + resourceToAdapter.keySet());
44 WeakReference<EditorAdapter> ref = resourceToAdapter.get(o);
47 EditorAdapter adapter = ref.get();
48 if (adapter == null) {
49 resourceToAdapter.remove(o);
56 public synchronized void clear() {
57 resourceToAdapter.clear();