Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Additional Validation check on filename in Refactor->Rename dialog
Additional Validation check on filename in Refactor->Rename dialog [message #241601] Tue, 13 March 2007 03:12 Go to next message
Eclipse UserFriend
Originally posted by: neerajkarandikar.gmail.com

Hi all,

Can we have a additional validation check on filename provided by user while
using Rename dialog? I wan't to disallow user to change filename to a string
with characters like '<', '>'.

Thanks,
Neeraj
Re: Additional Validation check on filename in Refactor->Rename dialog [message #241655 is a reply to message #241601] Wed, 14 March 2007 01:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: neerajkarandikar.gmail.com

Is this the right forum to ask this question?

"neeraj" <neerajkarandikar@gmail.com> wrote in message
news:et5ise$5tn$1@utils.eclipse.org...
> Hi all,
>
> Can we have a additional validation check on filename provided by user
> while using Rename dialog? I wan't to disallow user to change filename to
> a string with characters like '<', '>'.
>
> Thanks,
> Neeraj
>
Re: Additional Validation check on filename in Refactor->Rename dialog [message #241843 is a reply to message #241655] Wed, 21 March 2007 07:02 Go to previous message
Eclipse UserFriend
Originally posted by: mandola.verit.de

Hi Neeraj,
>> Can we have a additional validation check on filename provided by user
>> while using Rename dialog? I wan't to disallow user to change filename to
>> a string with characters like '<', '>'.
Here is the "solution" I found for my problem, maybe it can help.
I am not sure if it is the official way, but this was the only thing
that worked for me.

1) Create a Viewer extending
org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart

2) Create your own RenameAction class extending
org.eclipse.jdt.ui.actions.RenameAction;

3) Overwrite the run(IStructuredSelection) method in your RenameAction
with your checks and where your checks are not required call
super.run(IStructuredSelection).
This might require more tweaking since you have to write your own
dialog to enter the new name. The super.run() will still open the
old dialogs depending on the view.

4) in the init(IViewSite) method of your Viewer:
public void init(IViewSite site) throws PartInitException {

super.init(site);
renameAction = new MyRenameAction(site);
}

5) in the menuAboutToShow method of your Viewer:
get rid of the "old" refactor menu and inject our Action
(REFACTOR_MENU_ID = org.eclipse.jdt.ui.refactoring.menu)

public void menuAboutToShow(IMenuManager menu) {

super.menuAboutToShow(menu);
// now remove the things we do not want
MenuManager refactorMenu = (MenuManager)
menu.find(REFACTOR_MENU_ID);
if (refactorMenu != null) {
ActionContributionItem moveElement = null;
IContributionItem[] items = refactorMenu.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof ActionContributionItem) {
ActionContributionItem item =
(ActionContributionItem) items[i];
if (IJavaEditorActionDefinitionIds.
MOVE_ELEMENT.equals(item.
getAction().
getActionDefinitionId())) {
moveElement = item;
}
}
}
refactorMenu.removeAll();
refactorMenu.add(renameAction);
if (moveElement != null) {
refactorMenu.add(moveElement.getAction());
}
}
}

6) in the createPartControl method of your Viewer:
public void createPartControl(Composite parent) {

super.createPartControl(parent);
// add rename ActionHandler to Toolbar
getViewSite().getActionBars().
setGlobalActionHandler(JdtActionConstants.RENAME,
renameAction);
getViewSite().getActionBars().
setGlobalActionHandler("rename", renameAction);
}

I hope this helps in your case and doesn't cause serious heart attacks
among the eclipse developers ;-)

It would be nice to be able to add a validator to the Refactor/Rename
dialogs, maybe by using an extension point. I played around with
Refactor participants and such, but they get into the action when it is
too late already and I cannot give any feedback to the user.

Kind regards, Klaus
Previous Topic:Can I add a listener to the java editor?
Next Topic:Removing a field from a class using an ASTVisitor
Goto Forum:
  


Current Time: Wed Sep 24 14:58:58 EDT 2025

Powered by FUDForum. Page generated in 0.03493 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top