|
Lines 19-43
Link Here
|
| 19 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
| 20 |
import org.eclipse.core.runtime.IProgressMonitor; |
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 21 |
import org.eclipse.core.runtime.SubProgressMonitor; |
21 |
import org.eclipse.core.runtime.SubProgressMonitor; |
|
|
22 |
import org.eclipse.hyades.test.ui.UiPlugin; |
| 22 |
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages; |
23 |
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages; |
|
|
24 |
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.RenameRefactoring; |
| 23 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
25 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
|
|
26 |
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode; |
| 24 |
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer; |
27 |
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer; |
|
|
28 |
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer2; |
| 25 |
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus; |
29 |
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus; |
| 26 |
import org.eclipse.hyades.ui.internal.navigator.TreeNavigator; |
30 |
import org.eclipse.hyades.ui.internal.navigator.TreeNavigator; |
| 27 |
import org.eclipse.hyades.ui.util.IDisposable; |
31 |
import org.eclipse.hyades.ui.util.IDisposable; |
| 28 |
import org.eclipse.jface.action.Action; |
32 |
import org.eclipse.jface.action.Action; |
|
|
33 |
import org.eclipse.jface.dialogs.Dialog; |
| 29 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
34 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| 30 |
import org.eclipse.jface.viewers.IStructuredSelection; |
35 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 31 |
import org.eclipse.jface.viewers.StructuredSelection; |
36 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
|
37 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizard; |
| 38 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; |
| 39 |
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; |
| 32 |
import org.eclipse.swt.SWT; |
40 |
import org.eclipse.swt.SWT; |
| 33 |
import org.eclipse.swt.custom.TreeEditor; |
41 |
import org.eclipse.swt.custom.TreeEditor; |
| 34 |
import org.eclipse.swt.events.FocusAdapter; |
42 |
import org.eclipse.swt.events.FocusAdapter; |
| 35 |
import org.eclipse.swt.events.FocusEvent; |
43 |
import org.eclipse.swt.events.FocusEvent; |
|
|
44 |
import org.eclipse.swt.events.ModifyEvent; |
| 45 |
import org.eclipse.swt.events.ModifyListener; |
| 36 |
import org.eclipse.swt.graphics.Point; |
46 |
import org.eclipse.swt.graphics.Point; |
|
|
47 |
import org.eclipse.swt.layout.GridData; |
| 48 |
import org.eclipse.swt.layout.GridLayout; |
| 37 |
import org.eclipse.swt.widgets.Composite; |
49 |
import org.eclipse.swt.widgets.Composite; |
| 38 |
import org.eclipse.swt.widgets.Display; |
50 |
import org.eclipse.swt.widgets.Display; |
| 39 |
import org.eclipse.swt.widgets.Event; |
51 |
import org.eclipse.swt.widgets.Event; |
|
|
52 |
import org.eclipse.swt.widgets.Label; |
| 40 |
import org.eclipse.swt.widgets.Listener; |
53 |
import org.eclipse.swt.widgets.Listener; |
|
|
54 |
import org.eclipse.swt.widgets.Shell; |
| 41 |
import org.eclipse.swt.widgets.Text; |
55 |
import org.eclipse.swt.widgets.Text; |
| 42 |
import org.eclipse.swt.widgets.Tree; |
56 |
import org.eclipse.swt.widgets.Tree; |
| 43 |
import org.eclipse.swt.widgets.TreeItem; |
57 |
import org.eclipse.swt.widgets.TreeItem; |
|
Lines 60-65
Link Here
|
| 60 |
protected TreeNavigator navigator; |
74 |
protected TreeNavigator navigator; |
| 61 |
protected IContainer renamedResource; |
75 |
protected IContainer renamedResource; |
| 62 |
|
76 |
|
|
|
77 |
private class RenameRefactoringWizard extends RefactoringWizard { |
| 78 |
private RenameRefactoringNewNameInputPage page; |
| 79 |
|
| 80 |
private RenameRefactoringWizard(RenameRefactoring refactoring, String name) { |
| 81 |
super(refactoring, DIALOG_BASED_USER_INTERFACE/* | NONE*/); |
| 82 |
this.page = new RenameRefactoringNewNameInputPage(refactoring, name); |
| 83 |
} |
| 84 |
|
| 85 |
protected void addUserInputPages() { |
| 86 |
addPage(page); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
class RenameRefactoringNewNameInputPage extends UserInputWizardPage { |
| 91 |
private RenameRefactoring refactoring; |
| 92 |
private Text nameText; |
| 93 |
private String oldName; |
| 94 |
private String newName; |
| 95 |
|
| 96 |
public RenameRefactoringNewNameInputPage(RenameRefactoring refactoring, String oldName) { |
| 97 |
super(""); //$NON-NLS-1$ |
| 98 |
this.oldName = oldName; |
| 99 |
this.refactoring = refactoring; |
| 100 |
} |
| 101 |
|
| 102 |
public void createControl(Composite parent) { |
| 103 |
Composite result= new Composite(parent, SWT.NONE); |
| 104 |
setControl(result); |
| 105 |
result.setLayout(new GridLayout(2, false)); |
| 106 |
|
| 107 |
Label label= new Label(result, SWT.NONE); |
| 108 |
label.setText(ActionMessages.RENAME_NEW_NAME_LABEL); |
| 109 |
nameText = new Text(result, SWT.SINGLE | SWT.BORDER); |
| 110 |
nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 111 |
nameText.setText(oldName); |
| 112 |
nameText.addModifyListener(new ModifyListener() { |
| 113 |
public void modifyText(ModifyEvent e) { |
| 114 |
newName = nameText.getText(); |
| 115 |
refactoring.setNewName(newName); |
| 116 |
setPageComplete(isPageComplete()); |
| 117 |
} |
| 118 |
}); |
| 119 |
nameText.selectAll(); |
| 120 |
Dialog.applyDialogFont(result); |
| 121 |
} |
| 122 |
|
| 123 |
public boolean isPageComplete() { |
| 124 |
return newName != null && newName.length() > 0 && !newName.equals(oldName); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 63 |
public RenameAction(TreeNavigator treeNav) { |
128 |
public RenameAction(TreeNavigator treeNav) { |
| 64 |
super(TestNavigatorMessages.RenameAction_ActionName); |
129 |
super(TestNavigatorMessages.RenameAction_ActionName); |
| 65 |
this.navigator = treeNav; |
130 |
this.navigator = treeNav; |
|
Lines 82-97
Link Here
|
| 82 |
return true; |
147 |
return true; |
| 83 |
} else if (objSelected instanceof IProxyNode) { |
148 |
} else if (objSelected instanceof IProxyNode) { |
| 84 |
IProxyNode proxy = (IProxyNode) objSelected; |
149 |
IProxyNode proxy = (IProxyNode) objSelected; |
| 85 |
IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class); |
150 |
IProxyNodeRenamer2 renamer2 = (IProxyNodeRenamer2)proxy.getAdapter(IProxyNodeRenamer2.class); |
| 86 |
if (renamer != null) { |
151 |
if(renamer2 != null) { |
| 87 |
return renamer.isApplicableFor(); |
152 |
return true; |
| 88 |
} else { |
|
|
| 89 |
//- this means that there is no renamer for this proxy |
| 90 |
return false; |
| 91 |
} |
153 |
} |
| 92 |
} else { |
154 |
oldActionValidation(proxy); |
| 93 |
return false; |
|
|
| 94 |
} |
155 |
} |
|
|
156 |
return false; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* @param proxy |
| 161 |
* @return |
| 162 |
* @deprecated |
| 163 |
*/ |
| 164 |
private boolean oldActionValidation(IProxyNode proxy) { |
| 165 |
IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class); |
| 166 |
if (renamer != null) { |
| 167 |
return renamer.isApplicableFor(); |
| 168 |
} |
| 169 |
return false; |
| 95 |
} |
170 |
} |
| 96 |
|
171 |
|
| 97 |
/** |
172 |
/** |
|
Lines 111-117
Link Here
|
| 111 |
* Create the text editor widget. |
186 |
* Create the text editor widget. |
| 112 |
* This code has been imported from RenameResourceAction |
187 |
* This code has been imported from RenameResourceAction |
| 113 |
* @param renamer |
188 |
* @param renamer |
| 114 |
* |
189 |
* @deprecated |
| 115 |
*/ |
190 |
*/ |
| 116 |
private void createTextEditor(final IProxyNodeRenamer renamer) { |
191 |
private void createTextEditor(final IProxyNodeRenamer renamer) { |
| 117 |
//- Create text editor parent. This draws a nice bounding rect. |
192 |
//- Create text editor parent. This draws a nice bounding rect. |
|
Lines 165-170
Link Here
|
| 165 |
textActionHandler.addText(textEditor); |
240 |
textActionHandler.addText(textEditor); |
| 166 |
} |
241 |
} |
| 167 |
|
242 |
|
|
|
243 |
/** |
| 244 |
* |
| 245 |
* @param renamer |
| 246 |
* @param newName |
| 247 |
* @deprecated |
| 248 |
*/ |
| 168 |
protected void performRename(final IProxyNodeRenamer renamer, final String newName) { |
249 |
protected void performRename(final IProxyNodeRenamer renamer, final String newName) { |
| 169 |
Runnable query = new Runnable() { |
250 |
Runnable query = new Runnable() { |
| 170 |
public void run() { |
251 |
public void run() { |
|
Lines 242-247
Link Here
|
| 242 |
* This code is inspired from RenameResourceAction |
323 |
* This code is inspired from RenameResourceAction |
| 243 |
* @param oldName current value of the selected item |
324 |
* @param oldName current value of the selected item |
| 244 |
* @param renamer |
325 |
* @param renamer |
|
|
326 |
* @deprecated |
| 245 |
*/ |
327 |
*/ |
| 246 |
private void getNewNameInline(String oldName, IProxyNodeRenamer renamer) { |
328 |
private void getNewNameInline(String oldName, IProxyNodeRenamer renamer) { |
| 247 |
//- Make sure text editor is created only once. |
329 |
//- Make sure text editor is created only once. |
|
Lines 265-292
Link Here
|
| 265 |
Object objSelected = selection.getFirstElement(); |
347 |
Object objSelected = selection.getFirstElement(); |
| 266 |
if (objSelected instanceof IContainer) { |
348 |
if (objSelected instanceof IContainer) { |
| 267 |
renamedResource = (IContainer)objSelected; |
349 |
renamedResource = (IContainer)objSelected; |
| 268 |
//- reuse the inline editor to rename a project or folder node |
350 |
preformContainerRefactoringRename(renamedResource); |
| 269 |
getNewNameInline(((IContainer)objSelected).getName(), null); |
|
|
| 270 |
} else if (objSelected instanceof IProxyNode) { |
351 |
} else if (objSelected instanceof IProxyNode) { |
| 271 |
IProxyNode proxy = (IProxyNode) objSelected; |
352 |
IProxyNode proxy = (IProxyNode) objSelected; |
| 272 |
IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class); |
353 |
IProxyNodeRenamer2 renamer2 = (IProxyNodeRenamer2)proxy.getAdapter(IProxyNodeRenamer2.class); |
| 273 |
if (renamer != null) { |
354 |
if(renamer2 != null) { |
| 274 |
RenamerUIStatus status = renamer.performUserInteraction(proxy.getText()); |
355 |
performProxyRefactoringRename(proxy); |
| 275 |
switch (status.getStatus()) { |
356 |
} else { |
| 276 |
case RenamerUIStatus.OK : |
357 |
IReferencerProxyNode ref = (IReferencerProxyNode)proxy.getAdapter(IReferencerProxyNode.class); |
| 277 |
performRename(renamer, status.getNewName()); |
358 |
if(ref != null) { |
| 278 |
break; |
359 |
performProxyRefactoringRename(proxy); |
| 279 |
case RenamerUIStatus.CANCEL : |
360 |
} else { |
| 280 |
//- nothing to do |
361 |
performOldRename(proxy); |
| 281 |
break; |
|
|
| 282 |
case RenamerUIStatus.INLINE_EDITOR : |
| 283 |
getNewNameInline(proxy.getText(), renamer); |
| 284 |
break; |
| 285 |
} |
362 |
} |
| 286 |
} |
363 |
} |
| 287 |
} |
364 |
} |
| 288 |
} |
365 |
} |
| 289 |
|
366 |
|
|
|
367 |
/** |
| 368 |
* @param proxy |
| 369 |
* @deprecated |
| 370 |
*/ |
| 371 |
private void performOldRename(IProxyNode proxy) { |
| 372 |
//- this code will be removed in 5.0 |
| 373 |
IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class); |
| 374 |
if (renamer != null) { |
| 375 |
RenamerUIStatus status = renamer.performUserInteraction(proxy.getText()); |
| 376 |
switch (status.getStatus()) { |
| 377 |
case RenamerUIStatus.OK : |
| 378 |
performRename(renamer, status.getNewName()); |
| 379 |
break; |
| 380 |
case RenamerUIStatus.CANCEL : |
| 381 |
//- nothing to do |
| 382 |
break; |
| 383 |
case RenamerUIStatus.INLINE_EDITOR : |
| 384 |
getNewNameInline(proxy.getText(), renamer); |
| 385 |
break; |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
private void preformContainerRefactoringRename(IContainer container) { |
| 391 |
RenameRefactoring refactoring = new RenameRefactoring(container); |
| 392 |
performRefactoringRename(refactoring, container.getName()); |
| 393 |
} |
| 394 |
|
| 395 |
private void performProxyRefactoringRename(IProxyNode proxy) { |
| 396 |
RenameRefactoring refactoring = new RenameRefactoring(proxy); |
| 397 |
performRefactoringRename(refactoring, proxy.getText()); |
| 398 |
} |
| 399 |
|
| 400 |
private void performRefactoringRename(final RenameRefactoring refactoring, final String oldName) { |
| 401 |
Shell shell = Display.getCurrent().getActiveShell(); |
| 402 |
if (! canActivate(shell)) |
| 403 |
return; |
| 404 |
RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, oldName); |
| 405 |
wizard.setDefaultPageTitle(ActionMessages.RENAME_ACTION_NAME); |
| 406 |
wizard.setNeedsProgressMonitor(true); |
| 407 |
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard); |
| 408 |
try { |
| 409 |
op.run(shell , ""); //$NON-NLS-1$ |
| 410 |
} catch (InterruptedException e) { |
| 411 |
UiPlugin.logError(e); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
private boolean canActivate(Shell shell) { |
| 416 |
return EditorUtil.saveEditors(shell); |
| 417 |
} |
| 418 |
|
| 290 |
public void selectionChanged(IStructuredSelection structuredSelection) { |
419 |
public void selectionChanged(IStructuredSelection structuredSelection) { |
| 291 |
selection = structuredSelection; |
420 |
selection = structuredSelection; |
| 292 |
} |
421 |
} |