01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.schema;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
14: import org.eclipse.pde.internal.core.ischema.ISchemaType;
15: import org.eclipse.pde.internal.core.schema.SchemaAttribute;
16: import org.eclipse.pde.internal.core.schema.SchemaComplexType;
17: import org.eclipse.pde.internal.core.schema.SchemaElement;
18: import org.eclipse.pde.internal.core.schema.SchemaSimpleType;
19: import org.eclipse.pde.internal.ui.PDEPluginImages;
20: import org.eclipse.pde.internal.ui.PDEUIMessages;
21: import org.eclipse.pde.internal.ui.util.PDELabelUtility;
22:
23: public class NewAttributeAction extends Action {
24: private SchemaElement element;
25:
26: public NewAttributeAction() {
27: setText(PDEUIMessages.SchemaEditor_NewAttribute_label);
28: setImageDescriptor(PDEPluginImages.DESC_ATT_IMPL_OBJ);
29: setToolTipText(PDEUIMessages.SchemaEditor_NewAttribute_tooltip);
30: }
31:
32: public org.eclipse.pde.internal.core.schema.SchemaElement getElement() {
33: return element;
34: }
35:
36: private String getInitialName() {
37: return PDELabelUtility.generateName(
38: element.getAttributeNames(),
39: PDEUIMessages.SchemaEditor_NewAttribute_initialName,
40: false);
41: }
42:
43: public void run() {
44: String name = getInitialName();
45: SchemaAttribute att = new SchemaAttribute(element, name);
46: att
47: .setType(new SchemaSimpleType(element.getSchema(),
48: "string")); //$NON-NLS-1$
49: ISchemaType type = element.getType();
50: SchemaComplexType complexType = null;
51: if (!(type instanceof ISchemaComplexType)) {
52: complexType = new SchemaComplexType(element.getSchema());
53: element.setType(complexType);
54: } else {
55: complexType = (SchemaComplexType) type;
56: }
57: complexType.addAttribute(att);
58: // Any element that defines attributes cannot be translatable
59: if (element.hasTranslatableContent()) {
60: element.setTranslatableProperty(false);
61: }
62: }
63:
64: public void setElement(
65: org.eclipse.pde.internal.core.schema.SchemaElement newElement) {
66: element = newElement;
67: }
68: }
|