Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bd00b4aecba352074a25f6acdd4e9326c06950f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.processes.ui.internal.preferences;

import java.util.StringTokenizer;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.tcf.te.tcf.processes.ui.activator.UIPlugin;


/**
 * The bundle's preference initializer implementation.
 */
public class PreferencesInitializer extends AbstractPreferenceInitializer implements IPreferenceConsts {

	/**
	 * Constructor.
	 */
	public PreferencesInitializer() {
		super();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
	@Override
	public void initializeDefaultPreferences() {
		IPreferenceStore preferenceStore = UIPlugin.getDefault().getPreferenceStore();
		preferenceStore.setDefault(PREF_INTERVAL_GRADES, DEFAULT_INTERVAL_GRADES);
		preferenceStore.setDefault(PREF_INTERVAL_MRU_COUNT, DEFAULT_INTERVAL_MRU_COUNT);
	}

	/**
	 * Update the most recently  used interval adding
	 * a new interval.
	 *
	 * @param interval The new interval.
	 */
	public static void addMRUInterval(int interval){
        IPreferenceStore prefStore = UIPlugin.getDefault().getPreferenceStore();
        String mruList = prefStore.getString(PREF_INTERVAL_MRU_LIST);
        if (mruList == null || mruList.trim().length() == 0) {
        	mruList = "" + interval; //$NON-NLS-1$
        }else{
        	StringTokenizer st = new StringTokenizer(mruList, ":"); //$NON-NLS-1$
        	int maxCount = prefStore.getInt(PREF_INTERVAL_MRU_COUNT);
        	boolean found = false;
        	while (st.hasMoreTokens()) {
        		String token = st.nextToken();
        		try {
        			int s = Integer.parseInt(token);
        			if(s == interval ) {
        				found = true;
        				break;
        			}
        		}
        		catch (NumberFormatException nfe) {
        		}
        	}
        	if(!found) {
        		mruList = mruList + ":" + interval; //$NON-NLS-1$
        		st = new StringTokenizer(mruList, ":"); //$NON-NLS-1$
        		if(st.countTokens() > maxCount) {
        			int comma = mruList.indexOf(":"); //$NON-NLS-1$
        			if(comma != -1) {
        				mruList = mruList.substring(comma+1);
        			}
        		}
        	}
        }
        prefStore.setValue(PREF_INTERVAL_MRU_LIST, mruList);
    }
}

Back to the top