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.diagram.symbollibrary;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.HashSet;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.diagram.synchronization.graph.BasicResources;
20 import org.simantics.project.IProject;
21 import org.simantics.project.exception.ProjectException;
22 import org.simantics.project.features.AbstractProjectFeature;
23 import org.simantics.utils.datastructures.disposable.AbstractDisposable;
24 import org.simantics.utils.datastructures.disposable.IDisposable;
26 class SymbolManager extends AbstractDisposable implements ISymbolManager, IDisposable {
30 public SymbolManager(IProject project) {
31 this.project = project;
32 project.setHint(ISymbolManager.KEY_SYMBOL_GROUPS, Collections.emptySet());
36 protected void doDispose() {
37 project.setHint(KEY_SYMBOL_GROUPS, Collections.emptySet());
41 public void addEntryPoints(Collection<ISymbolGroup> eps) {
42 Collection<ISymbolGroup> groups = project.getHint(KEY_SYMBOL_GROUPS);
43 Collection<ISymbolGroup> newGroups = new HashSet<ISymbolGroup>(groups);
44 newGroups.addAll(eps);
45 project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups));
49 public void removeEntryPoints(Collection<ISymbolGroup> eps) {
50 Collection<ISymbolGroup> groups = project.getHint(KEY_SYMBOL_GROUPS);
51 Collection<ISymbolGroup> newGroups = new HashSet<ISymbolGroup>(groups);
52 newGroups.removeAll(eps);
53 project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups));
58 public class SymbolManagerFeature extends AbstractProjectFeature {
63 public void configure() throws ProjectException {
64 // IMPORTANT: This is vital for making sure that certain basic
65 // resource classes are loaded into the database session as its
66 // services (see org.simantics.db.ServiceLocator).
68 BasicResources.getInstance(getSession());
69 } catch (DatabaseException e) {
70 throw new ProjectException(e);
73 sm = new SymbolManager(getProject());
74 getProjectElement().setHint(ISymbolManager.KEY_SYMBOL_MANAGER, sm);
78 public void deconfigure() throws ProjectException {
79 if (getProjectElement().getHint(ISymbolManager.KEY_SYMBOL_MANAGER) == sm)
80 getProjectElement().removeHint(ISymbolManager.KEY_SYMBOL_MANAGER);