--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.symbollibrary;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.HashSet;\r
+\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.synchronization.graph.BasicResources;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.exception.ProjectException;\r
+import org.simantics.project.features.AbstractProjectFeature;\r
+import org.simantics.utils.datastructures.disposable.AbstractDisposable;\r
+import org.simantics.utils.datastructures.disposable.IDisposable;\r
+\r
+class SymbolManager extends AbstractDisposable implements ISymbolManager, IDisposable {\r
+\r
+ IProject project;\r
+\r
+ public SymbolManager(IProject project) {\r
+ this.project = project;\r
+ project.setHint(ISymbolManager.KEY_SYMBOL_GROUPS, Collections.emptySet());\r
+ }\r
+\r
+ @Override\r
+ protected void doDispose() {\r
+ project.setHint(KEY_SYMBOL_GROUPS, Collections.emptySet());\r
+ }\r
+\r
+ @Override\r
+ public void addEntryPoints(Collection<ISymbolGroup> eps) {\r
+ Collection<ISymbolGroup> groups = project.getHint(KEY_SYMBOL_GROUPS);\r
+ Collection<ISymbolGroup> newGroups = new HashSet<ISymbolGroup>(groups);\r
+ newGroups.addAll(eps);\r
+ project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups));\r
+ }\r
+\r
+ @Override\r
+ public void removeEntryPoints(Collection<ISymbolGroup> eps) {\r
+ Collection<ISymbolGroup> groups = project.getHint(KEY_SYMBOL_GROUPS);\r
+ Collection<ISymbolGroup> newGroups = new HashSet<ISymbolGroup>(groups);\r
+ newGroups.removeAll(eps);\r
+ project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups));\r
+ }\r
+\r
+}\r
+\r
+public class SymbolManagerFeature extends AbstractProjectFeature {\r
+\r
+ SymbolManager sm;\r
+\r
+ @Override\r
+ public void configure() throws ProjectException {\r
+ // IMPORTANT: This is vital for making sure that certain basic\r
+ // resource classes are loaded into the database session as its\r
+ // services (see org.simantics.db.ServiceLocator).\r
+ try {\r
+ BasicResources.getInstance(getSession());\r
+ } catch (DatabaseException e) {\r
+ throw new ProjectException(e);\r
+ }\r
+\r
+ sm = new SymbolManager(getProject());\r
+ getProjectElement().setHint(ISymbolManager.KEY_SYMBOL_MANAGER, sm);\r
+ }\r
+\r
+ @Override\r
+ public void deconfigure() throws ProjectException {\r
+ if (getProjectElement().getHint(ISymbolManager.KEY_SYMBOL_MANAGER) == sm)\r
+ getProjectElement().removeHint(ISymbolManager.KEY_SYMBOL_MANAGER);\r
+ sm.dispose();\r
+ sm = null;\r
+ }\r
+\r
+}
\ No newline at end of file