1 11 package org.eclipse.jdt.internal.ui.jarimport; 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 33 public class RefactoringLocationControl extends Composite { 34 35 36 protected final Combo fCombo; 37 38 39 protected final String fKey; 40 41 42 protected final IWizard fWizard; 43 44 45 protected final int MAX_HISTORY_SIZE= 5; 46 47 57 public RefactoringLocationControl(final IWizard wizard, final Composite parent, final String key) { 58 super(parent, SWT.NONE); 59 final GridLayout gridLayout= new GridLayout(1, true); 60 gridLayout.horizontalSpacing= 0; 61 gridLayout.marginWidth= 0; 62 setLayout(gridLayout); 63 fCombo= new Combo(this, SWT.SINGLE | SWT.BORDER); 64 fCombo.setLayoutData(createGridData(GridData.FILL_BOTH, 1, 0)); 65 Assert.isNotNull(wizard); 66 Assert.isTrue(key != null && !"".equals(key)); fWizard= wizard; 68 fKey= key; 69 } 70 71 82 protected GridData createGridData(final int flag, final int hspan, final int indent) { 83 final GridData data= new GridData(flag); 84 data.horizontalIndent= indent; 85 data.horizontalSpan= hspan; 86 return data; 87 } 88 89 94 public Combo getControl() { 95 return fCombo; 96 } 97 98 103 public String getText() { 104 return fCombo.getText(); 105 } 106 107 110 public void loadHistory() { 111 final IDialogSettings settings= fWizard.getDialogSettings(); 112 if (settings != null) { 113 String [] locations= settings.getArray(fKey); 114 if (locations == null || locations.length == 0) 115 return; 116 for (int index= 0; index < locations.length; index++) 117 fCombo.add(locations[index]); 118 fCombo.select(0); 119 } 120 } 121 122 125 public void saveHistory() { 126 final IDialogSettings settings= fWizard.getDialogSettings(); 127 if (settings != null) { 128 final LinkedList locations= new LinkedList (); 129 final String [] items= fCombo.getItems(); 130 for (int index= 0; index < items.length; index++) 131 locations.add(items[index]); 132 final String text= fCombo.getText().trim(); 133 if (!"".equals(text)) { locations.remove(text); 135 locations.addFirst(text); 136 } 137 final int size= locations.size(); 138 for (int index= 0; index < size - MAX_HISTORY_SIZE; index++) 139 locations.removeLast(); 140 settings.put(fKey, (String []) locations.toArray(new String [locations.size()])); 141 } 142 } 143 144 147 public void setEnabled(final boolean enabled) { 148 super.setEnabled(enabled); 149 fCombo.setEnabled(enabled); 150 } 151 152 158 public void setText(final String text) { 159 fCombo.setText(text); 160 } 161 } | Popular Tags |