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.ISchema; 18 import org.eclipse.pde.internal.core.schema.Schema; 19 import org.eclipse.pde.internal.core.schema.SchemaElement; 20 import org.eclipse.pde.internal.core.schema.SchemaRootElement; 21 import org.eclipse.pde.internal.core.schema.SchemaSimpleType; 22 import org.eclipse.pde.internal.ui.PDEPlugin; 23 import org.eclipse.pde.internal.ui.PDEPluginImages; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 26 public class NewElementAction extends Action { 27 private Schema schema; 28 private static final String NAME_COUNTER_KEY = "__schema_element_name"; public NewElementAction() { 30 setText(PDEUIMessages.SchemaEditor_NewElement_label); 31 setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ); 32 setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip); 33 } 34 private String getInitialName() { 35 Hashtable counters = PDEPlugin.getDefault().getDefaultNameCounters(); 36 Integer counter = (Integer ) counters.get(NAME_COUNTER_KEY); 37 if (counter == null) { 38 counter = new Integer (1); 39 } else { 40 counter = new Integer (counter.intValue() + 1); 41 } 42 counters.put(NAME_COUNTER_KEY, counter); 43 return NLS.bind(PDEUIMessages.SchemaEditor_NewElement_initialName, counter.intValue() + ""); } 45 public org.eclipse.pde.internal.core.schema.Schema getSchema() { 46 return schema; 47 } 48 public void run() { 49 String name = getInitialName(); 50 SchemaElement element; 51 if (name.equals("extension")) element = new SchemaRootElement(schema, name); 53 else 54 element = new SchemaElement(schema, name); 55 element.setType(new SchemaSimpleType(schema, "string")); schema.addElement(element); 57 schema.updateReferencesFor(element, ISchema.REFRESH_ADD); 58 } 59 public void setSchema(Schema newSchema) { 60 schema = newSchema; 61 } 62 } 63 | Popular Tags |