Author: yzhishko
Date: 2010-05-03 13:37:01 -0400 (Mon, 03 May 2010)
New Revision: 21861
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2QuickFixProcessor.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5930 - quick fixes to editor were added
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-05-03 17:16:01 UTC
(rev 21860)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2010-05-03 17:37:01 UTC
(rev 21861)
@@ -46,8 +46,8 @@
org.eclipse.jdt.core.manipulation,
org.eclipse.jst.j2ee,
org.eclipse.ui.ide,
- org.eclipse.wst.html.core;bundle-version="1.1.300"
+ org.eclipse.wst.html.core;bundle-version="1.1.300",
+ org.eclipse.wst.sse.ui;bundle-version="1.1.102"
Bundle-Version: 3.1.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Import-Package: org.eclipse.wst.sse.ui.internal.reconcile.validator
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-05-03 17:16:01 UTC (rev 21860)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2010-05-03 17:37:01 UTC (rev 21861)
@@ -553,12 +553,12 @@
<attribute
name="problemType">
</attribute>
+ <attribute
+ name="baseElement">
+ </attribute>
<super
type="org.eclipse.core.resources.textmarker">
</super>
- <attribute
- name="baseElement">
- </attribute>
</extension>
<extension
point="org.eclipse.wst.sse.ui.sourcevalidation">
@@ -576,4 +576,20 @@
</contentTypeIdentifier>
</validator>
</extension>
+ <extension
+ point="org.eclipse.wst.sse.ui.quickFixProcessor">
+ <quickFixProcessor
+
class="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2QuickFixProcessor"
+ problemType="org.jboss.tools.jsf.jsf2problemmarker">
+ </quickFixProcessor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editors.annotationTypes">
+ <type
+ markerSeverity="1"
+ markerType="org.jboss.tools.jsf.jsf2problemmarker"
+ name="org.jboss.tools.jsf.jsf2AnnotationSpec"
+ super="org.eclipse.wst.sse.ui.temp.warning">
+ </type>
+ </extension>
</plugin>
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -28,7 +28,11 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2AttrTempComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2CompositeTempComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2URITempComponent;
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentModelManager;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -43,6 +47,7 @@
public class JSF2SourceValidator implements IValidator, ISourceValidator {
private IDOMDocument document;
+ private IFile validateFile;
public void cleanup(IReporter reporter) {
}
@@ -64,6 +69,7 @@
IResource resource = project.findMember(filePath
.substring(filePath.indexOf('/') + 1));
if (resource instanceof IFile) {
+ validateFile = (IFile) resource;
reportProblems(reporter,
JSF2XMLValidator.getValidationComponents(document,
(IFile) resource));
@@ -79,6 +85,7 @@
public void disconnect(IDocument document) {
document = null;
+ validateFile = null;
}
public void validate(IRegion dirtyRegion, IValidationContext helper,
@@ -113,7 +120,7 @@
IJSF2ValidationComponent[] validationComponents) {
for (int i = 0; i < validationComponents.length; i++) {
reporter.addMessage(this, new LocalizedMessage(
- validationComponents[i]));
+ validationComponents[i], validateFile));
}
}
@@ -121,8 +128,33 @@
private IJSF2ValidationComponent component;
- public LocalizedMessage(IJSF2ValidationComponent component) {
+ public LocalizedMessage(IJSF2ValidationComponent component,
+ IFile validateFile) {
this.component = component;
+ setAttribute("problemType",
"org.jboss.tools.jsf.jsf2problemmarker"); //$NON-NLS-1$ //$NON-NLS-2$
+ setAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY, component
+ .getType());
+ setAttribute(
+ "validateResourcePath", validateFile == null ? "" :
validateFile.getFullPath().toString()); //$NON-NLS-1$//$NON-NLS-2$
+ setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
+ component.getComponentResourceLocation());
+ if (component instanceof JSF2URITempComponent) {
+ setAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY,
+ ((JSF2URITempComponent) component).getURI());
+ } else if (component instanceof JSF2AttrTempComponent) {
+ setAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY,
+ ((JSF2AttrTempComponent) component).getName());
+ } else if (component instanceof JSF2CompositeTempComponent) {
+ String[] attrNames = ((JSF2CompositeTempComponent) component)
+ .getAttrNames();
+ if (attrNames != null) {
+ for (int i = 0; i < attrNames.length; i++) {
+ setAttribute(
+ IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY
+ + String.valueOf(i), attrNames[i]);
+ }
+ }
+ }
}
@Override
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAttrs.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -15,6 +15,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -22,6 +23,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
@@ -39,8 +46,24 @@
*
*/
-public class CreateJSF2CompositeAttrs implements IMarkerResolution {
+@SuppressWarnings("restriction")
+public class CreateJSF2CompositeAttrs implements IMarkerResolution,
+ ICompletionProposal {
+ private String componentPath = null;
+ private IResource validateResource = null;
+ private String[] attrs = null;
+
+ public CreateJSF2CompositeAttrs() {
+ }
+
+ public CreateJSF2CompositeAttrs(IResource validateResource,
+ String compPath, String[] attrs) {
+ this.validateResource = validateResource;
+ this.componentPath = compPath;
+ this.attrs = attrs;
+ }
+
public String getLabel() {
return JSFUIMessages.Create_JSF_2_Interface_Attr;
}
@@ -48,16 +71,20 @@
@SuppressWarnings("unchecked")
public void run(final IMarker marker) {
try {
- Map attrsMap = marker.getAttributes();
- Object object = attrsMap
- .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ if (marker != null) {
+ validateResource = marker.getResource();
+ Map attrsMap = marker.getAttributes();
+ Object object = attrsMap
+ .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ componentPath = (String) object;
+ attrs = new String[] { (String) marker
+ .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY) };
+ }
final IFile createdFile = JSF2ResourceUtil
.createCompositeComponentFile(
- marker.getResource().getProject(),
- new Path((String) object),
- new String[] { (String) marker
- .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY) });
- marker.getResource().getProject().deleteMarkers(
+ validateResource.getProject(), new Path(
+ componentPath), attrs);
+ validateResource.getProject().deleteMarkers(
JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
if (createdFile != null) {
IDE.openEditor(PlatformUI.getWorkbench()
@@ -69,10 +96,11 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- ValidationFramework.getDefault().validate(
- new IProject[] { marker.getResource()
- .getProject() }, false, false,
- new NullProgressMonitor());
+ ValidationFramework.getDefault()
+ .validate(
+ new IProject[] { validateResource
+ .getProject() }, false, false,
+ new NullProgressMonitor());
} catch (CoreException e) {
return new Status(IStatus.CANCEL,
JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
@@ -86,4 +114,28 @@
}
}
+ public void apply(IDocument document) {
+ run(null);
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ public String getDisplayString() {
+ return JSFUIMessages.Create_JSF_2_Interface_Attr;
+ }
+
+ public Image getImage() {
+ return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeComponent.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -18,6 +18,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -25,6 +26,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
@@ -42,8 +49,24 @@
*
*/
-public class CreateJSF2CompositeComponent implements IMarkerResolution {
+@SuppressWarnings("restriction")
+public class CreateJSF2CompositeComponent implements IMarkerResolution,
+ ICompletionProposal {
+ private String componentPath = null;
+ private IResource validateResource = null;
+ private String[] attrs = null;
+
+ public CreateJSF2CompositeComponent() {
+ }
+
+ public CreateJSF2CompositeComponent(IResource validateResource,
+ String compPath, String[] attrs) {
+ this.validateResource = validateResource;
+ this.componentPath = compPath;
+ this.attrs = attrs;
+ }
+
public String getLabel() {
return JSFUIMessages.Create_JSF_2_Composite_Component;
}
@@ -51,15 +74,20 @@
@SuppressWarnings("unchecked")
public void run(final IMarker marker) {
try {
- Map attrsMap = marker.getAttributes();
- Object object = attrsMap
- .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ if (marker != null) {
+ validateResource = marker.getResource();
+ Map attrsMap = marker.getAttributes();
+ Object object = attrsMap
+ .get(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+ componentPath = (String) object;
+ attrs = getAttributes(marker);
+ }
final IFile createdFile = JSF2ResourceUtil
- .createCompositeComponentFile(marker.getResource()
- .getProject(), new Path((String) object),
- getAttributes(marker));
- marker.getResource().deleteMarkers(
- JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
+ .createCompositeComponentFile(
+ validateResource.getProject(), new Path(
+ componentPath), attrs);
+ validateResource.getProject().deleteMarkers(JSF2XMLValidator.JSF2_PROBLEM_ID,
+ false, 1);
if (createdFile != null) {
IDE.openEditor(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage(),
@@ -70,10 +98,11 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- ValidationFramework.getDefault().validate(
- new IProject[] { marker.getResource()
- .getProject() }, false, false,
- new NullProgressMonitor());
+ ValidationFramework.getDefault()
+ .validate(
+ new IProject[] { validateResource
+ .getProject() }, false, false,
+ new NullProgressMonitor());
} catch (CoreException e) {
return new Status(IStatus.CANCEL,
JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
@@ -104,4 +133,28 @@
return null;
}
+ public void apply(IDocument document) {
+ run(null);
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ public String getDisplayString() {
+ return JSFUIMessages.Create_JSF_2_Composite_Component;
+ }
+
+ public Image getImage() {
+ return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2ResourcesFolder.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -13,12 +13,19 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.wst.validation.ValidationFramework;
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
@@ -34,28 +41,46 @@
*
*/
-public class CreateJSF2ResourcesFolder implements IMarkerResolution {
+@SuppressWarnings("restriction")
+public class CreateJSF2ResourcesFolder implements IMarkerResolution,
+ ICompletionProposal {
+ private String componentPath = null;
+ private IResource validateResource = null;
+
public String getLabel() {
return JSFUIMessages.Create_JSF_2_Resources_Folder;
}
+ public CreateJSF2ResourcesFolder() {
+ }
+
+ public CreateJSF2ResourcesFolder(IResource validateResource, String compPath) {
+ this.componentPath = compPath;
+ this.validateResource = validateResource;
+ }
+
public void run(final IMarker marker) {
try {
- JSF2ResourceUtil.createResourcesFolderByNameSpace(marker
- .getResource().getProject(), (String) marker
- .getAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY));
- marker.getResource().getProject().deleteMarkers(
+ if (marker != null) {
+ componentPath = (String) marker
+ .getAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY);
+ validateResource = marker.getResource();
+ }
+ JSF2ResourceUtil.createResourcesFolderByNameSpace(validateResource
+ .getProject(), componentPath);
+ validateResource.getProject().deleteMarkers(
JSF2XMLValidator.JSF2_PROBLEM_ID, false, 1);
Job validateJob = new Job("JSF 2 Components Validator") { //$NON-NLS-1$
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- ValidationFramework.getDefault().validate(
- new IProject[] { marker.getResource()
- .getProject() }, false, false,
- new NullProgressMonitor());
+ ValidationFramework.getDefault()
+ .validate(
+ new IProject[] { validateResource
+ .getProject() }, false, false,
+ new NullProgressMonitor());
} catch (CoreException e) {
return new Status(IStatus.CANCEL,
JSFModelPlugin.PLUGIN_ID, "Cancel"); //$NON-NLS-1$
@@ -69,4 +94,28 @@
}
}
+ public void apply(IDocument document) {
+ run(null);
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ public String getDisplayString() {
+ return JSFUIMessages.Create_JSF_2_Resources_Folder;
+ }
+
+ public Image getImage() {
+ return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+
}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2QuickFixProcessor.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2QuickFixProcessor.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/JSF2QuickFixProcessor.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -0,0 +1,80 @@
+package org.jboss.tools.jsf.web.validation.jsf2.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.wst.sse.ui.StructuredTextInvocationContext;
+import org.jboss.tools.jsf.web.validation.jsf2.components.IJSF2ValidationComponent;
+import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ResourceUtil;
+
+public class JSF2QuickFixProcessor implements IQuickAssistProcessor {
+
+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
+ return false;
+ }
+
+ public boolean canFix(Annotation annotation) {
+ return false;
+ }
+
+ public ICompletionProposal[] computeQuickAssistProposals(
+ IQuickAssistInvocationContext invocationContext) {
+ if (invocationContext instanceof StructuredTextInvocationContext) {
+ StructuredTextInvocationContext context = (StructuredTextInvocationContext)
invocationContext;
+ String type = (String) context
+ .getAttribute(IJSF2ValidationComponent.JSF2_TYPE_KEY);
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(
+ (String) context
+ .getAttribute("validateResourcePath")); //$NON-NLS-1$
+ String compPath = (String) context
+ .getAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY);
+
+ if (type.equals(IJSF2ValidationComponent.JSF2_FIXABLE_ATTR_TYPE)) {
+ String[] attrs = new String[] { (String) context
+ .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY) };
+ ICompletionProposal proposal = new CreateJSF2CompositeAttrs(
+ resource, compPath, attrs);
+ return new ICompletionProposal[] { proposal };
+ } else if (type
+ .equals(IJSF2ValidationComponent.JSF2_COMPOSITE_COMPONENT_TYPE)) {
+ ICompletionProposal proposal = new CreateJSF2CompositeAttrs(
+ resource, compPath, retriveAttrsFromContext(context));
+ return new ICompletionProposal[] { proposal };
+ } else if (type.equals(IJSF2ValidationComponent.JSF2_URI_TYPE)) {
+ String uriPath = (String) context
+ .getAttribute(IJSF2ValidationComponent.JSF2_URI_NAME_KEY);
+ ICompletionProposal proposal = new CreateJSF2ResourcesFolder(
+ resource, uriPath);
+ return new ICompletionProposal[] { proposal };
+ }
+ }
+ return null;
+ }
+
+ private String[] retriveAttrsFromContext(
+ StructuredTextInvocationContext context) {
+ List<String> attrsList = new ArrayList<String>();
+ int i = 0;
+ while (!(context
+ .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY
+ + String.valueOf(i)) == null)) {
+ attrsList.add((String) context
+ .getAttribute(IJSF2ValidationComponent.JSF2_ATTR_NAME_KEY
+ + String.valueOf(i)));
+ i++;
+ }
+ return attrsList.toArray(new String[0]);
+ }
+
+ public String getErrorMessage() {
+ return null;
+ }
+
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/components/JSF2ComponentFactory.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -15,7 +15,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.internal.core.JarEntryFile;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
@@ -25,7 +24,6 @@
import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ComponentModelManager;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
*
@@ -64,7 +62,8 @@
.getReadableDOMDocument(container);
IDOMElement interfaceElement = JSF2ComponentModelManager.getManager()
.checkCompositeInterface(containerDocument);
- Set<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ Set<String> interfaceAttrs = JSF2ComponentModelManager.getManager()
+ .getInterfaceAttrs(interfaceElement);
interfaceAttrs.addAll(uncheckedAttrs);
IDOMAttr[] existingAttrs = getExistingAttrs(elementWithAttrs);
for (int i = 0; i < existingAttrs.length; i++) {
@@ -94,7 +93,8 @@
.getReadableDOMDocument(compContainerFile);
IDOMElement interfaceElement = JSF2ComponentModelManager.getManager()
.checkCompositeInterface(document);
- Set<String> interfaceAttrs = getInterfaceAttrs(interfaceElement);
+ Set<String> interfaceAttrs = JSF2ComponentModelManager.getManager()
+ .getInterfaceAttrs(interfaceElement);
interfaceAttrs.addAll(uncheckedAttrs);
IDOMAttr[] existingAttrs = getExistingAttrs(elementWithAttrs);
for (int i = 0; i < existingAttrs.length; i++) {
@@ -131,32 +131,6 @@
return component;
}
- private static Set<String> getInterfaceAttrs(IDOMElement interfaceElement) {
- Set<String> interfaceAttrs = new HashSet<String>(0);
- if (interfaceElement != null) {
- String prefix = interfaceElement.getPrefix();
- String nodeName = "attribute"; //$NON-NLS-1$
- if (prefix != null && !"".equals(prefix)) { //$NON-NLS-1$
- nodeName = prefix + ":" + nodeName; //$NON-NLS-1$
- }
- NodeList attrsElements = interfaceElement
- .getElementsByTagName(nodeName);
- if (attrsElements != null) {
- for (int i = 0; i < attrsElements.getLength(); i++) {
- Node el = attrsElements.item(i);
- if (el instanceof IDOMElement) {
- IDOMElement element = (IDOMElement) el;
- String attrvalue = element.getAttribute("name"); //$NON-NLS-1$
- if (attrvalue != null && !"".equals(attrvalue)) { //$NON-NLS-1$
- interfaceAttrs.add(attrvalue);
- }
- }
- }
- }
- }
- return interfaceAttrs;
- }
-
private static IDOMAttr[] getExistingAttrs(IDOMElement validateElement) {
List<IDOMAttr> existingAttrs = new ArrayList<IDOMAttr>(0);
NamedNodeMap attrsMap = validateElement.getAttributes();
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java 2010-05-03
17:16:01 UTC (rev 21860)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/util/JSF2ComponentModelManager.java 2010-05-03
17:37:01 UTC (rev 21861)
@@ -14,7 +14,10 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashSet;
import java.util.Scanner;
+import java.util.Set;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -127,20 +130,25 @@
String[] attrNames) {
Document document = (Document) element.getOwnerDocument();
String prefix = element.getPrefix();
+ Set<String> existInerfaceAttrs = getInterfaceAttrs(element);
if (prefix != null && !"".equals(prefix)) { //$NON-NLS-1$
for (int i = 0; i < attrNames.length; i++) {
- Element attrEl = document
- .createElementNS(JSF2ResourceUtil.JSF2_URI_PREFIX,
- prefix + ":attribute"); //$NON-NLS-1$
- attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
- element.appendChild(attrEl);
+ if (!existInerfaceAttrs.contains(attrNames[i])) {
+ Element attrEl = document.createElementNS(
+ JSF2ResourceUtil.JSF2_URI_PREFIX, prefix
+ + ":attribute"); //$NON-NLS-1$
+ attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
+ element.appendChild(attrEl);
+ }
}
} else {
for (int i = 0; i < attrNames.length; i++) {
- Element attrEl = document.createElementNS(
- JSF2ResourceUtil.JSF2_URI_PREFIX, "attribute"); //$NON-NLS-1$
- attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
- element.appendChild(attrEl);
+ if (!existInerfaceAttrs.contains(attrNames[i])) {
+ Element attrEl = document.createElementNS(
+ JSF2ResourceUtil.JSF2_URI_PREFIX, "attribute"); //$NON-NLS-1$
+ attrEl.setAttribute("name", attrNames[i]); //$NON-NLS-1$
+ element.appendChild(attrEl);
+ }
}
}
DocumentNodeFormatter formatter = new DocumentNodeFormatter();
@@ -256,4 +264,30 @@
return document;
}
+ public Set<String> getInterfaceAttrs(IDOMElement interfaceElement) {
+ Set<String> interfaceAttrs = new HashSet<String>(0);
+ if (interfaceElement != null) {
+ String prefix = interfaceElement.getPrefix();
+ String nodeName = "attribute"; //$NON-NLS-1$
+ if (prefix != null && !"".equals(prefix)) { //$NON-NLS-1$
+ nodeName = prefix + ":" + nodeName; //$NON-NLS-1$
+ }
+ NodeList attrsElements = interfaceElement
+ .getElementsByTagName(nodeName);
+ if (attrsElements != null) {
+ for (int i = 0; i < attrsElements.getLength(); i++) {
+ Node el = attrsElements.item(i);
+ if (el instanceof IDOMElement) {
+ IDOMElement element = (IDOMElement) el;
+ String attrvalue = element.getAttribute("name"); //$NON-NLS-1$
+ if (attrvalue != null && !"".equals(attrvalue)) { //$NON-NLS-1$
+ interfaceAttrs.add(attrvalue);
+ }
+ }
+ }
+ }
+ }
+ return interfaceAttrs;
+ }
+
}