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