1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.typicals;
\r
14 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
\r
15 import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
\r
16 import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
\r
17 import org.eclipse.core.runtime.preferences.InstanceScope;
\r
18 import org.simantics.db.service.GraphChangeListenerSupport;
\r
19 import org.simantics.project.IProject;
\r
22 * @author Tuukka Lehtonen
\r
23 * @deprecated not to be used anymore, will be removed
\r
25 public class TypicalSupport {
\r
27 protected IProject project;
\r
28 protected GraphChangeListenerSupport changeListenerSupport;
\r
30 private IEclipsePreferences typicalPreferences;
\r
31 private TypicalDiagramTemplateListener typicalDiagramTemplateListener;
\r
32 private IPreferenceChangeListener typicalSynchronizationPreferenceListener = new TypicalSynchronizationPreferenceListener();
\r
34 public TypicalSupport(IProject project) {
\r
35 this.project = project;
\r
36 this.changeListenerSupport = project.getSession().getService(GraphChangeListenerSupport.class);
\r
38 setTypicalSynchronization( isSyncEnabled() );
\r
39 typicalPreferences = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
\r
40 typicalPreferences.addPreferenceChangeListener(typicalSynchronizationPreferenceListener);
\r
43 public void dispose() {
\r
44 if (typicalPreferences != null) {
\r
45 typicalPreferences.removePreferenceChangeListener(typicalSynchronizationPreferenceListener);
\r
47 if (typicalDiagramTemplateListener != null) {
\r
48 changeListenerSupport.removeMetadataListener(typicalDiagramTemplateListener);
\r
49 typicalDiagramTemplateListener = null;
\r
53 public void setTypicalSynchronization(boolean enabled) {
\r
55 if (typicalDiagramTemplateListener == null) {
\r
56 typicalDiagramTemplateListener = new TypicalDiagramTemplateListener();
\r
57 changeListenerSupport.addMetadataListener( typicalDiagramTemplateListener );
\r
60 if (typicalDiagramTemplateListener != null) {
\r
61 changeListenerSupport.removeMetadataListener( typicalDiagramTemplateListener );
\r
62 typicalDiagramTemplateListener = null;
\r
67 private boolean isSyncEnabled() {
\r
68 return InstanceScope.INSTANCE
\r
69 .getNode(TypicalPreferences.P_NODE)
\r
71 TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED,
\r
72 TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
\r
75 private class TypicalSynchronizationPreferenceListener implements IPreferenceChangeListener {
\r
77 public void preferenceChange(PreferenceChangeEvent event) {
\r
78 if (project == null || project.isDisposed())
\r
81 if (TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED.equals(event.getKey())) {
\r
82 boolean enabled = isSyncEnabled();
\r
83 setTypicalSynchronization(enabled);
\r