X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftypicals%2FTypicalSupport.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftypicals%2FTypicalSupport.java;h=5fcc8634ebbe4dba0551cd777ab9ec30fe62f5ab;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=3caae3712f72270897f1ca86ef685e390f4198b0;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalSupport.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalSupport.java index 3caae3712..5fcc8634e 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalSupport.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalSupport.java @@ -1,88 +1,88 @@ -/******************************************************************************* - * Copyright (c) 2012 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.modeling.typicals; - -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; -import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.simantics.db.service.GraphChangeListenerSupport; -import org.simantics.project.IProject; - -/** - * @author Tuukka Lehtonen - * @deprecated not to be used anymore, will be removed - */ -public class TypicalSupport { - - protected IProject project; - protected GraphChangeListenerSupport changeListenerSupport; - - private IEclipsePreferences typicalPreferences; - private TypicalDiagramTemplateListener typicalDiagramTemplateListener; - private IPreferenceChangeListener typicalSynchronizationPreferenceListener = new TypicalSynchronizationPreferenceListener(); - - public TypicalSupport(IProject project) { - this.project = project; - this.changeListenerSupport = project.getSession().getService(GraphChangeListenerSupport.class); - - setTypicalSynchronization( isSyncEnabled() ); - typicalPreferences = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE); - typicalPreferences.addPreferenceChangeListener(typicalSynchronizationPreferenceListener); - } - - public void dispose() { - if (typicalPreferences != null) { - typicalPreferences.removePreferenceChangeListener(typicalSynchronizationPreferenceListener); - } - if (typicalDiagramTemplateListener != null) { - changeListenerSupport.removeMetadataListener(typicalDiagramTemplateListener); - typicalDiagramTemplateListener = null; - } - } - - public void setTypicalSynchronization(boolean enabled) { - if (enabled) { - if (typicalDiagramTemplateListener == null) { - typicalDiagramTemplateListener = new TypicalDiagramTemplateListener(); - changeListenerSupport.addMetadataListener( typicalDiagramTemplateListener ); - } - } else { - if (typicalDiagramTemplateListener != null) { - changeListenerSupport.removeMetadataListener( typicalDiagramTemplateListener ); - typicalDiagramTemplateListener = null; - } - } - } - - private boolean isSyncEnabled() { - return InstanceScope.INSTANCE - .getNode(TypicalPreferences.P_NODE) - .getBoolean( - TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, - TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED); - } - - private class TypicalSynchronizationPreferenceListener implements IPreferenceChangeListener { - @Override - public void preferenceChange(PreferenceChangeEvent event) { - if (project == null || project.isDisposed()) - return; - - if (TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED.equals(event.getKey())) { - boolean enabled = isSyncEnabled(); - setTypicalSynchronization(enabled); - } - } - } - -} +/******************************************************************************* + * Copyright (c) 2012 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.modeling.typicals; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.simantics.db.service.GraphChangeListenerSupport; +import org.simantics.project.IProject; + +/** + * @author Tuukka Lehtonen + * @deprecated not to be used anymore, will be removed + */ +public class TypicalSupport { + + protected IProject project; + protected GraphChangeListenerSupport changeListenerSupport; + + private IEclipsePreferences typicalPreferences; + private TypicalDiagramTemplateListener typicalDiagramTemplateListener; + private IPreferenceChangeListener typicalSynchronizationPreferenceListener = new TypicalSynchronizationPreferenceListener(); + + public TypicalSupport(IProject project) { + this.project = project; + this.changeListenerSupport = project.getSession().getService(GraphChangeListenerSupport.class); + + setTypicalSynchronization( isSyncEnabled() ); + typicalPreferences = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE); + typicalPreferences.addPreferenceChangeListener(typicalSynchronizationPreferenceListener); + } + + public void dispose() { + if (typicalPreferences != null) { + typicalPreferences.removePreferenceChangeListener(typicalSynchronizationPreferenceListener); + } + if (typicalDiagramTemplateListener != null) { + changeListenerSupport.removeMetadataListener(typicalDiagramTemplateListener); + typicalDiagramTemplateListener = null; + } + } + + public void setTypicalSynchronization(boolean enabled) { + if (enabled) { + if (typicalDiagramTemplateListener == null) { + typicalDiagramTemplateListener = new TypicalDiagramTemplateListener(); + changeListenerSupport.addMetadataListener( typicalDiagramTemplateListener ); + } + } else { + if (typicalDiagramTemplateListener != null) { + changeListenerSupport.removeMetadataListener( typicalDiagramTemplateListener ); + typicalDiagramTemplateListener = null; + } + } + } + + private boolean isSyncEnabled() { + return InstanceScope.INSTANCE + .getNode(TypicalPreferences.P_NODE) + .getBoolean( + TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, + TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED); + } + + private class TypicalSynchronizationPreferenceListener implements IPreferenceChangeListener { + @Override + public void preferenceChange(PreferenceChangeEvent event) { + if (project == null || project.isDisposed()) + return; + + if (TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED.equals(event.getKey())) { + boolean enabled = isSyncEnabled(); + setTypicalSynchronization(enabled); + } + } + } + +}