Author: dmaliarevich
Date: 2011-08-12 11:26:25 -0400 (Fri, 12 Aug 2011)
New Revision: 33851
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateFileList.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSafeWrapper.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSet.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ELResolver.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
Log:
https://issues.jboss.org/browse/JBIDE-9444 , templates' priority was added
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -84,6 +84,9 @@
/** The pseudo content creator. */
private VpePseudoContentCreator pseudoContentCreator;
+
+ /** The priority to load templates for the tag */
+ protected double priority = 0.0;
/** The Constant TAG_BREAKER. */
private static final String TAG_BREAKER = VpeTemplateManager.VPE_PREFIX
@@ -1430,4 +1433,12 @@
return new Region(offset, 0);
}
+ final public double getPriority() {
+ return priority;
+ }
+
+ final public void setPriority(double priority) {
+ this.priority = priority;
+ }
+
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplate.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -466,4 +466,8 @@
*/
public IRegion getSourceRegionForOpenOn(VpePageContext pageContext, Node
sourceNode,nsIDOMNode domNode);
+ public double getPriority();
+
+ public void setPriority(double priority);
+
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateFileList.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateFileList.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateFileList.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2011 Exadel, Inc. and Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.template;
import java.io.IOException;
@@ -34,7 +34,7 @@
VpeTemplateFileList() {
}
-
+
void load() {
VpeTemplateFile newAutoTemplateFile = new VpeTemplateFile(
VpeTemplateManager.getAutoTemplates(), null);
@@ -57,50 +57,50 @@
autoTemplateFile = newAutoTemplateFile;
templateFiles = newTemplateFiles;
}
-
+
VpeTemplateFile getAutoTemplateFile() {
return autoTemplateFile;
}
-
+
VpeTemplateFile[] getTemplateFiles() {
return templateFiles;
}
-
+
boolean isChanged() {
return changed;
}
-
+
private VpeTemplateFile[] createTemplateFileList() {
List<VpeTemplateFile> templateList = createTemplateFileListImpl();
return templateList.toArray(new VpeTemplateFile[templateList.size()]);
}
-
+
private List<VpeTemplateFile> createTemplateFileListImpl() {
List<VpeTemplateFile> templateList = new ArrayList<VpeTemplateFile>();
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint extensionPoint =
registry.getExtensionPoint(VpePlugin.EXTESION_POINT_VPE_TEMPLATES);
- IExtension[] extensions = extensionPoint.getExtensions();
- for (int i=0;i<extensions.length;i++) {
- IExtension extension = extensions[i];
- IConfigurationElement[] elements = extension.getConfigurationElements();
- for(int j=0;j<elements.length;j++) {
- String pathAttrValue = elements[j].getAttribute("path"); //$NON-NLS-1$
- try {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
registry.getExtensionPoint(VpePlugin.EXTESION_POINT_VPE_TEMPLATES);
+ IExtension[] extensions = extensionPoint.getExtensions();
+ for (int i = 0; i < extensions.length; i++) {
+ IExtension extension = extensions[i];
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for (int j = 0; j < elements.length; j++) {
+ String pathAttrValue = elements[j].getAttribute("path"); //$NON-NLS-1$
+ try {
VpeTemplateFile templateFile = new VpeTemplateFile(pathAttrValue, elements[j]);
- templateList.add(templateFile);
- } catch (IOException e) {
- VpePlugin.getPluginLog().logError("Error during loading template '" +
pathAttrValue + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ templateList.add(templateFile);
+ } catch (IOException e) {
+ VpePlugin.getPluginLog().logError("Error during loading template '" +
pathAttrValue + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+ }
return templateList;
}
static IPath getFilePath(String name, IConfigurationElement confElement) throws
IOException {
VpePlugin plugin = VpePlugin.getDefault();
Bundle bundle = confElement == null
- ? plugin.getBundle()
+ ? plugin.getBundle()
: Platform.getBundle(confElement.getContributor().getName());
URL url = bundle.getEntry("/"); //$NON-NLS-1$
IPath path = new Path(FileLocator.toFileURL(url).getFile());
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -312,6 +312,9 @@
*/
private static final String NAMESPACE_IDENTIFIER_ATTRIBUTE =
"namespaceIdentifier"; //$NON-NLS-1$
+ /** The priority to load tempaltes */
+ private static final String PRIORITY = "priority"; //$NON-NLS-1$
+
private static final IPath DEFAULT_AUTO_TEMPLATES_PATH = VpePlugin.getDefault()
.getStateLocation().append(VPE_TEMPLATES_AUTO);
@@ -1024,6 +1027,14 @@
.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_CLASS);
String nameSpaceIdentifyer = templateElement
.getAttribute(VpeTemplateManager.NAMESPACE_IDENTIFIER_ATTRIBUTE);
+ String priority = templateElement
+ .getAttribute(VpeTemplateManager.PRIORITY);
+ if (priority != null) {
+ priority = priority.trim();
+ }
+ if (priority == null || priority.isEmpty()) {
+ priority = "0"; //$NON-NLS-1$
+ }
if (templateClassName != null && templateClassName.length() > 0) {
if (nameSpaceIdentifyer == null
|| nameSpaceIdentifyer.length() == 0) {
@@ -1055,6 +1066,9 @@
template.init(templateElement, caseSensitive);
template = new VpeTemplateSafeWrapper(template);
}
+ if (template != null) {
+ template.setPriority(Double.parseDouble(priority));
+ }
return template;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSafeWrapper.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSafeWrapper.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSafeWrapper.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -590,4 +590,11 @@
}
return null;
};
+
+ public double getPriority() {
+ return delegate.getPriority();
+ }
+ public void setPriority(double priority) {
+ delegate.setPriority(priority);
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSet.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSet.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateSet.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -20,6 +20,7 @@
public class VpeTemplateSet {
private List<VpeTemplateSet> templates = new ArrayList<VpeTemplateSet>();
+ /** Default template */
private VpeTemplate defTemplate;
VpeTemplateSet(){
@@ -32,6 +33,8 @@
void setDefTemplate(VpeTemplate defTemplate) {
if (this.defTemplate == null) {
this.defTemplate = defTemplate;
+ } else if (this.defTemplate.getPriority() < defTemplate.getPriority()) {
+ this.defTemplate = defTemplate;
}
}
@@ -40,7 +43,11 @@
VpeTemplateSet set = (VpeTemplateSet)templates.get(i);
VpeTemplate template = set.getTemplate(pageContext, sourceNode, ifDependencySet);
if (template != null) {
- return template;
+ if ((defTemplate != null) && (defTemplate.getPriority() >
template.getPriority())) {
+ return defTemplate;
+ } else {
+ return template;
+ }
}
}
return defTemplate;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ELResolver.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ELResolver.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ELResolver.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -198,4 +198,10 @@
rst = replaceEl(rst);
return rst;
}
+
+ public void createScope() {
+ }
+
+ public void resolveScope() {
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2011-08-12
15:23:12 UTC (rev 33850)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2011-08-12
15:26:25 UTC (rev 33851)
@@ -59,5 +59,13 @@
public void setElResolver(ELResolver elResolver) {
this.elResolver = elResolver;
}
+
+ public void createScope() {
+ getElResolver().createScope();
+ }
+
+ public void resolveScope() {
+ getElResolver().resolveScope();
+ }
}