tmf: Fix Marker Set action handling
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / markers / MarkerUtils.java
1 /*******************************************************************************
2 * Copyright (c) 2017 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.tmf.ui.markers;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.jface.dialogs.IDialogSettings;
17 import org.eclipse.tracecompass.internal.tmf.core.markers.MarkerConfigXmlParser;
18 import org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet;
19 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
20
21 /**
22 * Utility class for markers
23 */
24 public class MarkerUtils {
25
26 private static final String MARKER_SET_KEY = "marker.set"; //$NON-NLS-1$
27
28 private static MarkerSet fDefaultMarkerSet = null;
29
30 /**
31 * Get the default marker set
32 *
33 * @return the default marker set, or null if none is set
34 */
35 public static synchronized @Nullable MarkerSet getDefaultMarkerSet() {
36 String id = getDialogSettings().get(MARKER_SET_KEY);
37 if (id == null) {
38 fDefaultMarkerSet = null;
39 } else {
40 if (fDefaultMarkerSet == null || !fDefaultMarkerSet.getId().equals(id)) {
41 for (MarkerSet markerSet : MarkerConfigXmlParser.getMarkerSets()) {
42 if (markerSet.getId().equals(id)) {
43 fDefaultMarkerSet = markerSet;
44 }
45 }
46 }
47 }
48 return fDefaultMarkerSet;
49 }
50
51 /**
52 * Set the default marker set
53 *
54 * @param markerSet
55 * the default marker set, or null to set none
56 */
57 public static synchronized void setDefaultMarkerSet(@Nullable MarkerSet markerSet) {
58 fDefaultMarkerSet = markerSet;
59 String id = (markerSet == null) ? null : markerSet.getId();
60 getDialogSettings().put(MARKER_SET_KEY, id);
61 }
62
63 private static IDialogSettings getDialogSettings() {
64 IDialogSettings settings = Activator.getDefault().getDialogSettings();
65 IDialogSettings dialogSettings = settings.getSection(MarkerUtils.class.getName());
66 if (dialogSettings == null) {
67 dialogSettings = settings.addNewSection(MarkerUtils.class.getName());
68 }
69 return dialogSettings;
70 }
71 }
This page took 0.032265 seconds and 5 git commands to generate.