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.diagram.symbolcontribution;
\r
14 import java.util.Collection;
\r
15 import java.util.Collections;
\r
16 import java.util.HashSet;
\r
17 import java.util.Set;
\r
19 import org.simantics.diagram.symbollibrary.ISymbolGroup;
\r
21 public abstract class AbstractSymbolProvider implements ISymbolProvider {
\r
22 protected volatile boolean disposed = false;
\r
23 protected Runnable listener;
\r
24 protected Collection<ISymbolGroup> groups = Collections.emptyList();
\r
25 private Set<ISymbolGroup> groupSet = null;
\r
27 public Collection<ISymbolGroup> getSymbolGroups() {
\r
31 public void setListener(Runnable listener) {
\r
32 this.listener = listener;
\r
35 public void dispose() {
\r
39 void setSymbolGroup(Collection<ISymbolGroup> groups) {
\r
41 throw new NullPointerException("null groups");
\r
42 this.groups = groups;
\r
45 protected Set<ISymbolGroup> getSymbolGroupSet() {
\r
46 synchronized (this) {
\r
47 if (groupSet != null)
\r
49 groupSet = new HashSet<ISymbolGroup>(getSymbolGroups());
\r
55 groups = Collections.unmodifiableCollection(groups);
\r
57 getSymbolGroupSet();
\r
61 public int hashCode() {
\r
62 return getSymbolGroupSet().hashCode();
\r
66 public boolean equals(Object obj) {
\r
71 if (!(obj instanceof AbstractSymbolProvider))
\r
73 AbstractSymbolProvider other = (AbstractSymbolProvider) obj;
\r
74 return getSymbolGroupSet().equals( other.getSymbolGroupSet() );
\r