1 11 package org.eclipse.pde.internal.ui.wizards; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.dialogs.IInputValidator; 19 import org.eclipse.pde.internal.ui.PDEPlugin; 20 import org.eclipse.pde.internal.ui.PDEUIMessages; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.events.ModifyEvent; 23 import org.eclipse.swt.events.ModifyListener; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.Button; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Label; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.swt.widgets.Text; 32 import org.eclipse.ui.dialogs.SelectionStatusDialog; 33 34 public class RenameDialog extends SelectionStatusDialog { 35 private ArrayList oldNames; 36 private String oldName; 37 private String newName; 38 private Text text; 39 private IStatus status; 40 private boolean isCaseSensitive; 41 private IInputValidator fValidator; 42 43 48 public RenameDialog(Shell shell, String oldName) { 49 super(shell); 50 this.isCaseSensitive = false; 51 initialize(); 52 setOldName(oldName); 53 } 54 55 62 public RenameDialog(Shell shell, boolean isCaseSensitive, String [] names, String oldName){ 63 super(shell); 64 this.isCaseSensitive = isCaseSensitive; 65 initialize(); 66 if (names!=null){ 67 for (int i = 0; i<names.length; i++) 68 addOldName(names[i]); 69 } 70 setOldName(oldName); 71 } 72 73 public void initialize(){ 74 oldNames = new ArrayList (); 75 setStatusLineAboveButtons(true); 76 } 77 public void addOldName(String oldName){ 78 if (!oldNames.contains(oldName)) 79 oldNames.add(oldName); 80 81 } 82 public void setOldName(String oldName) { 83 this.oldName = oldName; 84 addOldName(oldName); 85 if (text!=null) 86 text.setText(oldName); 87 this.newName = oldName; 88 } 89 90 protected Control createDialogArea(Composite parent) { 91 Composite container = new Composite(parent, SWT.NULL); 92 GridLayout layout = new GridLayout(); 93 layout.numColumns = 2; 94 layout.marginHeight = layout.marginWidth = 9; 95 container.setLayout(layout); 96 97 GridData gd = new GridData(GridData.FILL_BOTH); 98 container.setLayoutData(gd); 99 100 Label label = new Label(container, SWT.NULL); 101 label.setText(PDEUIMessages.RenameDialog_label); 102 103 text = new Text(container, SWT.SINGLE|SWT.BORDER); 104 text.addModifyListener(new ModifyListener() { 105 public void modifyText(ModifyEvent e) { 106 textChanged(text.getText()); 107 } 108 }); 109 gd = new GridData(GridData.FILL_HORIZONTAL); 110 text.setLayoutData(gd); 111 applyDialogFont(container); 112 return container; 113 } 114 115 public int open() { 116 text.setText(oldName); 117 text.selectAll(); 118 Button okButton = getButton(IDialogConstants.OK_ID); 119 120 status = new Status( 121 IStatus.OK, 122 PDEPlugin.getPluginId(), 123 IStatus.OK, 124 "", null); 126 updateStatus(status); 127 okButton.setEnabled(false); 128 return super.open(); 129 } 130 131 private void textChanged(String text) { 132 Button okButton = getButton(IDialogConstants.OK_ID); 133 if (fValidator != null) { 134 String message = fValidator.isValid(text); 135 if (message != null) { 136 status = new Status( 137 IStatus.ERROR, PDEPlugin.getPluginId(), 138 IStatus.ERROR, message, null); 139 updateStatus(status); 140 okButton.setEnabled(false); 141 return; 142 } 143 } 144 for (int i=0; i<oldNames.size(); i++){ 145 if((isCaseSensitive && text.equals(oldNames.get(i))) || 146 (!isCaseSensitive && text.equalsIgnoreCase(oldNames.get(i).toString()))){ 147 status = new Status( 148 IStatus.ERROR, 149 PDEPlugin.getPluginId(), 150 IStatus.ERROR, 151 PDEUIMessages.RenameDialog_validationError, 152 null); 153 updateStatus(status); 154 okButton.setEnabled(false); 155 break; 156 } 157 okButton.setEnabled(true); 158 status = new Status( 159 IStatus.OK, 160 PDEPlugin.getPluginId(), 161 IStatus.OK, 162 "", null); 164 updateStatus(status); 165 } 166 } 167 168 public String getNewName() { 169 return newName; 170 } 171 172 175 protected void okPressed() { 176 newName = text.getText().trim(); 177 super.okPressed(); 178 } 179 180 183 protected void computeResult() { 184 } 185 186 public void setTitle(String title) { 187 getShell().setText(title); 188 } 189 190 public void setInputValidator(IInputValidator validator) { 191 fValidator = validator; 192 } 193 } 194 | Popular Tags |