1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.editors
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.Arrays
;
19 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
23 * This class manages the column settings associated with a trace type.
25 * @author Patrick Tasse
28 public class TmfTraceColumnManager
{
30 private static final String ROOT_SECTION_NAME
= checkNotNull(TmfTraceColumnManager
.class.getSimpleName());
31 private static final String COLUMN_ORDER_SECTION_NAME
= "column.order"; //$NON-NLS-1$
34 * Get the latest saved table column order for the specified trace type.
35 * Returns null if no column order is set.
39 * @return the table column order, or null
41 public static int[] loadColumnOrder(String traceTypeId
) {
42 if (traceTypeId
== null) {
45 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
46 IDialogSettings section
= settings
.getSection(ROOT_SECTION_NAME
);
47 if (section
== null) {
50 IDialogSettings columnOrderSection
= section
.getSection(COLUMN_ORDER_SECTION_NAME
);
51 if (columnOrderSection
== null) {
54 String string
= columnOrderSection
.get(traceTypeId
);
55 if (string
== null || string
.length() < 3) {
58 if (string
.charAt(0) != '[' || string
.charAt(string
.length() - 1) != ']') {
61 String
[] array
= string
.substring(1, string
.length() - 1).split(", "); //$NON-NLS-1$
62 int[] columnOrder
= new int[array
.length
];
64 for (int i
= 0; i
< array
.length
; i
++) {
65 columnOrder
[i
] = Integer
.valueOf(array
[i
]);
68 } catch (NumberFormatException e
) {
74 * Saves the table column order for the specified trace type. Passing a null
75 * column order clears it.
80 * the table column order
82 public static void saveColumnOrder(String traceTypeId
, int[] columnOrder
) {
83 if (traceTypeId
== null) {
86 if (columnOrder
== null) {
87 clearColumnOrder(traceTypeId
);
90 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
91 IDialogSettings section
= settings
.getSection(ROOT_SECTION_NAME
);
92 if (section
== null) {
93 section
= settings
.addNewSection(ROOT_SECTION_NAME
);
95 IDialogSettings columnOrderSection
= section
.getSection(COLUMN_ORDER_SECTION_NAME
);
96 if (columnOrderSection
== null) {
97 columnOrderSection
= section
.addNewSection(COLUMN_ORDER_SECTION_NAME
);
99 columnOrderSection
.put(traceTypeId
, Arrays
.toString(columnOrder
));
103 * Clears the table column order for the specified trace type.
108 public static void clearColumnOrder(String traceTypeId
) {
109 if (traceTypeId
== null) {
112 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
113 IDialogSettings section
= settings
.getSection(ROOT_SECTION_NAME
);
114 if (section
== null) {
117 IDialogSettings columnOrderSection
= section
.getSection(COLUMN_ORDER_SECTION_NAME
);
118 if (columnOrderSection
== null) {
121 columnOrderSection
.put(traceTypeId
, (String
) null);