1 8 package com.mountainminds.eclemma.internal.ui.wizards; 9 10 import java.util.ArrayList ; 11 import java.util.Arrays ; 12 import java.util.List ; 13 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.swt.widgets.Combo; 16 17 24 public class ComboHistory { 25 26 29 public static final int HISTORY_LIMIT = 10; 30 31 41 public static void restore(IDialogSettings settings, String key, Combo combo) { 42 String [] destinations = settings.getArray(key); 43 if (destinations != null) { 44 combo.setItems(destinations); 45 if (destinations.length > 0) { 46 combo.setText(destinations[0]); 47 } 48 } 49 } 50 51 63 public static void save(IDialogSettings settings, String key, Combo combo) { 64 List history = new ArrayList (Arrays.asList(combo.getItems())); 65 history.remove(combo.getText()); 66 history.add(0, combo.getText()); 67 if (history.size() > HISTORY_LIMIT) { 68 history = history.subList(0, HISTORY_LIMIT); 69 } 70 settings.put(key, (String []) history.toArray(new String [0])); 71 } 72 73 } 74 | Popular Tags |