diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-refactor')
51 files changed, 0 insertions, 5718 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/Checks.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/Checks.java deleted file mode 100644 index 243aa72790..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/Checks.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.wst.xml.core.internal.provisional.NameValidator; - -public class Checks { - - public static RefactoringStatus checkName(String name) { - RefactoringStatus result= new RefactoringStatus(); - if ("".equals(name)) //$NON-NLS-1$ - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("Checks_Choose_name")); //$NON-NLS-1$ - return result; - } - - public static boolean isAlreadyNamed(RefactoringComponent element, String name){ - return name.equals(element.getName()); - } - - public static RefactoringStatus checkComponentName(String name) { - RefactoringStatus result= new RefactoringStatus(); - if (!NameValidator.isValid(name)) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("Checks_Choose_name")); //$NON-NLS-1$ - - return result; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/INameUpdating.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/INameUpdating.java deleted file mode 100644 index af89666c4e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/INameUpdating.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -/** - * @author ebelisar - */ -public interface INameUpdating { - - public abstract void setNewElementName(String newName); - public abstract String getNewElementName(); - public abstract String getCurrentElementName(); - public abstract RefactoringStatus checkNewElementName(String newName); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IReferenceUpdating.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IReferenceUpdating.java deleted file mode 100644 index 1ff48fe733..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IReferenceUpdating.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -public interface IReferenceUpdating { - - /** - * Checks if this refactoring object is capable of updating references to the renamed element. - */ - public boolean canEnableUpdateReferences(); - - /** - * If <code>canUpdateReferences</code> returns <code>true</code>, then this method is used to - * inform the refactoring object whether references should be updated. - * This call can be ignored if <code>canUpdateReferences</code> returns <code>false</code>. - */ - public void setUpdateReferences(boolean update); - - /** - * If <code>canUpdateReferences</code> returns <code>true</code>, then this method is used to - * ask the refactoring object whether references should be updated. - * This call can be ignored if <code>canUpdateReferences</code> returns <code>false</code>. - */ - public boolean getUpdateReferences(); - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java deleted file mode 100644 index 79dfec10a0..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -public interface IXSDRefactorConstants { - String REFACTOR_CONTEXT_MENU_ID = "org.eclipse.wst.xsd.ui.refactorMenuId"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java deleted file mode 100644 index a257bb7162..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - - -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - - -public class MakeAnonymousTypsGlobalEnablementTester extends RefactorEnablementTester -{ - - protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) - { - if (selectedObject == null) - { - return false; - } - - XSDSchema selectedComponentSchema = null; - boolean enable = false; - selectedComponentSchema = selectedObject.getSchema(); - - if (selectedComponentSchema != null && selectedComponentSchema == schema) - { - enable = true; - } - - if (enable && selectedObject instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition)selectedObject; - XSDConcreteComponent parent = typeDef.getContainer(); - if (parent instanceof XSDElementDeclaration) - { - return true; - } - } - else if (enable && selectedObject instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition)selectedObject; - XSDConcreteComponent parent = typeDef.getContainer(); - if (parent instanceof XSDElementDeclaration) - { - return true; - } - else if (parent instanceof XSDAttributeDeclaration) - { - return true; - } - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java deleted file mode 100644 index e4f4696d53..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - - -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; - - -public class MakeLocalElementGlobalEnablementTester extends RefactorEnablementTester -{ - protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) - { - if (selectedObject == null) - { - return false; - } - - boolean enable = false; - XSDSchema selectedComponentSchema = null; - selectedComponentSchema = selectedObject.getSchema(); - if (selectedComponentSchema != null && selectedComponentSchema == schema) - { - enable = true; - } - - if (enable && selectedObject instanceof XSDElementDeclaration) - { - XSDElementDeclaration element = (XSDElementDeclaration)selectedObject; - if (!element.isElementDeclarationReference() && !element.isGlobal()) - { - return true; - } - } - - return false; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/PerformUnsavedRefactoringOperation.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/PerformUnsavedRefactoringOperation.java deleted file mode 100644 index 10739ece9b..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/PerformUnsavedRefactoringOperation.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.TextFileChange; -import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; - -public class PerformUnsavedRefactoringOperation implements IWorkspaceRunnable -{ - private ProcessorBasedRefactoring refactoring; - - public PerformUnsavedRefactoringOperation(ProcessorBasedRefactoring refactoring) - { - this.refactoring = refactoring; - } - - public void run(IProgressMonitor pm) - { - if (pm == null) - { - pm = new NullProgressMonitor(); - } - try - { - refactoring.checkAllConditions(pm); - Change change = refactoring.createChange(pm); - if (change instanceof CompositeChange) - { - CompositeChange compositeChange = (CompositeChange)change; - setSaveMode(compositeChange); - } - change.perform(pm); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - private void setSaveMode(CompositeChange composite) - { - Change[] children = composite.getChildren(); - for (int i = 0; i < children.length; i++) - { - Change child = children[i]; - if (child instanceof TextFileChange) - { - ((TextFileChange)child).setSaveMode(TextFileChange.LEAVE_DIRTY); - } - else if (child instanceof CompositeChange) - { - setSaveMode((CompositeChange)child); - } - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java deleted file mode 100644 index b912ca0ea3..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Node; - - -public abstract class RefactorEnablementTester extends PropertyTester -{ - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) - { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) - { - return false; - } - - IWorkbenchPage activePage = window.getActivePage(); - if (activePage == null) - { - return false; - } - - IEditorPart editor = activePage.getActiveEditor(); - if (editor == null) - { - return false; - } - - XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class); - - if (receiver instanceof IStructuredSelection) - { - IStructuredSelection fStructuredSelection = (IStructuredSelection)receiver; - receiver = fStructuredSelection.getFirstElement(); - - if (receiver instanceof XSDBaseAdapter) - { - receiver = ((XSDBaseAdapter)receiver).getTarget(); - } - - if (receiver instanceof XSDConcreteComponent) - { - return canEnable((XSDConcreteComponent)receiver, schema); - } - else if (receiver instanceof Node) - { - Node node = (Node)receiver; - if (schema != null) - { - XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node); - return canEnable(concreteComponent, schema); - } - } - - return true; - } - return false; - } - - protected abstract boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema); - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringComponent.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringComponent.java deleted file mode 100644 index 554bc8a7d8..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringComponent.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; - - -public interface RefactoringComponent -{ - /** - * @return the name of the component that is refactored. E.g. "foo" - */ - public String getName(); - - /** - * @return the namespace of the component that is refactored. E.g. "http://foo" - */ - public String getNamespaceURI(); - - /** - * The basic DOM element is used by the refactoring processor/participant to get - * access to the file location. - * - * @return the Structured Source Editor XML DOM element object that underlines the - * combonent being refactore. - * - * @see IDOMElement - */ - public IDOMElement getElement(); - - /** - * @return the qualified name of the type of the refactored component. - * - * <p> - * A qualified name consists of a local name and a namespace. - * E.g. "complexType"-local name, "http://www.w3.org/2001/XMLSchema"-namespace - * </p> - * - * @see QualifiedName - */ - public QualifiedName getTypeQName(); - - /** - * The model object may be required to be given to the refactored participants as is or - * other objects could be derived from it. - * - * @return the principal object being refactored, such as an instance of WSDLElement or - * XSDNamedComponent - */ - public Object getModelObject(); - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringMessages.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringMessages.java deleted file mode 100644 index 68ed4b23d5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactoringMessages.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class RefactoringMessages { - - private static final String RESOURCE_BUNDLE= "org.eclipse.wst.xsd.ui.internal.refactor.messages";//$NON-NLS-1$ - - private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); - - private RefactoringMessages() { - } - - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ - } - } - - public static String[] getStrings(String keys[]) { - String[] result= new String[keys.length]; - for (int i= 0; i < keys.length; i++) { - result[i]= getString(keys[i]); - } - return result; - } - - public static String getFormattedString(String key, Object arg) { - return getFormattedString(key, new Object[] { arg }); - } - - public static String getFormattedString(String key, Object[] args) { - return MessageFormat.format(getString(key), args); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java deleted file mode 100644 index 99bb97e0a9..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - - -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDTypeDefinition; - - -public class RenameEnablementTester extends RefactorEnablementTester -{ - protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) - { - if (selectedObject == null) - { - return false; - } - - XSDNamedComponent selectedComponent = null; - boolean enable = false; - - XSDSchema selectedComponentSchema = null; - selectedComponentSchema = selectedObject.getSchema(); - if (selectedComponentSchema != null && selectedComponentSchema == schema) - { - enable = true; - } - - if (enable && selectedObject instanceof XSDNamedComponent) - { - selectedComponent = (XSDNamedComponent)selectedObject; - - if (selectedComponent instanceof XSDElementDeclaration) - { - XSDElementDeclaration element = (XSDElementDeclaration)selectedComponent; - if (element.isElementDeclarationReference()) - { - return false; - } - if (!element.isGlobal()) - { - return false; - } - } - if (selectedComponent instanceof XSDTypeDefinition) - { - XSDTypeDefinition type = (XSDTypeDefinition)selectedComponent; - XSDConcreteComponent parent = type.getContainer(); - if (parent instanceof XSDElementDeclaration) - { - XSDElementDeclaration element = (XSDElementDeclaration)parent; - if (element.getAnonymousTypeDefinition().equals(type)) - { - return false; - } - } - else if (parent instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration element = (XSDAttributeDeclaration)parent; - if (element.getAnonymousTypeDefinition().equals(type)) - { - return false; - } - } - } - return true; - } - return false; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/TextChangeManager.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/TextChangeManager.java deleted file mode 100644 index e1c53e8e26..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/TextChangeManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.TextFileChange; - -/** - * A <code>TextChangeManager</code> manages associations between <code>IFile</code> and <code>TextChange</code> objects. - */ -public class TextChangeManager { - - private Map fMap= new HashMap(10); // IFile -> TextChange - - private final boolean fKeepExecutedTextEdits; - - public TextChangeManager() { - this(false); - } - - public TextChangeManager(boolean keepExecutedTextEdits) { - fKeepExecutedTextEdits= keepExecutedTextEdits; - } - - /** - * Adds an association between the given file and the passed - * change to this manager. - * - * @param file the file (key) - * @param change the change associated with the file - */ - public void manage(IFile file, TextChange change) { - fMap.put(file, change); - } - - /** - * Returns the <code>TextChange</code> associated with the given file. - * If the manager does not already manage an association it creates a one. - * - * @param file the file for which the text buffer change is requested - * @return the text change associated with the given file. - */ - public TextChange get(IFile file) { - TextChange result= (TextChange)fMap.get(file); - if (result == null) { - result= new TextFileChange(file.toString(), file); - result.setKeepPreviewEdits(fKeepExecutedTextEdits); - result.initializeValidationData(new NullProgressMonitor()); - fMap.put(file, result); - } - return result; - } - - /** - * Removes the <tt>TextChange</tt> managed under the given key - * <code>unit<code>. - * - * @param unit the key determining the <tt>TextChange</tt> to be removed. - * @return the removed <tt>TextChange</tt>. - */ - public TextChange remove(IFile unit) { - return (TextChange)fMap.remove(unit); - } - - /** - * Returns all text changes managed by this instance. - * - * @return all text changes managed by this instance - */ - public TextChange[] getAllChanges(){ - return (TextChange[])fMap.values().toArray(new TextChange[fMap.values().size()]); - } - - /** - * Returns all files managed by this instance. - * - * @return all files managed by this instance - */ - public IFile[] getAllCompilationUnits(){ - return (IFile[]) fMap.keySet().toArray(new IFile[fMap.keySet().size()]); - } - - /** - * Clears all associations between resources and text changes. - */ - public void clear() { - fMap.clear(); - } - - /** - * Returns if any text changes are managed for the specified file. - * - * @param file the file - * @return <code>true</code> if any text changes are managed for the specified file and <code>false</code> otherwise - */ - public boolean containsChangesIn(IFile file){ - return fMap.containsKey(file); - } -} - - diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/XMLRefactoringComponent.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/XMLRefactoringComponent.java deleted file mode 100644 index ad779b1ee4..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/XMLRefactoringComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor; - -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; - - -public class XMLRefactoringComponent implements RefactoringComponent -{ - // The name of the component being refactored - String name; - - // The namespace in which component is defined, e.g. XML or WSDL target namespace - String targetNamespace; - - // Optional model object that is refactored - Object model; - - // SED DOM object that underlines the component being refactored - IDOMElement domElement; - - public XMLRefactoringComponent(Object modelObject, IDOMElement domElement, String name, String namespace) - { - super(); - this.model = modelObject; - this.domElement = domElement; - this.name = name; - this.targetNamespace = namespace; - - - } - - public XMLRefactoringComponent(IDOMElement domElement, String name, String namespace) - { - super(); - this.domElement = domElement; - this.name = name; - this.targetNamespace = namespace; - } - - public Object getModelObject() - { - return model; - } - - public IDOMElement getElement() - { - return domElement; - } - - public String getName() - { - - return name; - } - - public String getNamespaceURI() - { - return targetNamespace; - } - - - public QualifiedName getTypeQName() - { - return new QualifiedName(domElement.getNamespaceURI(), domElement.getLocalName()); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java deleted file mode 100644 index 891476461f..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeAnonymousTypeGobalHandler; -import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeAnonymousTypeGlobalCommand; -import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeTypeGlobalProcessor; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.w3c.dom.Node; - -/** - * @deprecated Use {@link MakeAnonymousTypeGobalHandler} - */ -public class MakeAnonymousTypeGlobalAction extends XSDSelectionDispatchAction { - - private String fParentName; - private boolean isComplexType = true; - private XSDTypeDefinition fSelectedComponent; - - public MakeAnonymousTypeGlobalAction(ISelection selection, XSDSchema schema) { - super(selection, schema); - setText(RefactoringWizardMessages.MakeAnonymousTypeGlobalAction_text); //$NON-NLS-1$ - } - - public boolean canRun() { - - return fSelectedComponent != null; - } - - - private String getNewDefaultName(){ - if(fParentName != null && !"".equals(fParentName)){ //$NON-NLS-1$ - if(isComplexType){ - return fParentName + "ComplexType"; //$NON-NLS-1$ - } - else{ - return fParentName + "SimpleType"; //$NON-NLS-1$ - } - } - else{ - if(isComplexType){ - return "NewComplexType"; //$NON-NLS-1$ - } - else{ - return "NewSimpleType"; //$NON-NLS-1$ - } - } - - } - private boolean canEnable(XSDConcreteComponent xsdComponent){ - if (xsdComponent instanceof XSDComplexTypeDefinition) { - fSelectedComponent = (XSDComplexTypeDefinition)xsdComponent; - isComplexType = true; - XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent; - XSDConcreteComponent parent = typeDef.getContainer(); - if(parent instanceof XSDElementDeclaration){ - fParentName = ((XSDElementDeclaration)parent).getName(); - return true; - } - } - else if (xsdComponent instanceof XSDSimpleTypeDefinition){ - fSelectedComponent = (XSDSimpleTypeDefinition)xsdComponent; - isComplexType = false; - XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent; - XSDConcreteComponent parent = typeDef.getContainer(); - if(parent instanceof XSDElementDeclaration){ - fParentName = ((XSDElementDeclaration)parent).getName(); - return true; - } - else if(parent instanceof XSDAttributeDeclaration){ - fParentName = ((XSDAttributeDeclaration)parent).getName(); - return true; - } - - } - return false; - } - - protected boolean canEnable(Object selectedObject) { - - if (selectedObject instanceof XSDConcreteComponent) { - return canEnable((XSDConcreteComponent)selectedObject) && super.canEnable(selectedObject); - } - else if (selectedObject instanceof Node) { - Node node = (Node) selectedObject; - XSDConcreteComponent concreteComponent = getSchema().getCorrespondingComponent(node); - return canEnable(concreteComponent) && super.canEnable(concreteComponent); - - } - return false; - - } - - public void run1() { - - if(fSelectedComponent == null){ - return; - } - - if(fSelectedComponent.getSchema() == null){ - getSchema().updateElement(true); - } - MakeTypeGlobalProcessor processor = new MakeTypeGlobalProcessor(fSelectedComponent, getNewDefaultName()); - RenameRefactoring refactoring = new RenameRefactoring(processor); - try { - RefactoringWizard wizard = new RenameRefactoringWizard( - refactoring, - RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, // TODO: provide correct strings - RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null); - RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(wizard); - op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle()); - //triggerBuild(); - } catch (InterruptedException e) { - // do nothing. User action got cancelled - } - - } - - public void run(){ - if(fSelectedComponent == null){ - return; - } - - if(fSelectedComponent.getSchema() == null){ - getSchema().updateElement(true); - } - DocumentImpl doc = (DocumentImpl) fSelectedComponent.getElement().getOwnerDocument(); - doc.getModel().beginRecording( - this, - RefactoringWizardMessages.MakeAnonymousTypeGlobalAction_text); - MakeAnonymousTypeGlobalCommand command = new MakeAnonymousTypeGlobalCommand( - fSelectedComponent, getNewDefaultName()); - command.run(); - doc.getModel().endRecording(this); - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java deleted file mode 100644 index 49d877c8c8..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeLocalElementGlobalHandler; -import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Node; - -/** - * @deprecated Use {@link MakeLocalElementGlobalHandler} - */ -public class MakeLocalElementGlobalAction extends XSDSelectionDispatchAction { - - XSDElementDeclaration fSelectedComponent; - - public MakeLocalElementGlobalAction(ISelection selection, XSDSchema schema) { - super(selection, schema); - setText(RefactoringMessages.getString("MakeLocalElementGlobalAction.text")); //$NON-NLS-1$ - } - - public boolean canRun() { - - return fSelectedComponent != null; - } - - protected boolean canEnable(XSDConcreteComponent selectedObject) { - - fSelectedComponent = null; - if (selectedObject instanceof XSDElementDeclaration) { - XSDElementDeclaration element = (XSDElementDeclaration) selectedObject; - if (!element.isElementDeclarationReference() && !element.isGlobal()) { - fSelectedComponent = element; - } - } - return canRun(); - } - - - protected boolean canEnable(Object selectedObject) { - - if (selectedObject instanceof XSDConcreteComponent) { - return canEnable((XSDConcreteComponent)selectedObject) && super.canEnable(selectedObject); - } - else if (selectedObject instanceof Node) { - Node node = (Node) selectedObject; - XSDConcreteComponent concreteComponent = getSchema() - .getCorrespondingComponent(node); - return canEnable(concreteComponent) && super.canEnable(concreteComponent); - } - return false; - - } - - - public void run() { - DocumentImpl doc = (DocumentImpl) fSelectedComponent.getElement() - .getOwnerDocument(); - doc.getModel().beginRecording(this, getText()); - MakeLocalElementGlobalCommand command = new MakeLocalElementGlobalCommand( - fSelectedComponent); - command.run(); - doc.getModel().endRecording(this); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameAction.java deleted file mode 100644 index 01d2fb7546..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameAction.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; - - - -/** -* Renames a XML Schema element or workbench resource. -* <p> -* Action is applicable to selections containing elements of type -* <code></code> or <code>IResource</code>. -* -* <p> -* This class may be instantiated; it is not intended to be subclassed. -* </p> - -*/ -public class RenameAction extends SelectionDispatchAction { - - private SelectionDispatchAction renameComponentAction; - private SelectionDispatchAction renameResourceAction; - - - public RenameAction(ISelection selection) { - super(selection); - setText(RefactoringWizardMessages.RenameAction_text); - renameResourceAction= new RenameResourceAction(selection); - renameResourceAction.setText(getText()); - - } - public RenameAction(ISelection selection, Object model) { - super(selection); - setText(RefactoringWizardMessages.RenameAction_text); - renameComponentAction= new RenameComponentAction(selection, model); - renameComponentAction.setText(getText()); - renameResourceAction= new RenameResourceAction(selection); - renameResourceAction.setText(getText()); - - } - - - - /* - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - renameComponentAction.selectionChanged(event); - if (renameResourceAction != null) - renameResourceAction.selectionChanged(event); - setEnabled(computeEnabledState()); - } - - /* - * @see SelectionDispatchAction#update(ISelection) - */ - public void update(ISelection selection) { - if(renameComponentAction != null){ - renameComponentAction.update(selection); - } - if (renameResourceAction != null) - renameResourceAction.update(selection); - setEnabled(computeEnabledState()); - } - - private boolean computeEnabledState(){ - if (renameResourceAction != null) { - return renameComponentAction.isEnabled() || renameResourceAction.isEnabled(); - } else { - return renameComponentAction.isEnabled(); - } - } - - public void run(IStructuredSelection selection) { - if (renameComponentAction != null && renameComponentAction.isEnabled()) - renameComponentAction.run(selection); - if (renameResourceAction != null && renameResourceAction.isEnabled()) - renameResourceAction.run(selection); - } - - public void run(ITextSelection selection) { - if (renameComponentAction != null && renameComponentAction.canRun()) - renameComponentAction.run(selection); - else - MessageDialog.openInformation(XSDEditorPlugin.getShell(), RefactoringWizardMessages.RenameAction_rename, RefactoringWizardMessages.RenameAction_unavailable); - } - public void run(ISelection selection) { - if(selection == null){ - super.run(); - } - else{ - super.run(selection); - } - - } - public final void setRenameComponentAction( - SelectionDispatchAction renameComponentAction) - { - this.renameComponentAction = renameComponentAction; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java deleted file mode 100644 index e0447ef2de..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.ui.actions.GlobalBuildAction; -import org.eclipse.wst.common.ui.internal.dialogs.SaveDirtyFilesDialog; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.handlers.RenameHandler; -import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDTypeDefinition; -import org.w3c.dom.Node; - -/** - * @deprecated Use {@link RenameHandler} - */ -public class RenameComponentAction extends XSDSelectionDispatchAction { - - private XSDNamedComponent selectedComponent; - - public RenameComponentAction(ISelection selection, - Object aModel) { - super(selection, aModel); - - } - - protected boolean canEnable(XSDConcreteComponent selectedObject) { - - selectedComponent = null; - if (selectedObject instanceof XSDNamedComponent) { - selectedComponent = (XSDNamedComponent) selectedObject; - - // if it's element reference, then this action is not appropriate - if (selectedComponent instanceof XSDElementDeclaration) { - XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent; - if (element.isElementDeclarationReference()) { - selectedComponent = null; - } - } - if(selectedComponent instanceof XSDTypeDefinition){ - XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent; - XSDConcreteComponent parent = type.getContainer(); - if (parent instanceof XSDElementDeclaration) { - XSDElementDeclaration element = (XSDElementDeclaration) parent; - if(element.getAnonymousTypeDefinition().equals(type)){ - selectedComponent = null; - } - } - else if(parent instanceof XSDAttributeDeclaration) { - XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent; - if(element.getAnonymousTypeDefinition().equals(type)){ - selectedComponent = null; - } - } - } - } - - return canRun(); - } - - protected boolean canEnable(Object selectedObject) { - - if (selectedObject instanceof XSDConcreteComponent) - { - return canEnable((XSDConcreteComponent) selectedObject) && super.canEnable(selectedObject); - } else if (selectedObject instanceof Node) - { - Node node = (Node) selectedObject; - if (getSchema() != null) - { - XSDConcreteComponent concreteComponent = getSchema() - .getCorrespondingComponent(node); - return canEnable(concreteComponent) && super.canEnable(concreteComponent); - } - } - return false; - - } - - public boolean canRun() { - - return selectedComponent != null; - } - - 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 - } - - } - - public static void triggerBuild() { - if (ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) { - new GlobalBuildAction(XSDEditorPlugin.getPlugin().getWorkbench() - .getActiveWorkbenchWindow(), - IncrementalProjectBuilder.INCREMENTAL_BUILD).run(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceAction.java deleted file mode 100644 index 17d7d9fa8a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameResourceProcessor; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard; - - - -public class RenameResourceAction extends SelectionDispatchAction { - - - - - public RenameResourceAction(ISelection selection) - { - super(selection); - } - - public void selectionChanged(IStructuredSelection selection) { - IResource element= getResource(selection); - if (element == null) { - setEnabled(false); - } else { - RenameResourceProcessor processor= new RenameResourceProcessor(element); - setEnabled(processor.isApplicable()); - - } - } - - public void run(IStructuredSelection selection) { - IResource resource = getResource(selection); - RenameResourceProcessor processor= new RenameResourceProcessor(resource); - - if(!processor.isApplicable()) - return; - RenameRefactoring refactoring= new RenameRefactoring(processor); - try { - RefactoringWizard wizard = new RenameRefactoringWizard( - refactoring, - RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, //TODO: provide correct strings - RefactoringWizardMessages.RenameComponentWizard_inputPage_description, - null); - RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(wizard); - op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle()); - } catch (InterruptedException e) { - // do nothing. User action got cancelled - } - - } - - private static IResource getResource(IStructuredSelection selection) { - if (selection.size() != 1) - return null; - Object first= selection.getFirstElement(); - if (! (first instanceof IResource)) - return null; - return (IResource)first; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceActionDelegate.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceActionDelegate.java deleted file mode 100644 index 444a5abbf9..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameResourceActionDelegate.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -/** - * @author ebelisar@ca.ibm.com - */ -public class RenameResourceActionDelegate implements IObjectActionDelegate { - - private ISelection fCurrentSelection; - -// private IWorkbenchPart fPart; - - /* (non-Javadoc) - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { -// fPart = targetPart; - } - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - if (fCurrentSelection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection= (IStructuredSelection) fCurrentSelection; - Object first= structuredSelection.getFirstElement(); - if (first instanceof IFile) { - RenameResourceAction renameAction = new RenameResourceAction(structuredSelection); - renameAction.run(structuredSelection); - } - } - - } - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - fCurrentSelection= selection; - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameTargetNamespaceAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameTargetNamespaceAction.java deleted file mode 100644 index 58ceedc9ac..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameTargetNamespaceAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.ui.actions.GlobalBuildAction; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameTargetNamespaceProcessor; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard; - -public class RenameTargetNamespaceAction extends XSDSelectionDispatchAction { - - public RenameTargetNamespaceAction(ISelection selection, - Object aModel) { - super(selection, aModel); - setText(RefactoringWizardMessages.RenameTargetNamespace_text); - - } - - - protected boolean canEnable(Object selectedObject) { - - return super.canEnable(selectedObject); - - } - - public boolean canRun() { - - return getSchema() != null; - } - - - public void run(ISelection selection) { - - - RenameTargetNamespaceProcessor processor = new RenameTargetNamespaceProcessor(getSchema(), getSchema().getTargetNamespace()); - RenameRefactoring refactoring = new RenameRefactoring(processor); - try { - RefactoringWizard wizard = new RenameRefactoringWizard( - refactoring, - RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle,//TODO: provide correct strings - RefactoringWizardMessages.RenameComponentWizard_inputPage_description, - null); - RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation( - wizard); - op.run(XSDEditorPlugin.getShell(), wizard - .getDefaultPageTitle()); - triggerBuild(); - } catch (InterruptedException e) { - // do nothing. User action got cancelled - } - - } - - public static void triggerBuild() { - if (ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) { - new GlobalBuildAction(XSDEditorPlugin.getPlugin().getWorkbench() - .getActiveWorkbenchWindow(), - IncrementalProjectBuilder.INCREMENTAL_BUILD).run(); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/SelectionDispatchAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/SelectionDispatchAction.java deleted file mode 100644 index 7a2aaca5e4..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/SelectionDispatchAction.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; - - - -/** - * Action that dispatches the <code>IAction#run()</code> and the - * <code>ISelectionChangedListener#selectionChanged</code> - * according to the type of the selection. - * - * <ul> - * <li>if selection is of type <code>ITextSelection</code> then - * <code>run(ITextSelection)</code> and <code>selectionChanged(ITextSelection)</code> - * is called.</li> - * <li>if selection is of type <code>IStructuredSelection</code> then - * <code>run(IStructuredSelection)</code> and <code> - * selectionChanged(IStructuredSelection)</code> is called.</li> - * <li>default is to call <code>run(ISelection)</code> and <code> - * selectionChanged(ISelection)</code>.</li> - * </ul> - * - * <p> - * adapted from <code>org.eclipse.jdt.ui.actions.SelectionDispatchAction</code> - * </p> - * - * - */ -public abstract class SelectionDispatchAction extends Action implements ISelectionChangedListener { - - private ISelection selection; - - private Object model; - - protected SelectionDispatchAction(ISelection selection) { - Assert.isNotNull(selection); - this.selection = selection; - - } - - /** - * Returns the selection provided by the site owning this action. - * - * @return the site's selection - */ - public ISelection getSelection() { - return selection; - } - - /** - * Updates the action's enablement state according to the given selection. This - * default implementation calls one of the <code>selectionChanged</code> - * methods depending on the type of the passed selection. - * - * @param selection the selection this action is working on - */ - public void update(ISelection selection) { - dispatchSelectionChanged(selection); - } - - /** - * Notifies this action that the given structured selection has changed. This default - * implementation calls <code>selectionChanged(ISelection selection)</code>. - * - * @param selection the new selection - */ - public void selectionChanged(IStructuredSelection selection) { - if (selection.size() == 1) { - Object object = selection.getFirstElement(); - setEnabled(canEnable(object)); - } - else{ - setEnabled(false); - } - } - - protected boolean canEnable(Object selectedObject){ - return false; - } - - /** - * Executes this actions with the given structured selection. This default implementation - * calls <code>run(ISelection selection)</code>. - */ - public void run(IStructuredSelection selection) { - run((ISelection)selection); - } - - - /** - * Notifies this action that the given text selection has changed. This default - * implementation calls <code>selectionChanged(ISelection selection)</code>. - * - * @param selection the new selection - */ - public void selectionChanged(ITextSelection selection) { - selectionChanged((ISelection)selection); - } - - /** - * Executes this actions with the given text selection. This default implementation - * calls <code>run(ISelection selection)</code>. - */ - public void run(ITextSelection selection) { - run((ISelection)selection); - } - - /** - * Notifies this action that the given selection has changed. This default - * implementation sets the action's enablement state to <code>false</code>. - * - * @param selection the new selection - */ - public void selectionChanged(ISelection selection) { - setEnabled(false); - } - - /** - * Executes this actions with the given selection. This default implementation - * does nothing. - */ - public void run(ISelection selection) { - - } - - /* (non-Javadoc) - * Method declared on IAction. - */ - public void run() { - dispatchRun(getSelection()); - - } - - /* (non-Javadoc) - * Method declared on ISelectionChangedListener. - */ - public void selectionChanged(SelectionChangedEvent event) { - dispatchSelectionChanged(event.getSelection()); - } - - private void dispatchSelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - selectionChanged((IStructuredSelection)selection); - } else if (selection instanceof ITextSelection) { - selectionChanged((ITextSelection)selection); - } else { - selectionChanged(selection); - } - } - - protected void dispatchRun(ISelection selection) { - if (selection instanceof IStructuredSelection) { - run((IStructuredSelection)selection); - } else if (selection instanceof ITextSelection) { - run((ITextSelection)selection); - } else { - run(selection); - } - } - - public final Object getModel() - { - return model; - } - - public final void setModel(Object model) - { - this.model = model; - } - - public boolean canRun() { - - return true; - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorActionGroup.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorActionGroup.java deleted file mode 100644 index 0169f2625e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorActionGroup.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import java.util.ArrayList; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorActionGroup; -import org.eclipse.xsd.XSDSchema; - -public class XSDRefactorActionGroup extends RefactorActionGroup { - - private static final String MAKE_ELEMENT_GLOBAL = "org.eclipse.wst.xsd.ui.refactor.makeElementGlobal"; //$NON-NLS-1$ - - private static final String MAKE_TYPE_GLOBAL = "org.eclipse.wst.xsd.ui.refactor.makeTypeGlobal"; //$NON-NLS-1$ - - private static final String RENAME_ELEMENT = "org.eclipse.wst.xsd.ui.refactor.rename.element"; //$NON-NLS-1$ - - //private static final String RENAME_TARGET_NAMESPCE = "org.eclipse.wst.xsd.ui.refactor.renameTargetNamespace"; //$NON-NLS-1$ - - private SelectionDispatchAction fMakeLocalElementGlobal; - - private SelectionDispatchAction fMakeLocalTypeGlobal; - - public XSDRefactorActionGroup(ISelection selection, - XSDSchema schema) { - super(selection); - fEditorActions = new ArrayList(); - fRenameAction = new RenameAction(selection, schema); - fRenameAction.setActionDefinitionId(RENAME_ELEMENT); - fEditorActions.add(fRenameAction); - - //fRenameTargetNamespace = new RenameTargetNamespaceAction( - // selection, schema); - //fRenameTargetNamespace.setActionDefinitionId(RENAME_TARGET_NAMESPCE); - //fEditorActions.add(fRenameTargetNamespace); - - fMakeLocalElementGlobal = new MakeLocalElementGlobalAction( - selection, schema); - fMakeLocalElementGlobal.setActionDefinitionId(MAKE_ELEMENT_GLOBAL); - fEditorActions.add(fMakeLocalElementGlobal); - - fMakeLocalTypeGlobal = new MakeAnonymousTypeGlobalAction( - selection, schema); - fMakeLocalTypeGlobal.setActionDefinitionId(MAKE_TYPE_GLOBAL); - fEditorActions.add(fMakeLocalTypeGlobal); - - initAction(fRenameAction, selection); - //initAction(fRenameTargetNamespace, selection); - initAction(fMakeLocalElementGlobal, selection); - initAction(fMakeLocalTypeGlobal, selection); - } - - public void dispose() { -// disposeAction(fRenameAction, selection); -// disposeAction(fMakeLocalElementGlobal, selection); -// disposeAction(fMakeLocalTypeGlobal, selection); -// disposeAction(fRenameTargetNamespace, selection); - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorGroupActionDelegate.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorGroupActionDelegate.java deleted file mode 100644 index a0873fc8cb..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDRefactorGroupActionDelegate.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.wst.xsd.ui.internal.editor.ISelectionMapper; -import org.eclipse.wst.xsd.ui.internal.refactor.actions.XSDRefactorActionGroup; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorActionGroup; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupActionDelegate; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupSubMenu; -import org.eclipse.xsd.XSDSchema; - -public class XSDRefactorGroupActionDelegate extends RefactorGroupActionDelegate { - - public XSDRefactorGroupActionDelegate() { - super(); - } - - /** - * Fills the menu with applicable refactor sub-menues - * @param menu The menu to fill - */ - protected void fillMenu(Menu menu) { - if (fSelection == null) { - return; - } - if (workbenchPart != null) { - IWorkbenchPartSite site = workbenchPart.getSite(); - if (site == null) - return; - - IEditorPart editor = site.getPage().getActiveEditor(); - if (editor != null) { - XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class); - ISelectionMapper mapper = (ISelectionMapper)editor.getAdapter(ISelectionMapper.class); - if (schema != null) - { - ISelection selection = mapper != null ? mapper.mapSelection(fSelection) : fSelection; - RefactorActionGroup refactorMenuGroup = new XSDRefactorActionGroup(selection, schema); - RefactorGroupSubMenu subMenu = new RefactorGroupSubMenu(refactorMenuGroup); - subMenu.fill(menu, -1); - } - } - - } - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDSelectionDispatchAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDSelectionDispatchAction.java deleted file mode 100644 index ba28df9f87..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/XSDSelectionDispatchAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.actions; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public class XSDSelectionDispatchAction extends SelectionDispatchAction -{ - - - - public XSDSelectionDispatchAction(ISelection selection, Object model) - { - super(selection); - setModel(model); - } - - protected XSDSchema getSchema(){ - Object model = getModel(); - if(model instanceof XSDSchema) - { - return (XSDSchema) model; - } - - return null; - } - - protected boolean canEnable(Object selectedComponent) - { - XSDSchema selectedComponentSchema = null; - if (selectedComponent instanceof XSDConcreteComponent) - { - selectedComponentSchema = ((XSDConcreteComponent)selectedComponent).getSchema(); - } - - if (selectedComponentSchema != null && selectedComponentSchema == getSchema() ) - { - return true; - } - return false; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java deleted file mode 100644 index efd80873a7..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.handlers; - - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeAnonymousTypeGlobalCommand; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.w3c.dom.Node; - - -public class MakeAnonymousTypeGobalHandler extends RefactoringHandler -{ - private String parentName; - private boolean isComplexType = true; - - public Object doExecute(ISelection selection, XSDSchema schema) - { - if (selection != null) - { - Object selectedObject = ((StructuredSelection)selection).getFirstElement(); - - if (selectedObject instanceof XSDBaseAdapter) - { - selectedObject = ((XSDBaseAdapter)selectedObject).getTarget(); - } - - XSDConcreteComponent concreteComp = null; - - if (selectedObject instanceof Node) - { - Node node = (Node)selectedObject; - concreteComp = schema.getCorrespondingComponent(node); - } - else if (selectedObject instanceof XSDConcreteComponent) - { - concreteComp = ((XSDConcreteComponent)selectedObject); - } - - if (concreteComp != null) - { - if (concreteComp instanceof XSDComplexTypeDefinition) - { - - isComplexType = true; - XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition)concreteComp; - XSDConcreteComponent parent = typeDef.getContainer(); - if (parent instanceof XSDElementDeclaration) - { - parentName = ((XSDElementDeclaration)parent).getName(); - run(selection, schema, typeDef); - } - else if (concreteComp instanceof XSDSimpleTypeDefinition) - { - isComplexType = false; - XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition)concreteComp; - XSDConcreteComponent parentComp = simpleTypeDef.getContainer(); - if (parentComp instanceof XSDElementDeclaration) - { - parentName = ((XSDElementDeclaration)parent).getName(); - - } - else if (parent instanceof XSDAttributeDeclaration) - { - parentName = ((XSDAttributeDeclaration)parent).getName(); - - } - run(selection, schema, simpleTypeDef); - } - } - } - } - - return null; - } - - private String getNewDefaultName() - { - if (parentName != null && !"".equals(parentName)) { //$NON-NLS-1$ - if (isComplexType) - { - return parentName + "ComplexType"; //$NON-NLS-1$ - } - else - { - return parentName + "SimpleType"; //$NON-NLS-1$ - } - } - else - { - if (isComplexType) - { - return "NewComplexType"; //$NON-NLS-1$ - } - else - { - return "NewSimpleType"; //$NON-NLS-1$ - } - } - - } - - public void run(ISelection selection, XSDSchema schema, XSDTypeDefinition selectedComponent) - { - if (selectedComponent == null) - { - return; - } - - if (selectedComponent.getSchema() == null) - { - schema.updateElement(true); - } - DocumentImpl doc = (DocumentImpl)selectedComponent.getElement().getOwnerDocument(); - doc.getModel().beginRecording(this, RefactoringWizardMessages.MakeAnonymousTypeGlobalAction_text); - MakeAnonymousTypeGlobalCommand command = new MakeAnonymousTypeGlobalCommand(selectedComponent, getNewDefaultName()); - command.run(); - doc.getModel().endRecording(this); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java deleted file mode 100644 index 8578d88c01..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.handlers; - - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Node; - - -public class MakeLocalElementGlobalHandler extends RefactoringHandler -{ - - public Object doExecute(ISelection selection, XSDSchema schema) - { - if (selection != null) - { - Object selectedObject = ((StructuredSelection)selection).getFirstElement(); - if (selectedObject instanceof XSDBaseAdapter) - { - selectedObject = ((XSDBaseAdapter)selectedObject).getTarget(); - } - if (selectedObject instanceof XSDElementDeclaration) - { - run(selection, (XSDElementDeclaration)selectedObject); - } - else if (selectedObject instanceof Node) - { - Node node = (Node)selectedObject; - XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node); - if (concreteComponent instanceof XSDElementDeclaration) - run(selection, (XSDElementDeclaration)concreteComponent); - } - - } - return null; - } - - public void run(ISelection selection, XSDElementDeclaration selectedComponent) - { - DocumentImpl doc = (DocumentImpl)selectedComponent.getElement().getOwnerDocument(); - doc.getModel().beginRecording(this, "MakeLocalElementGlobalHandler.text"); - MakeLocalElementGlobalCommand command = new MakeLocalElementGlobalCommand(selectedComponent); - command.run(); - doc.getModel().endRecording(this); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java deleted file mode 100644 index bbe02fc7ea..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xsd.ui.internal.refactor.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.xsd.XSDSchema; - -public abstract class RefactoringHandler extends AbstractHandler -{ - public Object execute(ExecutionEvent event) throws ExecutionException { - - IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); - if (workbenchWindow == null) return null; - - IWorkbenchPage activePage = workbenchWindow.getActivePage(); - if (activePage == null) return null; - - IEditorPart editor = activePage.getActiveEditor(); - if (editor == null) return null; - XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class); - - ISelection selection = activePage.getSelection(); - - return doExecute(selection, schema); - } - - protected abstract Object doExecute(ISelection selection, XSDSchema schema); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java deleted file mode 100644 index c06bd43d09..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.handlers; - - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.wst.common.ui.internal.dialogs.SaveDirtyFilesDialog; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Node; - - -public class RenameHandler extends RefactoringHandler -{ - - protected Object doExecute(ISelection selection, XSDSchema schema) - { - return execute(selection, schema); - } - - public Object execute(ISelection selection, XSDSchema schema) - { - if (selection != null) - { - - Object selectedObject = ((StructuredSelection)selection).getFirstElement(); - if (selectedObject instanceof XSDBaseAdapter) - { - selectedObject = ((XSDBaseAdapter)selectedObject).getTarget(); - } - - if (selectedObject instanceof XSDNamedComponent) - { - run(selection, schema, (XSDNamedComponent)selectedObject); - } - else if (selectedObject instanceof Node) - { - Node node = (Node)selectedObject; - if (schema != null) - { - XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node); - if (concreteComponent instanceof XSDNamedComponent) - { - run(selection, schema, (XSDNamedComponent)concreteComponent); - } - } - } - } - return null; - - } - - 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 - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/messages.properties deleted file mode 100644 index 9c8b012e1c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/messages.properties +++ /dev/null @@ -1,55 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2010 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -RefactorMenu.label=Refactor -RefactorActionGroup.no_refactoring_available=<no refactoring available> - -RenameAction.rename=Rename -RenameAction.unavailable=Operation unavailable on the current selection.\nSelect a .... -RenameAction.text=Re&name... - -RenameInputWizardPage.new_name= &New name: -RenameRefactoringWizard.internal_error= Internal error during name checking: {0} - - -RenameXSDElementAction.exception=Unexpected exception occurred. See log for details -RenameXSDElementAction.not_available=Operation unavailable on the current selection.\nSelect a XSD project, folder, resource, file, attribute declarations, attribute group definitions, complex type definitions, element declarations, identity constraint definitions, model groups definitions, notation declarations, or simple type definitions. -RenameXSDElementAction.name=Rename - - -RenameSupport.dialog.title=Rename -RenameSupport.not_available=Rename support not available - -RenameComponentWizard.defaultPageTitle=Rename wizard -RenameComponentWizard.inputPage.description=Rename XML Schema component - -RenameInputWizardPage.update_references=Update references -XSDComponentRenameChange.name=XML Schema component renaming in {0}: {1} to {2} -XSDComponentRenameChange.Renaming=Renaming... -ResourceRenameParticipant.compositeChangeName=XSD file rename references updating changes -RenameResourceChange.rename_resource_reference_change=Renaming resource name references -XSDRenameResourceChange.name=Resource rename: {0} to {1} -RenameResourceRefactoring.Internal_Error=Internal error -RenameResourceRefactoring.alread_exists=Resource already exist -RenameResourceRefactoring.invalidName=Invalid resource name -RenameResourceProcessor.name=Resource renaming -MakeLocalElementGlobalAction.text=Make &Local Element Global -XSDComponentRenameParticipant.Component_Refactoring_updates=XML Schema refactoring changes -WSDLComponentRenameParticipant.Component_Refactoring_updates=WSDL refactoring changes -RenameComponentProcessor.Component_Refactoring_updates=Component name refactoring changes -RenameComponentProcessor.Component_Refactoring_update_declatation=Update component declaration/definition -RenameComponentProcessor.Component_Refactoring_update_reference=Update component reference -XSDComponentRenameParticipant.xsd_component_rename_participant=XSD component rename participant -WSDLComponentRenameParticipant.wsdl_component_rename_participant=WSDL component rename participant -ResourceRenameParticipant.File_Rename_update_reference=File rename refactoring changes -RenameComponentRefactoring_checking=Checking... -RenameComponentRefactoring_searching=Searching... -Checks_Choose_name=Invalid name -RenameComponentRefactoring_another_name=Name already used diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java deleted file mode 100644 index ebdf3d03ec..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.Map; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; - -public class ComponentRenameArguments extends RenameArguments { - - TextChangeManager changeManager; - Map matches; - String qualifier; - - public ComponentRenameArguments(String newName, boolean updateReferences) { - super(newName, updateReferences); - } - - public TextChangeManager getChangeManager() { - return changeManager; - } - - public void setChangeManager(TextChangeManager changeManager) { - this.changeManager = changeManager; - } - - public Map getMatches() { - return matches; - } - - public void setMatches(Map matches) { - this.matches = matches; - } - - public String getQualifier() { - return qualifier; - } - - public void setQualifier(String qualifier) { - this.qualifier = qualifier; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java deleted file mode 100644 index b49d4fbe6d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java +++ /dev/null @@ -1,519 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -//import com.ibm.icu.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.text.Position; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.wst.common.core.search.SearchEngine; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.common.core.search.scope.SearchScope; -import org.eclipse.wst.common.core.search.scope.SelectionSearchScope; -import org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope; -import org.eclipse.wst.common.core.search.util.CollectingSearchRequestor; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern; -import org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern; -import org.eclipse.wst.xsd.ui.internal.refactor.Checks; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.IReferenceUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.wst.xsd.ui.internal.refactor.util.TextChangeCompatibility; - - - -public class RenameComponentProcessor extends RenameProcessor implements INameUpdating, IReferenceUpdating { - public static final String IDENTIFIER = "org.eclipse.wst.xml.refactor.renameComponentProcessor"; //$NON-NLS-1$ - private boolean singleFileOnly = false; - - public static String quoteString(String value) { - value = value == null ? "" : value; - - StringBuffer sb = new StringBuffer(); - if (!value.startsWith("\"")) { - sb.append("\""); - } - sb.append(value); - if (!value.endsWith("\"")) { - sb.append("\""); - } - return sb.toString(); - } - - private TextChangeManager changeManager; - - private String newName; - - private RefactoringComponent selectedComponent; - - private boolean updateReferences = true; - - private Map references = new HashMap(); - - public RenameComponentProcessor(RefactoringComponent selectedComponent) { - this.selectedComponent = selectedComponent; - } - - public RenameComponentProcessor(RefactoringComponent selectedComponent, String newName) { - this(selectedComponent, newName, false); - } - - public RenameComponentProcessor(RefactoringComponent selectedComponent, String newName, boolean singleFileOnly) { - this.newName = newName; - this.selectedComponent = selectedComponent; - this.singleFileOnly = singleFileOnly; - } - - private void addDeclarationUpdate(TextChangeManager manager) throws CoreException { - String fileStr = selectedComponent.getElement().getModel().getBaseLocation(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileStr)); - addDeclarationUpdate(manager, file); - } - - final void addDeclarationUpdate(TextChangeManager manager, IFile file) throws CoreException { - - String componentName = selectedComponent.getName(); - String componentNamespace = selectedComponent.getNamespaceURI(); - QualifiedName elementQName = new QualifiedName(componentNamespace, componentName); - QualifiedName typeQName = selectedComponent.getTypeQName(); - - - - SearchScope scope = new WorkspaceSearchScope(); - if (file != null) { - scope = new SelectionSearchScope(new IResource[]{file}); - } - CollectingSearchRequestor requestor = new CollectingSearchRequestor(); - SearchPattern pattern = new XMLComponentDeclarationPattern(file, elementQName, typeQName); - SearchEngine searchEngine = new SearchEngine(); - HashMap map = new HashMap(); - if (singleFileOnly) - { - map.put("searchDirtyContent", Boolean.TRUE); - } - searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor()); - List results = requestor.getResults(); - - // more than one declaration found, so use offset as additional check - Position offsetPosition = null; - if (results.size() > 1) { - IDOMElement selectedElement = selectedComponent.getElement(); - if (selectedElement != null) { - int startOffset = selectedElement.getStartOffset(); - offsetPosition = new Position(startOffset, (selectedElement.getEndOffset() - startOffset)); - } - } - - for (Iterator iter = results.iterator(); iter.hasNext();) { - SearchMatch match = (SearchMatch) iter.next(); - if (match != null) { - boolean addTextChange = true; - // additional check to verify correct declaration is changed - if (offsetPosition != null) { - addTextChange = offsetPosition.overlapsWith(match.getOffset(), match.getLength()); - } - if (addTextChange) { - TextChange textChange = manager.get(match.getFile()); - String newName = getNewElementName(); - newName = quoteString(newName); - - ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName); - String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_declatation"); - TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit); - } - } - } - } - - void addOccurrences(TextChangeManager manager, IProgressMonitor pm, RefactoringStatus status) throws CoreException { - - String fileStr = selectedComponent.getElement().getModel().getBaseLocation(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileStr)); - - String componentName = selectedComponent.getName(); - String componentNamespace = selectedComponent.getNamespaceURI(); - QualifiedName elementQName = new QualifiedName(componentNamespace, componentName); - QualifiedName typeQName = selectedComponent.getTypeQName(); - - SearchEngine searchEngine = new SearchEngine(); - SearchScope scope = null; - HashMap map = new HashMap(); - if (singleFileOnly) - { - map.put("searchDirtyContent", Boolean.TRUE); - scope = new SelectionSearchScope(new IResource[]{file}); - } - else - { - scope = new WorkspaceSearchScope(); - } - SortingSearchRequestor requestor = new SortingSearchRequestor(); - SearchPattern pattern = new XMLComponentReferencePattern(file, elementQName, typeQName); - - searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor()); - references = requestor.getResults(); - // for (Iterator iter = references.iterator(); iter.hasNext();) { - // SearchMatch match = (SearchMatch) iter.next(); - - // TextChange textChange = manager.get(match.getFile()); - // String newName = getNewElementName(); - // if(match.getObject() instanceof Node){ - // Node node = (Node)match.getObject(); - // if(node instanceof IDOMAttr){ - // IDOMAttr attr = (IDOMAttr)node; - // IDOMElement element = (IDOMElement)attr.getOwnerElement() ; - // newName = getNewQName(element, componentNamespace, newName); - // } - // newName = quoteString(newName); - // } - // - // ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), - // match.getLength(), newName ); - // String editName = - // RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference"); - // TextChangeCompatibility.addTextEdit(textChange, editName, - // replaceEdit); - - // } - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating() - */ - public boolean canEnableTextUpdating() { - return true; - } - - public boolean canEnableUpdateReferences() { - return true; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, - * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException { - Assert.isNotNull(monitor); - Assert.isNotNull(context); - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask("", 2); //$NON-NLS-1$ - monitor.setTaskName(RefactoringMessages.getString("RenameComponentRefactoring_checking")); //$NON-NLS-1$ - status.merge(checkNewElementName(getNewElementName())); - monitor.worked(1); - monitor.setTaskName(RefactoringMessages.getString("RenameComponentRefactoring_searching")); //$NON-NLS-1$ - status.merge(createRenameChanges(new SubProgressMonitor(monitor, 1))); - } - finally { - monitor.done(); - } - return status; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { - // TODO add code to check initial conditions for component rename - Assert.isNotNull(pm); - try { - return new RefactoringStatus(); - } - finally { - pm.done(); - } - - } - - public final RefactoringStatus checkNewElementName(final String name) { - Assert.isNotNull(name); - final RefactoringStatus result = Checks.checkName(name); - result.merge(Checks.checkComponentName(name)); - if (Checks.isAlreadyNamed(selectedComponent, name)) - result.addFatalError(RefactoringMessages.getString("RenameComponentRefactoring_another_name")); //$NON-NLS-1$ - return result; - } - - private Object[] computeDerivedElements() { - - Object[] elements = getElements(); - // Object[] results = new Object[elements.length]; - // for(int i=0; i< elements.length; i++){ - // RefactoringComponent component = (RefactoringComponent)elements[i]; - // results[i] = component.getAdaptee(); - // - // } - return elements; - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { - // don't create any change now, all the changes are in changeManger - // variable and will be combined in postCreateChange method - return null; - } - - private TextChangeManager updateChangeManager(IProgressMonitor pm, RefactoringStatus status) throws CoreException { - TextChangeManager manager = getChangeManager(); - // only one declaration gets updated - addDeclarationUpdate(manager); - if (getUpdateReferences()) { - addOccurrences(manager, pm, status); - } - return manager; - } - - private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException { - Assert.isNotNull(monitor); - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask(RefactoringMessages.getString("RenameComponentRefactoring_searching"), 1); //$NON-NLS-1$ - updateChangeManager(new SubProgressMonitor(monitor, 1), status); - } - finally { - monitor.done(); - } - return status; - } - - public TextChangeManager getChangeManager() { - - if (changeManager == null) { - changeManager = new TextChangeManager(false); - } - return changeManager; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#getAffectedProjectNatures() - */ - protected String[] getAffectedProjectNatures() throws CoreException { - // TODO: find project natures of the files that are going to be - // refactored - return new String[]{"org.eclipse.jdt.core.javanature"}; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#getCurrentElementName() - */ - public String getCurrentElementName() { - // - return selectedComponent.getName(); - } - - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements() - */ - public Object[] getElements() { - Object model = selectedComponent.getModelObject(); - if (model != null) { - return new Object[]{model}; - } - return new Object[0]; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier() - */ - public String getIdentifier() { - return IDENTIFIER; - } - - public String getNewElementName() { - return newName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName() - */ - public String getProcessorName() { - return RefactoringMessages.getFormattedString("RenameComponentRefactoring.name", //$NON-NLS-1$ - new String[]{selectedComponent.getNamespaceURI() + ":" + selectedComponent.getName(), newName}); - - } - - - public boolean getUpdateReferences() { - return updateReferences; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable() - */ - public boolean isApplicable() throws CoreException { - if (selectedComponent == null) - return false; - // TODO implement isApplicable logic for the named component, - // verify how it is different from other condition checks - // if (fNamedComponent.isAnonymous()) - // return false; - // if (! Checks.isAvailable(fType)) - // return false; - // if (isSpecialCase(fType)) - // return false; - return true; - } - - protected void loadDerivedParticipants(RefactoringStatus status, List result, Object[] derivedElements, ComponentRenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - if (derivedElements != null) { - for (int i = 0; i < derivedElements.length; i++) { - RenameParticipant[] participants = ParticipantManager.loadRenameParticipants(status, this, derivedElements[i], arguments, natures, shared); - result.addAll(Arrays.asList(participants)); - } - } - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#loadDerivedParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus, - * java.util.List, java.lang.String[], - * org.eclipse.ltk.core.refactoring.participants.SharableParticipants) - */ - protected void loadDerivedParticipants(RefactoringStatus status, List result, String[] natures, SharableParticipants shared) throws CoreException { - ComponentRenameArguments arguments = new ComponentRenameArguments(getNewElementName(), getUpdateReferences()); - arguments.setMatches(references); - arguments.setQualifier(selectedComponent.getNamespaceURI()); - // pass in changeManger to the participants so that it can collect all - // changes/per files - arguments.setChangeManager(getChangeManager()); - loadDerivedParticipants(status, result, computeDerivedElements(), arguments, natures, shared); - } - - protected void loadElementParticipants(RefactoringStatus status, List result, RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - Object[] elements = new Object[0];// getElements(); - for (int i = 0; i < elements.length; i++) { - result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, this, elements[i], arguments, natures, shared))); - } - } - - - public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException { - RenameArguments arguments = new RenameArguments(getNewElementName(), getUpdateReferences()); - String[] natures = getAffectedProjectNatures(); - List result = new ArrayList(); - loadElementParticipants(status, result, arguments, natures, sharedParticipants); - loadDerivedParticipants(status, result, natures, sharedParticipants); - for (Iterator i = result.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof XMLComponentRenameParticipant) { - XMLComponentRenameParticipant p = (XMLComponentRenameParticipant) o; - // getChangeManager() - p.setChangeManager(getChangeManager()); - } - } - - return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]); - } - - public void setNewElementName(String newName) { - Assert.isNotNull(newName); - this.newName = newName; - } - - public void setUpdateReferences(boolean update) { - updateReferences = update; - - } - - public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException, OperationCanceledException { - Assert.isNotNull(pm); - try { - String changeName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_updates"); - TextChange[] changes = changeManager.getAllChanges(); -// Comparator c = new Comparator() { -// public int compare(Object o1, Object o2) { -// TextFileChange c1 = (TextFileChange) o1; -// TextFileChange c2 = (TextFileChange) o2; -// return Collator.getInstance().compare(c1.getFile().getFullPath(), c2.getFile().getFullPath()); -// } -// }; - if (changes.length > 0) { - // Arrays.sort(changes, c); - CompositeChange compositeChange = new CompositeChange("!" + changeName, changes); - compositeChange.markAsSynthetic(); - return compositeChange; - } - else { - return null; - } - - } - finally { - pm.done(); - } - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java deleted file mode 100644 index e817083664..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; - -public class RenameResourceProcessor extends RenameProcessor implements INameUpdating { - - private IResource fResource; - private String fNewElementName; - - public static final String IDENTIFIER= "org.eclipse.wst.ui.xsd.renameResourceProcessor"; //$NON-NLS-1$ - - public RenameResourceProcessor(IResource resource) { - fResource= resource; - if (fResource != null) { - setNewElementName(fResource.getName()); - } - } - - //---- INameUpdating --------------------------------------------------- - - public void setNewElementName(String newName) { - Assert.isNotNull(newName); - fNewElementName= newName; - } - - public String getNewElementName() { - return fNewElementName; - } - - //---- IRenameProcessor methods --------------------------------------- - - public String getIdentifier() { - return IDENTIFIER; - } - - public boolean isApplicable() { - if (fResource == null) - return false; - if (! fResource.exists()) - return false; - if (! fResource.isAccessible()) - return false; - return true; - } - - public String getProcessorName() { - String message= RefactoringMessages.getFormattedString("RenameResourceProcessor.name", //$NON-NLS-1$ - new String[]{getCurrentElementName(), getNewElementName()}); - return message; - } - - public Object[] getElements() { - return new Object[] {fResource}; - } - - public String getCurrentElementName() { - return fResource.getName(); - } - - public String[] getAffectedProjectNatures() throws CoreException { - return new String[0]; - } - - public Object getNewElement() { - - - return ResourcesPlugin.getWorkspace().getRoot().findMember(createNewPath(getNewElementName())); - } - - public boolean getUpdateReferences() { - return true; - } - - public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException { - Object[] elements= getElements(); - String[] natures= getAffectedProjectNatures(); - List result= new ArrayList(); - RenameArguments arguments= new RenameArguments(getNewElementName(), getUpdateReferences()); - for (int i= 0; i < elements.length; i++) { - result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, - this, elements[i], - arguments, natures, shared))); - } - return (RefactoringParticipant[])result.toArray(new RefactoringParticipant[result.size()]); - } - - //--- Condition checking -------------------------------------------- - - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { - return new RefactoringStatus(); - } - - /* non java-doc - * @see IRenameRefactoring#checkNewName() - */ - public RefactoringStatus checkNewElementName(String newName) { - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - IContainer c= fResource.getParent(); - if (c == null) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.Internal_Error")); //$NON-NLS-1$ - - if (c.findMember(newName) != null) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.alread_exists")); //$NON-NLS-1$ - - if (!c.getFullPath().isValidSegment(newName)) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.invalidName")); //$NON-NLS-1$ - - RefactoringStatus result= RefactoringStatus.create(c.getWorkspace().validateName(newName, fResource.getType())); - if (! result.hasFatalError()) - result.merge(RefactoringStatus.create(c.getWorkspace().validatePath(createNewPath(newName), fResource.getType()))); - return result; - } - - /* non java-doc - * @see Refactoring#checkInput(IProgressMonitor) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) { - pm.beginTask("", 1); //$NON-NLS-1$ - try{ - return new RefactoringStatus(); - } finally{ - pm.done(); - } - } - - private String createNewPath(String newName){ - return fResource.getFullPath().removeLastSegments(1).append(newName).toString(); - } - - //--- changes - - /* non java-doc - * @see IRefactoring#createChange(IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) { - pm.beginTask("", 1); //$NON-NLS-1$ - try{ - return new ResourceRenameChange(fResource, getNewElementName()); - } finally{ - pm.done(); - } - } -} - diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java deleted file mode 100644 index 4cd3c85c65..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.IReferenceUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.xsd.XSDSchema; - - -public class RenameTargetNamespaceProcessor extends RenameProcessor implements INameUpdating, IReferenceUpdating -{ - private String newNamespace; - private boolean updateReferences = true; - private TextChangeManager changeManager; - private XSDSchema model; - - - public static final String IDENTIFIER = "org.eclipse.wst.ui.xsd.renameComponentProcessor"; //$NON-NLS-1$ - - public RenameTargetNamespaceProcessor(XSDSchema model, String newName) - { - this.model = model; - this.newNamespace = newName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating() - */ - public boolean canEnableTextUpdating() - { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#getCurrentElementName() - */ - public String getCurrentElementName() - { - // - return model.getTargetNamespace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#getAffectedProjectNatures() - */ - protected String[] getAffectedProjectNatures() throws CoreException - { - // TODO: find project natures of the files that are going to be - // refactored - return new String[]{"org.eclipse.jdt.core.javanature"}; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#loadDerivedParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus, - * java.util.List, java.lang.String[], - * org.eclipse.ltk.core.refactoring.participants.SharableParticipants) - */ - protected void loadDerivedParticipants(RefactoringStatus status, - List result, String[] natures, SharableParticipants shared) - throws CoreException - { - String newCUName= getNewElementName(); //$NON-NLS-1$ - RenameArguments arguments= new RenameArguments(newCUName, getUpdateReferences()); - loadDerivedParticipants(status, result, - computeDerivedElements(), arguments, - natures, shared); - } - - protected void loadDerivedParticipants(RefactoringStatus status, List result, Object[] derivedElements, - RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - if (derivedElements != null) { - for (int i= 0; i < derivedElements.length; i++) { - RenameParticipant[] participants= ParticipantManager.loadRenameParticipants(status, - this, derivedElements[i], - arguments, natures, shared); - result.addAll(Arrays.asList(participants)); - } - } - - } - - private Object[] computeDerivedElements() { - - Object[] elements = getElements(); - Object[] results = new Object[elements.length]; - for(int i=0; i< elements.length; i++){ - RefactoringComponent component = (RefactoringComponent)elements[i]; - results[i] = component.getModelObject(); - - } - return results; - - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, - * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor pm, - CheckConditionsContext context) throws CoreException, - OperationCanceledException - { - try - { - RefactoringStatus result = new RefactoringStatus(); - pm.beginTask("", 9); //$NON-NLS-1$ - changeManager = createChangeManager(new SubProgressMonitor(pm, 1), - result); - return result; - } finally - { - pm.done(); - } - - - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) - throws CoreException, OperationCanceledException - { - // TODO add code to check initial conditions for component rename - return new RefactoringStatus(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException - { - try - { - String changeName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_updates"); - return new CompositeChange(changeName, changeManager.getAllChanges()); - } finally - { - pm.done(); - } - - // Change[] changes = ComponentRenameChange.createChangesFor( - // this.fNamedComponent, getNewElementName()); - // - // if (changes.length > 0) - // { - // CompositeChange multiChange = null; - // multiChange = new CompositeChange( - // "XSD component rename participant changes", changes); //$NON-NLS-1$ - // TODO: externalize string - // return multiChange; - // } else - // { - // - // return new ComponentRenameChange( - // fNamedComponent, - // fNamedComponent.getName(), - // getNewElementName(), - // fNamedComponent.getSchema()); - // } - - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements() - */ - public Object[] getElements() - { - return new Object[] { model }; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier() - */ - public String getIdentifier() - { - return IDENTIFIER; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName() - */ - public String getProcessorName() - { - return RefactoringMessages.getFormattedString( - "RenameComponentRefactoring.name", //$NON-NLS-1$ - new String[] - { - getCurrentElementName(), - getNewElementName() }); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable() - */ - public boolean isApplicable() throws CoreException - { - if (getModel() == null) - return false; - // TODO implement isApplicable logic for the named component, - // verify how it is different from other condition checks - // if (fNamedComponent.isAnonymous()) - // return false; - // if (! Checks.isAvailable(fType)) - // return false; - // if (isSpecialCase(fType)) - // return false; - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#checkNewElementName(java.lang.String) - */ - public RefactoringStatus checkNewElementName(String newName) - { - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - // TODO: implement new name checking - // RefactoringStatus result = Checks.checkTypeName(newName); - // if (Checks.isAlreadyNamed(fType, newName)) - // result.addFatalError(RefactoringCoreMessages.getString("RenameTypeRefactoring.choose_another_name")); - // //$NON-NLS-1$ - return new RefactoringStatus(); - } - - public final RefactoringParticipant[] loadParticipants( - RefactoringStatus status, SharableParticipants sharedParticipants) - throws CoreException - { - RenameArguments arguments = new RenameArguments(getNewElementName(), - true); - String[] natures = getAffectedProjectNatures(); - List result = new ArrayList(); - loadElementParticipants(status, result, arguments, natures, - sharedParticipants); - loadDerivedParticipants(status, result, natures, sharedParticipants); - return (RefactoringParticipant[]) result - .toArray(new RefactoringParticipant[result.size()]); - } - - protected void loadElementParticipants(RefactoringStatus status, - List result, RenameArguments arguments, String[] natures, - SharableParticipants shared) throws CoreException - { - Object[] elements = getElements(); - for (int i = 0; i < elements.length; i++) - { - result.addAll(Arrays.asList(ParticipantManager - .loadRenameParticipants(status, this, elements[i], - arguments, natures, shared))); - } - } - - private TextChangeManager createChangeManager(IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { - TextChangeManager manager = new TextChangeManager(false); - // only one declaration gets updated - addDeclarationUpdate(manager); - return manager; - } - - private void addDeclarationUpdate(TextChangeManager manager) - - { - String fileStr = getModel().getSchemaLocation(); - URI uri = URI.createPlatformResourceURI(fileStr); - try - { - URL url = new URL(uri.toString()); - url = Platform.resolve(url); - if(url != null){ - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = root.getFileForLocation(new Path(url.getFile())); - if(file != null ){ - TextChange change = manager.get(file); - addDeclarationUpdate(change); - } - } - } catch (MalformedURLException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - - - - final void addDeclarationUpdate(TextChange change) - { -// String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_declatation");; -// -// NamedComponentRenamer renamer = new NamedComponentRenamer( -// selectedComponent.getElement(), newNamespace); -// renamer.renameComponent(); -// List textEdits = renamer.getTextEdits(); -// for (int j = 0; j < textEdits.size(); j++) -// { -// ReplaceEdit replaceEdit = (ReplaceEdit) textEdits -// .get(j); -// TextChangeCompatibility.addTextEdit(change, -// editName, replaceEdit); -// } - } - - public void setNewElementName(String newName) - { - this.newNamespace = newName; - } - - public String getNewElementName() - { - return newNamespace; - } - - - - public boolean canEnableUpdateReferences() - { - return true; - } - - public boolean getUpdateReferences() - { - return updateReferences; - } - - public void setUpdateReferences(boolean update) - { - updateReferences = update; - - } - - public final TextChangeManager getChangeManager() - { - return changeManager; - } - - public final XSDSchema getModel() - { - return model; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java deleted file mode 100644 index e213e2af3b..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; - -/** - * Represents a change that renames a given resource - */ -public class ResourceRenameChange extends Change { - - /* - * we cannot use handles because they became invalid when you rename the resource. - * paths do not. - */ - private IPath fResourcePath; - - private String fNewName; - - /** - * @param newName includes the extension - */ - public ResourceRenameChange(IResource resource, String newName) { - this(resource.getFullPath(), newName); - } - - private ResourceRenameChange(IPath resourcePath, String newName) { - fResourcePath= resourcePath; - fNewName= newName; - } - - private IResource getResource() { - return ResourcesPlugin.getWorkspace().getRoot().findMember(fResourcePath); - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - - // TODO: implement file validation, see JDTChange - return new RefactoringStatus(); - } - - /* - * to avoid the exception senders should check if a resource with the new name - * already exists - */ - public Change perform(IProgressMonitor pm) throws CoreException { - try { - pm.beginTask(RefactoringMessages.getString("XSDRenameResourceChange.rename_resource"), 1); //$NON-NLS-1$ - - getResource().move(renamedResourcePath(fResourcePath, fNewName), getCoreRenameFlags(), pm); - - String oldName= fResourcePath.lastSegment(); - IPath newPath= renamedResourcePath(fResourcePath, fNewName); - return new ResourceRenameChange(newPath, oldName); - } finally { - pm.done(); - } - } - - private int getCoreRenameFlags() { - if (getResource().isLinked()) - return IResource.SHALLOW; - else - return IResource.NONE; - } - - /* - * changes resource names /s/p/A.java renamed to B.java becomes /s/p/B.java - */ - public static IPath renamedResourcePath(IPath path, String newName) { - return path.removeLastSegments(1).append(newName); - } - - public String getName() { - return RefactoringMessages.getFormattedString( - "XSDRenameResourceChange.name", new String[]{fResourcePath.toString(), //$NON-NLS-1$ - renamedResourcePath(fResourcePath, fNewName).toString()}); - } - - public Object getModifiedElement() { - return getResource(); - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor) - */ - public void initializeValidationData(IProgressMonitor pm) { - // TODO Auto-generated method stub - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java deleted file mode 100644 index ec2bf8e350..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; - -/** - * This rename participant creates text changes for the references of the XSD and WSDL files - */ -public class ResourceRenameParticipant extends RenameParticipant { - -// private IFile file = null; - private TextChangeManager changeManager; - - - private static String XSD_CONTENT_TYPE_ID = "org.eclipse.wst.xsd.core.xsdsource"; - private static String WSDL_CONTENT_TYPE_ID = "org.eclipse.wst.wsdl.wsdlsource"; - - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - if(element instanceof IFile) { - // check if file has XSD or WSDL content - IFile aFile = (IFile) element; - try { - IContentDescription description = aFile.getContentDescription(); - if ( description == null ) - return false; - IContentType contentType = description.getContentType(); - if(contentType != null){ - if(XSD_CONTENT_TYPE_ID.equals(contentType.getId()) || - WSDL_CONTENT_TYPE_ID.equals(contentType.getId())){ -// file = aFile; - return true; - } - } - } catch (CoreException e) { - return false; - } - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - return RefactoringMessages.getString("ResourceRenameParticipant.compositeChangeName"); - } - -// private IPath getNewFilePath() { -// -// IPath oldPath = file.getRawLocation(); -// IPath newPath = oldPath.removeLastSegments(1).append(getArguments().getNewName()); -// return newPath; -// } - - public RefactoringStatus checkConditions(IProgressMonitor pm, - CheckConditionsContext context) throws OperationCanceledException - { - RefactoringStatus result = new RefactoringStatus(); - try - { - pm.beginTask("", 9); //$NON-NLS-1$ - changeManager = createChangeManager(new SubProgressMonitor(pm, 1), - result); - - } catch(CoreException e){ - result.addFatalError(e.toString()); - } - finally - { - pm.done(); - } - return result; - - } - - - - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException - { - try - { - String changeName = RefactoringMessages.getString("RenameResourceChange.rename_resource_reference_change"); - TextChange[] changes = changeManager.getAllChanges(); - if(changes.length > 0){ - return new CompositeChange(changeName, changes); - } - else{ - return null; - } - - } finally - { - pm.done(); - } - - } - - - private TextChangeManager createChangeManager(IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { - TextChangeManager manager = new TextChangeManager(false); - // only one declaration gets updated - //addDeclarationUpdate(manager); - if (getArguments().getUpdateReferences()) - addOccurrences(manager, pm, status); - return manager; - } - - - - void addOccurrences(TextChangeManager manager, IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { -// -// Object[] occurrences = SearchTools.getFileDependencies(file); -// pm.beginTask("", occurrences.length); //$NON-NLS-1$ -// -// for (int i = 0; i < occurrences.length; i++) -// { -// Object object = occurrences[i]; -// -// if (object instanceof SearchResultGroup) -// { -// SearchResultGroup searchResult = (SearchResultGroup) object; -// if (searchResult == null) -// continue; -// -// IFile referencingFile = (IFile)searchResult.getResource(); -// -// resourceSet = new ResourceSetImpl(); -// // for each result file create XSD model and get component from that model -// resourceSet.getAdapterFactories().add( -// new XSDSchemaLocationResolverAdapterFactory()); -// URI uri = URI.createFileURI(referencingFile.getLocation().toPortableString()); -// try -// { -// XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema(); -// IStructuredModel structuredModel = StructuredModelManager.getModelManager().getModelForRead(referencingFile); -// IDOMModel domModel = (IDOMModel) structuredModel; -// Resource resource = new XSDResourceImpl(); -// resource.setURI(uri); -// schema = XSDFactory.eINSTANCE.createXSDSchema(); -// resource.getContents().add(schema); -// resourceSet.getResources().add(resource); -// schema.setElement(domModel.getDocument().getDocumentElement()); -// // get target namespace -// String stringPath = file.getLocation().toString(); -// String targetNamespace = XMLQuickScan.getTargetNamespace(stringPath); -// targetNamespace = targetNamespace == null ? "" : targetNamespace; -// -// List textEdits = new ArrayList(); -// SearchMatch[] matches = searchResult.getSearchResults(); -// -// for (int j = 0; j < matches.length; j++) { -// SearchMatch match = matches[j]; -// -// FileReferenceRenamer renamer = new FileReferenceRenamer( -// match.getAttrValue(), targetNamespace, getNewFilePath().toString(), schema); -// renamer.visitSchema(schema); -// textEdits.addAll(renamer.getTextEdits()); -// } -// -// -// if(!textEdits.isEmpty()){ -// TextChange textChange = manager.get(referencingFile); -// for (int j = 0; j < textEdits.size(); j++) -// { -// ReplaceEdit replaceEdit = (ReplaceEdit) textEdits -// .get(j); -// String editName = RefactoringMessages.getString("ResourceRenameParticipant.File_Rename_update_reference"); -// TextChangeCompatibility.addTextEdit(textChange, -// editName, replaceEdit); -// } -// } -// -// } catch (Exception e) -// { -// e.printStackTrace(); -// } finally -// { -// -// } -// } -// } - } - - - public class ReferenceLocationFinder - { - protected XSDNamedComponent component; - protected String name; - protected XSDSchema referencingSchema; - protected List results = new ArrayList(); - - public ReferenceLocationFinder(XSDNamedComponent component, - String name, XSDSchema referencingSchema) - { - this.component = component; - this.name = name; - this.referencingSchema = referencingSchema; - } - - public void run() - { - - //XSDSwitch xsdSwitch = new XSDSwitch() -// { -// public Object caseXSDTypeDefinition(XSDTypeDefinition object) -// { -// GlobalTypeReferenceRenamer renamer = new GlobalTypeReferenceRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// results.addAll(renamer.getTextEdits()); -// return null; -// } -// -// public Object caseXSDElementDeclaration( -// XSDElementDeclaration object) -// { -// if (object.isGlobal()) -// { -// GlobalElementRenamer renamer = new GlobalElementRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// results.addAll(renamer.getTextEdits()); -// } -// return null; -// } -// -// public Object caseXSDModelGroupDefinition( -// XSDModelGroupDefinition object) -// { -// GlobalGroupRenamer renamer = new GlobalGroupRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// return null; -// } -// }; - //xsdSwitch.doSwitch(component); -// component.setName(name); -// try -// { -// referencingSchema.eResource().save(new HashMap()); -// } catch (IOException e) -// { -// e.printStackTrace(); -// } - - } - - public final List getResults() - { - return results; - } - } - - - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java deleted file mode 100644 index d140a8c9e5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.SearchRequestor; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class SortingSearchRequestor extends SearchRequestor { - - public static String NONAMESPACE = "nonamespace"; - - - private Map fFound; - - public SortingSearchRequestor() { - fFound= new HashMap(); - } - - - - /** - * @return a List of {@link SearchMatch}es (sorted by namespace) - */ - public Map/* namespace - <SearchMatch>*/ getResults() { - return fFound; - } - - - - /* (non-Javadoc) - * @see org.eclipse.wst.common.core.search.internal.provisional.SearchRequestor#acceptSearchMatch(org.eclipse.wst.common.search.internal.provisional.SearchMatch) - */ - public void acceptSearchMatch(SearchMatch match) throws CoreException { - - - if(match != null && match.getObject() instanceof Node){ - Node node = (Node)match.getObject(); - Element domElement = null; - switch (node.getNodeType()) { - case Node.ATTRIBUTE_NODE: - domElement = ((Attr)node).getOwnerElement(); - break; - case Node.ELEMENT_NODE: - domElement = ((Element)node); - break; - default: - break; - } - String namespace = domElement.getNamespaceURI(); - if(namespace == null || namespace.equals("")){ - namespace = NONAMESPACE; - } - List matches = getMatches(namespace); - matches.add(match); - } - - } - - private List getMatches(String namespace){ - Object matches = fFound.get(namespace); - if(!(matches instanceof List)){ - matches = new ArrayList(); - fFound.put(namespace, matches); - } - return (List)matches; - - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java deleted file mode 100644 index 4aba3206ff..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.Iterator; -import java.util.List; - -//import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -//import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.wst.xsd.ui.internal.refactor.util.TextChangeCompatibility; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Node; - -public class XMLComponentRenameParticipant extends RenameParticipant { - - protected SearchMatch match; - - protected TextChangeManager changeManager; - protected List matches; - - - - protected boolean initialize(Object element) { - - if(getArguments() instanceof ComponentRenameArguments){ - // changeManger is passed in from the RenameComponentProcessor to collect all the changes - changeManager = ((ComponentRenameArguments)getArguments()).getChangeManager(); - } - - return false; - } - - public String getName() { - return "XML Component Rename Participant"; - } - - public RefactoringStatus checkConditions(IProgressMonitor monitor, - CheckConditionsContext context) throws OperationCanceledException { - return null; - } - - public TextChangeManager getChangeManager(){ - - if(changeManager == null){ - changeManager = new TextChangeManager(false); - } - return changeManager; - - } - -// private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException { -// Assert.isNotNull(monitor); -// final RefactoringStatus status= new RefactoringStatus(); -// try { -// monitor.beginTask("RefactoringMessages.RenameComponentRefactoring_searching", 1); -// createRenameChanges(new SubProgressMonitor(monitor, 1)); -// //updateChangeManager(new SubProgressMonitor(monitor, 1), status); -// } finally { -// monitor.done(); -// } -// return status; -// } - - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException { - for (Iterator iter = matches.iterator(); iter.hasNext();) { - SearchMatch match = (SearchMatch) iter.next(); - TextChange textChange = getChangeManager().get(match.getFile()); - String newName = getArguments().getNewName(); - String qualifier = ""; - if(getArguments() instanceof ComponentRenameArguments){ - qualifier = ((ComponentRenameArguments)getArguments()).getQualifier(); - } - if(match.getObject() instanceof Node){ - Node node = (Node)match.getObject(); - if(node instanceof IDOMAttr){ - IDOMAttr attr = (IDOMAttr)node; - IDOMElement element = (IDOMElement)attr.getOwnerElement() ; - newName = getNewQName(element, qualifier, newName); - } - newName = RenameComponentProcessor.quoteString(newName); - } - - ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName ); - String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference"); - TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit); - } - // don't create any change now, all the changes are in changeManger variable and will be combined in RenameComponentProcessor.postCreateChange method - return null; - } - - private static String getNewQName(Node node, String targetNamespace, String newName) { - StringBuffer sb = new StringBuffer(); - if (newName != null) { - String prefix = XSDConstants.lookupQualifier(node, targetNamespace); - if (prefix != null && prefix.length() > 0) { - sb.append(prefix); - sb.append(":"); - sb.append(newName); - } else { - sb.append(newName); - } - } else { - sb.append(newName); - } - - return sb.toString(); - } - - public void setChangeManager(TextChangeManager changeManager) - { - this.changeManager = changeManager; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java deleted file mode 100644 index 3d169fdd79..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.List; -import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants; -import org.eclipse.xsd.XSDNamedComponent; - -/** - * This participant takes case of renaming matches that are XSD components - */ -public class XSDComponentRenameParticipant extends XMLComponentRenameParticipant { - -protected boolean initialize(Object element) { - super.initialize(element); - if(element instanceof XSDNamedComponent){ - if(getArguments() instanceof ComponentRenameArguments){ - matches = (List)((ComponentRenameArguments)getArguments()).getMatches().get(IXSDSearchConstants.XMLSCHEMA_NAMESPACE); - } - if(matches != null){ - return true; - } - } - return false; - } - - public String getName() { - - return "XSD component rename participant"; - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/AbstractCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/AbstractCommand.java deleted file mode 100644 index a39ebafae5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/AbstractCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.structure; - -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; -import org.eclipse.xsd.XSDConcreteComponent; -import org.w3c.dom.Element; - -public abstract class AbstractCommand -{ - private XSDConcreteComponent parent; - private XSDConcreteComponent model; - - protected AbstractCommand(XSDConcreteComponent parent) - { - this.parent = parent; - } - - public abstract void run(); - - protected XSDConcreteComponent getParent() - { - return parent; - } - - public XSDConcreteComponent getModelObject() - { - return model; - } - - protected void setModelObject(XSDConcreteComponent model) - { - this.model = model; - } - - // Establish part-whole relationship - protected abstract boolean adopt(XSDConcreteComponent model); - - protected void formatChild(Element child) - { - if (child instanceof IDOMNode) - { - IDOMModel model = ((IDOMNode)child).getModel(); - try - { - // tell the model that we are about to make a big model change - model.aboutToChangeModel(); - - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(child); - } - finally - { - // tell the model that we are done with the big model change - model.changedModel(); - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeAnonymousTypeGlobalCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeAnonymousTypeGlobalCommand.java deleted file mode 100644 index d9fc1b022c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeAnonymousTypeGlobalCommand.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.structure; - -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; - -public final class MakeAnonymousTypeGlobalCommand extends AbstractCommand { - - String fNewName; - - public MakeAnonymousTypeGlobalCommand(XSDConcreteComponent element, - String newName) { - super(element.getContainer()); - setModelObject(element); - fNewName = newName; - } - - public void run() { - XSDConcreteComponent model = getModelObject(); - XSDConcreteComponent parent = model.getContainer(); - XSDTypeDefinition globalTypeDef = null; - if (model instanceof XSDComplexTypeDefinition) { - if (parent instanceof XSDElementDeclaration) { - // clone typedef with it's content and set it global - globalTypeDef = (XSDComplexTypeDefinition) model - .cloneConcreteComponent(true, false); - globalTypeDef.setName(fNewName); - parent.getSchema().getContents().add(globalTypeDef); - ((XSDElementDeclaration) parent) - .setTypeDefinition(globalTypeDef); - } - } else if (model instanceof XSDSimpleTypeDefinition) { - - XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) model; - if (parent instanceof XSDElementDeclaration) { - // clone typedef with it's content and set it global - globalTypeDef = (XSDSimpleTypeDefinition) typeDef - .cloneConcreteComponent(true, false); - globalTypeDef.setName(fNewName); - parent.getSchema().getContents().add(globalTypeDef); - ((XSDElementDeclaration) parent) - .setTypeDefinition(globalTypeDef); - formatChild(globalTypeDef.getElement()); - - } else if (parent instanceof XSDAttributeDeclaration) { - // clone typedef with it's content and set it global - globalTypeDef = (XSDSimpleTypeDefinition) typeDef - .cloneConcreteComponent(true, false); - globalTypeDef.setName(fNewName); - parent.getSchema().getContents().add(globalTypeDef); - ((XSDAttributeDeclaration) parent) - .setTypeDefinition((XSDSimpleTypeDefinition) globalTypeDef); - - } - - } - - formatChild(globalTypeDef.getElement()); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.ui.internal.commands.AbstractCommand#adopt(org.eclipse.xsd.XSDConcreteComponent) - */ - protected boolean adopt(XSDConcreteComponent model) { - // TODO Auto-generated method stub - return true; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeLocalElementGlobalCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeLocalElementGlobalCommand.java deleted file mode 100644 index d7eb8a7177..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeLocalElementGlobalCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.structure; - - -import org.eclipse.emf.common.util.EList; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDSchema; - - -public final class MakeLocalElementGlobalCommand extends AbstractCommand -{ - public MakeLocalElementGlobalCommand(XSDConcreteComponent element) - { - super(element.getContainer()); - setModelObject(element); - } - - public void run() - { - if (getModelObject() instanceof XSDElementDeclaration) - { - - XSDElementDeclaration localElementDeclaration = (XSDElementDeclaration)getModelObject(); - XSDConcreteComponent parent = getParent(); - XSDConcreteComponent container = parent.getContainer(); - - // Clone the local element with its content and set it global - - XSDElementDeclaration globalElementDeclaration = (XSDElementDeclaration)localElementDeclaration.cloneConcreteComponent(true, false); - - // The schema may already have a global element declaration with this name. In that case, ensure the name of the newly created - // element does not collide with an existing one. - - XSDSchema schema = container.getSchema(); - String localElementName = localElementDeclaration.getName(); - XSDElementDeclaration existingGlobalElement = schema.resolveElementDeclaration(localElementName); - boolean elementExists = existingGlobalElement != null && existingGlobalElement.getSchema() != null; - if (elementExists) - { - String newElementName = XSDCommonUIUtils.createUniqueElementName(localElementName, schema.getElementDeclarations()); - globalElementDeclaration.setName(newElementName); - } - - EList schemaContents = schema.getContents(); - schemaContents.add(globalElementDeclaration); - - // Modify the local element to become a reference to the global element. - - localElementDeclaration.setName(null); - localElementDeclaration.setTypeDefinition(null); - localElementDeclaration.setAnonymousTypeDefinition(null); - localElementDeclaration.setResolvedElementDeclaration(globalElementDeclaration); - XSDModelGroup modelGroup = (XSDModelGroup)container; - - // Format the markup. - - formatChild(modelGroup.getElement()); - formatChild(globalElementDeclaration.getElement()); - } - } - - /* (non-Javadoc) - * @see org.eclipse.wst.xsd.ui.internal.commands.AbstractCommand#adopt(org.eclipse.xsd.XSDConcreteComponent) - */ - protected boolean adopt(XSDConcreteComponent model) - { - return true; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalChange.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalChange.java deleted file mode 100644 index 23b1d23b88..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalChange.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.structure; - -import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.text.Assert; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.TextFileChange; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.xsd.XSDTypeDefinition; - -/** - * @author ebelisar - * - */ -public class MakeTypeGlobalChange extends Change { - - private Map fChanges; - - private String fNewName; - - private XSDTypeDefinition fTypeComponent; - - public MakeTypeGlobalChange(XSDTypeDefinition component, - String newName) { - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - - fTypeComponent = component; - fNewName = newName; - } - - // public static Change[] createChangesFor(XSDNamedComponent component, - // String newName) { - // // TODO: P1 implement search of XSD files - // XSDSearchSupport support = XSDSearchSupport.getInstance(); - // RefactorSearchRequestor requestor = new - // RefactorSearchRequestor(component, newName); - // support.searchRunnable(component, IXSDSearchConstants.WORKSPACE_SCOPE, - // requestor); - // - // return requestor.getChanges(); - // - // } - - protected Change createUndoChange() { - return new MakeTypeGlobalChange(fTypeComponent, getNewName()); - } - - protected void doRename(IProgressMonitor pm) throws CoreException { - // TODO P1 change temporary rename of XSD model components - performModify(getNewName()); - } - - public void performModify(final String value) { -// DelayedRenameRunnable runnable = new DelayedRenameRunnable( -// fTypeComponent, value); - // TODO: remove Display - //Display.getCurrent().asyncExec(runnable); - } - - protected static class DelayedRenameRunnable implements Runnable { - protected XSDTypeDefinition component; - - protected String name; - - public DelayedRenameRunnable(XSDTypeDefinition component, String name) { - this.component = component; - this.name = name; - } - - public void run() { - DocumentImpl doc = (DocumentImpl) component.getElement().getOwnerDocument(); - doc.getModel().beginRecording( - this, - RefactoringMessages - .getString("_UI_ACTION_MAKE_ANONYMOUS_TYPE_GLOBAL")); - MakeAnonymousTypeGlobalCommand command = new MakeAnonymousTypeGlobalCommand( - component, name); - command.run(); - doc.getModel().endRecording(this); - } - } - - public TextChange getChange(IFile file) { - TextChange result = (TextChange) fChanges.get(file); - if (result == null) { - result = new TextFileChange(file.getName(), file); - fChanges.put(file, result); - } - return result; - } - - public String getName() { - return RefactoringMessages - .getFormattedString( - "MakeTypeGlobalChange.name", new String[] {getNewName() }); //$NON-NLS-1$ - } - - public final Change perform(IProgressMonitor pm) throws CoreException { - try { - pm.beginTask(RefactoringMessages - .getString("XSDComponentRenameChange.Renaming"), 1); //$NON-NLS-1$ - Change result = createUndoChange(); - doRename(new SubProgressMonitor(pm, 1)); - return result; - } finally { - pm.done(); - } - } - - /** - * Gets the newName. - * - * @return Returns a String - */ - protected String getNewName() { - return fNewName; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement() - */ - public Object getModifiedElement() { - // TODO Auto-generated method stub - return fTypeComponent; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor) - */ - public void initializeValidationData(IProgressMonitor pm) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, - OperationCanceledException { - // TODO implement change validation - return new RefactoringStatus(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalProcessor.java deleted file mode 100644 index 0b793f3716..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/structure/MakeTypeGlobalProcessor.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.structure; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.xsd.XSDTypeDefinition; - -public class MakeTypeGlobalProcessor extends RenameProcessor implements INameUpdating{ - - private XSDTypeDefinition fTypeComponent; - private String fNewElementName; - - public static final String IDENTIFIER= "org.eclipse.wst.ui.xsd.makeTypeGlobalProcessor"; //$NON-NLS-1$ - - //private QualifiedNameSearchResult fNameSearchResult; - - public MakeTypeGlobalProcessor(XSDTypeDefinition element, String newName) { - fTypeComponent= element; - fNewElementName = newName; - - } - - public XSDTypeDefinition getTypeComponent() { - return fTypeComponent; - } - - - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating() - */ - public boolean canEnableTextUpdating() { - return true; - } - - protected String[] getAffectedProjectNatures() throws CoreException { - //TODO: find project natures of the files that are going to be refactored - return new String[0]; - } - - protected void loadDerivedParticipants(RefactoringStatus status, - List result, String[] natures, SharableParticipants shared) - throws CoreException { - // TODO: provide a way to load rename participants - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor pm, - CheckConditionsContext context) throws CoreException, - OperationCanceledException { - // TODO add code to check final conditions for component rename - return new RefactoringStatus(); - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) - throws CoreException, OperationCanceledException { -// TODO add code to check initial conditions for component rename - return new RefactoringStatus(); - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException { - // TODO P1 add change creation -// Change[] changes = XSDComponentRenameChange.createChangesFor(this.fNamedComponent, getNewElementName()); -// CompositeChange multiChange = null; -// if(changes.length > 0) -// multiChange = new CompositeChange("XSD component rename participant changes", changes); //$NON-NLS-1$ TODO: externalize string -// return multiChange; - -// computeNameMatches(pm); -// Change[] changes = fNameSearchResult.getAllChanges(); -// return new CompositeChange("XSD file rename participant changes", changes); //TODO: externalize string - pm.beginTask("", 1); //$NON-NLS-1$ - try{ - return new MakeTypeGlobalChange(fTypeComponent, getNewElementName()); - } finally{ - pm.done(); - } - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements() - */ - public Object[] getElements() { - - return new Object[] {fTypeComponent}; - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier() - */ - public String getIdentifier() { - return IDENTIFIER; - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName() - */ - public String getProcessorName() { - return RefactoringMessages.getFormattedString( - "MakeLocalTypeGlobalRefactoring.name", //$NON-NLS-1$ - new String[]{getNewElementName()}); - - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable() - */ - public boolean isApplicable() throws CoreException { - if (fTypeComponent == null) - return false; - // TODO implement isApplicable logic for the named component, - // verify how it is different from other condition checks -// if (fNamedComponent.isAnonymous()) -// return false; -// if (! Checks.isAvailable(fType)) -// return false; -// if (isSpecialCase(fType)) -// return false; - return true; - } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#checkNewElementName(java.lang.String) - */ - public RefactoringStatus checkNewElementName(String newName){ - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - // TODO: implement new name checking -// RefactoringStatus result = Checks.checkTypeName(newName); -// if (Checks.isAlreadyNamed(fType, newName)) -// result.addFatalError(RefactoringCoreMessages.getString("RenameTypeRefactoring.choose_another_name")); //$NON-NLS-1$ - return new RefactoringStatus(); - } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#getNewElement() - */ - public Object getNewElement() throws CoreException { - // TODO implement this method, it's used for updating selection on new element - return null; - } - -// private void computeNameMatches(IProgressMonitor pm) throws CoreException { -// -// IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); -// try { -// URL fileURL = Platform.resolve(new URL(fNamedComponent.getSchema().getSchemaLocation())); -// IFile file = workspaceRoot.getFileForLocation(new Path(fileURL.getPath())); -// if (fNameSearchResult == null) -// fNameSearchResult= new QualifiedNameSearchResult(); -// QualifiedNameFinder.process(fNameSearchResult, getNamedComponent().getName(), -// getNewElementName(), -// "*.xsd", file.getProject(), pm); -// } catch (IOException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } - - public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException { - RenameArguments arguments= new RenameArguments(getNewElementName(), true); - String[] natures= getAffectedProjectNatures(); - List result= new ArrayList(); - loadElementParticipants(status, result, arguments, natures, sharedParticipants); - loadDerivedParticipants(status, result, natures, sharedParticipants); - return (RefactoringParticipant[])result.toArray(new RefactoringParticipant[result.size()]); - } - - protected void loadElementParticipants(RefactoringStatus status, List result, RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - Object[] elements= getElements(); - for (int i= 0; i < elements.length; i++) { - result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, - this, elements[i], - arguments, natures, shared))); - } - } - - - public void setNewElementName(String newName) { - - fNewElementName= newName; - } - - public String getNewElementName() { - return fNewElementName; - } - - public String getCurrentElementName() { - // TODO Auto-generated method stub - return fNewElementName; - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/util/TextChangeCompatibility.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/util/TextChangeCompatibility.java deleted file mode 100644 index 04a75e8ada..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/util/TextChangeCompatibility.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.util; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.text.edits.TextEditGroup; - -/** - * A utility class to provide compatibility with the old - * text change API of adding text edits directly and auto - * inserting them into the tree. - */ -public class TextChangeCompatibility { - - public static void addTextEdit(TextChange change, String name, TextEdit edit) { - Assert.isNotNull(change); - Assert.isNotNull(name); - Assert.isNotNull(edit); - TextEdit root= change.getEdit(); - if (root == null) { - root= new MultiTextEdit(); - change.setEdit(root); - } - insert(root, edit); - change.addTextEditGroup(new TextEditGroup(name, edit)); - } - - public static void addTextEdit(TextChange change, String name, TextEdit[] edits) { - Assert.isNotNull(change); - Assert.isNotNull(name); - Assert.isNotNull(edits); - TextEdit root= change.getEdit(); - if (root == null) { - root= new MultiTextEdit(); - change.setEdit(root); - } - for (int i= 0; i < edits.length; i++) { - insert(root, edits[i]); - } - change.addTextEditGroup(new TextEditGroup(name, edits)); - } - - public static void insert(TextEdit parent, TextEdit edit) { - if (!parent.hasChildren()) { - parent.addChild(edit); - return; - } - TextEdit[] children= parent.getChildren(); - // First dive down to find the right parent. - for (int i= 0; i < children.length; i++) { - TextEdit child= children[i]; - if (covers(child, edit)) { - insert(child, edit); - return; - } - } - // We have the right parent. Now check if some of the children have to - // be moved under the new edit since it is covering it. - for (int i= children.length - 1; i >= 0; i--) { - TextEdit child= children[i]; - if (covers(edit, child)) { - parent.removeChild(i); - edit.addChild(child); - } - } - parent.addChild(edit); - } - - private static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { - if (thisEdit.getLength() == 0) // an insertion point can't cover anything - return false; - - int thisOffset= thisEdit.getOffset(); - int thisEnd= thisEdit.getExclusiveEnd(); - if (otherEdit.getLength() == 0) { - int otherOffset= otherEdit.getOffset(); - return thisOffset < otherOffset && otherOffset < thisEnd; - } else { - int otherOffset= otherEdit.getOffset(); - int otherEnd= otherEdit.getExclusiveEnd(); - return thisOffset <= otherOffset && otherEnd <= thisEnd; - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorActionGroup.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorActionGroup.java deleted file mode 100644 index 7318d093ef..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorActionGroup.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.wst.xsd.ui.internal.refactor.actions.RenameAction; -import org.eclipse.wst.xsd.ui.internal.refactor.actions.SelectionDispatchAction; - -/** - * Action group that adds refactor actions (for example 'Rename', 'Move') to a - * context menu and the global menu bar. - * - */ -public abstract class RefactorActionGroup extends ActionGroup { - - private static class NoActionAvailable extends Action { - public NoActionAvailable() { - setEnabled(true); - setText(RefactoringWizardMessages.RefactorActionGroup_no_refactoring_available); - } - } - - /** - * Pop-up menu: name of group for reorganize actions (value - * <code>"group.reorganize"</code>). - */ - public static final String GROUP_REORGANIZE = IWorkbenchActionConstants.GROUP_REORGANIZE; - - public static final String MENU_ID = "org.eclipse.wst.xsd.ui.refactoring.menu"; //$NON-NLS-1$ - - public static final String RENAME = "org.eclipse.wst.xsd.ui.refactoring.actions.Rename"; //$NON-NLS-1$ - - - protected static void initAction(SelectionDispatchAction action, - ISelection selection) { - - Assert.isNotNull(selection); - Assert.isNotNull(action); - action.update(selection); - //provider.addSelectionChangedListener(action); - } - - protected List fEditorActions; - - private String fGroupName = GROUP_REORGANIZE; - - private Action fNoActionAvailable = new NoActionAvailable(); - - protected RenameAction fRenameAction; - - protected SelectionDispatchAction fRenameTargetNamespace; - - protected ISelection selection; - - public RefactorActionGroup(ISelection selection) { - this.selection = selection; - - } - - public int addAction(IAction action) { - if (action != null && action.isEnabled()) { - fEditorActions.add(action); - return 1; - } - return 0; - } - - private void addRefactorSubmenu(IMenuManager menu) { - - IMenuManager refactorSubmenu = new MenuManager(RefactoringWizardMessages.RefactorMenu_label, MENU_ID); - refactorSubmenu.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - refactorMenuShown(manager); - } - }); - refactorSubmenu.add(fNoActionAvailable); - if (menu.find(refactorSubmenu.getId()) == null) { - if (menu.find(fGroupName) == null) { - menu.add(refactorSubmenu); - } else { - menu.appendToGroup(fGroupName, refactorSubmenu); - } - } - } - - protected void disposeAction(ISelectionChangedListener action, - ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } - - /* - * (non-Javadoc) Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - super.fillActionBars(actionBars); - actionBars.setGlobalActionHandler(RENAME, fRenameAction); - retargetFileMenuActions(actionBars); - } - - public void fillActions(List enabledActions) { - - if(selection != null && fEditorActions != null){ - for (Iterator iter = fEditorActions.iterator(); iter.hasNext();) { - Action action = (Action) iter.next(); - if (action instanceof SelectionDispatchAction) { - SelectionDispatchAction selectionAction = (SelectionDispatchAction) action; - selectionAction.update(selection); - } - - } - for (Iterator iter = fEditorActions.iterator(); iter.hasNext();) { - Action action = (Action) iter.next(); - if (action != null) { - enabledActions.add(action); - } - } - } - - } - - /* - * (non-Javadoc) Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - addRefactorSubmenu(menu); - } - - private int fillRefactorMenu(IMenuManager refactorSubmenu) { - int added = 0; - refactorSubmenu.add(new Separator(GROUP_REORGANIZE)); - for (Iterator iter = fEditorActions.iterator(); iter.hasNext();) { - Action action = (Action) iter.next(); - if (action != null && action.isEnabled()) { - fEditorActions.add(action); - return 1; - } - } - return added; - } - - private void refactorMenuHidden(IMenuManager manager) { - - for (Iterator iter = fEditorActions.iterator(); iter.hasNext();) { - Action action = (Action) iter.next(); - if (action instanceof SelectionDispatchAction) { - SelectionDispatchAction selectionAction = (SelectionDispatchAction) action; - selectionAction.update(selection); - } - - } - } - - private void refactorMenuShown(final IMenuManager refactorSubmenu) { - // we know that we have an MenuManager since we created it in - // addRefactorSubmenu. - Menu menu = ((MenuManager) refactorSubmenu).getMenu(); - menu.addMenuListener(new MenuAdapter() { - public void menuHidden(MenuEvent e) { - refactorMenuHidden(refactorSubmenu); - } - }); - - for (Iterator iter = fEditorActions.iterator(); iter.hasNext();) { - Action action = (Action) iter.next(); - if (action instanceof SelectionDispatchAction) { - SelectionDispatchAction selectionAction = (SelectionDispatchAction) action; - selectionAction.update(selection); - } - } - refactorSubmenu.removeAll(); - if (fillRefactorMenu(refactorSubmenu) == 0) - refactorSubmenu.add(fNoActionAvailable); - } - - /** - * Retargets the File actions with the corresponding refactoring actions. - * - * @param actionBars - * the action bar to register the move and rename action with - */ - public void retargetFileMenuActions(IActionBars actionBars) { - actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), - fRenameAction); - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupActionDelegate.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupActionDelegate.java deleted file mode 100644 index 29c56783ab..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupActionDelegate.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuCreator; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -public abstract class RefactorGroupActionDelegate implements IObjectActionDelegate, IEditorActionDelegate, IMenuCreator { - - protected ISelection fSelection; - private IAction fDelegateAction; - // whether to re-fill the menu (reset on selection change) - private boolean fFillMenu = true; - protected IWorkbenchPart workbenchPart; - protected ResourceSet resourceSet = new ResourceSetImpl(); - - - public RefactorGroupActionDelegate() { - - } - - /* - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - workbenchPart = targetPart; - } - /* (non-Javadoc) - * @see org.eclipse.jface.action.IMenuCreator#dispose() - */ - public void dispose() { - // nothing to do - } - /* (non-Javadoc) - * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control) - */ - public Menu getMenu(Control parent) { - // never called - return null; - } - /* (non-Javadoc) - * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu) - */ - public Menu getMenu(Menu parent) { - //Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu). - Menu menu = new Menu(parent); - /** - * Add listener to repopulate the menu each time - * it is shown because MenuManager.update(boolean, boolean) - * doesn't dispose pulldown ActionContribution items for each popup menu. - */ - menu.addMenuListener(new MenuAdapter() { - public void menuShown(MenuEvent e) { - if (fFillMenu) { - Menu m = (Menu)e.widget; - MenuItem[] items = m.getItems(); - for (int i=0; i < items.length; i++) { - items[i].dispose(); - } - fillMenu(m); - fFillMenu = false; - } - } - }); - return menu; - } - - /* - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - // Never called because we become a menu. - } - - /* - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - fDelegateAction = action; - updateWith(selection); - - } - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - workbenchPart = targetEditor; - fDelegateAction = action; - if (targetEditor != null && targetEditor.getEditorSite() != null && targetEditor.getEditorSite().getSelectionProvider() != null) { - updateWith(targetEditor.getEditorSite().getSelectionProvider().getSelection()); - } - - } - - public void updateWith(ISelection selection) { - fSelection = selection; - if (fDelegateAction != null) { - boolean enable = false; - if (selection != null) { - if (selection instanceof ITextSelection) { - //if (((ITextSelection) selection).getLength() > 0) { - enable = true; - //} - } - else if(selection instanceof IStructuredSelection ){ - enable = !selection.isEmpty(); - } - } - // enable action - fDelegateAction.setEnabled(enable); - - // fill submenu - fFillMenu = true; - fDelegateAction.setMenuCreator(this); - - - } - - } - - - protected abstract void fillMenu(Menu menu); - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupSubMenu.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupSubMenu.java deleted file mode 100644 index 77780e100f..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactorGroupSubMenu.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - -import java.util.ArrayList; -import java.util.Iterator; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.ui.actions.CompoundContributionItem; - -public class RefactorGroupSubMenu extends CompoundContributionItem { - - RefactorActionGroup fRefactorMenuGroup; - - - public RefactorGroupSubMenu(RefactorActionGroup refactorMenuGroup) { - super(); - fRefactorMenuGroup = refactorMenuGroup; - } - - public RefactorGroupSubMenu(String id) { - super(id); - } - - protected IContributionItem[] getContributionItems() { - ArrayList actionsList = new ArrayList(); - ArrayList contribList = new ArrayList(); - fRefactorMenuGroup.fillActions(actionsList); - - if (actionsList != null && !actionsList.isEmpty()) { - for (Iterator iter = actionsList.iterator(); iter.hasNext();) { - IAction action = (IAction) iter.next(); - contribList.add(new ActionContributionItem(action)); - } - } else { - Action dummyAction = new Action(RefactoringWizardMessages.RefactorActionGroup_no_refactoring_available) { - // dummy inner class; no methods - }; - dummyAction.setEnabled(false); - contribList.add(new ActionContributionItem(dummyAction)); - } - return (IContributionItem[]) contribList.toArray(new IContributionItem[contribList.size()]); - - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactoringWizardMessages.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactoringWizardMessages.java deleted file mode 100644 index 6bac54b55e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RefactoringWizardMessages.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - -import org.eclipse.osgi.util.NLS; - -public class RefactoringWizardMessages extends NLS { - - private static final String BUNDLE_NAME= "org.eclipse.wst.xsd.ui.internal.refactor.wizard.messages";//$NON-NLS-1$ - - public static String RefactorMenu_label; - public static String RefactorActionGroup_no_refactoring_available; - - public static String RenameAction_rename; - public static String RenameAction_unavailable; - public static String RenameAction_text; - - public static String RenameInputWizardPage_new_name; - public static String RenameRefactoringWizard_internal_error; - - public static String RenameTargetNamespace_text; - - public static String RenameXSDElementAction_exception; - public static String RenameXSDElementAction_not_available; - public static String RenameXSDElementAction_name; - - public static String RenameSupport_dialog_title; - public static String RenameSupport_not_available; - - public static String RenameComponentWizard_defaultPageTitle; - public static String RenameComponentWizard_inputPage_description; - - public static String RenameInputWizardPage_update_references; - public static String XSDComponentRenameChange_name; - public static String XSDComponentRenameChange_Renaming; - public static String ResourceRenameParticipant_compositeChangeName; - public static String RenameResourceChange_rename_resource_reference_change; - public static String XSDRenameResourceChange_name; - public static String RenameResourceRefactoring_Internal_Error; - public static String RenameResourceRefactoring_alread_exists; - public static String RenameResourceRefactoring_invalidName; - public static String RenameResourceProcessor_name; - public static String MakeAnonymousTypeGlobalAction_text; - public static String MakeLocalElementGlobalAction_text; - public static String XSDComponentRenameParticipant_Component_Refactoring_updates; - public static String WSDLComponentRenameParticipant_Component_Refactoring_updates; - public static String RenameComponentProcessor_Component_Refactoring_updates; - public static String RenameComponentProcessor_Component_Refactoring_update_declatation; - public static String RenameComponentProcessor_Component_Refactoring_update_reference; - public static String XSDComponentRenameParticipant_xsd_component_rename_participant; - public static String WSDLComponentRenameParticipant_wsdl_component_rename_participant; - public static String ResourceRenameParticipant_File_Rename_update_reference; - - - private RefactoringWizardMessages() { - // Do not instantiate - } - - static { - NLS.initializeMessages(BUNDLE_NAME, RefactoringWizardMessages.class); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameInputWizardPage.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameInputWizardPage.java deleted file mode 100644 index 10bf304d09..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameInputWizardPage.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - - - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.util.Assert; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.refactor.IReferenceUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; - -/** - * @author ebelisar - * - */ -public class RenameInputWizardPage extends UserInputWizardPage{ - private String fInitialValue; - private Text fTextField; - private Button fUpdateReferences; - /** - * Creates a new text input page. - * @param isLastUserPage <code>true</code> if this page is the wizard's last - * user input page. Otherwise <code>false</code>. - */ - public RenameInputWizardPage(String description, boolean isLastUserPage) { - this(description, isLastUserPage, ""); //$NON-NLS-1$ - } - - /** - * Creates a new text input page. - * @param isLastUserPage <code>true</code> if this page is the wizard's last - * user input page. Otherwise <code>false</code> - * @param initialValue the initial value - */ - public RenameInputWizardPage(String description, boolean isLastUserPage, String initialValue) { - super("RenameInputWizardPage"); - Assert.isNotNull(initialValue); - setDescription(description); - fInitialValue= initialValue; - } - - /** - * Returns whether the initial input is valid. Typically it is not, because the - * user is required to provide some information e.g. a new type name etc. - * - * @return <code>true</code> iff the input provided at initialization is valid - */ - protected boolean isInitialInputValid(){ - return false; - } - - /** - * Returns whether an empty string is a valid input. Typically it is not, because - * the user is required to provide some information e.g. a new type name etc. - * - * @return <code>true</code> iff an empty string is valid - */ - protected boolean isEmptyInputValid(){ - return false; - } - - /** - * Returns the content of the text input field. - * - * @return the content of the text input field. Returns <code>null</code> if - * not text input field has been created - */ - protected String getText() { - if (fTextField == null) - return null; - return fTextField.getText(); - } - - /** - * Sets the new text for the text field. Does nothing if the text field has not been created. - * @param text the new value - */ - protected void setText(String text) { - if (fTextField == null) - return; - fTextField.setText(text); - } - - /** - * Performs input validation. Returns a <code>RefactoringStatus</code> which - * describes the result of input validation. <code>Null<code> is interpreted - * as no error. - */ - protected RefactoringStatus validateTextField(String text){ - return null; - } - - protected Text createTextInputField(Composite parent) { - return createTextInputField(parent, SWT.BORDER); - } - - protected Text createTextInputField(Composite parent, int style) { - fTextField= new Text(parent, style); - fTextField.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - textModified(getText()); - } - }); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextField, XSDEditorCSHelpIds.RENAME_NEW_NAME); - fTextField.setText(fInitialValue); - return fTextField; - } - - /** - * Checks the page's state and issues a corresponding error message. The page validation - * is computed by calling <code>validatePage</code>. - */ - protected void textModified(String text) { - if (! isEmptyInputValid() && text.equals("")){ //$NON-NLS-1$ - setPageComplete(false); - setErrorMessage(null); - restoreMessage(); - return; - } - if ((! isInitialInputValid()) && text.equals(fInitialValue)){ - setPageComplete(false); - setErrorMessage(null); - restoreMessage(); - return; - } - - setPageComplete(validateTextField(text)); - -// TODO: enable preview in M4 - getRefactoringWizard().setForcePreviewReview(false); - getContainer().updateButtons(); - - } - - /** - * Subclasses can override if they want to restore the message differently. - * This implementation calls <code>setMessage(null)</code>, which clears the message - * thus exposing the description. - */ - protected void restoreMessage(){ - setMessage(null); - } - - /* (non-Javadoc) - * Method declared in IDialogPage - */ - public void dispose() { - fTextField= null; - } - - /* (non-Javadoc) - * Method declared in WizardPage - */ - public void setVisible(boolean visible) { - if (visible) { - textModified(getText()); - } - super.setVisible(visible); - if (visible && fTextField != null) { - fTextField.setFocus(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - Composite superComposite= new Composite(parent, SWT.NONE); - setControl(superComposite); - initializeDialogUnits(superComposite); - - superComposite.setLayout(new GridLayout()); - Composite composite= new Composite(superComposite, SWT.NONE); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.verticalSpacing= 8; - composite.setLayout(layout); - - - Label label= new Label(composite, SWT.NONE); - label.setText(getLabelText()); - - Text text= createTextInputField(composite); - text.selectAll(); - GridData gd= new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint= convertWidthInCharsToPixels(25); - text.setLayoutData(gd); - PlatformUI.getWorkbench().getHelpSystem().setHelp(text, XSDEditorCSHelpIds.RENAME_NEW_NAME); - - addOptionalUpdateReferencesCheckbox(superComposite); - gd= new GridData(GridData.FILL_HORIZONTAL); - text.setLayoutData(gd); - - getRefactoringWizard().setForcePreviewReview(false); - - Dialog.applyDialogFont(superComposite); - //WorkbenchHelp.setHelp(getControl(), fHelpContextID); - - } - - private static Button createCheckbox(Composite parent, String title, boolean value) { - Button checkBox= new Button(parent, SWT.CHECK); - checkBox.setText(title); - checkBox.setSelection(value); - return checkBox; - } - - private void addOptionalUpdateReferencesCheckbox(Composite result) { - - final IReferenceUpdating ref= (IReferenceUpdating)getRefactoring().getAdapter(IReferenceUpdating.class); - if (ref == null || !ref.canEnableUpdateReferences()) - return; - String title= RefactoringMessages.getString("RenameInputWizardPage.update_references"); //$NON-NLS-1$ - boolean defaultValue= true; - fUpdateReferences= createCheckbox(result, title, defaultValue); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fUpdateReferences, XSDEditorCSHelpIds.RENAME_UPDATE_REFERENCES); - ref.setUpdateReferences(fUpdateReferences.getSelection()); - fUpdateReferences.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - ref.setUpdateReferences(fUpdateReferences.getSelection()); - } - }); - fUpdateReferences.setEnabled(true); - } - - protected String getLabelText() { - return RefactoringMessages.getString("RenameInputWizardPage.new_name"); //$NON-NLS-1$ - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameRefactoringWizard.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameRefactoringWizard.java deleted file mode 100644 index e24977b91d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/RenameRefactoringWizard.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.wizard; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; - -public class RenameRefactoringWizard extends RefactoringWizard { - - private final String fInputPageDescription; - - private final ImageDescriptor fInputPageImageDescriptor; - - public RenameRefactoringWizard(Refactoring refactoring, String defaultPageTitle, String inputPageDescription, - ImageDescriptor inputPageImageDescriptor) { - super(refactoring, DIALOG_BASED_USER_INTERFACE); - setDefaultPageTitle(defaultPageTitle); - fInputPageDescription= inputPageDescription; - fInputPageImageDescriptor= inputPageImageDescriptor; - - } - - /* non java-doc - * @see RefactoringWizard#addUserInputPages - */ - protected void addUserInputPages() { - String initialSetting= getProcessor().getCurrentElementName(); - RenameInputWizardPage inputPage= createInputPage(fInputPageDescription, initialSetting); - inputPage.setImageDescriptor(fInputPageImageDescriptor); - addPage(inputPage); - } - - protected INameUpdating getProcessor() { - - return (INameUpdating)getRefactoring().getAdapter(INameUpdating.class); - } - - - protected RenameInputWizardPage createInputPage(String message, String initialSetting) { - return new RenameInputWizardPage(message, true, initialSetting) { - protected RefactoringStatus validateTextField(String text) { - return validateNewName(text); - } - }; - } - - protected RefactoringStatus validateNewName(String newName) { - INameUpdating ref= getProcessor(); - ref.setNewElementName(newName); -// try{ - return ref.checkNewElementName(newName); -// } catch (CoreException e){ -// //XXX: should log the exception -// String msg= e.getMessage() == null ? "": e.getMessage(); //$NON-NLS-1$ -// return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getFormattedString("RenameRefactoringWizard.internal_error", msg));//$NON-NLS-1$ -// } - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/messages.properties deleted file mode 100644 index f10fccce6a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/wizard/messages.properties +++ /dev/null @@ -1,55 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2010 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -RefactorMenu_label=Refactor -RefactorActionGroup_no_refactoring_available=<no refactoring available> - -RenameAction_rename=Rename -RenameAction_unavailable=Operation unavailable on the current selection.\nSelect a .... -RenameAction_text=Re&name... - -RenameInputWizardPage_new_name= &New name: -RenameRefactoringWizard_internal_error= Internal error during name checking: {0} - - -RenameXSDElementAction_exception=Unexpected exception occurred. See log for details -RenameXSDElementAction_not_available=Operation unavailable on the current selection.\nSelect a XSD project, folder, resource, file, attribute declarations, attribute group definitions, complex type definitions, element declarations, identity constraint definitions, model groups definitions, notation declarations, or simple type definitions. -RenameXSDElementAction_name=Rename - - -RenameSupport_dialog_title=Rename -RenameSupport_not_available=Rename support not available - -RenameComponentWizard_defaultPageTitle=Rename wizard -RenameComponentWizard_inputPage_description=Rename XML Schema component - -RenameInputWizardPage_update_references=Update references -XSDComponentRenameChange_name=XML Schema component renaming in {0}: {1} to {2} -XSDComponentRenameChange_Renaming=Renaming... -ResourceRenameParticipant_compositeChangeName=XSD file rename references updating changes -RenameResourceChange_rename_resource_reference_change=Renaming resource name references -XSDRenameResourceChange_name=Resource rename: {0} to {1} -RenameResourceRefactoring_Internal_Error=Internal error -RenameResourceRefactoring_alread_exists=Resource already exist -RenameResourceRefactoring_invalidName=Invalid resource name -RenameResourceProcessor_name=Resource renaming -MakeAnonymousTypeGlobalAction_text=Make &Anonymous Type Global -MakeLocalElementGlobalAction_text=Make &Local Element Global -XSDComponentRenameParticipant_Component_Refactoring_updates=XML Schema refactoring changes -WSDLComponentRenameParticipant_Component_Refactoring_updates=WSDL Schema refactoring changes -RenameComponentProcessor_Component_Refactoring_updates=Component name refactoring changes -RenameComponentProcessor_Component_Refactoring_update_declatation=Update component declaration/definition -RenameComponentProcessor_Component_Refactoring_update_reference=Update component reference -XSDComponentRenameParticipant_xsd_component_rename_participant=XSD component rename participant -WSDLComponentRenameParticipant_wsdl_component_rename_participant=WSDL component rename participant -ResourceRenameParticipant_File_Rename_update_reference=File rename refactoring changes - -RenameTargetNamespace_text=Rename Target Namespace |