Search in sources :

Example 1 with PerformUnsavedRefactoringOperation

use of org.eclipse.wst.xsd.ui.internal.refactor.PerformUnsavedRefactoringOperation in project webtools.sourceediting by eclipse.

the class UpdateNameCommand method renameComponent.

/**
 * Performs a rename refactoring to rename the component and all the
 * references to it within the current schema.
 *
 * @param newName the new component name.
 */
private void renameComponent(String newName) {
    // this is a 'globally' defined component (e.g. global element)
    if (component.eContainer() instanceof XSDSchema) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workbenchWindow != null) {
            IWorkbenchPage page = workbenchWindow.getActivePage();
            if (page != null) {
                IEditorInput editorInput = page.getActiveEditor().getEditorInput();
                if (editorInput instanceof FileEditorInput) {
                    RefactoringComponent refactoringComponent = new XMLRefactoringComponent(component, (IDOMElement) component.getElement(), component.getName(), component.getTargetNamespace());
                    RenameComponentProcessor processor = new RenameComponentProcessor(refactoringComponent, newName, true);
                    RenameRefactoring refactoring = new RenameRefactoring(processor);
                    PerformUnsavedRefactoringOperation operation = new PerformUnsavedRefactoringOperation(refactoring);
                    operation.run(null);
                } else {
                    // We can't refactor rename external files
                    component.setName(newName);
                }
            }
        }
    } else {
        // this is a 'locally' defined component (e.g. local element)
        // no need to call refactoring since this component can't be referenced
        component.setName(newName);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) RenameComponentProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent) PerformUnsavedRefactoringOperation(org.eclipse.wst.xsd.ui.internal.refactor.PerformUnsavedRefactoringOperation) IEditorInput(org.eclipse.ui.IEditorInput) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 PerformUnsavedRefactoringOperation (org.eclipse.wst.xsd.ui.internal.refactor.PerformUnsavedRefactoringOperation)1 RefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)1 XMLRefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent)1 RenameComponentProcessor (org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor)1 XSDSchema (org.eclipse.xsd.XSDSchema)1