analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / colors / ColorSettingsManager.java
index a271b0bfa99e50b0b27f380f62247f898f70ba1b..eaef6568e3d648dd7f63aa021e89b4ce14f21fa8 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.tracecompass.tmf.ui.views.colors;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
 
 /**
  * Static class for managing color settings.
@@ -38,11 +39,20 @@ public class ColorSettingsManager {
     private static final String COLOR_SETTINGS_PATH_NAME =
         Activator.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString();
 
+    /*
+     * Legacy path to the XML definitions file (in Linux Tools)
+     *  TODO Remove once we feel the transition phase is over.
+     */
+    private static final IPath COLOR_SETTINGS_PATH_NAME_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1)
+                    .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$
+                    .append(COLOR_SETTINGS_FILE_NAME);
+
     // The default color setting
     private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting(
-            Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
-            Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),
-            Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
+            null,
+            null,
+            null,
             null);
 
     /**
@@ -51,7 +61,25 @@ public class ColorSettingsManager {
     public static final int PRIORITY_NONE = Integer.MAX_VALUE;
 
     // The stored color settings
-    private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
+    private static ColorSetting[] fColorSettings;
+
+    static {
+        File defaultFile = new File(COLOR_SETTINGS_PATH_NAME);
+        /*
+         * If there is no file at the expected location, check the legacy
+         * location instead.
+         */
+        if (!defaultFile.exists()) {
+            File legacyFileCore = COLOR_SETTINGS_PATH_NAME_LEGACY.toFile();
+            if (legacyFileCore.exists()) {
+                ColorSetting[] colorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME_LEGACY.toString());
+                if (colorSettings != null) {
+                    ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, colorSettings);
+                }
+            }
+        }
+        fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
+    }
 
     // The listener list
     private static List<IColorSettingsListener> fListeners = new ArrayList<>();
@@ -72,7 +100,9 @@ public class ColorSettingsManager {
      */
     public static void setColorSettings(ColorSetting[] colorSettings) {
         fColorSettings = (colorSettings != null) ? Arrays.copyOf(colorSettings, colorSettings.length) : null;
-        ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
+        if (fColorSettings != null) {
+            ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
+        }
         fireColorSettingsChanged();
     }
 
@@ -88,7 +118,8 @@ public class ColorSettingsManager {
     public static ColorSetting getColorSetting(ITmfEvent event) {
         for (int i = 0; i < fColorSettings.length; i++) {
             ColorSetting colorSetting = fColorSettings[i];
-            if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
+            ITmfFilter filter = colorSetting.getFilter();
+            if (filter != null && filter.matches(event)) {
                 return colorSetting;
             }
         }
@@ -104,7 +135,8 @@ public class ColorSettingsManager {
     public static int getColorSettingPriority(ITmfEvent event) {
         for (int i = 0; i < fColorSettings.length; i++) {
             ColorSetting colorSetting = fColorSettings[i];
-            if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
+            ITmfFilter filter = colorSetting.getFilter();
+            if (filter != null && filter.matches(event)) {
                 return i;
             }
         }
This page took 0.042877 seconds and 5 git commands to generate.