Search in sources :

Example 1 with EditElementDialog

use of org.eclipse.wst.xml.ui.internal.dialogs.EditElementDialog in project webtools.sourceediting by eclipse.

the class EditElementAction method run.

public void run() {
    Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
    if (validateEdit(manager.getModel(), shell)) {
        manager.beginNodeAction(this);
        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) {
                // 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);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EditElementDialog(org.eclipse.wst.xml.ui.internal.dialogs.EditElementDialog) Document(org.w3c.dom.Document) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Aggregations

Shell (org.eclipse.swt.widgets.Shell)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 EditElementDialog (org.eclipse.wst.xml.ui.internal.dialogs.EditElementDialog)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1