KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.jface.action.Action;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
16 import org.eclipse.pde.internal.core.schema.SchemaCompositor;
17 import org.eclipse.pde.internal.core.schema.SchemaElementReference;
18 import org.eclipse.pde.internal.ui.PDEPluginImages;
19
20 public class NewReferenceAction extends Action {
21     private Object JavaDoc object;
22
23     private ISchemaElement referencedElement;
24
25     public NewReferenceAction(ISchemaElement source, Object JavaDoc object,
26             ISchemaElement referencedElement) {
27         this.object = object;
28         this.referencedElement = referencedElement;
29         setText(referencedElement.getName());
30         ImageDescriptor desc = PDEPluginImages.DESC_ELREF_SC_OBJ;
31         setImageDescriptor(desc);
32         setEnabled(source.getSchema().isEditable());
33     }
34
35     public void run() {
36         if (object != null && object instanceof SchemaCompositor) {
37             SchemaCompositor parent = (SchemaCompositor) object;
38             SchemaElementReference reference = new SchemaElementReference(parent,
39                     referencedElement.getName());
40             reference.setReferencedObject(referencedElement);
41             parent.addChild(reference);
42         }
43     }
44 }
45
Popular Tags