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);
}
}
Aggregations