1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.typicals;
14 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
15 import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
16 import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
17 import org.eclipse.core.runtime.preferences.InstanceScope;
18 import org.simantics.db.service.GraphChangeListenerSupport;
19 import org.simantics.project.IProject;
22 * @author Tuukka Lehtonen
23 * @deprecated not to be used anymore, will be removed
25 public class TypicalSupport {
27 protected IProject project;
28 protected GraphChangeListenerSupport changeListenerSupport;
30 private IEclipsePreferences typicalPreferences;
31 private TypicalDiagramTemplateListener typicalDiagramTemplateListener;
32 private IPreferenceChangeListener typicalSynchronizationPreferenceListener = new TypicalSynchronizationPreferenceListener();
34 public TypicalSupport(IProject project) {
35 this.project = project;
36 this.changeListenerSupport = project.getSession().getService(GraphChangeListenerSupport.class);
38 setTypicalSynchronization( isSyncEnabled() );
39 typicalPreferences = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
40 typicalPreferences.addPreferenceChangeListener(typicalSynchronizationPreferenceListener);
43 public void dispose() {
44 if (typicalPreferences != null) {
45 typicalPreferences.removePreferenceChangeListener(typicalSynchronizationPreferenceListener);
47 if (typicalDiagramTemplateListener != null) {
48 changeListenerSupport.removeMetadataListener(typicalDiagramTemplateListener);
49 typicalDiagramTemplateListener = null;
53 public void setTypicalSynchronization(boolean enabled) {
55 if (typicalDiagramTemplateListener == null) {
56 typicalDiagramTemplateListener = new TypicalDiagramTemplateListener();
57 changeListenerSupport.addMetadataListener( typicalDiagramTemplateListener );
60 if (typicalDiagramTemplateListener != null) {
61 changeListenerSupport.removeMetadataListener( typicalDiagramTemplateListener );
62 typicalDiagramTemplateListener = null;
67 private boolean isSyncEnabled() {
68 return InstanceScope.INSTANCE
69 .getNode(TypicalPreferences.P_NODE)
71 TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED,
72 TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
75 private class TypicalSynchronizationPreferenceListener implements IPreferenceChangeListener {
77 public void preferenceChange(PreferenceChangeEvent event) {
78 if (project == null || project.isDisposed())
81 if (TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED.equals(event.getKey())) {
82 boolean enabled = isSyncEnabled();
83 setTypicalSynchronization(enabled);