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