1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.pde.internal.core.ischema.ISchemaComplexType; 18 import org.eclipse.pde.internal.core.ischema.ISchemaType; 19 import org.eclipse.pde.internal.core.schema.SchemaAttribute; 20 import org.eclipse.pde.internal.core.schema.SchemaComplexType; 21 import org.eclipse.pde.internal.core.schema.SchemaElement; 22 import org.eclipse.pde.internal.core.schema.SchemaSimpleType; 23 import org.eclipse.pde.internal.ui.PDEPlugin; 24 import org.eclipse.pde.internal.ui.PDEPluginImages; 25 import org.eclipse.pde.internal.ui.PDEUIMessages; 26 27 public class NewAttributeAction extends Action { 28 private SchemaElement element; 29 private static final String NAME_COUNTER_KEY = "__schema_attribute_name"; public NewAttributeAction() { 31 setText(PDEUIMessages.SchemaEditor_NewAttribute_label); 32 setImageDescriptor(PDEPluginImages.DESC_ATT_IMPL_OBJ); 33 setToolTipText(PDEUIMessages.SchemaEditor_NewAttribute_tooltip); 34 } 35 public org.eclipse.pde.internal.core.schema.SchemaElement getElement() { 36 return element; 37 } 38 private String getInitialName() { 39 Hashtable counters = PDEPlugin.getDefault().getDefaultNameCounters(); 40 Integer counter = (Integer )counters.get(NAME_COUNTER_KEY); 41 if (counter==null) { 42 counter = new Integer (1); 43 } 44 else { 45 counter = new Integer (counter.intValue()+1); 46 } 47 counters.put(NAME_COUNTER_KEY, counter); 48 return NLS.bind(PDEUIMessages.SchemaEditor_NewAttribute_initialName, counter.intValue()+""); } 50 public void run() { 51 String name = getInitialName(); 52 SchemaAttribute att = new SchemaAttribute(element, name); 53 att.setType(new SchemaSimpleType(element.getSchema(), "string")); ISchemaType type = element.getType(); 55 SchemaComplexType complexType=null; 56 if (!(type instanceof ISchemaComplexType)) { 57 complexType = new SchemaComplexType(element.getSchema()); 58 element.setType(complexType); 59 } 60 else { 61 complexType = (SchemaComplexType)type; 62 } 63 complexType.addAttribute(att); 64 } 65 public void setElement(org.eclipse.pde.internal.core.schema.SchemaElement newElement) { 66 element = newElement; 67 } 68 } 69 | Popular Tags |