KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > NewAttributeAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.schema;
12
13 import java.util.Hashtable JavaDoc;
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 JavaDoc NAME_COUNTER_KEY = "__schema_attribute_name"; //$NON-NLS-1$
30
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 JavaDoc getInitialName() {
39     Hashtable JavaDoc counters = PDEPlugin.getDefault().getDefaultNameCounters();
40     Integer JavaDoc counter = (Integer JavaDoc)counters.get(NAME_COUNTER_KEY);
41     if (counter==null) {
42         counter = new Integer JavaDoc(1);
43     }
44     else {
45         counter = new Integer JavaDoc(counter.intValue()+1);
46     }
47     counters.put(NAME_COUNTER_KEY, counter);
48     return NLS.bind(PDEUIMessages.SchemaEditor_NewAttribute_initialName, counter.intValue()+""); //$NON-NLS-1$
49
}
50 public void run() {
51     String JavaDoc name = getInitialName();
52     SchemaAttribute att = new SchemaAttribute(element, name);
53     att.setType(new SchemaSimpleType(element.getSchema(), "string")); //$NON-NLS-1$
54
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