Package: VdmColoredViewersManager$1

VdmColoredViewersManager$1

nameinstructionbranchcomplexitylinemethod
run()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.ui.internal.viewsupport;
23:
24: import java.util.HashSet;
25: import java.util.Iterator;
26: import java.util.Set;
27:
28:
29: import org.eclipse.jface.preference.JFacePreferences;
30: import org.eclipse.jface.resource.JFaceResources;
31: import org.eclipse.jface.util.IPropertyChangeListener;
32: import org.eclipse.jface.util.PropertyChangeEvent;
33: import org.eclipse.swt.widgets.Display;
34: import org.eclipse.ui.IWorkbenchPreferenceConstants;
35: import org.eclipse.ui.PlatformUI;
36:
37: public class VdmColoredViewersManager implements IPropertyChangeListener {
38:
39:         public static final String INHERITED_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.inherited"; //$NON-NLS-1$
40:
41:         public static final String HIGHLIGHT_BG_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.match_highlight"; //$NON-NLS-1$
42:         public static final String HIGHLIGHT_WRITE_BG_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.writeaccess_highlight"; //$NON-NLS-1$
43:
44:         private static VdmColoredViewersManager fgInstance= new VdmColoredViewersManager();
45:
46:         private Set<VdmColoringLabelProvider> fManagedLabelProviders;
47:
48:         public VdmColoredViewersManager() {
49:                 fManagedLabelProviders= new HashSet<VdmColoringLabelProvider>();
50:         }
51:
52:         public void installColoredLabels(VdmColoringLabelProvider labelProvider) {
53:                 if (fManagedLabelProviders.contains(labelProvider))
54:                         return;
55:
56:                 if (fManagedLabelProviders.isEmpty()) {
57:                         // first lp installed
58:                         PlatformUI.getPreferenceStore().addPropertyChangeListener(this);
59:                         JFaceResources.getColorRegistry().addListener(this);
60:                 }
61:                 fManagedLabelProviders.add(labelProvider);
62:         }
63:
64:         public void uninstallColoredLabels(VdmColoringLabelProvider labelProvider) {
65:                 if (!fManagedLabelProviders.remove(labelProvider))
66:                         return; // not installed
67:
68:                 if (fManagedLabelProviders.isEmpty()) {
69:                         PlatformUI.getPreferenceStore().removePropertyChangeListener(this);
70:                         JFaceResources.getColorRegistry().removeListener(this);
71:                         // last viewer uninstalled
72:                 }
73:         }
74:
75:         public void propertyChange(PropertyChangeEvent event) {
76:                 String property= event.getProperty();
77:                 if (property.equals(JFacePreferences.QUALIFIER_COLOR)
78:                                 || property.equals(JFacePreferences.COUNTER_COLOR)
79:                                 || property.equals(JFacePreferences.DECORATIONS_COLOR)
80:                                 || property.equals(HIGHLIGHT_BG_COLOR_NAME)
81:                                 || property.equals(HIGHLIGHT_WRITE_BG_COLOR_NAME)
82:                                 || property.equals(INHERITED_COLOR_NAME)
83:                                 || property.equals(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)
84:                 ) {
85:                         Display.getDefault().asyncExec(new Runnable() {
86:                                 public void run() {
87:                                         updateAllViewers();
88:                                 }
89:                         });
90:                 }
91:         }
92:
93:         protected final void updateAllViewers() {
94:                 for (Iterator<VdmColoringLabelProvider> iterator= fManagedLabelProviders.iterator(); iterator.hasNext();) {
95:                         VdmColoringLabelProvider lp= (VdmColoringLabelProvider) iterator.next();
96:                         lp.update();
97:                 }
98:         }
99:
100:         public static boolean showColoredLabels() {
101:                 return PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS);
102:         }
103:
104:         public static void install(VdmColoringLabelProvider labelProvider) {
105:                 fgInstance.installColoredLabels(labelProvider);
106:         }
107:
108:         public static void uninstall(VdmColoringLabelProvider labelProvider) {
109:                 fgInstance.uninstallColoredLabels(labelProvider);
110:         }
111:
112: }