1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.util.LinkedList ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Combo; 21 import org.eclipse.swt.widgets.Composite; 22 23 import org.eclipse.jface.dialogs.IDialogSettings; 24 import org.eclipse.jface.wizard.IWizard; 25 26 31 public class RefactoringLocationControl extends Composite { 32 33 34 protected final Combo fCombo; 35 36 37 protected final String fKey; 38 39 40 protected final IWizard fWizard; 41 42 43 protected final int MAX_HISTORY_SIZE= 5; 44 45 55 public RefactoringLocationControl(final IWizard wizard, final Composite parent, final String key) { 56 super(parent, SWT.NONE); 57 final GridLayout gridLayout= new GridLayout(1, true); 58 gridLayout.horizontalSpacing= 0; 59 gridLayout.marginWidth= 0; 60 setLayout(gridLayout); 61 fCombo= new Combo(this, SWT.SINGLE | SWT.BORDER); 62 fCombo.setLayoutData(createGridData(GridData.FILL_BOTH, 1, 0)); 63 Assert.isNotNull(wizard); 64 Assert.isLegal(key != null && !"".equals(key)); fWizard= wizard; 66 fKey= key; 67 } 68 69 80 protected GridData createGridData(final int flag, final int hspan, final int indent) { 81 final GridData data= new GridData(flag); 82 data.horizontalIndent= indent; 83 data.horizontalSpan= hspan; 84 return data; 85 } 86 87 92 public Combo getControl() { 93 return fCombo; 94 } 95 96 101 public String getText() { 102 return fCombo.getText(); 103 } 104 105 108 public void loadHistory() { 109 final IDialogSettings settings= fWizard.getDialogSettings(); 110 if (settings != null) { 111 String [] locations= settings.getArray(fKey); 112 if (locations == null || locations.length == 0) 113 return; 114 for (int index= 0; index < locations.length; index++) 115 fCombo.add(locations[index]); 116 fCombo.select(0); 117 } 118 } 119 120 123 public void saveHistory() { 124 final IDialogSettings settings= fWizard.getDialogSettings(); 125 if (settings != null) { 126 final LinkedList locations= new LinkedList (); 127 final String [] items= fCombo.getItems(); 128 for (int index= 0; index < items.length; index++) 129 locations.add(items[index]); 130 final String text= fCombo.getText().trim(); 131 if (!"".equals(text)) { locations.remove(text); 133 locations.addFirst(text); 134 } 135 final int size= locations.size(); 136 for (int index= 0; index < size - MAX_HISTORY_SIZE; index++) 137 locations.removeLast(); 138 settings.put(fKey, (String []) locations.toArray(new String [locations.size()])); 139 } 140 } 141 142 145 public void setEnabled(final boolean enabled) { 146 super.setEnabled(enabled); 147 fCombo.setEnabled(enabled); 148 } 149 150 156 public void setText(final String text) { 157 fCombo.setText(text); 158 } 159 } | Popular Tags |