KickJava   Java API By Example, From Geeks To Geeks.

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


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.osgi.util.NLS;
16 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
17 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
18 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
19 import org.eclipse.pde.internal.core.schema.SchemaComplexType;
20 import org.eclipse.pde.internal.core.schema.SchemaCompositor;
21 import org.eclipse.pde.internal.core.schema.SchemaElement;
22 import org.eclipse.pde.internal.ui.PDEPluginImages;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24
25 public class NewCompositorAction extends Action {
26     private ISchemaElement source;
27     private Object JavaDoc object;
28     private int kind;
29
30     public NewCompositorAction(ISchemaElement source, Object JavaDoc object, int kind) {
31         this.source = source;
32         this.object = object;
33         this.kind = kind;
34         setText("&" + ISchemaCompositor.kindTable[kind]); //$NON-NLS-1$
35
setToolTipText(NLS.bind(PDEUIMessages.SchemaEditor_NewCompositor_tooltip, ISchemaCompositor.kindTable[kind]));
36         ImageDescriptor desc = null;
37     
38         switch (kind) {
39             case ISchemaCompositor.SEQUENCE :
40                 desc = PDEPluginImages.DESC_SEQ_SC_OBJ;
41                 break;
42             case ISchemaCompositor.CHOICE :
43                 desc = PDEPluginImages.DESC_CHOICE_SC_OBJ;
44                 break;
45         }
46         setImageDescriptor(desc);
47         setEnabled(source.getSchema().isEditable());
48     }
49     public void run() {
50         SchemaCompositor compositor = new SchemaCompositor(source, kind);
51         if (object instanceof SchemaElement) {
52             SchemaComplexType type = null;
53             SchemaElement element = (SchemaElement) source;
54             if (element.getType() instanceof SchemaComplexType) {
55                 type = (SchemaComplexType) element.getType();
56                 ISchemaCompositor oldComp = type.getCompositor();
57                 if (oldComp != null) {
58                     ISchemaObject[] oldChildren = oldComp.getChildren();
59                     for (int i = 0; i < oldChildren.length; i++) {
60                         compositor.addChild(oldChildren[i]);
61                     }
62                 }
63                 type.setCompositor(compositor);
64             } else {
65                 type = new SchemaComplexType(source.getSchema());
66                 type.setCompositor(compositor);
67                 ((SchemaElement) source).setType(type);
68             }
69         } else if (object instanceof SchemaCompositor) {
70             ((SchemaCompositor) object).addChild(compositor);
71         }
72     }
73 }
74
Popular Tags