X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsymbollibrary%2FSymbolManagerFeature.java;h=f699e2950a4ee802bdbb11f750656c4701aa2c76;hb=86617be247efb3b904b3180d0569049aff232d75;hp=85ed7e6c6ed82ec2e96877b00ef4cb7e83181f36;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/SymbolManagerFeature.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/SymbolManagerFeature.java index 85ed7e6c6..f699e2950 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/SymbolManagerFeature.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/SymbolManagerFeature.java @@ -1,85 +1,85 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.symbollibrary; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; - -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.synchronization.graph.BasicResources; -import org.simantics.project.IProject; -import org.simantics.project.exception.ProjectException; -import org.simantics.project.features.AbstractProjectFeature; -import org.simantics.utils.datastructures.disposable.AbstractDisposable; -import org.simantics.utils.datastructures.disposable.IDisposable; - -class SymbolManager extends AbstractDisposable implements ISymbolManager, IDisposable { - - IProject project; - - public SymbolManager(IProject project) { - this.project = project; - project.setHint(ISymbolManager.KEY_SYMBOL_GROUPS, Collections.emptySet()); - } - - @Override - protected void doDispose() { - project.setHint(KEY_SYMBOL_GROUPS, Collections.emptySet()); - } - - @Override - public void addEntryPoints(Collection eps) { - Collection groups = project.getHint(KEY_SYMBOL_GROUPS); - Collection newGroups = new HashSet(groups); - newGroups.addAll(eps); - project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups)); - } - - @Override - public void removeEntryPoints(Collection eps) { - Collection groups = project.getHint(KEY_SYMBOL_GROUPS); - Collection newGroups = new HashSet(groups); - newGroups.removeAll(eps); - project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups)); - } - -} - -public class SymbolManagerFeature extends AbstractProjectFeature { - - SymbolManager sm; - - @Override - public void configure() throws ProjectException { - // IMPORTANT: This is vital for making sure that certain basic - // resource classes are loaded into the database session as its - // services (see org.simantics.db.ServiceLocator). - try { - BasicResources.getInstance(getSession()); - } catch (DatabaseException e) { - throw new ProjectException(e); - } - - sm = new SymbolManager(getProject()); - getProjectElement().setHint(ISymbolManager.KEY_SYMBOL_MANAGER, sm); - } - - @Override - public void deconfigure() throws ProjectException { - if (getProjectElement().getHint(ISymbolManager.KEY_SYMBOL_MANAGER) == sm) - getProjectElement().removeHint(ISymbolManager.KEY_SYMBOL_MANAGER); - sm.dispose(); - sm = null; - } - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.symbollibrary; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; + +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.graph.BasicResources; +import org.simantics.project.IProject; +import org.simantics.project.exception.ProjectException; +import org.simantics.project.features.AbstractProjectFeature; +import org.simantics.utils.datastructures.disposable.AbstractDisposable; +import org.simantics.utils.datastructures.disposable.IDisposable; + +class SymbolManager extends AbstractDisposable implements ISymbolManager, IDisposable { + + IProject project; + + public SymbolManager(IProject project) { + this.project = project; + project.setHint(ISymbolManager.KEY_SYMBOL_GROUPS, Collections.emptySet()); + } + + @Override + protected void doDispose() { + project.setHint(KEY_SYMBOL_GROUPS, Collections.emptySet()); + } + + @Override + public void addEntryPoints(Collection eps) { + Collection groups = project.getHint(KEY_SYMBOL_GROUPS); + Collection newGroups = new HashSet(groups); + newGroups.addAll(eps); + project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups)); + } + + @Override + public void removeEntryPoints(Collection eps) { + Collection groups = project.getHint(KEY_SYMBOL_GROUPS); + Collection newGroups = new HashSet(groups); + newGroups.removeAll(eps); + project.setHint(KEY_SYMBOL_GROUPS, Collections.unmodifiableCollection(newGroups)); + } + +} + +public class SymbolManagerFeature extends AbstractProjectFeature { + + SymbolManager sm; + + @Override + public void configure() throws ProjectException { + // IMPORTANT: This is vital for making sure that certain basic + // resource classes are loaded into the database session as its + // services (see org.simantics.db.ServiceLocator). + try { + BasicResources.getInstance(getSession()); + } catch (DatabaseException e) { + throw new ProjectException(e); + } + + sm = new SymbolManager(getProject()); + getProjectElement().setHint(ISymbolManager.KEY_SYMBOL_MANAGER, sm); + } + + @Override + public void deconfigure() throws ProjectException { + if (getProjectElement().getHint(ISymbolManager.KEY_SYMBOL_MANAGER) == sm) + getProjectElement().removeHint(ISymbolManager.KEY_SYMBOL_MANAGER); + sm.dispose(); + sm = null; + } + } \ No newline at end of file