KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > correction > CreateClassXMLResolution


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.correction;
12
13 import org.eclipse.core.resources.IMarker;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.pde.core.plugin.IPluginExtension;
17 import org.eclipse.pde.core.plugin.IPluginModelBase;
18 import org.eclipse.pde.internal.core.PDECore;
19 import org.eclipse.pde.internal.core.ischema.ISchema;
20 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
21 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
22 import org.eclipse.pde.internal.core.schema.SchemaRegistry;
23 import org.eclipse.pde.internal.core.text.IDocumentNode;
24 import org.eclipse.pde.internal.core.text.plugin.PluginAttribute;
25 import org.eclipse.pde.internal.ui.PDEUIMessages;
26 import org.eclipse.pde.internal.ui.editor.plugin.JavaAttributeValue;
27 import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI;
28 import org.eclipse.pde.internal.ui.util.TextUtil;
29
30 public class CreateClassXMLResolution extends AbstractXMLMarkerResolution {
31
32     public CreateClassXMLResolution(int resolutionType, IMarker marker) {
33         super(resolutionType, marker);
34     }
35
36     
37     // create class code copied from org.eclipse.pde.internal.ui.editor.plugin.rows.ClassAttributeRow
38
protected void createChange(IPluginModelBase model) {
39         Object JavaDoc object = findNode(model);
40         if (!(object instanceof PluginAttribute))
41             return;
42         
43         PluginAttribute attr = (PluginAttribute)object;
44         String JavaDoc name = TextUtil.trimNonAlphaChars(attr.getValue()).replace('$', '.');
45         IProject project = model.getUnderlyingResource().getProject();
46         
47         JavaAttributeValue value = new JavaAttributeValue(project, model, getAttribute(attr), name);
48         name = PDEJavaHelperUI.createClass(name, project, value, true);
49         if (name != null && !name.equals(attr.getValue()))
50             attr.getEnclosingElement().setXMLAttribute(attr.getName(), name);
51     }
52
53     private ISchemaAttribute getAttribute(PluginAttribute attr) {
54         SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
55         IDocumentNode element = attr.getEnclosingElement();
56         IPluginExtension extension = null;
57         while (element.getParentNode() != null) {
58             if (element instanceof IPluginExtension) {
59                 extension = (IPluginExtension)element;
60                 break;
61             }
62             element = element.getParentNode();
63         }
64         if (extension == null)
65             return null;
66         
67         ISchema schema = registry.getSchema(extension.getPoint());
68         ISchemaElement schemaElement = schema.findElement(attr.getEnclosingElement().getXMLTagName());
69         if (schemaElement == null)
70             return null;
71         return schemaElement.getAttribute(attr.getName());
72     }
73
74     public String JavaDoc getLabel() {
75         return NLS.bind(PDEUIMessages.CreateClassXMLResolution_label, getNameOfNode());
76     }
77 }
78
Popular Tags