1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.pde.core.plugin.IPluginElement; 16 import org.eclipse.pde.core.plugin.IPluginParent; 17 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 18 import org.eclipse.pde.internal.core.text.IDocumentNode; 19 import org.eclipse.pde.internal.core.text.plugin.PluginElementNode; 20 import org.eclipse.pde.internal.ui.PDEPlugin; 21 import org.eclipse.pde.internal.ui.PDEPluginImages; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.pde.internal.ui.editor.contentassist.XMLInsertionComputer; 24 25 public class NewElementAction extends Action { 26 public static final String UNKNOWN_ELEMENT_TAG = PDEUIMessages.NewElementAction_generic; 27 28 private ISchemaElement elementInfo; 29 30 private IPluginParent parent; 31 32 public NewElementAction(ISchemaElement elementInfo, IPluginParent parent) { 33 this.elementInfo = elementInfo; 34 this.parent = parent; 36 setText(getElementName()); 37 setImageDescriptor(PDEPluginImages.DESC_GENERIC_XML_OBJ); 38 setEnabled(parent.getModel().isEditable()); 39 } 40 41 private String getElementName() { 42 return elementInfo != null ? elementInfo.getName() : UNKNOWN_ELEMENT_TAG; 43 } 44 45 public void run() { 46 IPluginElement newElement = parent.getModel().getFactory().createElement(parent); 47 try { 48 newElement.setName(getElementName()); 49 ((PluginElementNode)newElement).setParentNode((IDocumentNode)parent); 50 parent.add(newElement); 51 52 if (elementInfo != null) { 55 XMLInsertionComputer.computeInsertion(elementInfo, newElement); 56 } 57 58 } catch (CoreException e) { 59 PDEPlugin.logException(e); 60 } 61 } 62 63 } 64 | Popular Tags |