Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions')
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java115
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java667
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java204
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java82
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java514
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java136
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java197
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java80
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java187
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java117
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java94
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java164
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java145
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java26
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java86
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java79
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java170
17 files changed, 0 insertions, 3063 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java
deleted file mode 100644
index 13eee15b93..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.ui.IActionDelegate2;
-import org.eclipse.ui.IEditorActionDelegate;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.xml.ui.internal.Logger;
-
-/**
- * Abstract comment action delegate for XML editors
- */
-abstract public class AbstractCommentActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
- static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$
- static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$
-
- IEditorPart fEditor;
-
- public void setActiveEditor(IAction action, IEditorPart targetEditor) {
- fEditor = targetEditor;
- }
-
- public void dispose() {
- // nulling out just in case
- fEditor = null;
- }
-
- public void runWithEvent(IAction action, Event event) {
- run(action);
- }
-
- public void run(IAction action) {
- if (fEditor instanceof ITextEditor) {
- ITextEditor textEditor = (ITextEditor) fEditor;
- IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
- if (document != null) {
- // get current text selection
- ITextSelection textSelection = getCurrentSelection();
- if (textSelection.isEmpty())
- return;
-
- processAction(document, textSelection);
- }
- }
- }
-
- public void init(IViewPart view) {
- // do nothing
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- // do nothing
- }
-
- private ITextSelection getCurrentSelection() {
- if (fEditor instanceof ITextEditor) {
- ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider();
- if (provider != null) {
- ISelection selection = provider.getSelection();
- if (selection instanceof ITextSelection)
- return (ITextSelection) selection;
- }
- }
- return TextSelection.emptySelection();
- }
-
- abstract void processAction(IDocument document, ITextSelection textSelection);
-
- void removeOpenCloseComments(IDocument document, int offset, int length) {
- try {
- int adjusted_length = length;
-
- // remove open comments
- String string = document.get(offset, length);
- int index = string.lastIndexOf(OPEN_COMMENT);
- while (index != -1) {
- document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
- index = string.lastIndexOf(OPEN_COMMENT, index - 1);
- adjusted_length -= OPEN_COMMENT.length();
- }
-
- // remove close comments
- string = document.get(offset, adjusted_length);
- index = string.lastIndexOf(CLOSE_COMMENT);
- while (index != -1) {
- document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
- index = string.lastIndexOf(CLOSE_COMMENT, index - 1);
- }
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java
deleted file mode 100644
index 10bb371fb2..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java
+++ /dev/null
@@ -1,667 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilder;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilderImpl;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-
-public abstract class AbstractNodeActionManager extends BaseNodeActionManager {
-
-
- /**
- * AddNodeAction
- */
- public class AddNodeAction extends NodeAction {
- protected CMNode cmnode;
- protected String description;
- protected int index;
- protected int nodeType;
- protected Node parent;
- protected String undoDescription;
-
-
- public AddNodeAction(CMNode cmnode, Node parent, int index) {
- this.cmnode = cmnode;
- this.parent = parent;
- this.index = index;
-
- String text = getLabel(parent, cmnode);
- setText(text);
- description = text;
- undoDescription = XMLUIMessages._UI_MENU_ADD + " " + text; //$NON-NLS-1$ //$NON-NLS-2$
- ImageDescriptor descriptor = CMImageUtil.getImageDescriptor(cmnode);
- if (descriptor == null) {
- descriptor = imageDescriptorCache.getImageDescriptor(cmnode);
- }
- setImageDescriptor(descriptor);
- }
-
-
- public AddNodeAction(int nodeType, Node parent, int index) {
- this.nodeType = nodeType;
- this.index = index;
- this.parent = parent;
-
- switch (nodeType) {
- case Node.COMMENT_NODE : {
- description = XMLUIMessages._UI_MENU_COMMENT; //$NON-NLS-1$
- undoDescription = XMLUIMessages._UI_MENU_ADD_COMMENT; //$NON-NLS-1$
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- description = XMLUIMessages._UI_MENU_PROCESSING_INSTRUCTION; //$NON-NLS-1$
- undoDescription = XMLUIMessages._UI_MENU_ADD_PROCESSING_INSTRUCTION; //$NON-NLS-1$
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- description = XMLUIMessages._UI_MENU_CDATA_SECTION; //$NON-NLS-1$
- undoDescription = XMLUIMessages._UI_MENU_ADD_CDATA_SECTION; //$NON-NLS-1$
- break;
- }
- case Node.TEXT_NODE : {
- description = XMLUIMessages._UI_MENU_PCDATA; //$NON-NLS-1$
- undoDescription = XMLUIMessages._UI_MENU_ADD_PCDATA; //$NON-NLS-1$
- break;
- }
- }
- setText(description);
- setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType)));
- }
-
-
- protected void addNodeForCMNode() {
- if (parent != null) {
- insert(parent, cmnode, index);
- }
- }
-
-
- protected void addNodeForNodeType() {
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
- Node newChildNode = null;
- boolean format = true;
- switch (nodeType) {
- case Node.COMMENT_NODE : {
- newChildNode = document.createComment(XMLUIMessages._UI_COMMENT_VALUE); //$NON-NLS-1$
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- newChildNode = document.createProcessingInstruction(XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); //$NON-NLS-1$ //$NON-NLS-2$
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- newChildNode = document.createCDATASection(""); //$NON-NLS-1$
- break;
- }
- case Node.TEXT_NODE : {
- format = false;
- newChildNode = document.createTextNode(parent.getNodeName());
- break;
- }
- }
-
- if (newChildNode != null) {
- List list = new Vector(1);
- list.add(newChildNode);
- insertNodesAtIndex(parent, list, index, format);
- }
- }
-
-
- public String getUndoDescription() {
- return undoDescription;
- }
-
-
- public void run() {
- beginNodeAction(this);
- if (cmnode != null) {
- addNodeForCMNode();
- } else {
- addNodeForNodeType();
- }
- endNodeAction(this);
- }
- }
-
-
- /**
- * DeleteAction
- */
- public class DeleteAction extends NodeAction {
- protected List list;
-
- public DeleteAction(List list) {
- setText(XMLUIMessages._UI_MENU_REMOVE); //$NON-NLS-1$
- this.list = list;
- }
-
- public DeleteAction(Node node) {
- setText(XMLUIMessages._UI_MENU_REMOVE); //$NON-NLS-1$
- list = new Vector();
- list.add(node);
- }
-
- public String getUndoDescription() {
- return XMLUIMessages.DELETE; //$NON-NLS-1$
- }
-
- public void run() {
- beginNodeAction(this);
-
- for (Iterator i = list.iterator(); i.hasNext();) {
- Node node = (Node) i.next();
- if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
- Attr attr = (Attr) node;
- attr.getOwnerElement().removeAttributeNode(attr);
- } else {
- Node parent = node.getParentNode();
- if (parent != null) {
- Node previousSibling = node.getPreviousSibling();
- if (previousSibling != null && isWhitespaceTextNode(previousSibling)) {
- parent.removeChild(previousSibling);
- }
- parent.removeChild(node);
- }
- }
- }
-
- endNodeAction(this);
- }
- }
-
-
- class ImageDescriptorCache {
- protected ImageDescriptor attributeImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
- protected ImageDescriptor attributeReqImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
- protected ImageDescriptor cdataSectionImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_CDATASECTION);
- protected ImageDescriptor commentImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_COMMENT);
- protected ImageDescriptor elementImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT);
- protected ImageDescriptor piImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION);
- protected ImageDescriptor textImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_TXTEXT);
-
- public ImageDescriptor getImageDescriptor(Object object) {
- ImageDescriptor result = null;
- if (object instanceof CMNode) {
- CMNode cmnode = (CMNode) object;
- switch (cmnode.getNodeType()) {
- case CMNode.ATTRIBUTE_DECLARATION : {
- result = CMImageUtil.getImageDescriptor(cmnode);
- if (result == null)
- if (((CMAttributeDeclaration) cmnode).getUsage() == CMAttributeDeclaration.REQUIRED)
- result = attributeReqImage;
- else
- result = attributeImage;
- break;
- }
- case CMNode.DATA_TYPE : {
- result = textImage;
- break;
- }
- case CMNode.ELEMENT_DECLARATION : {
- result = CMImageUtil.getImageDescriptor(cmnode);
- if (result == null)
- result = elementImage;
- break;
- }
- case CMNode.GROUP : {
- result = elementImage;
- break;
- }
- }
- } else if (object instanceof Integer) {
- Integer integer = (Integer) object;
- switch (integer.intValue()) {
- case Node.COMMENT_NODE : {
- result = commentImage;
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- result = piImage;
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- result = cdataSectionImage;
- break;
- }
- case Node.TEXT_NODE : {
- result = textImage;
- break;
- }
- }
- }
- return result;
- }
- }
-
- // TODO... remove this class. I'm pretty sure it is no longer used by
- // anyone.
- /**
- * @depracated
- */
- public class InsertAction extends NodeAction {
- protected String description;
- protected int index;
- protected int nodeType;
- protected Node parent;
-
- public InsertAction(int nodeType, Node parent, int index) {
- this.nodeType = nodeType;
- this.index = index;
- this.parent = parent;
- switch (nodeType) {
- case Node.COMMENT_NODE : {
- description = XMLUIMessages._UI_MENU_COMMENT; //$NON-NLS-1$
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- description = XMLUIMessages._UI_MENU_PROCESSING_INSTRUCTION; //$NON-NLS-1$
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- description = XMLUIMessages._UI_MENU_CDATA_SECTION; //$NON-NLS-1$
- break;
- }
- case Node.TEXT_NODE : {
- description = XMLUIMessages._UI_MENU_PCDATA; //$NON-NLS-1$
- break;
- }
- }
- setText(description);
- setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType)));
- }
-
- public InsertAction(int nodeType, Node parent, int index, String title) {
- this.nodeType = nodeType;
- this.index = index;
- this.parent = parent;
- description = title;
- setText(description);
- setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType)));
- }
-
- public String getUndoDescription() {
- return XMLUIMessages._UI_MENU_ADD + " " + description; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void run() {
- beginNodeAction(this);
-
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
- Node newChildNode = null;
- boolean format = true;
- switch (nodeType) {
- case Node.COMMENT_NODE : {
- newChildNode = document.createComment(XMLUIMessages._UI_COMMENT_VALUE); //$NON-NLS-1$
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- newChildNode = document.createProcessingInstruction(XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); //$NON-NLS-1$ //$NON-NLS-2$
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- newChildNode = document.createCDATASection(""); //$NON-NLS-1$
- break;
- }
- case Node.TEXT_NODE : {
- format = false;
- newChildNode = document.createTextNode(parent.getNodeName());
- break;
- }
- }
-
- if (newChildNode != null) {
- List list = new Vector(1);
- list.add(newChildNode);
- insertNodesAtIndex(parent, list, index, format);
- }
-
- endNodeAction(this);
- }
- }
-
-
- /**
- * ReplaceNodeAction
- */
- public class ReplaceNodeAction extends NodeAction {
- protected CMNode cmnode;
- protected String description;
- protected int endIndex;
- protected Node parent;
- protected int startIndex;
-
-
- public ReplaceNodeAction(Node parent, CMNode cmnode, int startIndex, int endIndex) {
- this.parent = parent;
- this.cmnode = cmnode;
- this.startIndex = startIndex;
- this.endIndex = endIndex;
-
- setText(getLabel(parent, cmnode));
- setImageDescriptor(imageDescriptorCache.getImageDescriptor(cmnode));
- }
-
- public String getUndoDescription() {
- String result = XMLUIMessages._UI_LABEL_UNDO_REPLACE_DESCRIPTION; //$NON-NLS-1$
- result += " " + getLabel(parent, cmnode); //$NON-NLS-1$
- return result;
- }
-
- public void run() {
- beginNodeAction(this);
-
- if (parent != null && cmnode != null) {
- remove(parent, startIndex, endIndex);
- insert(parent, cmnode, startIndex);
- }
- endNodeAction(this);
- }
- }
-
- protected ImageDescriptorCache imageDescriptorCache = new ImageDescriptorCache();
- protected Viewer fViewer;
-
- public AbstractNodeActionManager(IStructuredModel model, ModelQuery modelQuery, Viewer viewer) {
- super(model, modelQuery);
- this.fViewer = viewer;
- }
-
-
- public void beginNodeAction(NodeAction action) {
- fModel.beginRecording(action, action.getUndoDescription());
- }
-
-
- protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad) {
- Action action = null;
- if (ad == null) {
- action = new EditAttributeAction(this, parent, null, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE_TITLE); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- action = new AddNodeAction(ad, parent, -1);
- }
- return action;
- }
-
-
- protected Action createAddCDataSectionAction(Node parent, int index) {
- return new AddNodeAction(Node.CDATA_SECTION_NODE, parent, index);
- }
-
-
- protected Action createAddCommentAction(Node parent, int index) {
- return new AddNodeAction(Node.COMMENT_NODE, parent, index);
- }
-
-
- protected Action createAddDoctypeAction(Document document, int index) {
- return new EditDoctypeAction(fModel, document, fModel.getBaseLocation(), XMLUIMessages._UI_MENU_ADD_DTD_INFORMATION); //$NON-NLS-1$
- }
-
-
- protected Action createAddElementAction(Node parent, CMElementDeclaration ed, int index) {
- Action action = null;
- if (ed == null) {
- action = new EditElementAction(this, parent, index, XMLUIMessages._UI_MENU_NEW_ELEMENT, XMLUIMessages._UI_MENU_NEW_ELEMENT_TITLE); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- action = new AddNodeAction(ed, parent, index);
- }
- return action;
- }
-
-
- protected Action createAddPCDataAction(Node parent, CMDataType dataType, int index) {
- Action action = null;
- if (dataType == null) {
- action = new AddNodeAction(Node.TEXT_NODE, parent, index);
- } else {
- action = new AddNodeAction(dataType, parent, index);
- }
- return action;
- }
-
-
- protected Action createAddProcessingInstructionAction(Node parent, int index) {
- Node refChild = getRefChildNodeAtIndex(parent, index);
- Action action = new EditProcessingInstructionAction(this, parent, refChild, XMLUIMessages._UI_MENU_ADD_PROCESSING_INSTRUCTION, XMLUIMessages.ADD_PROCESSING_INSTRUCTION); //$NON-NLS-1$ //$NON-NLS-2$
- action.setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(Node.PROCESSING_INSTRUCTION_NODE)));
- return action;
- }
-
-
- protected Action createAddSchemaInfoAction(Element element) {
- return new EditSchemaInfoAction(this, element.getOwnerDocument(), fModel.getBaseLocation(), XMLUIMessages._UI_MENU_ADD_SCHEMA_INFORMATION); //$NON-NLS-1$
- }
-
-
- protected Action createDeleteAction(List selection) {
- DeleteAction deleteAction = new DeleteAction(selection);
- deleteAction.setEnabled(selection.size() > 0);
- return deleteAction;
- }
-
-
- public DOMContentBuilder createDOMContentBuilder(Document document) {
- DOMContentBuilderImpl builder = new DOMContentBuilderImpl(document);
- return builder;
- }
-
-
- protected Action createEditAttributeAction(Attr attr, CMAttributeDeclaration ad) {
- return new EditAttributeAction(this, attr.getOwnerElement(), attr, XMLUIMessages._UI_MENU_EDIT_ATTRIBUTE, XMLUIMessages._UI_MENU_EDIT_ATTRIBUTE_TITLE); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
- protected Action createEditDoctypeAction(DocumentType doctype) {
- return new EditDoctypeAction(fModel, doctype, fModel.getBaseLocation(), XMLUIMessages._UI_MENU_EDIT_DOCTYPE); //$NON-NLS-1$
- }
-
-
- protected Action createEditProcessingInstructionAction(ProcessingInstruction pi) {
- return new EditProcessingInstructionAction(this, pi, XMLUIMessages._UI_MENU_EDIT_PROCESSING_INSTRUCTION, XMLUIMessages._UI_MENU_EDIT_PROCESSING_INSTRUCTION_TITLE); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
- protected Action createEditSchemaInfoAction(Element element) {
- return new EditSchemaInfoAction(this, element.getOwnerDocument(), fModel.getBaseLocation(), XMLUIMessages._UI_MENU_EDIT_NAMESPACES); //$NON-NLS-1$
- }
-
-
- protected Action createRenameAction(Node node) {
- Action result = null;
- if (node instanceof Element) {
- result = new EditElementAction(this, (Element) node, XMLUIMessages._UI_MENU_RENAME, XMLUIMessages._UI_MENU_RENAME_TITLE); //$NON-NLS-1$ //$NON-NLS-2$
- }
- return result;
- }
-
-
- protected Action createReplaceAction(Node parent, CMNode cmnode, int startIndex, int endIndex) {
- return new ReplaceNodeAction(parent, cmnode, startIndex, endIndex);
- }
-
- public void endNodeAction(NodeAction action) {
- fModel.endRecording(action);
- }
-
-
-
- public void fillContextMenu(IMenuManager menuManager, ISelection selection) {
- try {
- List selectionList = new ArrayList();
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection es = (IStructuredSelection) selection;
- for (Iterator i = es.iterator(); i.hasNext();) {
- selectionList.add(i.next());
- }
- }
-
- contributeActions(menuManager, selectionList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- */
- public String getLabel(Node parent, CMNode cmnode) {
- String result = "?" + cmnode + "?"; //$NON-NLS-1$ //$NON-NLS-2$
- if (cmnode != null) {
- result = (String) cmnode.getProperty("description"); //$NON-NLS-1$
- if (result == null) {
- if (cmnode.getNodeType() == CMNode.GROUP) {
- CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
- result = descriptionBuilder.buildDescription(cmnode);
- } else {
- result = DOMNamespaceHelper.computeName(cmnode, parent, null);
- }
- }
- }
- return result;
- }
-
-
- public IStructuredModel getModel() {
- return fModel;
- }
-
-
- public Shell getWorkbenchWindowShell() {
- return XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
- }
-
-
- public void insert(Node parent, CMNode cmnode, int index) {
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
- DOMContentBuilder builder = createDOMContentBuilder(document);
- builder.setBuildPolicy(DOMContentBuilder.BUILD_ONLY_REQUIRED_CONTENT);
- builder.build(parent, cmnode);
- insertNodesAtIndex(parent, builder.getResult(), index);
- }
-
-
- public void insertNodesAtIndex(Node parent, List list, int index) {
- insertNodesAtIndex(parent, list, index, true);
- }
-
-
- public void insertNodesAtIndex(Node parent, List list, int index, boolean format) {
- NodeList nodeList = parent.getChildNodes();
- if (index == -1) {
- index = nodeList.getLength();
- }
- Node refChild = (index < nodeList.getLength()) ? nodeList.item(index) : null;
-
- // here we consider the case where the previous node is a 'white
- // space' Text node
- // we should really do the insert before this node
- //
- int prevIndex = index - 1;
- Node prevChild = (prevIndex < nodeList.getLength()) ? nodeList.item(prevIndex) : null;
- if (isWhitespaceTextNode(prevChild)) {
- refChild = prevChild;
- }
-
- for (Iterator i = list.iterator(); i.hasNext();) {
- Node newNode = (Node) i.next();
-
- if (newNode.getNodeType() == Node.ATTRIBUTE_NODE) {
- Element parentElement = (Element) parent;
- parentElement.setAttributeNode((Attr) newNode);
- } else {
- parent.insertBefore(newNode, refChild);
- }
- }
-
- boolean formatDeep = false;
- for (Iterator i = list.iterator(); i.hasNext();) {
- Node newNode = (Node) i.next();
- if (newNode.getNodeType() == Node.ELEMENT_NODE) {
- formatDeep = true;
- }
-
- if (format) {
- reformat(newNode, formatDeep);
- }
- }
-
- setViewerSelection(list);
- }
-
-
- /**
- * This method is abstract since currently, the sed editor is required to
- * perform formating and we don't want to create a dependency on the sed
- * editor.
- */
- public abstract void reformat(Node parent, boolean deep);
-
-
- public void remove(Node parent, int startIndex, int endIndex) {
- NodeList nodeList = parent.getChildNodes();
- for (int i = endIndex; i >= startIndex; i--) {
- Node node = nodeList.item(i);
- if (node != null) {
- parent.removeChild(node);
- }
- }
- }
-
-
- public void setViewerSelection(List list) {
- if (fViewer != null) {
- fViewer.setSelection(new StructuredSelection(list), true);
- }
- }
-
-
- public void setViewerSelection(Node node) {
- if (fViewer != null) {
- fViewer.setSelection(new StructuredSelection(node), true);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java
deleted file mode 100644
index 6aaa8b1ac4..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import java.util.ResourceBundle;
-
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IStatusLineManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
-import org.eclipse.ui.texteditor.RetargetTextEditorAction;
-import org.eclipse.wst.sse.ui.internal.actions.ActionContributor;
-import org.eclipse.wst.sse.ui.internal.actions.ActionDefinitionIds;
-import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-
-/**
- * XMLEditorActionContributor
- *
- * This class should not be used inside multi page editor's
- * ActionBarContributor, since cascaded init() call from the
- * ActionBarContributor will causes exception and it leads to lose whole
- * toolbars.
- *
- * Instead, use SourcePageActionContributor for source page contributor of
- * multi page editor.
- *
- * Note that this class is still valid for single page editor.
- */
-public class ActionContributorXML extends ActionContributor {
- private static final String[] EDITOR_IDS = {"org.eclipse.core.runtime.xml.source", "org.eclipse.core.runtime.xml.source2", "org.eclipse.wst.sse.ui.StructuredTextEditor"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- protected RetargetTextEditorAction fCleanupDocument = null;
- protected RetargetTextEditorAction fComment = null;
- // tooltip
- // action
- protected RetargetTextEditorAction fContentAssist = null;
- // action
- protected RetargetTextEditorAction fFindOccurrences = null;
- protected RetargetTextEditorAction fFormatActiveElements = null;
- protected RetargetTextEditorAction fFormatDocument = null;
- protected MenuManager fFormatMenu = null;
- protected RetargetTextEditorAction fOpenFileAction = null; // open file
- protected RetargetTextEditorAction fQuickFix = null;
-
- protected RetargetTextEditorAction fShowTooltipAction = null; // show
- protected RetargetTextEditorAction fUncomment = null;
-
- public ActionContributorXML() {
- super();
-
- ResourceBundle resourceBundle = XMLUIMessages.getResourceBundle();
-
- // edit commands
- fShowTooltipAction = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fShowTooltipAction.setActionDefinitionId(ActionDefinitionIds.INFORMATION);
-
- fContentAssist = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-
- fQuickFix = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fQuickFix.setActionDefinitionId(ActionDefinitionIds.QUICK_FIX);
-
- // source commands
- fCleanupDocument = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fCleanupDocument.setActionDefinitionId(ActionDefinitionIds.CLEANUP_DOCUMENT);
-
- fFormatDocument = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fFormatDocument.setActionDefinitionId(ActionDefinitionIds.FORMAT_DOCUMENT);
-
- fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fFormatActiveElements.setActionDefinitionId(ActionDefinitionIds.FORMAT_ACTIVE_ELEMENTS);
-
- fFormatMenu = new MenuManager(XMLUIMessages.FormatMenu_label);
- fFormatMenu.add(fFormatDocument);
- fFormatMenu.add(fFormatActiveElements);
-
- // navigate commands
- fOpenFileAction = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fOpenFileAction.setActionDefinitionId(ActionDefinitionIds.OPEN_FILE);
-
- fFindOccurrences = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
- fFindOccurrences.setActionDefinitionId(ActionDefinitionIds.FIND_OCCURRENCES);
- }
-
- protected void addToMenu(IMenuManager menu) {
- // edit commands
- IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
- if (editMenu != null) {
- editMenu.add(fCommandsSeparator);
- editMenu.add(fToggleInsertModeAction);
- editMenu.add(fCommandsSeparator);
- editMenu.add(fExpandSelectionToMenu);
- editMenu.add(fCommandsSeparator);
- editMenu.add(fShowTooltipAction);
- editMenu.add(fContentAssist);
- editMenu.add(fQuickFix);
- editMenu.add(fMenuAdditionsGroupMarker);
- }
-
- // source commands
- String sourceMenuLabel = XMLUIMessages.SourceMenu_label;
- String sourceMenuId = "sourceMenuId"; //$NON-NLS-1$
- IMenuManager sourceMenu = new MenuManager(sourceMenuLabel, sourceMenuId);
- menu.insertAfter(IWorkbenchActionConstants.M_EDIT, sourceMenu);
- if (sourceMenu != null) {
- sourceMenu.add(fCommandsSeparator);
- sourceMenu.add(fToggleComment);
- sourceMenu.add(fAddBlockComment);
- sourceMenu.add(fRemoveBlockComment);
- sourceMenu.add(fShiftRight);
- sourceMenu.add(fShiftLeft);
- sourceMenu.add(fCleanupDocument);
- sourceMenu.add(fFormatMenu);
- sourceMenu.add(fCommandsSeparator);
- sourceMenu.add(fFindOccurrences);
- }
-
- // navigate commands
- IMenuManager navigateMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
- if (navigateMenu != null) {
- navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fCommandsSeparator);
- navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenFileAction);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.edit.util.ActionContributor#getExtensionIDs()
- */
- protected String[] getExtensionIDs() {
- return EDITOR_IDS;
- }
-
- /**
- * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart)
- */
- public void setActiveEditor(IEditorPart activeEditor) {
- if (getActiveEditorPart() == activeEditor)
- return;
- super.setActiveEditor(activeEditor);
-
- IActionBars actionBars = getActionBars();
- if (actionBars != null) {
- IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
- if (statusLineManager != null) {
- statusLineManager.setMessage(null);
- statusLineManager.setErrorMessage(null);
- }
- }
-
- ITextEditor textEditor = getTextEditor(activeEditor);
-
- fShowTooltipAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION));
- fContentAssist.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS));
- fQuickFix.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX));
-
- fCleanupDocument.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT));
- fFormatDocument.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT));
- fFormatActiveElements.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS));
- fCleanupDocument.setEnabled(textEditor != null && textEditor.isEditable());
- fFormatDocument.setEnabled(textEditor != null && textEditor.isEditable());
- fFormatActiveElements.setEnabled(textEditor != null && textEditor.isEditable());
-
- fOpenFileAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE));
-
- fFindOccurrences.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor#setViewerSpecificContributionsEnabled(boolean)
- */
- public void setViewerSpecificContributionsEnabled(boolean enabled) {
- super.setViewerSpecificContributionsEnabled(enabled);
-
- fShowTooltipAction.setEnabled(enabled);
- fContentAssist.setEnabled(enabled);
- fQuickFix.setEnabled(enabled);
- // cleanup and format document actions do not rely on source viewer
- // being enabled
- // fCleanupDocument.setEnabled(enabled);
- // fFormatDocument.setEnabled(enabled);
-
- fFormatActiveElements.setEnabled(enabled);
- fOpenFileAction.setEnabled(enabled);
- fFindOccurrences.setEnabled(enabled);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java
deleted file mode 100644
index 5521493ac5..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.xml.core.internal.document.CommentImpl;
-import org.eclipse.wst.xml.ui.internal.Logger;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-
-/**
- * Add block comment action delegate for XML editor
- */
-public class AddBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
-
- public void init(IAction action) {
- if (action != null) {
- action.setText(XMLUIMessages.AddBlockComment_label);
- action.setToolTipText(XMLUIMessages.AddBlockComment_tooltip);
- action.setDescription(XMLUIMessages.AddBlockComment_description);
- }
- }
-
- void processAction(IDocument document, ITextSelection textSelection) {
- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
- if (model != null) {
- try {
- IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
- IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
-
- if (selectionStartIndexedRegion == null)
- return;
- if (selectionEndIndexedRegion == null && textSelection.getLength() > 0) {
- selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1);
- }
- if (selectionEndIndexedRegion == null)
- return;
-
- int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
- int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length();
-
-
- if (textSelection.getLength() == 0 && selectionStartIndexedRegion instanceof CommentImpl)
- return;
-
- model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip);
- model.aboutToChangeModel();
-
- try {
- document.replace(openCommentOffset, 0, OPEN_COMMENT);
- document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- finally {
- model.changedModel();
- model.endRecording(this);
- }
- }
- finally {
- model.releaseFromEdit();
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java
deleted file mode 100644
index 9eef9a0c55..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java
+++ /dev/null
@@ -1,514 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-
-public abstract class BaseNodeActionManager {
-
-
- /**
- * MyMenuManager
- */
- public static class MyMenuManager extends MenuManager {
- protected String title;
-
- public MyMenuManager(String s) {
- super(s);
- title = s;
- }
-
- public boolean isEnabled() {
- return !isEmpty();
- }
-
- public String toString() {
- return title;
- }
- }
-
- public static DocumentType getDoctype(Node node) {
- Document document = (node.getNodeType() == Node.DOCUMENT_NODE) ? (Document) node : node.getOwnerDocument();
- return document.getDoctype();
- }
-
- protected MenuBuilder menuBuilder = new MenuBuilder();
- protected IStructuredModel fModel;
- protected ModelQuery modelQuery;
-
- protected BaseNodeActionManager(IStructuredModel model, ModelQuery modelQuery) {
- this.fModel = model;
- this.modelQuery = modelQuery;
- }
-
-
- protected void addActionHelper(IMenuManager menu, List modelQueryActionList) {
- List actionList = new Vector();
- for (Iterator i = modelQueryActionList.iterator(); i.hasNext();) {
- ModelQueryAction action = (ModelQueryAction) i.next();
- if (action.getCMNode() != null) {
- int cmNodeType = action.getCMNode().getNodeType();
- if (action.getKind() == ModelQueryAction.INSERT) {
- switch (cmNodeType) {
- case CMNode.ATTRIBUTE_DECLARATION : {
- actionList.add(createAddAttributeAction((Element) action.getParent(), (CMAttributeDeclaration) action.getCMNode()));
- break;
- }
- case CMNode.ELEMENT_DECLARATION : {
- actionList.add(createAddElementAction(action.getParent(), (CMElementDeclaration) action.getCMNode(), action.getStartIndex()));
- break;
- }
- }
- } else if (action.getKind() == ModelQueryAction.REPLACE) {
- if (action.getParent() != null && action.getCMNode() != null) {
- actionList.add(createReplaceAction(action.getParent(), action.getCMNode(), action.getStartIndex(), action.getEndIndex()));
- }
- }
- }
- }
- menuBuilder.populateMenu(menu, actionList, false);
- }
-
- protected void contributeAction(IMenuManager menu, Action action) {
- if (action != null) {
- menu.add(action);
- }
- }
-
-
- public void contributeActions(IMenuManager menu, List selection) {
- int editMode = modelQuery.getEditMode();
- int ic = ModelQuery.INCLUDE_CHILD_NODES;
- int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.VALIDITY_STRICT : ModelQuery.VALIDITY_NONE;
-
- List implicitlySelectedNodeList = null;
-
- if (selection.size() > 0) {
- implicitlySelectedNodeList = getSelectedNodes(selection, true);
-
- // contribute delete actions
- contributeDeleteActions(menu, implicitlySelectedNodeList, ic, vc);
- }
-
- if (selection.size() == 1) {
- Node node = (Node) selection.get(0);
-
- // contribute edit actions
- contributeEditActions(menu, node);
-
- // contribute add child actions
- contributeAddChildActions(menu, node, ic, vc);
-
- // contribute add before actions
- contributeAddSiblingActions(menu, node, ic, vc);
- }
-
- if (selection.size() > 0) {
- // contribute replace actions
- contributeReplaceActions(menu, implicitlySelectedNodeList, ic, vc);
- }
-
- if (selection.size() == 0) {
- Document document = ((IDOMModel) fModel).getDocument();
- contributeAddDocumentChildActions(menu, document, ic, vc);
- contributeEditGrammarInformationActions(menu, document);
- }
- }
-
-
- protected void contributeAddChildActions(IMenuManager menu, Node node, int ic, int vc) {
- int nodeType = node.getNodeType();
-
- if (nodeType == Node.ELEMENT_NODE) {
- // 'Add Child...' and 'Add Attribute...' actions
- //
- Element element = (Element) node;
-
- IMenuManager addAttributeMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_ATTRIBUTE); //$NON-NLS-1$
- IMenuManager addChildMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_CHILD); //$NON-NLS-1$
- menu.add(addAttributeMenu);
- menu.add(addChildMenu);
-
- CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element);
- if (ed != null) {
- // add insert attribute actions
- //
- List modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(element, ed, -1, ModelQuery.INCLUDE_ATTRIBUTES, vc, modelQueryActionList);
- addActionHelper(addAttributeMenu, modelQueryActionList);
-
- // add insert child node actions
- //
- modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(element, ed, -1, ic, vc, modelQueryActionList);
- addActionHelper(addChildMenu, modelQueryActionList);
- }
-
- // add PI and COMMENT
- contributePIAndCommentActions(addChildMenu, element, ed, -1);
-
- // add PCDATA, CDATA_SECTION
- contributeTextNodeActions(addChildMenu, element, ed, -1);
-
- // add NEW ELEMENT
- contributeUnconstrainedAddElementAction(addChildMenu, element, ed, -1);
-
- // add ATTRIBUTE
- contributeUnconstrainedAttributeActions(addAttributeMenu, element, ed);
- }
- }
-
-
- protected void contributeAddDocumentChildActions(IMenuManager menu, Document document, int ic, int vc) {
- IMenuManager addChildMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_CHILD); //$NON-NLS-1$
- menu.add(addChildMenu);
-
- // add PI and COMMENT
- contributePIAndCommentActions(addChildMenu, document, -1);
-
- // add NEW ELEMENT
- contributeUnconstrainedAddElementAction(addChildMenu, document, -1);
- }
-
-
- protected void contributeAddSiblingActions(IMenuManager menu, Node node, int ic, int vc) {
- IMenuManager addBeforeMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_BEFORE); //$NON-NLS-1$
- IMenuManager addAfterMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_AFTER); //$NON-NLS-1$
- menu.add(addBeforeMenu);
- menu.add(addAfterMenu);
-
- Node parentNode = node.getParentNode();
- if (parentNode != null) {
- int index = getIndex(parentNode, node);
- if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
- Element parentElement = (Element) parentNode;
- CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement);
- if (parentED != null) {
- // 'Add Before...' and 'Add After...' actions
- //
- List modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(parentElement, parentED, index, ic, vc, modelQueryActionList);
- addActionHelper(addBeforeMenu, modelQueryActionList);
-
- modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(parentElement, parentED, index + 1, ic, vc, modelQueryActionList);
- addActionHelper(addAfterMenu, modelQueryActionList);
- }
-
- // add COMMENT and PI before and after
- contributePIAndCommentActions(addBeforeMenu, parentElement, parentED, index);
- contributePIAndCommentActions(addAfterMenu, parentElement, parentED, index + 1);
-
- // add PCDATA, CDATA_SECTION before and after
- contributeTextNodeActions(addBeforeMenu, parentElement, parentED, index);
- contributeTextNodeActions(addAfterMenu, parentElement, parentED, index + 1);
-
- // add NEW ELEMENT before and after
- contributeUnconstrainedAddElementAction(addBeforeMenu, parentElement, parentED, index);
- contributeUnconstrainedAddElementAction(addAfterMenu, parentElement, parentED, index + 1);
- } else if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
- Document document = (Document) parentNode;
- CMDocument cmDocument = modelQuery.getCorrespondingCMDocument(parentNode);
- if (cmDocument != null) {
- // add possible root element insertions
- //
- List modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(document, cmDocument, index, ic, vc, modelQueryActionList);
- addActionHelper(addAfterMenu, modelQueryActionList);
-
- modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(document, cmDocument, index + 1, ic, vc, modelQueryActionList);
- addActionHelper(addAfterMenu, modelQueryActionList);
- }
-
- // add COMMENT and PI before and after
- contributePIAndCommentActions(addBeforeMenu, document, index);
- contributePIAndCommentActions(addAfterMenu, document, index + 1);
-
- // add ELEMENT before and after
- contributeUnconstrainedAddElementAction(addBeforeMenu, document, index);
- contributeUnconstrainedAddElementAction(addAfterMenu, document, index + 1);
- }
- }
- }
-
- protected void contributeDeleteActions(IMenuManager menu, List list, int ic, int vc) {
- boolean canRemove = modelQuery.canRemove(list, vc);
-
-
- // a delete action with an empty list will produce a disabled menu
- // item
- //
- List resultList = canRemove ? list : Collections.EMPTY_LIST;
- contributeAction(menu, createDeleteAction(resultList));
- }
-
-
- protected void contributeEditActions(IMenuManager menu, Node node) {
- contributeEditGrammarInformationActions(menu, node);
-
- if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- contributeAction(menu, createEditProcessingInstructionAction((ProcessingInstruction) node));
- } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
- contributeAction(menu, createEditAttributeAction((Attr) node, null));
- }
- }
-
-
- protected void contributeEditGrammarInformationActions(IMenuManager menu, Node node) {
- Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
-
- DocumentType doctype = getDoctype(node);
- if (doctype == null) {
- contributeAction(menu, createAddDoctypeAction(document, -1));
- }
-
- if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
- contributeAction(menu, createEditDoctypeAction((DocumentType) node));
- }
-
- if (doctype == null && getRootElement(document) != null) {
- contributeAction(menu, createEditSchemaInfoAction(getRootElement(document)));
- }
- }
-
- protected void contributePIAndCommentActions(IMenuManager menu, Document document, int index) {
- // test to make sure that the index isn't before the XML declaration
- //
- contributeAction(menu, createAddCommentAction(document, index));
- contributeAction(menu, createAddProcessingInstructionAction(document, index));
- }
-
-
- protected void contributePIAndCommentActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) {
- if (parentEd == null || isCommentAllowed(parentEd)) {
- contributeAction(menu, createAddCommentAction(parentElement, index));
- contributeAction(menu, createAddProcessingInstructionAction(parentElement, index));
- }
- }
-
-
- protected void contributeReplaceActions(IMenuManager menu, List selectedNodeList, int ic, int vc) {
- // 'Replace With...' actions
- //
- IMenuManager replaceWithMenu = new MyMenuManager(XMLUIMessages._UI_MENU_REPLACE_WITH); //$NON-NLS-1$
- menu.add(replaceWithMenu);
-
- if (modelQuery.getEditMode() == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT && selectedNodeList.size() > 0) {
- Node node = (Node) selectedNodeList.get(0);
- Node parentNode = node.getParentNode();
- if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
- Element parentElement = (Element) parentNode;
- CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement);
- if (parentED != null) {
- List replaceActionList = new Vector();
- modelQuery.getReplaceActions(parentElement, parentED, selectedNodeList, ic, vc, replaceActionList);
- addActionHelper(replaceWithMenu, replaceActionList);
- }
- }
- }
- }
-
- protected void contributeTextNodeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) {
- if (parentEd == null || isTextAllowed(parentEd)) {
- CMDataType dataType = parentEd != null ? parentEd.getDataType() : null;
- contributeAction(menu, createAddPCDataAction(parentElement, dataType, index));
- contributeAction(menu, createAddCDataSectionAction(parentElement, index));
- }
- }
-
-
- protected void contributeUnconstrainedAddElementAction(IMenuManager menu, Document document, int index) {
- if (isUnconstrainedActionAllowed()) {
- if (getRootElement(document) == null) {
- int xmlDeclarationIndex = -1;
- int doctypeIndex = -1;
- NodeList nodeList = document.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int i = 0; i < nodeListLength; i++) {
- Node node = nodeList.item(i);
- int nodeType = node.getNodeType();
- if (nodeType == Node.DOCUMENT_TYPE_NODE) {
- doctypeIndex = i;
- break;
- } else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
- ProcessingInstruction pi = (ProcessingInstruction) node;
- if (pi.getTarget().equalsIgnoreCase("xml") && xmlDeclarationIndex == -1) { //$NON-NLS-1$
- xmlDeclarationIndex = i;
- }
- }
- }
-
- if ((xmlDeclarationIndex == -1 || index > xmlDeclarationIndex) && (doctypeIndex == -1 || index > doctypeIndex)) {
- contributeAction(menu, createAddElementAction(document, null, index));
- }
- }
- }
- }
-
-
- protected void contributeUnconstrainedAddElementAction(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) {
- if (isUnconstrainedActionAllowed()) {
- if (parentEd == null || parentEd.getProperty("isInferred") == Boolean.TRUE || (modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT && isElementAllowed(parentEd))) { //$NON-NLS-1$
- contributeAction(menu, createAddElementAction(parentElement, null, index));
- }
- }
- }
-
-
- protected void contributeUnconstrainedAttributeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd) {
- if (isUnconstrainedActionAllowed()) {
- if (parentEd == null || parentEd.getProperty("isInferred") == Boolean.TRUE || modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { //$NON-NLS-1$
- contributeAction(menu, createAddAttributeAction(parentElement, null));
- }
- }
- }
-
- abstract protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad);
-
- abstract protected Action createAddCDataSectionAction(Node parent, int index);
-
- abstract protected Action createAddCommentAction(Node parent, int index);
-
- abstract protected Action createAddDoctypeAction(Document parent, int index);
-
- abstract protected Action createAddElementAction(Node parent, CMElementDeclaration ed, int index);
-
- abstract protected Action createAddPCDataAction(Node parent, CMDataType dataType, int index);
-
- abstract protected Action createAddProcessingInstructionAction(Node parent, int index);
-
- abstract protected Action createAddSchemaInfoAction(Element element);
-
- abstract protected Action createDeleteAction(List selection);
-
- abstract protected Action createEditAttributeAction(Attr attribute, CMAttributeDeclaration ad);
-
- abstract protected Action createEditDoctypeAction(DocumentType doctype);
-
- abstract protected Action createEditProcessingInstructionAction(ProcessingInstruction pi);
-
- abstract protected Action createEditSchemaInfoAction(Element element);
-
- abstract protected Action createRenameAction(Node node);
-
- abstract protected Action createReplaceAction(Node parent, CMNode cmnode, int startIndex, int endIndex);
-
-
- public int getIndex(Node parentNode, Node child) {
- NodeList nodeList = parentNode.getChildNodes();
- int index = -1;
- int size = nodeList.getLength();
- for (int i = 0; i < size; i++) {
- if (nodeList.item(i) == child) {
- index = i;
- break;
- }
- }
- return index;
- }
-
-
- public Node getRefChildNodeAtIndex(Node parent, int index) {
- NodeList nodeList = parent.getChildNodes();
- Node refChild = (index >= 0 && index < nodeList.getLength()) ? nodeList.item(index) : null;
- return refChild;
- }
-
-
- protected Element getRootElement(Document document) {
- Element result = null;
- NodeList nodeList = document.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int i = 0; i < nodeListLength; i++) {
- Node node = nodeList.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- result = (Element) node;
- break;
- }
- }
- return result;
- }
-
-
- protected List getSelectedNodes(List list, boolean includeTextNodes) {
- List result = new ArrayList(0);
- for (Iterator i = list.iterator(); i.hasNext();) {
- Object object = i.next();
- if (object instanceof Node) {
- Node node = (Node) object;
- if (node.getNodeType() == Node.TEXT_NODE) {
- if (includeTextNodes) {
- result.add(object);
- }
- } else {
- result.add(node);
- }
- }
- }
- return result;
- }
-
-
- protected boolean isCommentAllowed(CMElementDeclaration parentEd) {
- int contentType = parentEd.getContentType();
- return contentType == CMElementDeclaration.ELEMENT || contentType == CMElementDeclaration.MIXED || contentType == CMElementDeclaration.PCDATA || contentType == CMElementDeclaration.ANY;
- }
-
-
- protected boolean isElementAllowed(CMElementDeclaration parentEd) {
- int contentType = parentEd.getContentType();
- return contentType == CMElementDeclaration.ELEMENT || contentType == CMElementDeclaration.MIXED || contentType == CMElementDeclaration.ANY;
- }
-
-
- protected boolean isTextAllowed(CMElementDeclaration parentEd) {
- int contentType = parentEd.getContentType();
- return contentType == CMElementDeclaration.MIXED || contentType == CMElementDeclaration.PCDATA || contentType == CMElementDeclaration.ANY;
- }
-
-
- protected boolean isUnconstrainedActionAllowed() {
- return true;
- }
-
-
- protected boolean isWhitespaceTextNode(Node node) {
- return (node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().trim().length() == 0);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java
deleted file mode 100644
index 81ddbd241d..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.ui.IActionDelegate2;
-import org.eclipse.ui.IEditorActionDelegate;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
-import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-
-/**
- * Cleanup action delegate for CSS editor
- */
-public class CleanupActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
- private IEditorPart fEditor;
- private IStructuredCleanupProcessor fCleanupProcessor;
-
- public void setActiveEditor(IAction action, IEditorPart targetEditor) {
- fEditor = targetEditor;
- }
-
- public void dispose() {
- // nulling out just in case
- fEditor = null;
- fCleanupProcessor = null;
- }
-
- public void init(IAction action) {
- if (action != null) {
- action.setText(XMLUIMessages.CleanupDocument_label);
- action.setToolTipText(XMLUIMessages.CleanupDocument_tooltip);
- action.setDescription(XMLUIMessages.CleanupDocument_description);
- }
- }
-
- public void runWithEvent(IAction action, Event event) {
- run(action);
- }
-
- public void init(IViewPart view) {
- // do nothing
- }
-
- public void run(IAction action) {
- if (fEditor instanceof ITextEditor) {
- final ITextEditor editor = (ITextEditor) fEditor;
- Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
- if (cleanupDialog.open() == Window.OK) {
- // setup runnable
- Runnable runnable = new Runnable() {
- public void run() {
- IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
- if (cleanupProcessor != null) {
- IStructuredModel model = null;
- try {
- model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
- if (model != null)
- cleanupProcessor.cleanupModel(model);
- }
- finally {
- if (model != null)
- model.releaseFromEdit();
- }
- }
- }
- };
-
- // TODO: make independent of 'model'.
- IStructuredModel model = null;
- try {
- model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
- if (model != null) {
- // begin recording
- ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
- model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
-
- // tell the model that we are about to make a big
- // model change
- model.aboutToChangeModel();
-
- // run
- BusyIndicator.showWhile(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
- }
- }
- finally {
- if (model != null) {
- // tell the model that we are done with the big
- // model
- // change
- model.changedModel();
-
- // end recording
- ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
- model.endRecording(this, selection.getOffset(), selection.getLength());
- model.releaseFromEdit();
- }
- }
- }
- }
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- // do nothing
- }
-
- IStructuredCleanupProcessor getCleanupProcessor() {
- if (fCleanupProcessor == null)
- fCleanupProcessor = new CleanupProcessorXML();
-
- return fCleanupProcessor;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java
deleted file mode 100644
index 3e170a044e..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds;
-
-public class CleanupDialogXML extends Dialog implements SelectionListener {
- protected Button fCheckBoxCompressEmptyElementTags;
- protected Button fCheckBoxConvertEOLCodes;
- protected Button fCheckBoxFormatSource;
- protected Button fCheckBoxInsertMissingTags;
- protected Button fCheckBoxInsertRequiredAttrs;
- protected Button fCheckBoxQuoteAttrValues;
- protected IStructuredModel fModel = null;
- protected Preferences fPreferences = null;
- protected Button fRadioButtonAttrNameCaseAsis;
- protected Button fRadioButtonAttrNameCaseLower;
- protected Button fRadioButtonAttrNameCaseUpper;
- protected Button fRadioButtonConvertEOLMac;
- protected Button fRadioButtonConvertEOLUnix;
- protected Button fRadioButtonConvertEOLWindows;
-
- protected Button fRadioButtonTagNameCaseAsis;
- protected Button fRadioButtonTagNameCaseLower;
- protected Button fRadioButtonTagNameCaseUpper;
-
- public CleanupDialogXML(Shell shell) {
-
- super(shell);
- }
-
- public Control createDialogArea(Composite parent) {
-
- getShell().setText(XMLUIMessages.Cleanup_UI_);
- Composite composite = new Composite(parent, SWT.NULL);
- createDialogAreaInComposite(composite);
- initializeOptions();
- return composite;
- }
-
- protected void createDialogAreaInComposite(Composite composite) {
-
- PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CLEANUP_XML_HELPID); // use
- // XML
- // specific
- // help
-
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- layout.makeColumnsEqualWidth = true;
- composite.setLayout(layout);
-
- // Compress empty element tags
- fCheckBoxCompressEmptyElementTags = new Button(composite, SWT.CHECK);
- fCheckBoxCompressEmptyElementTags.setText(XMLUIMessages.Compress_empty_element_tags_UI_);
- fCheckBoxCompressEmptyElementTags.addSelectionListener(this);
-
- // Insert missing required attrs
- fCheckBoxInsertRequiredAttrs = new Button(composite, SWT.CHECK);
- fCheckBoxInsertRequiredAttrs.setText(XMLUIMessages.Insert_required_attributes_UI_);
- fCheckBoxInsertRequiredAttrs.addSelectionListener(this);
-
- // Insert missing begin/end tags
- fCheckBoxInsertMissingTags = new Button(composite, SWT.CHECK);
- fCheckBoxInsertMissingTags.setText(XMLUIMessages.Insert_missing_tags_UI_);
- fCheckBoxInsertMissingTags.addSelectionListener(this);
-
- // Quote attribute values
- fCheckBoxQuoteAttrValues = new Button(composite, SWT.CHECK);
- fCheckBoxQuoteAttrValues.setText(XMLUIMessages.Quote_attribute_values_UI_);
- fCheckBoxQuoteAttrValues.addSelectionListener(this);
-
- // Format source
- fCheckBoxFormatSource = new Button(composite, SWT.CHECK);
- fCheckBoxFormatSource.setText(XMLUIMessages.Format_source_UI_);
- fCheckBoxFormatSource.addSelectionListener(this);
-
- // Convert EOL code
- fCheckBoxConvertEOLCodes = new Button(composite, SWT.CHECK);
- fCheckBoxConvertEOLCodes.setText(XMLUIMessages.Convert_EOL_codes_UI_);
- fCheckBoxConvertEOLCodes.addSelectionListener(this);
- Composite EOLCodes = new Composite(composite, SWT.NULL);
- GridLayout hLayout = new GridLayout();
- hLayout.numColumns = 3;
- EOLCodes.setLayout(hLayout);
- fRadioButtonConvertEOLWindows = new Button(EOLCodes, SWT.RADIO);
- fRadioButtonConvertEOLWindows.setText(XMLUIMessages.EOL_Windows_UI);
- fRadioButtonConvertEOLWindows.addSelectionListener(this);
- fRadioButtonConvertEOLUnix = new Button(EOLCodes, SWT.RADIO);
- fRadioButtonConvertEOLUnix.setText(XMLUIMessages.EOL_Unix_UI);
- fRadioButtonConvertEOLUnix.addSelectionListener(this);
- fRadioButtonConvertEOLMac = new Button(EOLCodes, SWT.RADIO);
- fRadioButtonConvertEOLMac.setText(XMLUIMessages.EOL_Mac_UI);
- fRadioButtonConvertEOLMac.addSelectionListener(this);
- }
-
- protected void enableEOLCodeRadios(boolean enable) {
-
- if ((fRadioButtonConvertEOLWindows != null) && (fRadioButtonConvertEOLUnix != null) && (fRadioButtonConvertEOLMac != null)) {
- fRadioButtonConvertEOLWindows.setEnabled(enable);
- fRadioButtonConvertEOLUnix.setEnabled(enable);
- fRadioButtonConvertEOLMac.setEnabled(enable);
- if (!fRadioButtonConvertEOLWindows.getSelection() && !fRadioButtonConvertEOLUnix.getSelection() && !fRadioButtonConvertEOLMac.getSelection())
- fRadioButtonConvertEOLWindows.setSelection(true);
- }
- }
-
- protected Preferences getModelPreferences() {
- return XMLCorePlugin.getDefault().getPluginPreferences();
- }
-
- protected void initializeOptions() {
-
- fCheckBoxCompressEmptyElementTags.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
- fCheckBoxInsertRequiredAttrs.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
- fCheckBoxInsertMissingTags.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS));
- fCheckBoxQuoteAttrValues.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES));
- fCheckBoxFormatSource.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.FORMAT_SOURCE));
- fCheckBoxConvertEOLCodes.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES));
- String EOLCode = getModelPreferences().getString(XMLCorePreferenceNames.CLEANUP_EOL_CODE);
- if (EOLCode.compareTo(CommonEncodingPreferenceNames.LF) == 0)
- fRadioButtonConvertEOLUnix.setSelection(true);
- else if (EOLCode.compareTo(CommonEncodingPreferenceNames.CR) == 0)
- fRadioButtonConvertEOLMac.setSelection(true);
- else
- fRadioButtonConvertEOLWindows.setSelection(true);
- enableEOLCodeRadios(fCheckBoxConvertEOLCodes.getSelection());
- }
-
- protected void okPressed() {
-
- storeOptions();
- super.okPressed();
- }
-
- public void setModel(IStructuredModel model) {
-
- fModel = model;
- }
-
- protected void storeOptions() {
-
- getModelPreferences().setValue(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, fCheckBoxCompressEmptyElementTags.getSelection());
- getModelPreferences().setValue(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, fCheckBoxInsertRequiredAttrs.getSelection());
- getModelPreferences().setValue(XMLCorePreferenceNames.INSERT_MISSING_TAGS, fCheckBoxInsertMissingTags.getSelection());
- getModelPreferences().setValue(XMLCorePreferenceNames.QUOTE_ATTR_VALUES, fCheckBoxQuoteAttrValues.getSelection());
- getModelPreferences().setValue(XMLCorePreferenceNames.FORMAT_SOURCE, fCheckBoxFormatSource.getSelection());
- getModelPreferences().setValue(XMLCorePreferenceNames.CONVERT_EOL_CODES, fCheckBoxConvertEOLCodes.getSelection());
- if (fRadioButtonConvertEOLUnix.getSelection()) {
- getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.LF);
- } else if (fRadioButtonConvertEOLMac.getSelection()) {
- getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CR);
- } else {
- getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CRLF);
- }
- // explicitly save plugin preferences so values are stored
- XMLCorePlugin.getDefault().savePluginPreferences();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
-
- getButton(OK).setEnabled((fRadioButtonTagNameCaseLower != null && (fRadioButtonTagNameCaseLower.getSelection() || fRadioButtonTagNameCaseUpper.getSelection())) || (fRadioButtonAttrNameCaseLower != null && (fRadioButtonAttrNameCaseLower.getSelection() || fRadioButtonAttrNameCaseUpper.getSelection())) || fCheckBoxInsertMissingTags.getSelection() || fCheckBoxQuoteAttrValues.getSelection() || fCheckBoxFormatSource.getSelection() || fCheckBoxConvertEOLCodes.getSelection() || (fRadioButtonConvertEOLUnix != null && (fRadioButtonConvertEOLUnix.getSelection() || fRadioButtonConvertEOLMac.getSelection() || fRadioButtonConvertEOLWindows.getSelection())));
- if (e.widget == fCheckBoxConvertEOLCodes)
- enableEOLCodeRadios(fCheckBoxConvertEOLCodes.getSelection());
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java
deleted file mode 100644
index 5e3a98402b..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.dialogs.EditAttributeDialog;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-public class EditAttributeAction extends NodeAction {
- protected static ImageDescriptor imageDescriptor;
-
- public static ImageDescriptor createImageDescriptor() {
- if (imageDescriptor == null) {
- imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
- }
- return imageDescriptor;
- }
-
- protected Attr attr;
- protected AbstractNodeActionManager manager;
- protected Element ownerElement;
- protected String title;
-
- public EditAttributeAction(AbstractNodeActionManager manager, Element ownerElement, Attr attr, String actionLabel, String title) {
- this.manager = manager;
- this.ownerElement = ownerElement;
- this.attr = attr;
- this.title = title;
- setText(actionLabel);
- // assume if attr is null then this is an 'Add' that requires action
- // an icons... otherwise this is an edit
- if (attr == null) {
- setImageDescriptor(createImageDescriptor());
- }
- }
-
- public String getUndoDescription() {
- return title;
- }
-
- public void run() {
- manager.beginNodeAction(this);
- Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
- EditAttributeDialog dialog = new EditAttributeDialog(shell, ownerElement, attr);
- dialog.create();
- dialog.getShell().setText(title);
- dialog.setBlockOnOpen(true);
- dialog.open();
-
- if (dialog.getReturnCode() == Window.OK) {
- if (attr != null) {
- ownerElement.removeAttributeNode(attr);
- }
- Document document = ownerElement.getOwnerDocument();
- Attr newAttribute = document.createAttribute(dialog.getAttributeName());
- newAttribute.setValue(dialog.getAttributeValue());
- ownerElement.setAttributeNode(newAttribute);
- manager.setViewerSelection(newAttribute);
- }
- manager.endNodeAction(this);
- }
-}
-
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java
deleted file mode 100644
index 0a7c2bfb09..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.dialogs.EditDoctypeDialog;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * EditDoctypeAction
- */
-public class EditDoctypeAction extends Action {
- protected DocumentType doctype;
- protected Document document;
- protected IStructuredModel model;
- protected String resourceLocation;
- protected String title;
-
- /**
- * This constructor is used to create a new doctype.
- */
- public EditDoctypeAction(IStructuredModel model, Document document, String resourceLocation, String title) {
- setText(title);
- this.model = model;
- this.document = document;
- this.resourceLocation = resourceLocation;
- this.title = title;
- }
-
- /**
- * This constructor is used to edit an exisitng doctype.
- */
- public EditDoctypeAction(IStructuredModel model, DocumentType doctype, String resourceLocation, String title) {
- setText(title);
- this.model = model;
- this.doctype = doctype;
- this.resourceLocation = resourceLocation;
- this.title = title;
- }
-
-
- protected DocumentType createDoctype(EditDoctypeDialog dialog, Document document) {
- DocumentType result = null;
- if (document instanceof DocumentImpl) {
- IDOMDocument documentImpl = (IDOMDocument) document;
- IDOMDocumentType doctypeImpl = (IDOMDocumentType) documentImpl.createDoctype(dialog.getName());
- doctypeImpl.setPublicId(dialog.getPublicId());
- doctypeImpl.setSystemId(dialog.getSystemId());
- result = doctypeImpl;
- }
- return result;
- }
-
- private Display getDisplay() {
-
- return PlatformUI.getWorkbench().getDisplay();
- }
-
-
- protected String getRootElementName(Document document) {
- Element rootElement = null;
- NodeList nodeList = document.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int i = 0; i < nodeListLength; i++) {
- Node childNode = nodeList.item(i);
- if (childNode.getNodeType() == Node.ELEMENT_NODE) {
- rootElement = (Element) childNode;
- break;
- }
- }
- return rootElement != null ? rootElement.getNodeName() : XMLUIMessages._UI_LABEL_ROOT_ELEMENT_VALUE; //$NON-NLS-1$
- }
-
- public String getUndoDescription() {
- return title;
- }
-
-
- protected void insertDoctype(DocumentType doctype, Document document) {
- Node refChild = null;
- NodeList nodeList = document.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int i = 0; i < nodeListLength; i++) {
- Node childNode = nodeList.item(i);
- if (childNode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE || childNode.getNodeType() == Node.COMMENT_NODE) {
- // continue on to the nextNode
- } else {
- refChild = childNode;
- break;
- }
- }
-
- document.insertBefore(doctype, refChild);
- //manager.reformat(doctype, false);
- }
-
- public void run() {
- model.beginRecording(this, getUndoDescription());
- //Shell shell =
- // XMLCommonUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
- Shell shell = getDisplay().getActiveShell();
- EditDoctypeDialog dialog = showEditDoctypeDialog(shell);
-
- if (dialog.getReturnCode() == Window.OK) {
- if (doctype != null) {
- updateDoctype(dialog, doctype);
- } else if (document != null) {
- DocumentType doctype = createDoctype(dialog, document);
- if (doctype != null) {
- insertDoctype(doctype, document);
- }
- }
- }
- model.endRecording(this);
- }
-
- protected EditDoctypeDialog showEditDoctypeDialog(Shell shell) {
- EditDoctypeDialog dialog = null;
-
- if (doctype != null) {
- dialog = new EditDoctypeDialog(shell, doctype);
- if (title == null) {
- title = XMLUIMessages._UI_LABEL_EDIT_DOCTYPE; //$NON-NLS-1$
- }
- } else if (document != null) {
- String rootElementName = getRootElementName(document);
- dialog = new EditDoctypeDialog(shell, rootElementName, "", rootElementName + ".dtd"); //$NON-NLS-1$ //$NON-NLS-2$
- if (title == null) {
- title = XMLUIMessages._UI_MENU_ADD_DTD_INFORMATION_TITLE; //$NON-NLS-1$
- }
- }
-
- dialog.setComputeSystemId(doctype == null || doctype.getSystemId() == null || doctype.getSystemId().trim().length() == 0);
-
- dialog.setErrorChecking(false);//!model.getType().equals(IStructuredModel.HTML));
- dialog.create();
- dialog.getShell().setText(title);
- dialog.setBlockOnOpen(true);
- dialog.setResourceLocation(new Path(resourceLocation));
- dialog.open();
-
- return dialog;
- }
-
-
- protected void updateDoctype(EditDoctypeDialog dialog, DocumentType doctype) {
- if (doctype instanceof IDOMDocumentType) {
- IDOMDocumentType doctypeImpl = (IDOMDocumentType) doctype;
- if (doctypeImpl.getName().equals(dialog.getName())) {
- doctypeImpl.setPublicId(dialog.getPublicId());
- doctypeImpl.setSystemId(dialog.getSystemId());
- } else {
- // we need to create a new one and remove the old
- //
- Document document = doctype.getOwnerDocument();
- DocumentType newDoctype = createDoctype(dialog, document);
- document.insertBefore(newDoctype, doctype);
- document.removeChild(doctype);
- //manager.reformat(newDoctype, false);
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java
deleted file mode 100644
index 9084fa9523..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.dialogs.EditElementDialog;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class EditElementAction extends NodeAction {
-
- protected static ImageDescriptor imageDescriptor;
-
- public static ImageDescriptor createImageDescriptor() {
- if (imageDescriptor == null) {
- imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT);
- }
- return imageDescriptor;
- }
-
- protected Element element;
- protected int insertionIndex = -1;
- protected AbstractNodeActionManager manager;
- protected Node parent;
- protected String title;
-
- public EditElementAction(AbstractNodeActionManager manager, Element element, String actionLabel, String dialogTitle) {
- this(manager, element.getParentNode(), -1, element, actionLabel, dialogTitle);
- }
-
- protected EditElementAction(AbstractNodeActionManager manager, Node parent, int index, Element element, String actionLabel, String title) {
- this.manager = manager;
- this.parent = parent;
- this.insertionIndex = index;
- this.element = element;
- this.title = title;
- setText(actionLabel);
- if (element == null) {
- setImageDescriptor(createImageDescriptor());
- }
- }
-
- public EditElementAction(AbstractNodeActionManager manager, Node parent, int index, String actionLabel, String title) {
- this(manager, parent, index, null, actionLabel, title);
- }
-
- public String getUndoDescription() {
- return title;
- }
-
- public void run() {
- manager.beginNodeAction(this);
- Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
- EditElementDialog dialog = new EditElementDialog(shell, element);
- dialog.create();
- dialog.getShell().setText(title);
- dialog.setBlockOnOpen(true);
- dialog.open();
-
- if (dialog.getReturnCode() == Window.OK) {
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
- if (element != null) {
- // here we need to do a rename... which seems to be quite hard
- // to do :-(
- if (element instanceof IDOMElement) {
- IDOMElement elementImpl = (IDOMElement) element;
- IDOMModel model = elementImpl.getModel();
- String oldName = elementImpl.getNodeName();
- String newName = dialog.getElementName();
- setStructuredDocumentRegionElementName(model, elementImpl.getStartStructuredDocumentRegion(), oldName, newName);
- setStructuredDocumentRegionElementName(model, elementImpl.getEndStructuredDocumentRegion(), oldName, newName);
- }
- } else {
- Element newElement = document.createElement(dialog.getElementName());
- NodeList nodeList = parent.getChildNodes();
- int nodeListLength = nodeList.getLength();
- Node refChild = insertionIndex < nodeListLength && insertionIndex >= 0 ? nodeList.item(insertionIndex) : null;
- parent.insertBefore(newElement, refChild);
- manager.reformat(newElement, false);
- manager.setViewerSelection(newElement);
- }
- }
- manager.endNodeAction(this);
- }
-
- protected void setStructuredDocumentRegionElementName(IDOMModel model, IStructuredDocumentRegion flatNode, String oldName, String newName) {
- if (flatNode != null) {
- String string = flatNode.getText();
- int index = string.indexOf(oldName);
- if (index != -1) {
- index += flatNode.getStart();
- model.getStructuredDocument().replaceText(this, index, oldName.length(), newName);
- }
- }
- }
-}
-
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java
deleted file mode 100644
index cf1cc1d164..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.dialogs.EditProcessingInstructionDialog;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-
-/**
- * EditProcessingInstructionAction
- */
-public class EditProcessingInstructionAction extends NodeAction {
- protected Node childRef;
- protected AbstractNodeActionManager manager;
- protected Node parent;
- protected ProcessingInstruction pi;
- protected String title;
-
- /**
- * This constructor is used to add a new ProcessingInstruction
- */
- public EditProcessingInstructionAction(AbstractNodeActionManager manager, Node parent, Node childRef, String actionLabel, String title) {
- setText(actionLabel);
- this.manager = manager;
- this.parent = parent;
- this.childRef = childRef;
- this.title = title;
- }
-
- /**
- * This constructor is used to edit a ProcessingInstruction
- */
- public EditProcessingInstructionAction(AbstractNodeActionManager manager, ProcessingInstruction pi, String actionLabel, String title) {
- setText(actionLabel);
- this.manager = manager;
- this.pi = pi;
- this.parent = pi.getParentNode();
- this.title = title;
- }
-
- public String getUndoDescription() {
- return title;
- }
-
- public void run() {
- manager.beginNodeAction(this);
- Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
-
- EditProcessingInstructionDialog dialog = null;
- if (pi != null) {
- dialog = new EditProcessingInstructionDialog(shell, pi);
- } else {
- dialog = new EditProcessingInstructionDialog(shell, XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- dialog.create();
- dialog.getShell().setText(title);
- dialog.setBlockOnOpen(true);
- dialog.open();
-
- if (dialog.getReturnCode() == Window.OK) {
- if (pi != null) {
- childRef = pi;
- }
-
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();
- Node newNode = document.createProcessingInstruction(dialog.getTarget(), dialog.getData());
- parent.insertBefore(newNode, childRef);
-
- if (pi != null) {
- parent.removeChild(pi);
- }
-
- manager.reformat(newNode, false);
- manager.setViewerSelection(newNode);
- }
- manager.endNodeAction(this);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java
deleted file mode 100644
index 391931bdac..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.dialogs.EditSchemaInfoDialog;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * EditDoctypeAction
- */
-public class EditSchemaInfoAction extends NodeAction {
- protected AbstractNodeActionManager manager;
- protected DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager();
- protected Node node;
- protected String resourceLocation;
- protected String title;
-
- public EditSchemaInfoAction(AbstractNodeActionManager manager, Node node, String resourceLocation, String title) {
- this.manager = manager;
- this.node = node;
- setText(title);
- this.resourceLocation = resourceLocation;
- this.title = title;
- }
-
- protected Map createPrefixMapping(List oldList, List newList) {
- Map map = new Hashtable();
-
- Hashtable oldURIToPrefixTable = new Hashtable();
- for (Iterator i = oldList.iterator(); i.hasNext();) {
- NamespaceInfo oldInfo = (NamespaceInfo) i.next();
- oldURIToPrefixTable.put(oldInfo.uri, oldInfo);
- }
-
- for (Iterator i = newList.iterator(); i.hasNext();) {
- NamespaceInfo newInfo = (NamespaceInfo) i.next();
- NamespaceInfo oldInfo = (NamespaceInfo) oldURIToPrefixTable.get(newInfo.uri != null ? newInfo.uri : ""); //$NON-NLS-1$
-
-
- // if oldInfo is non null ... there's a matching URI in the old
- // set
- // we can use its prefix to detemine out mapping
- //
- // if oldInfo is null ... we use the 'oldCopy' we stashed away
- // assuming that the user changed the URI and the prefix
- if (oldInfo == null) {
- oldInfo = (NamespaceInfo) newInfo.getProperty("oldCopy"); //$NON-NLS-1$
- }
-
- if (oldInfo != null) {
- String newPrefix = newInfo.prefix != null ? newInfo.prefix : ""; //$NON-NLS-1$
- String oldPrefix = oldInfo.prefix != null ? oldInfo.prefix : ""; //$NON-NLS-1$
- if (!oldPrefix.equals(newPrefix)) {
- map.put(oldPrefix, newPrefix);
- }
- }
- }
- return map;
- }
-
- public Element getElement(Node node) {
- Element result = null;
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- result = (Element) node;
- } else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- result = getRootElement((Document) node);
- }
- return result;
- }
-
-
- public Element getRootElement(Document document) {
- Element rootElement = null;
- NodeList nodeList = document.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int i = 0; i < nodeListLength; i++) {
- Node childNode = nodeList.item(i);
- if (childNode.getNodeType() == Node.ELEMENT_NODE) {
- rootElement = (Element) childNode;
- break;
- }
- }
- return rootElement;
- }
-
- public String getUndoDescription() {
- return title;
- }
-
- public void run() {
- manager.beginNodeAction(this);
-
- // todo... change constructor to take an element
- Element element = getElement(node);
- if (element != null) {
- Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
- EditSchemaInfoDialog dialog = new EditSchemaInfoDialog(shell, new Path(resourceLocation));
-
- List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element);
- List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList);
-
- // here we store a copy of the old info for each NamespaceInfo
- // this info will be used in createPrefixMapping() to figure out
- // how to update the document
- // in response to these changes
- for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) {
- NamespaceInfo info = (NamespaceInfo) i.next();
- NamespaceInfo oldCopy = new NamespaceInfo(info);
- info.setProperty("oldCopy", oldCopy); //$NON-NLS-1$
- }
-
- dialog.setNamespaceInfoList(namespaceInfoList);
- dialog.create();
- //dialog.getShell().setSize(500, 300);
- dialog.getShell().setText(XMLUIMessages._UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE); //$NON-NLS-1$
- dialog.setBlockOnOpen(true);
- dialog.open();
-
- if (dialog.getReturnCode() == Window.OK) {
- List newInfoList = dialog.getNamespaceInfoList();
- namespaceInfoManager.removeNamespaceInfo(element);
- namespaceInfoManager.addNamespaceInfo(element, newInfoList, true);
-
- // see if we need to rename any prefixes
- Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList);
- if (prefixMapping.size() > 0) {
- try {
- manager.getModel().aboutToChangeModel();
- ReplacePrefixAction replacePrefixAction = new ReplacePrefixAction(manager, element, prefixMapping);
- replacePrefixAction.run();
- } finally {
- manager.getModel().changedModel();
- }
- }
- }
- }
- manager.endNodeAction(this);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java
deleted file mode 100644
index ed716d7446..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-
-
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import com.ibm.icu.text.Collator;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-
-
-public class MenuBuilder {
-
-
- protected Comparator comparator = new Comparator() {
-
- public int compare(Object o1, Object o2) {
- return Collator.getInstance().compare(getSortKey(o1), getSortKey(o2));
- }
-
- protected String getSortKey(Object o) {
- String result = ""; //$NON-NLS-1$
- if (o instanceof IAction) {
- IAction action = (IAction) o;
- result = action.getText();
- }
- //else if (o instanceof MenuData)
- //{
- // result = "z" + ((MenuData)o).name;
- //}
- return result;
- }
- };
-
-
- protected void createAlphebeticalGrouping(IMenuManager menu, List actionList) {
- Object[] array = actionList.toArray();
- if (array.length > 0) {
- Arrays.sort(array, comparator);
- }
-
- int groupSize = 15;
- int minGroupSize = 5;
- int numberOfGroups = (array.length / groupSize) + ((array.length % groupSize > minGroupSize) ? 1 : 0);
-
- for (int i = 0; i < numberOfGroups; i++) {
- boolean isLastGroup = (i == (numberOfGroups - 1));
- int firstIndex = i * groupSize;
- int lastIndex = isLastGroup ? array.length - 1 : i * groupSize + groupSize - 1;
- Action firstAction = (Action) array[firstIndex];
- Action lastAction = (Action) array[lastIndex];
- MenuManager submenu = new MenuManager(firstAction.getText() + " - " + lastAction.getText()); //$NON-NLS-1$
- menu.add(submenu);
- for (int j = firstIndex; j <= lastIndex; j++) {
- submenu.add((Action) array[j]);
- }
- }
- }
-
-
- public void populateMenu(IMenuManager menu, List actionList, boolean createTiered) {
- // sort the actions
- if (actionList.size() < 25) {
- Object[] array = actionList.toArray();
- if (array.length > 0) {
- Arrays.sort(array, comparator);
- }
- for (int i = 0; i < array.length; i++) {
- menu.add((Action) array[i]);
- }
- } else {
- createAlphebeticalGrouping(menu, actionList);
- }
- }
-
- /*
- * protected void createPropertyGrouping(IMenuManager menu, List
- * actionList) { MenuDataTable menuDataTable = new MenuDataTable();
- *
- * for (Iterator i = actionList.iterator(); i.hasNext(); ) { String
- * groupName = null; Action action = (Action)i.next(); if (action
- * instanceof NodeAction) { groupName =
- * ((NodeAction)action).getGroupName(); } if (groupName == null) {
- * groupName = ""; } MenuData menuData =
- * menuDataTable.lookupOrCreate(groupName, "");
- * menuData.childList.add(action); } populateMenu(menu,
- * menuDataTable.getRoot()); }
- *
- *
- * protected void populateMenu(MenuManager menuManager, MenuData menuData) {
- * for (Iterator i = menuData.childList.iterator(); i.hasNext(); ) {
- * Object o = i.next(); if (o instanceof Action) {
- * menuManager.add((Action)o); } else if (o instanceof MenuData) {
- * MenuData childMenuData = (MenuData)o; MenuManager childMenuManager =
- * new MenuManager(childMenuData.name); menuManager.add(childMenuManager);
- * populateMenu(childMenuManager, childMenuData); } } }
- *
- *
- * public MenuDataTable { protected Hashtable table = new Hashtable();
- * protected MenuData root;
- *
- * public MenuDataTable() { root = lookupOrCreateMenuData(null, null); }
- *
- * protected MenuData lookupMenuData(String name) { String key = name !=
- * null ? name : ""; return (MenuData)menuDataTable.get(key); }
- *
- * protected MenuData lookupOrCreateMenuData(String name, String
- * parentName) { String key = name != null ? name : ""; MenuData menuData =
- * (MenuData)menuDataTable.get(key); if (menuData == null) { menuData =
- * new MenuData(name, parentName); menuDataTable.put(key, menuData); }
- * return menuData; }
- *
- * public MenuData getRoot() { return root; } }
- *
- *
- * protected class MenuData { public String name; public String
- * parentName; public List childList = new Vector();
- *
- * MenuData(String name, String parentName) { this.name = name;
- * this.parentName = parentName; }
- *
- * protected void sort() { Object[] array = childList.toArray(); if
- * (array.length > 0 ) { Arrays.sort(array, comparator); } childList =
- * Arrays.asList(array);
- *
- * for (Iterator i = childList.iterator(); i.hasNext(); ) { Object o =
- * i.next(); if (o instanceof MenuData) { ((MenuData)o).sort(); } } } }
- */
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java
deleted file mode 100644
index 64c472813f..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-
-
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.Action;
-
-public abstract class NodeAction extends Action {
-
- public String getSortKey() {
- return null;
- }
-
- public abstract String getUndoDescription();
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java
deleted file mode 100644
index a762ceac50..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.xml.core.internal.document.CommentImpl;
-import org.eclipse.wst.xml.ui.internal.Logger;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-
-/**
- * Remove block comment action delegate for XML editor
- */
-public class RemoveBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
-
- void processAction(IDocument document, ITextSelection textSelection) {
- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
- if (model != null) {
- try {
- IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
- IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
-
- if (selectionStartIndexedRegion == null || selectionEndIndexedRegion == null)
- return;
-
- int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
- int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length();
-
- model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip);
- model.aboutToChangeModel();
-
- try {
- if (textSelection.getLength() == 0) {
- if (selectionStartIndexedRegion instanceof CommentImpl) {
- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
- }
- }
- else {
- if (selectionStartIndexedRegion instanceof CommentImpl) {
- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
- }
-
- if (selectionEndIndexedRegion instanceof CommentImpl) {
- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
- }
- }
- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- finally {
- model.changedModel();
- model.endRecording(this);
- }
- }
- finally {
- model.releaseFromEdit();
- }
- }
- }
-
- public void init(IAction action) {
- if (action != null) {
- action.setText(XMLUIMessages.RemoveBlockComment_label);
- action.setToolTipText(XMLUIMessages.RemoveBlockComment_tooltip);
- action.setDescription(XMLUIMessages.RemoveBlockComment_description);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java
deleted file mode 100644
index 46430e974d..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.actions;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMVisitor;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-
-public class ReplacePrefixAction extends NodeAction {
-
- class NodeCollectingDOMVisitor extends DOMVisitor {
- public List list = new Vector();
-
- protected boolean isPrefixChangedNeeded(Node node) {
- String key = node.getPrefix() != null ? node.getPrefix() : ""; //$NON-NLS-1$
- return prefixMapping.get(key) != null;
- }
-
- public void visitAttr(Attr attr) {
- /*
- * if (isPrefixChangedNeeded(element)) { list.add(attr); }
- */
- }
-
- protected void visitElement(Element element) {
- super.visitElement(element);
- if (isPrefixChangedNeeded(element)) {
- list.add(element);
- }
- }
- }
-
- protected static ImageDescriptor imageDescriptor;
- protected Element element;
- protected AbstractNodeActionManager manager;
- protected Map prefixMapping;
-
- public ReplacePrefixAction(AbstractNodeActionManager manager, Element element, Map prefixMapping) {
- this.manager = manager;
- this.element = element;
- this.prefixMapping = prefixMapping;
- }
-
- public String getUndoDescription() {
- return ""; //$NON-NLS-1$
- }
-
- public void run() {
- NodeCollectingDOMVisitor visitor = new NodeCollectingDOMVisitor();
- visitor.visitNode(element);
- for (Iterator i = visitor.list.iterator(); i.hasNext();) {
- Node node = (Node) i.next();
- String key = node.getPrefix() != null ? node.getPrefix() : ""; //$NON-NLS-1$
- String newPrefix = (String) prefixMapping.get(key);
- if (newPrefix != null) {
- node.setPrefix(newPrefix);
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java
deleted file mode 100644
index 5c6710f3d9..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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.xml.ui.internal.actions;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.ui.internal.Logger;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-
-/**
- * Toggle comment action delegate for XML editor
- */
-public class ToggleCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
- public void init(IAction action) {
- if (action != null) {
- action.setText(XMLUIMessages.ToggleComment_label);
- action.setToolTipText(XMLUIMessages.ToggleComment_tooltip);
- action.setDescription(XMLUIMessages.ToggleComment_description);
- }
- }
-
- void processAction(IDocument document, ITextSelection textSelection) {
- // get text selection lines info
- int selectionStartLine = textSelection.getStartLine();
- int selectionEndLine = textSelection.getEndLine();
- try {
- int selectionEndLineOffset = document.getLineOffset(selectionEndLine);
- int selectionEndOffset = textSelection.getOffset() + textSelection.getLength();
-
- // adjust selection end line
- if (selectionEndLine > selectionStartLine && selectionEndLineOffset == selectionEndOffset)
- selectionEndLine--;
-
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
-
- // save the selection position since it will be changing
- Position selectionPosition = null;
- boolean updateStartOffset = false;
- try {
- selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength());
- document.addPosition(selectionPosition);
-
- // extra check if commenting from beginning of line
- int selectionStartLineOffset = document.getLineOffset(selectionStartLine);
- if (textSelection.getLength() > 0 && selectionStartLineOffset == textSelection.getOffset() && !isCommentLine(document, selectionStartLine))
- updateStartOffset = true;
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
-
- processAction(document, selectionStartLine, selectionEndLine);
-
- updateCurrentSelection(selectionPosition, document, updateStartOffset);
- }
-
- private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) {
- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
- if (model != null) {
- try {
- model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip);
- model.aboutToChangeModel();
-
- for (int i = selectionStartLine; i <= selectionEndLine; i++) {
- try {
- if (document.getLineLength(i) > 0) {
- if (isCommentLine(document, i)) {
- int lineOffset = document.getLineOffset(i);
- IRegion region = document.getLineInformation(i);
- String string = document.get(region.getOffset(), region.getLength());
- int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT);
- int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length();
- uncomment(document, openCommentOffset, closeCommentOffset);
- }
- else {
- int openCommentOffset = document.getLineOffset(i);
- int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length();
- int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length();
- comment(document, openCommentOffset, closeCommentOffset);
- }
- }
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- }
- }
- finally {
- model.changedModel();
- model.endRecording(this);
- model.releaseFromEdit();
- }
- }
- }
-
- private boolean isCommentLine(IDocument document, int line) {
- boolean isComment = false;
-
- try {
- IRegion region = document.getLineInformation(line);
- String string = document.get(region.getOffset(), region.getLength()).trim();
- isComment = string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length() && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT);
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- return isComment;
- }
-
- private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) {
- try {
- document.replace(openCommentOffset, 0, OPEN_COMMENT);
- document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- }
-
- private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) {
- try {
- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- }
-
- private void updateCurrentSelection(Position selectionPosition, IDocument document, boolean updateStartOffset) {
- if (fEditor instanceof ITextEditor) {
- // update the selection if text selection changed
- if (selectionPosition != null) {
- ITextSelection selection = null;
- if (updateStartOffset)
- selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length());
- else
- selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength());
- ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider();
- if (provider != null) {
- provider.setSelection(selection);
- }
- document.removePosition(selectionPosition);
- }
- }
- }
-}

Back to the top