Commit 6f54d5cd authored by Marie-Aline Pantais's avatar Marie-Aline Pantais
Browse files

lien vers le target depuis un form. TODO optimiser la recherche du controller

parent 8cf2b3ed
......@@ -63,6 +63,11 @@ public class OfbizConfigPatterns {
.withParent(XmlPatterns.xmlTag().withName("include-form"))
.withName("name");
public static final XmlNamedElementPattern.XmlAttributePattern FORM_TARGET_PATTERN =
XmlPatterns.xmlAttribute()
.withParent(XmlPatterns.xmlTag().withName("form"))
.withName("target");
public static final XmlNamedElementPattern.XmlAttributePattern PROPERTY_ATTR_PATTERN =
XmlPatterns.xmlAttribute().withValue(
XmlPatterns.string().startsWith("${uiLabelMap."));
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ofbiz.dom.references;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import org.apache.ofbiz.dom.controller.tags.RequestMapTag;
import org.apache.ofbiz.dom.screen.tags.FormWidgetTag;
import org.apache.ofbiz.services.OfbizProjectStructureService;
import org.jetbrains.annotations.Nullable;
public class ControllerReference extends PsiReferenceBase<XmlAttributeValue> {
public ControllerReference(XmlAttributeValue element, boolean soft) {
super(element, soft);
}
@Nullable
public PsiElement resolve() {
OfbizProjectStructureService structureService = ServiceManager.getService(this.getElement().getProject(), OfbizProjectStructureService.class);
RequestMapTag definition = structureService.getControllerUri(this.getValue());
return definition != null ? definition.getXmlElement() : null;
}
public Object[] getVariants() {
return null;
}
private String getControllerComponent(PsiElement element) {
XmlAttribute parent = (XmlAttribute) this.getElement().getParent();
String locationName = parent.getParent().getAttributeValue("location");
if (locationName == null) {
locationName = this.getElement().getContainingFile().getName();
}
return locationName.substring(locationName.lastIndexOf(47) + 1, locationName.length());
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ofbiz.dom.references;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
public class ControllerReferenceProvider extends PsiReferenceProvider {
public ControllerReferenceProvider() {
}
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
return element instanceof XmlAttributeValue ? new PsiReference[]{new ControllerReference((XmlAttributeValue) element, true)}
: PsiReference.EMPTY_ARRAY;
}
}
......@@ -56,5 +56,8 @@ public class OfbizReferenceContributor extends PsiReferenceContributor {
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
.withParent(OfbizConfigPatterns.FORM_NAME_ATTR_PATTERN), new FormReferenceProvider()
);
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
.withParent(OfbizConfigPatterns.FORM_TARGET_PATTERN), new ControllerReferenceProvider()
);
}
}
......@@ -24,6 +24,7 @@ import org.apache.ofbiz.dom.build.tags.OfbizClasspathEntry;
import org.apache.ofbiz.dom.build.tags.OfbizClasspathSpecTag;
import org.apache.ofbiz.dom.component.tags.ClasspathTag;
import org.apache.ofbiz.dom.component.tags.OfbizComponentTag;
import org.apache.ofbiz.dom.controller.tags.RequestMapTag;
import org.apache.ofbiz.dom.entity.tags.EntityTag;
import org.apache.ofbiz.dom.screen.tags.FormWidgetTag;
import org.apache.ofbiz.dom.screen.tags.ScreenTag;
......@@ -65,6 +66,8 @@ public interface OfbizProjectStructureService {
FormWidgetTag getFormDefinition(String fileName, String name);
RequestMapTag getControllerUri(String name);
PropertyTag getPropertyDefinition(String name);
PropertyTag getPropertyDefinition(String resource, String name);
......
......@@ -41,6 +41,8 @@ import org.apache.ofbiz.dom.build.tags.OfbizClasspathEntry;
import org.apache.ofbiz.dom.build.tags.OfbizClasspathSpecTag;
import org.apache.ofbiz.dom.component.tags.ClasspathTag;
import org.apache.ofbiz.dom.component.tags.OfbizComponentTag;
import org.apache.ofbiz.dom.controller.tags.OfbizControllerTag;
import org.apache.ofbiz.dom.controller.tags.RequestMapTag;
import org.apache.ofbiz.dom.entity.tags.EntityModelTag;
import org.apache.ofbiz.dom.entity.tags.EntityTag;
import org.apache.ofbiz.dom.screen.tags.FormWidgetTag;
......@@ -397,6 +399,19 @@ public class OfbizProjectStructureServiceImpl implements OfbizProjectStructureSe
return null;
}
public RequestMapTag getControllerUri(String name) {
List<DomFileElement<OfbizControllerTag>> controllerFiles = this.getControllerFiles();
for (DomFileElement<OfbizControllerTag> controllerFile: controllerFiles) {
List<RequestMapTag> requestMaps = controllerFile.getRootElement().getRequestMap();
for (RequestMapTag request : requestMaps) {
if (request.getUri().getValue().equalsIgnoreCase(name)) return request;
}
}
return null;
}
private List<DomFileElement<OfbizControllerTag>> getControllerFiles() {
return DomService.getInstance().getFileElements(OfbizControllerTag.class, this.project, GlobalSearchScope.allScope(this.project));
}
public void addOrUpdateProjectLibraries() {
DumbService dumbService = DumbService.getInstance(this.project);
dumbService.runWhenSmart(() -> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment