1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
13 import java.util.StringTokenizer;
15 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.util.IPropertyChangeListener;
19 import org.eclipse.jface.util.PropertyChangeEvent;
24 public class MembersOrderPreferenceCache implements IPropertyChangeListener {
26 public static final int TYPE_INDEX= 0;
27 public static final int CONSTRUCTORS_INDEX= 1;
28 public static final int METHOD_INDEX= 2;
29 public static final int FIELDS_INDEX= 3;
30 public static final int INIT_INDEX= 4;
31 public static final int STATIC_FIELDS_INDEX= 5;
32 public static final int STATIC_INIT_INDEX= 6;
33 public static final int STATIC_METHODS_INDEX= 7;
34 public static final int N_ENTRIES= STATIC_METHODS_INDEX + 1;
36 private int[] fOffsets= null;
38 public void propertyChange(PropertyChangeEvent event) {
39 if (PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER.equals(event.getProperty())) {
44 public int getIndex(int kind) {
45 if (fOffsets == null) {
46 fOffsets= getOffsets();
48 return fOffsets[kind];
51 private int[] getOffsets() {
52 int[] offsets= new int[N_ENTRIES];
53 IPreferenceStore store= PreferenceConstants.getPreferenceStore();
54 String key= PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER;
55 boolean success= fillOffsetsFromPreferenceString(store.getString(key), offsets);
57 store.setToDefault(key);
58 fillOffsetsFromPreferenceString(store.getDefaultString(key), offsets);
63 private boolean fillOffsetsFromPreferenceString(String str, int[] offsets) {
64 StringTokenizer tokenizer= new StringTokenizer(str, ","); //$NON-NLS-1$
66 while (tokenizer.hasMoreTokens()) {
67 String token= tokenizer.nextToken().trim();
68 if ("T".equals(token)) { //$NON-NLS-1$
69 offsets[TYPE_INDEX]= i++;
70 } else if ("M".equals(token)) { //$NON-NLS-1$
71 offsets[METHOD_INDEX]= i++;
72 } else if ("F".equals(token)) { //$NON-NLS-1$
73 offsets[FIELDS_INDEX]= i++;
74 } else if ("I".equals(token)) { //$NON-NLS-1$
75 offsets[INIT_INDEX]= i++;
76 } else if ("SF".equals(token)) { //$NON-NLS-1$
77 offsets[STATIC_FIELDS_INDEX]= i++;
78 } else if ("SI".equals(token)) { //$NON-NLS-1$
79 offsets[STATIC_INIT_INDEX]= i++;
80 } else if ("SM".equals(token)) { //$NON-NLS-1$
81 offsets[STATIC_METHODS_INDEX]= i++;
82 } else if ("C".equals(token)) { //$NON-NLS-1$
83 offsets[CONSTRUCTORS_INDEX]= i++;
86 return i == N_ENTRIES;