]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/SymbolManagerFeature.java
Fix SymbolLibraryComposite DnD to cope also with GroupProxySymbolItems
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / symbollibrary / SymbolManagerFeature.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.symbollibrary;
13
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.HashSet;
17
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;
25
26 class SymbolManager extends AbstractDisposable implements ISymbolManager, IDisposable {
27
28     IProject project;
29
30     public SymbolManager(IProject project) {
31         this.project = project;
32         project.setHint(ISymbolManager.KEY_SYMBOL_GROUPS, Collections.emptySet());
33     }
34
35     @Override
36     protected void doDispose() {
37         project.setHint(KEY_SYMBOL_GROUPS, Collections.emptySet());
38     }
39
40     @Override
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));
46     }
47
48     @Override
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));
54     }
55
56 }
57
58 public class SymbolManagerFeature extends AbstractProjectFeature {
59
60     SymbolManager sm;
61
62     @Override
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).
67         try {
68             BasicResources.getInstance(getSession());
69         } catch (DatabaseException e) {
70             throw new ProjectException(e);
71         }
72
73         sm = new SymbolManager(getProject());
74         getProjectElement().setHint(ISymbolManager.KEY_SYMBOL_MANAGER, sm);
75     }
76
77     @Override
78     public void deconfigure() throws ProjectException {
79         if (getProjectElement().getHint(ISymbolManager.KEY_SYMBOL_MANAGER) == sm)
80             getProjectElement().removeHint(ISymbolManager.KEY_SYMBOL_MANAGER);
81         sm.dispose();
82         sm = null;
83     }
84
85 }