-/*******************************************************************************\r
- * Copyright (c) 2012 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.modeling.typicals;\r
-\r
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;\r
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;\r
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;\r
-import org.eclipse.core.runtime.preferences.InstanceScope;\r
-import org.simantics.db.service.GraphChangeListenerSupport;\r
-import org.simantics.project.IProject;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- * @deprecated not to be used anymore, will be removed\r
- */\r
-public class TypicalSupport {\r
-\r
- protected IProject project;\r
- protected GraphChangeListenerSupport changeListenerSupport;\r
-\r
- private IEclipsePreferences typicalPreferences;\r
- private TypicalDiagramTemplateListener typicalDiagramTemplateListener;\r
- private IPreferenceChangeListener typicalSynchronizationPreferenceListener = new TypicalSynchronizationPreferenceListener();\r
-\r
- public TypicalSupport(IProject project) {\r
- this.project = project;\r
- this.changeListenerSupport = project.getSession().getService(GraphChangeListenerSupport.class);\r
-\r
- setTypicalSynchronization( isSyncEnabled() );\r
- typicalPreferences = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);\r
- typicalPreferences.addPreferenceChangeListener(typicalSynchronizationPreferenceListener);\r
- }\r
-\r
- public void dispose() {\r
- if (typicalPreferences != null) {\r
- typicalPreferences.removePreferenceChangeListener(typicalSynchronizationPreferenceListener);\r
- }\r
- if (typicalDiagramTemplateListener != null) {\r
- changeListenerSupport.removeMetadataListener(typicalDiagramTemplateListener);\r
- typicalDiagramTemplateListener = null;\r
- }\r
- }\r
-\r
- public void setTypicalSynchronization(boolean enabled) {\r
- if (enabled) {\r
- if (typicalDiagramTemplateListener == null) {\r
- typicalDiagramTemplateListener = new TypicalDiagramTemplateListener();\r
- changeListenerSupport.addMetadataListener( typicalDiagramTemplateListener );\r
- }\r
- } else {\r
- if (typicalDiagramTemplateListener != null) {\r
- changeListenerSupport.removeMetadataListener( typicalDiagramTemplateListener );\r
- typicalDiagramTemplateListener = null;\r
- }\r
- }\r
- }\r
-\r
- private boolean isSyncEnabled() {\r
- return InstanceScope.INSTANCE\r
- .getNode(TypicalPreferences.P_NODE)\r
- .getBoolean(\r
- TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED,\r
- TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);\r
- }\r
-\r
- private class TypicalSynchronizationPreferenceListener implements IPreferenceChangeListener {\r
- @Override\r
- public void preferenceChange(PreferenceChangeEvent event) {\r
- if (project == null || project.isDisposed())\r
- return;\r
-\r
- if (TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED.equals(event.getKey())) {\r
- boolean enabled = isSyncEnabled();\r
- setTypicalSynchronization(enabled);\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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);
+ }
+ }
+ }
+
+}