source: default/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/refactoring/rename/RenameRefactoringHandler.java @ 17

Last change on this file since 17 was 17, checked in by zeiss, 14 years ago

sdfsd

  • Property svn:mime-type set to text/plain
File size: 2.7 KB
Line 
1package de.ugoe.cs.swe.bnftools.ui.refactoring.rename;
2
3import org.eclipse.core.commands.AbstractHandler;
4import org.eclipse.core.commands.ExecutionEvent;
5import org.eclipse.core.commands.ExecutionException;
6import org.eclipse.jface.dialogs.MessageDialog;
7import org.eclipse.jface.text.ITextSelection;
8import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
9import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
10import org.eclipse.swt.widgets.Display;
11import org.eclipse.ui.handlers.HandlerUtil;
12import org.eclipse.xtext.parsetree.CompositeNode;
13import org.eclipse.xtext.resource.IEObjectDescription;
14import org.eclipse.xtext.resource.IResourceDescriptions;
15import org.eclipse.xtext.ui.editor.XtextEditor;
16
17import com.google.inject.Inject;
18
19import de.ugoe.cs.swe.bnftools.ebnf.Rule;
20import de.ugoe.cs.swe.bnftools.utils.EObjectSelectionResolver;
21import de.ugoe.cs.swe.bnftools.utils.URIFragmentResolver;
22
23public class RenameRefactoringHandler extends AbstractHandler {
24
25        @Inject
26        private IResourceDescriptions resourceDescriptions;
27
28        // --------------------------------------------------------------------------------
29
30        public Object execute(ExecutionEvent event) throws ExecutionException {
31                try {
32                        String currentName = "";
33
34                        XtextEditor editor = (XtextEditor) HandlerUtil
35                                        .getActiveEditor(event);
36
37                        final ITextSelection selection = (ITextSelection) editor
38                                        .getSelectionProvider().getSelection();
39
40                        final IEObjectDescription eObjectDescription = editor
41                                        .getDocument()
42                                        .readOnly(
43                                                        new EObjectSelectionResolver(selection, resourceDescriptions));
44
45                        CompositeNode o = editor.getDocument().readOnly(
46                                        new URIFragmentResolver(eObjectDescription.getEObjectURI()
47                                                        .fragment()));
48
49                        if (o.getElement() instanceof Rule) {
50                                Rule r = (Rule) o.getElement();
51                                currentName = r.getName();
52                        }
53                       
54                        RenameProcessor processor = new RenameProcessor(editor,
55                                        resourceDescriptions);
56                        RenameRefactoring refactoring = new RenameRefactoring(processor);
57
58                        RenameRefactoringWizard wizard = new RenameRefactoringWizard(
59                                        refactoring, RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
60                        wizard.setRenameText(currentName);
61
62                        RefactoringWizardOpenOperation openOperation = new RefactoringWizardOpenOperation(
63                                        wizard);
64
65                        openOperation.run(Display.getCurrent().getActiveShell(),
66                                        "Refactoring not possible!");
67
68                } catch (Exception e) {
69                        MessageDialog.openInformation(
70                                        Display.getDefault().getActiveShell(),
71                                        "Rename Refactoring",
72                                        "Error while applying refactoring to workbench/wizard: "
73                                                        + e.getMessage());
74                        //e.printStackTrace();
75                }
76                return null;
77        }
78
79}
Note: See TracBrowser for help on using the repository browser.