Search in sources :

Example 1 with RenameComponentProcessor

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

the class RenameHandler method run.

public void run(ISelection selection, XSDSchema schema, XSDNamedComponent selectedComponent) {
    if (selectedComponent.getName() == null) {
        selectedComponent.setName(new String());
    }
    if (selectedComponent.getSchema() == null) {
        if (schema != null) {
            schema.updateElement(true);
        }
    }
    boolean rc = SaveDirtyFilesDialog.saveDirtyFiles();
    if (!rc) {
        return;
    }
    RefactoringComponent component = new XMLRefactoringComponent(selectedComponent, (IDOMElement) selectedComponent.getElement(), selectedComponent.getName(), selectedComponent.getTargetNamespace());
    RenameComponentProcessor processor = new RenameComponentProcessor(component, selectedComponent.getName());
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    } catch (InterruptedException e) {
    // do nothing. User action got canceled
    }
}
Also used : RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameComponentProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)

Example 2 with RenameComponentProcessor

use of org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor 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)

Example 3 with RenameComponentProcessor

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

the class RenameComponentAction method run.

public void run(ISelection selection) {
    if (selectedComponent.getName() == null) {
        selectedComponent.setName(new String());
    }
    if (selectedComponent.getSchema() == null) {
        if (getSchema() != null) {
            getSchema().updateElement(true);
        }
    }
    boolean rc = SaveDirtyFilesDialog.saveDirtyFiles();
    if (!rc) {
        return;
    }
    RefactoringComponent component = new XMLRefactoringComponent(selectedComponent, (IDOMElement) selectedComponent.getElement(), selectedComponent.getName(), selectedComponent.getTargetNamespace());
    RenameComponentProcessor processor = new RenameComponentProcessor(component, selectedComponent.getName());
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    // TODO (cs) I'm not sure why we need to do this.  See bug 145700
    // triggerBuild();
    } catch (InterruptedException e) {
    // do nothing. User action got cancelled
    }
}
Also used : RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameComponentProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)

Aggregations

RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)3 RefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)3 XMLRefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent)3 RenameComponentProcessor (org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor)3 RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)2 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)2 RenameRefactoringWizard (org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard)2 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 XSDSchema (org.eclipse.xsd.XSDSchema)1