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.ISchema;
14: import org.eclipse.pde.internal.core.schema.Schema;
15: import org.eclipse.pde.internal.core.schema.SchemaElement;
16: import org.eclipse.pde.internal.core.schema.SchemaRootElement;
17: import org.eclipse.pde.internal.core.schema.SchemaSimpleType;
18: import org.eclipse.pde.internal.ui.PDEPluginImages;
19: import org.eclipse.pde.internal.ui.PDEUIMessages;
20: import org.eclipse.pde.internal.ui.util.PDELabelUtility;
21:
22: public class NewElementAction extends Action {
23: private Schema schema;
24:
25: public NewElementAction() {
26: setText(PDEUIMessages.SchemaEditor_NewElement_label);
27: setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ);
28: setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip);
29: }
30:
31: private String getInitialName() {
32: return PDELabelUtility.generateName(schema.getElementNames(),
33: PDEUIMessages.SchemaEditor_NewElement_initialName,
34: false);
35: }
36:
37: public org.eclipse.pde.internal.core.schema.Schema getSchema() {
38: return schema;
39: }
40:
41: public void run() {
42: String name = getInitialName();
43: SchemaElement element;
44: if (name.equals("extension")) //$NON-NLS-1$
45: element = new SchemaRootElement(schema, name);
46: else
47: element = new SchemaElement(schema, name);
48: element.setType(new SchemaSimpleType(schema, "string")); //$NON-NLS-1$
49: schema.addElement(element);
50: schema.updateReferencesFor(element, ISchema.REFRESH_ADD);
51: }
52:
53: public void setSchema(Schema newSchema) {
54: schema = newSchema;
55: }
56: }
|