JBoss Tools SVN: r7270 - in trunk/jst/plugins/org.jboss.tools.jst.jsp: src/org/jboss/tools/jst/jsp/jspeditor and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2008-04-02 12:22:17 -0400 (Wed, 02 Apr 2008)
New Revision: 7270
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPEditorMessages.properties
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1373
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2008-04-02 16:07:01 UTC (rev 7269)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2008-04-02 16:22:17 UTC (rev 7270)
@@ -46,7 +46,11 @@
<provisionalDefinition
type="showintarget"
value="org.eclipse.jdt.ui.PackageExplorer"
- target="org.eclipse.jst.jsp.core.jspsource"/>
+ target="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"/>
+ <provisionalDefinition
+ type="showintarget"
+ value="org.jboss.tools.jst.web.ui.navigator.WebProjectsView"
+ target="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"/>
<provisionalDefinition
type="preferencepages"
value="org.eclipse.wst.sse.ui.preferences.jsp.occurrences"
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPEditorMessages.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPEditorMessages.properties 2008-04-02 16:07:01 UTC (rev 7269)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPEditorMessages.properties 2008-04-02 16:22:17 UTC (rev 7270)
@@ -1,4 +1,5 @@
JSPMultiPageEditor.TabLabel.VisualSource = Visual/Source
JSPMultiPageEditor.TabLabel.Visual = Visual
JSPMultiPageEditor.TabLabel.Source = Source
-JSPMultiPageEditor.TabLabel.Preview = Preview
\ No newline at end of file
+JSPMultiPageEditor.TabLabel.Preview = Preview
+JSPMultiPageEditor.ContextMenu.ShowInMenu = Show In
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-04-02 16:07:01 UTC (rev 7269)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-04-02 16:22:17 UTC (rev 7270)
@@ -16,6 +16,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextListener;
@@ -57,6 +60,7 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
@@ -127,6 +131,8 @@
import org.w3c.dom.Node;
import org.w3c.dom.Text;
+import com.sun.org.apache.xpath.internal.operations.Minus;
+
/**
* @author Jeremy
*
@@ -150,6 +156,8 @@
protected SourceEditorPageContext pageContext = null;
private TextEditorDropProviderImpl textEditorDropProvider;
+
+ private static final String SHOW_IN_MENU = "JSPMultiPageEditor.ContextMenu.ShowInMenu"; //$NON-NLS-1$
public JSPTextEditor(JSPMultiPageEditor parentEditor) {
JspEditorPlugin.getDefault().initDefaultPluginPreferences();
@@ -1202,4 +1210,31 @@
}
return false;
}
+
+ @Override
+ public void editorContextMenuAboutToShow(IMenuManager menu) {
+
+ super.editorContextMenuAboutToShow(menu);
+
+ /*
+ * added by Dmitrovich Sergey JBIDE-1373 so as StructuredTextEditor
+ * create context menu by hard code. The easiest way to add "show in"
+ * menu is insert to prepared by
+ * StructuredTextEditorStructuredTextEditor
+ */
+
+ MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
+ showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
+ .create(getEditorSite().getWorkbenchWindow()));
+ menu.insertBefore(ITextEditorActionConstants.GROUP_COPY, new Separator(
+ ITextEditorActionConstants.GROUP_SHOW_IN));
+ menu.appendToGroup(ITextEditorActionConstants.GROUP_SHOW_IN,
+ showInSubMenu);
+
+ }
+
+ private String getShowInMenuLabel() {
+
+ return JSPEditorMessages.getString(SHOW_IN_MENU);
+ }
}
16 years, 1 month
JBoss Tools SVN: r7269 - in trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam: internal/core and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-04-02 12:07:01 -0400 (Wed, 02 Apr 2008)
New Revision: 7269
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
Log:
JBIDE-1409
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2008-04-02 13:49:14 UTC (rev 7268)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2008-04-02 16:07:01 UTC (rev 7269)
@@ -35,6 +35,13 @@
* or null if project has no parent project.
*/
public String getParentProjectName();
+
+ /**
+ *
+ * @return parent project or null
+ * @see getParentProjectName()
+ */
+ public ISeamProject getParentProject();
/**
* Returns Seam runtime name.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2008-04-02 13:49:14 UTC (rev 7268)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2008-04-02 16:07:01 UTC (rev 7269)
@@ -161,6 +161,13 @@
IEclipsePreferences p = getSeamPreferences();
return p == null ? null : p.get("seam.parent.project", null);
}
+
+ public ISeamProject getParentProject() {
+ String n = getParentProjectName();
+ if(n == null || n.length() == 0) return null;
+ IProject parent = ResourcesPlugin.getWorkspace().getRoot().getProject(n);
+ return n == null ? null : SeamCorePlugin.getSeamProject(parent, true);
+ }
public void setRuntimeName(String runtimeName) {
if(this.runtimeName == runtimeName) return;
@@ -267,14 +274,19 @@
// }
// });
}
+
+ IEclipsePreferences preferences = null;
/**
*
* @return
*/
public IEclipsePreferences getSeamPreferences() {
- IScopeContext projectScope = new ProjectScope(project);
- return projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
+ if(preferences == null) {
+ IScopeContext projectScope = new ProjectScope(project);
+ preferences = projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
+ }
+ return preferences;
}
/**
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2008-04-02 13:49:14 UTC (rev 7268)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2008-04-02 16:07:01 UTC (rev 7269)
@@ -56,6 +56,11 @@
*/
public static List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType scope, String name, boolean onlyEqualNames) {
if (project == null || name == null) return null;
+
+ ISeamProject parent = project.getParentProject();
+ if(parent != null) {
+ project = parent;
+ }
/*
* JBIDE-670 scope isn't used anymore
*/
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2008-04-02 13:49:14 UTC (rev 7268)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2008-04-02 16:07:01 UTC (rev 7269)
@@ -580,6 +580,12 @@
if(bijection.isOfType(BijectedAttributeType.IN)) {
Set<ISeamContextVariable> variables = project.getVariablesByName(name);
if(variables==null || variables.size()<1) {
+ ISeamProject parentProject = project.getParentProject();
+ if(parentProject != null) {
+ variables = parentProject.getVariablesByName(name);
+ }
+ }
+ if(variables==null || variables.size()<1) {
// Injection has unknown name. Mark it.
IResource declarationResource = declaration.getResource();
addError(UNKNOWN_VARIABLE_NAME_MESSAGE_ID, SeamPreferences.UNKNOWN_VARIABLE_NAME, new String[]{name}, bijection, declarationResource);
16 years, 1 month
JBoss Tools SVN: r7268 - in trunk/jsf/tests/org.jboss.tools.jsf.test: projects/JSFKickStart1/JavaSource and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-04-02 09:49:14 -0400 (Wed, 02 Apr 2008)
New Revision: 7268
Added:
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/BaseBean.java
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/User.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JSFBeansTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/WebContent/WEB-INF/faces-config.xml
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfAllTests.java
Log:
JBIDE-1884 Test added
Added: trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/BaseBean.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/BaseBean.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/BaseBean.java 2008-04-02 13:49:14 UTC (rev 7268)
@@ -0,0 +1,11 @@
+package demo;
+
+public class BaseBean {
+
+ public String getParent() {
+ return "";
+ }
+
+ public void fuck() {}
+
+}
Added: trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/User.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/User.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/JavaSource/demo/User.java 2008-04-02 13:49:14 UTC (rev 7268)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package demo;
+
+/**
+ * Created by JBoss Developer Studio
+ */
+public class User extends BaseBean {
+
+ private String name;
+
+ /**
+ * @return User Name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param User Name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
\ No newline at end of file
Modified: trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/WebContent/WEB-INF/faces-config.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/WebContent/WEB-INF/faces-config.xml 2008-04-02 13:38:11 UTC (rev 7267)
+++ trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStart1/WebContent/WEB-INF/faces-config.xml 2008-04-02 13:49:14 UTC (rev 7268)
@@ -48,23 +48,14 @@
</converter>
<managed-bean>
<description>Input Value Holder</description>
- <managed-bean-name>nameBean</managed-bean-name>
- <managed-bean-class>demo.NameBean</managed-bean-class>
+ <managed-bean-name>user</managed-bean-name>
+ <managed-bean-class>demo.User</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
- <property-name>userName</property-name>
+ <property-name>name</property-name>
<property-class>java.lang.String</property-class>
<value/>
</managed-property>
- <managed-property>
- <property-name>aliases</property-name>
- <property-class>java.util.List</property-class>
- <list-entries>
- <value-class>java.lang.String</value-class>
- <null-value/>
- <value>Red Hat</value>
- </list-entries>
- </managed-property>
</managed-bean>
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
Added: trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JSFBeansTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JSFBeansTest.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JSFBeansTest.java 2008-04-02 13:49:14 UTC (rev 7268)
@@ -0,0 +1,50 @@
+package org.jboss.tools.jsf.test;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.test.util.TestProjectProvider;
+import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
+import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
+
+import junit.framework.TestCase;
+
+public class JSFBeansTest extends TestCase {
+ TestProjectProvider provider = null;
+ IProject project = null;
+ boolean makeCopy = true;
+
+ public JSFBeansTest() {}
+
+ public void setUp() throws Exception {
+ provider = new TestProjectProvider("org.jboss.tools.jsf.test", null, "JSFKickStart1", false);
+ project = provider.getProject();
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void testBeanWithSuper() {
+ IModelNature n = EclipseResourceUtil.getModelNature(project);
+ assertNotNull("Test project " + project.getName() + " has no model nature.", n);
+ assertNotNull("XModel for project " + project.getName() + " is not loaded.", n.getModel());
+ List<Object> result = WebPromptingProvider.getInstance().getList(n.getModel(), IWebPromptingProvider.JSF_BEAN_PROPERTIES, "user.", new Properties());
+ assertNotNull("No results for bean " + " user.", n.getModel());
+
+ assertTrue("Property 'parent' inherited from super class is not found in bean 'user'", result.contains("parent"));
+ }
+
+ protected void tearDown() throws Exception {
+ if(provider != null) {
+ provider.dispose();
+ }
+ }
+
+}
Modified: trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfAllTests.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfAllTests.java 2008-04-02 13:38:11 UTC (rev 7267)
+++ trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfAllTests.java 2008-04-02 13:49:14 UTC (rev 7268)
@@ -22,6 +22,7 @@
suite.addTestSuite(JSFModelTest.class);
suite.addTestSuite(ModelFormat_2_0_0_Test.class);
suite.addTestSuite(JSFImportTest.class);
+ suite.addTestSuite(JSFBeansTest.class);
return suite;
}
16 years, 1 month
JBoss Tools SVN: r7267 - trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates.
by jbosstools-commits@lists.jboss.org
Author: svasilyev
Date: 2008-04-02 09:38:11 -0400 (Wed, 02 Apr 2008)
New Revision: 7267
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-1843
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2008-04-02 13:26:50 UTC (rev 7266)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2008-04-02 13:38:11 UTC (rev 7267)
@@ -222,7 +222,7 @@
<vpe:tag name="a4j:portlet" case-sensitive="yes">
<vpe:template children="yes" modify="no">
- <span style="display:none">
+ <span>
</span>
</vpe:template>
</vpe:tag>
16 years, 1 month
JBoss Tools SVN: r7266 - in trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces: src/org/jboss/tools/jsf/vpe/richfaces/template and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: dmaliarevich
Date: 2008-04-02 09:26:50 -0400 (Wed, 02 Apr 2008)
New Revision: 7266
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuItem/style.css
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1588, panrlMenuItem icon's attributes were added
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuItem/style.css
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuItem/style.css 2008-04-02 13:13:33 UTC (rev 7265)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuItem/style.css 2008-04-02 13:26:50 UTC (rev 7266)
@@ -37,11 +37,11 @@
}
-.dr-pmenu-group-self-label {
+.rich-pmenu-item-label {
padding-left:5px;
}
-.dr-pmenu-item-disabled {
+.rich-pmenu-disabled-element {
color:#B1ADA7;
font-family:Arial,Verdana,sans-serif;
font-size:11px;
@@ -49,20 +49,17 @@
padding:2px 1px 1px;
}
-.dr-pmenu-item {
+.rich-pmenu-item {
cursor:pointer;
margin-top:1px;
padding:2px 1px 1px;
-}
-
-.dr-pmenu-item {
color:#000000;
font-family:Arial,Verdana,sans-serif;
font-size:11px;
}
.dr-pmenu-nowrap {
- white-space:nowrap;
+ white-space: nowrap;
}
.dr-pmenu-top-self-div {
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java 2008-04-02 13:13:33 UTC (rev 7265)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java 2008-04-02 13:26:50 UTC (rev 7266)
@@ -32,6 +32,7 @@
public class RichFacesPanelMenuGroupTemplate extends VpeAbstractTemplate {
public static final String GROUP_COUNT_SEPARATOR = "-"; //$NON-NLS-1$
+ public static final Map<String, String> DEFAULT_ICON_MAP = new HashMap<String, String>();
/*
* pich:panelMenuGroup attributes
@@ -70,8 +71,6 @@
private static final String STYLE_PATH = "/panelMenuGroup/style.css"; //$NON-NLS-1$
private static final String EMPTY_DIV_STYLE = "display: none;"; //$NON-NLS-1$
- private static final Map<String, String> DEFAULT_ICON_MAP = new HashMap<String, String>();
-
private static final String TRUE = "true"; //$NON-NLS-1$
private static final String RIGHT = "right"; //$NON-NLS-1$
private static final String SPACE = " "; //$NON-NLS-1$
@@ -285,11 +284,11 @@
if (childOfPanelMenu) {
+ tableBodyRow.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_TOP_GROUP + SPACE + CSS_GROUP);
columnn1_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_TOP_GROUP_ICON + SPACE + CSS_GROUP_ICON);
- column2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_TOP_GROUP_LABEL + SPACE + CSS_GROUP_LABEL);
+ column2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_GROUP_LABEL + SPACE + CSS_TOP_GROUP_LABEL);
column3_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_TOP_GROUP_ICON + SPACE + CSS_GROUP_ICON);
- styleClass = CSS_TOP_GROUP + SPACE + CSS_GROUP;
-
+
if (attrPresents(pm_topGroupClass)) {
styleClass = SPACE + pm_topGroupClass;
}
@@ -299,10 +298,10 @@
div.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_TOP_GROUP_DIV + SPACE + CSS_GROUP_DIV);
} else {
+ tableBodyRow.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_GROUP);
columnn1_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_GROUP_ICON);
column2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_GROUP_LABEL);
column3_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_GROUP_ICON);
- styleClass = CSS_GROUP;
if (attrPresents(pm_groupClass)) {
styleClass = SPACE + pm_groupClass;
@@ -507,13 +506,13 @@
/**
- * Checks is attribute presents.
+ * Checks is attribute have some value.
*
* @param attr the attribute
*
* @return true, if successful
*/
private static boolean attrPresents(String attr) {
- return null != attr;
+ return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
}
}
\ No newline at end of file
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java 2008-04-02 13:13:33 UTC (rev 7265)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java 2008-04-02 13:26:50 UTC (rev 7266)
@@ -25,12 +25,14 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+
public class RichFacesPanelMenuItemTemplate extends VpeAbstractTemplate {
/*
* rich:panelMenuItem attributes
*/
private static final String DISABLED = "disabled"; //$NON-NLS-1$
+ private static final String LABEL = "label"; //$NON-NLS-1$
private static final String ICON = "icon"; //$NON-NLS-1$
private static final String ICON_DISABLED = "iconDisabled"; //$NON-NLS-1$
private static final String DISABLED_CLASS = "disabledClass"; //$NON-NLS-1$
@@ -53,11 +55,8 @@
/*
* rich:panelMenuItem default css styles
*/
- private static final String DR_ITEM_CLASS = "dr-pmenu-item"; //$NON-NLS-1$
private static final String DR_NOWARP_CLASS = "dr-pmenu-nowrap"; //$NON-NLS-1$
- private static final String DR_LABEL_CLASS = "dr-pmenu-group-self-label"; //$NON-NLS-1$
private static final String DR_TOP_DIV = "dr-pmenu-top-self-div"; //$NON-NLS-1$
- private static final String DR_DISABLED_CLASS_NAME = "dr-pmenu-item-disabled"; //$NON-NLS-1$
private static final String IMG_POINTS_SRC = "/panelMenuItem/points.gif"; //$NON-NLS-1$
private static final String IMG_SPACER_SRC = "/panelMenuItem/spacer.gif"; //$NON-NLS-1$
@@ -70,8 +69,12 @@
private static final String LEFT = "left"; //$NON-NLS-1$
private static final String NO_SIZE_VALUE = "0"; //$NON-NLS-1$
private static final String DEFAULT_SIZE_VALUE = "16"; //$NON-NLS-1$
+ private static final String SRC = "16"; //$NON-NLS-1$
+ private static final String FILE = "16"; //$NON-NLS-1$
- private static final String PANEL_MENU_ITEM = "panelMenuItem"; //$NON-NLS-1$
+ private static final String COMPONENT_NAME = "panelMenuItem"; //$NON-NLS-1$
+ private static final String PANEL_MENU_END_TAG = ":panelMenu"; //$NON-NLS-1$
+ private static final String PANEL_MENU_GROUP_END_TAG = ":panelMenuGroup"; //$NON-NLS-1$
private static final String EMPTY_DIV_STYLE = "display: none;"; //$NON-NLS-1$
/*
@@ -120,30 +123,29 @@
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMElement parentVisualElement) {
- ComponentUtil.setCSSLink(pageContext, STYLE_PATH, PANEL_MENU_ITEM);
+ ComponentUtil.setCSSLink(pageContext, STYLE_PATH, COMPONENT_NAME);
readPanelMenuAttributes(sourceParentElement);
readPanelMenuItemAttributes(sourceElement);
- nsIDOMElement parentDiv = visualDocument.createElement("div"); //$NON-NLS-1$
- parentDiv.setAttribute("CLASS", DR_TOP_DIV); //$NON-NLS-1$
+ nsIDOMElement parentDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ parentDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, DR_TOP_DIV);
parentVisualElement.appendChild(parentDiv);
nsIDOMElement div = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
-
parentDiv.appendChild(div);
- if (sourceElement.getParentNode().getNodeName().endsWith(
- ":panelMenuGroup") //$NON-NLS-1$
- || (sourceElement.getParentNode().getNodeName()
- .endsWith(":panelMenu"))) { //$NON-NLS-1$
- div.setAttribute("vpeSupport", PANEL_MENU_ITEM); //$NON-NLS-1$
+ boolean childOfPanelMenu = sourceElement.getParentNode().getNodeName().endsWith(
+ PANEL_MENU_END_TAG);
+ boolean childOfPanelMenuGroup = sourceElement.getParentNode().getNodeName().endsWith(
+ PANEL_MENU_GROUP_END_TAG);
+
+ if (childOfPanelMenu || childOfPanelMenuGroup) {
+ div.setAttribute("vpeSupport", COMPONENT_NAME); //$NON-NLS-1$
nsIDOMElement table = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
div.appendChild(table);
- table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- DR_ITEM_CLASS);
table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR,
NO_SIZE_VALUE);
table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR,
@@ -158,22 +160,17 @@
nsIDOMElement tdNowrap = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
tr.appendChild(tdNowrap);
- tdNowrap.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- DR_NOWARP_CLASS);
+
- nsIDOMElement tdLable = visualDocument
+ nsIDOMElement tdLabel = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
- tr.appendChild(tdLable);
- tdLable.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- DR_LABEL_CLASS);
- tdLable.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- "element.style"); //$NON-NLS-1$
+ tr.appendChild(tdLabel);
- String value = sourceElement.getAttribute("label"); //$NON-NLS-1$
- nsIDOMText text = visualDocument.createTextNode(value == null ? EMPTY //$NON-NLS-1$
+ String value = sourceElement.getAttribute(LABEL);
+ nsIDOMText text = visualDocument.createTextNode(value == null ? EMPTY
: value);
- tdLable.appendChild(text);
+ tdLabel.appendChild(text);
nsIDOMElement td = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
@@ -192,54 +189,18 @@
nsIDOMElement imgSpacer2 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_IMG);
- if (sourceElement.getParentNode().getNodeName().endsWith(
- ":panelMenu")) { //$NON-NLS-1$
-
- if ((TRUE.equalsIgnoreCase(pmi_disabled))
- || (TRUE.equalsIgnoreCase(pm_disabled))) {
- setIcon(pageContext, imgPoints, sourceElement,
- sourceParentElement, pm_iconTopDisabledItem,
- pmi_iconDisabled);
- setItemClassAndStyle(table, pm_disabledItemClass,
- pmi_disabledClass, DR_DISABLED_CLASS_NAME,
- pm_disabledItemStyle, pmi_disabledStyle);
- } else {
- setIcon(pageContext, imgPoints, sourceElement,
- sourceParentElement, pm_iconTopItem, pmi_icon);
- setItemClassAndStyle(table, pm_topItemClass,
- pmi_styleClass, DR_ITEM_CLASS,
- pm_topItemStyle, pmi_style);
- }
- setIconPosition(pm_iconItemTopPosition, td, tdNowrap,
- imgPoints, imgSpacer2);
-
- } else {
- if ((TRUE.equalsIgnoreCase(pmi_disabled))
- || (TRUE.equalsIgnoreCase(pm_disabled))) {
- setIcon(pageContext, imgPoints, sourceElement,
- sourceParentElement, pm_iconDisabledItem,
- pmi_iconDisabled);
- setItemClassAndStyle(table, pm_disabledItemClass,
- pmi_disabledClass, DR_DISABLED_CLASS_NAME,
- pm_disabledItemStyle, pmi_disabledStyle);
- } else {
- setIcon(pageContext, imgPoints, sourceElement,
- sourceParentElement, pm_iconItem, pmi_icon);
- setItemClassAndStyle(table, pm_itemClass, pmi_styleClass,
- DR_ITEM_CLASS, pm_itemStyle, pmi_style);
- }
- setIconPosition(pm_iconItemPosition, td, tdNowrap, imgPoints,
- imgSpacer2);
- }
-
+ setItemClassAndStyle(childOfPanelMenu, table, tr, imgPoints, tdLabel, imgSpacer1);
+ setIcon(childOfPanelMenu, pageContext, imgPoints);
+ setIconPosition(pm_iconItemTopPosition, td, tdNowrap, imgPoints, imgSpacer2);
+
List<Node> children = ComponentUtil.getChildren(sourceElement);
if (!children.isEmpty()) {
- VpeChildrenInfo childInfo = new VpeChildrenInfo(tdLable);
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(tdLabel);
creationData.addChildrenInfo(childInfo);
for (Node child : children) {
- if (!(child.getNodeName().endsWith(":panelMenuGroup") || child //$NON-NLS-1$
- .getNodeName().endsWith(":panelMenu"))) { //$NON-NLS-1$
+ if (!(child.getNodeName().endsWith(PANEL_MENU_GROUP_END_TAG) || child
+ .getNodeName().endsWith(PANEL_MENU_END_TAG))) {
childInfo.addSourceChild(child);
}
}
@@ -267,24 +228,7 @@
place.appendChild(image);
setDefaultImgAttributes(image);
}
-
- private static void setIcon(VpePageContext pageContext,
- nsIDOMElement imgPoints, Element sourceElement,
- Element parentElement, String parentIconPath,
- String iconPath) {
- if (iconPath == null || iconPath.length() == 0) {
- if (!(parentIconPath == null || parentIconPath.length() == 0)) {
- ComponentUtil.setImgFromResources(pageContext, imgPoints,
- parentIconPath, IMG_SPACER_SRC);
- } else {
- ComponentUtil.setImg(imgPoints, IMG_POINTS_SRC);
- }
- } else {
- ComponentUtil.setImgFromResources(pageContext, imgPoints, iconPath,
- IMG_SPACER_SRC);
- }
- }
-
+
private static void setIconPosition(String iconPosition,
nsIDOMElement right, nsIDOMElement left, nsIDOMElement imgPoints,
nsIDOMElement imgSpacer2) {
@@ -304,31 +248,160 @@
ComponentUtil.setImg(imgSpacer2, IMG_SPACER_SRC);
}
}
+
+ /**
+ * Gets the specified icon from panelMenu or .panelMenuGroupItem
+ *
+ * @param pm_icon the panelMenu icon attribute
+ * @param pmi_icon the panelMenuGroupItem icon attribute
+ *
+ * @return the specified icon
+ */
+ private static String[] getSpecifiedIcon(String pm_icon, String pmi_icon) {
+ String[] imgPath = {EMPTY, EMPTY};
+ if (attrPresents(pmi_icon)) {
+ /*
+ * Icon was set in the panelMenuItem attribute.
+ */
+ imgPath[0] = pmi_icon;
+ if (RichFacesPanelMenuGroupTemplate.DEFAULT_ICON_MAP.containsKey(pmi_icon)) {
+ imgPath[1] = RichFacesPanelMenuGroupTemplate.DEFAULT_ICON_MAP.get(pmi_icon);
+ }
+ } else if (attrPresents(pm_iconTopDisabledItem)) {
+ /*
+ * Icon was set in the panelMenu attribute.
+ */
+ imgPath[0] = pm_icon;
+ if (RichFacesPanelMenuGroupTemplate.DEFAULT_ICON_MAP.containsKey(pm_icon)) {
+ imgPath[1] = RichFacesPanelMenuGroupTemplate.DEFAULT_ICON_MAP.get(pm_icon);
+ }
+ }
+ return imgPath;
+ }
+
+ /**
+ * Sets the src attribute value for the image.
+ *
+ * @param childOfPanelMenu if the item is the child of panelMenu
+ * @param pageContext the page context
+ * @param img the image
+ */
+ private static void setIcon(boolean childOfPanelMenu, VpePageContext pageContext, nsIDOMElement img) {
+ String[] imgPath = {EMPTY, EMPTY};
+ boolean disabled = (TRUE.equalsIgnoreCase(pmi_disabled))
+ || (TRUE.equalsIgnoreCase(pm_disabled));
+
+ if (childOfPanelMenu) {
+ if (disabled) {
+ imgPath = getSpecifiedIcon(pm_iconTopDisabledItem, pmi_iconDisabled);
+ } else {
+ imgPath = getSpecifiedIcon(pm_iconTopItem, pmi_icon);
+ }
+ } else {
+ if (disabled) {
+ imgPath = getSpecifiedIcon(pm_iconDisabledItem, pmi_iconDisabled);
+ } else {
+ imgPath = getSpecifiedIcon(pm_iconItem, pmi_icon);
+ }
+ }
+
+ if (EMPTY.equalsIgnoreCase(imgPath[0])) {
+ /*
+ * Icon wasn't set. Set default image.
+ */
+ ComponentUtil.setImg(img, IMG_POINTS_SRC);
+ } else {
+ /*
+ * Set specified icon.
+ */
+ if (RichFacesPanelMenuGroupTemplate.DEFAULT_ICON_MAP.containsKey(imgPath[0])) {
+ ComponentUtil.setImg(img, imgPath[1]);
+ } else {
+ // TODO ADD SPACER OR IMG PATH
+ img.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, HtmlComponentUtil.FILE_PROTOCOL+imgPath[1]);
+// ComponentUtil.setImgFromResources(pageContext, imgPoints, imgPath[1],
+// IMG_SPACER_SRC);
+ }
+ }
+ }
- private static void setItemClassAndStyle(nsIDOMElement table,
- String parentClass, String itemClass, String defaultClass,
- String parentStyle, String itemStyle) {
+
+ /**
+ * Sets the item class and style for the item.
+ *
+ * @param childOfPanelMenu if the item is the child of panelMenu
+ * @param table the table
+ * @param tr the table row
+ * @param img1 the first table row column image
+ * @param td2 the second table row column
+ * @param img3 the third table row column image
+ */
+ private static void setItemClassAndStyle(boolean childOfPanelMenu,
+ nsIDOMElement table,
+ nsIDOMElement tr,
+ nsIDOMElement img1,
+ nsIDOMElement td2,
+ nsIDOMElement img3) {
- String resultClass = EMPTY;
- if (!(defaultClass == null || defaultClass.length() == 0)) {
- resultClass += defaultClass;
+ String tableStyle = EMPTY;
+ String tableClass = EMPTY;
+ String trClass = CSS_ITEM;
+ String img1Class = DR_NOWARP_CLASS + SPACE + CSS_ITEM_ICON;
+ String td2Class = CSS_ITEM_LABEL;
+ String img3Class = CSS_ITEM_ICON;
+
+ if (attrPresents(pm_itemClass)) {
+ tableClass += pm_itemClass;
}
- if (!(parentClass == null || parentClass.length() == 0)) {
- resultClass += SPACE + parentClass;
+ if (attrPresents(pmi_styleClass)) {
+ tableClass += pmi_styleClass;
}
- if (!(itemClass == null || itemClass.length() == 0)) {
- resultClass += SPACE + itemClass;
+ if (attrPresents(pm_itemStyle)) {
+ tableStyle += pm_itemStyle;
}
- table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, resultClass);
-
- String resultStyle = EMPTY;
- if (!(parentStyle == null || parentStyle.length() == 0)) {
- resultStyle += parentStyle;
+ if (attrPresents(pmi_style)) {
+ tableStyle += pmi_style;
}
- if (!(itemStyle == null || itemStyle.length() == 0)) {
- resultStyle += SPACE + itemStyle;
+
+ if (childOfPanelMenu) {
+ trClass += SPACE + CSS_TOP_ITEM;
+ img1Class += SPACE + CSS_TOP_ITEM_ICON;
+ td2Class += SPACE + CSS_TOP_ITEM_LABEL;
+ img3Class += SPACE + CSS_TOP_ITEM_ICON;
+ if (attrPresents(pm_topItemClass)) {
+ tableClass += pm_topItemClass;
+ }
+ if (attrPresents(pm_topItemStyle)) {
+ tableStyle += pm_topItemStyle;
+ }
}
- table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, resultStyle);
+
+ if ((TRUE.equalsIgnoreCase(pmi_disabled))
+ || (TRUE.equalsIgnoreCase(pm_disabled))) {
+ trClass += SPACE + CSS_DISABLED_ELEMENT;
+ img1Class += SPACE + CSS_DISABLED_ELEMENT;
+ td2Class += SPACE + CSS_DISABLED_ELEMENT;
+ img3Class += SPACE + CSS_DISABLED_ELEMENT;
+ if (attrPresents(pm_disabledItemClass)) {
+ tableClass += pm_disabledItemClass;
+ }
+ if (attrPresents(pmi_disabledClass)) {
+ tableClass += pmi_disabledClass;
+ }
+ if (attrPresents(pm_disabledItemStyle)) {
+ tableStyle += pm_disabledItemStyle;
+ }
+ if (attrPresents(pmi_disabledStyle)) {
+ tableStyle += pmi_disabledStyle;
+ }
+ }
+
+ table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, tableStyle);
+ table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, tableClass);
+ tr.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, trClass);
+ img3.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, img1Class);
+ td2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, td2Class);
+ img3.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, img3Class);
}
/**
@@ -377,7 +450,7 @@
}
/*
- * pich:panelMenuItem attributes
+ * rich:panelMenuItem attributes
*/
pmi_disabled = sourceElement.getAttribute(DISABLED);
pmi_icon = sourceElement.getAttribute(ICON);
@@ -388,4 +461,15 @@
pmi_styleClass = sourceElement.getAttribute(STYLE_CLASS);
}
+
+ /**
+ * Checks is attribute have some value.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private static boolean attrPresents(String attr) {
+ return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
+ }
}
\ No newline at end of file
16 years, 1 month
JBoss Tools SVN: r7265 - in trunk/jsf/plugins/org.jboss.tools.jsf: src/org/jboss/tools/jsf/model/pv and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-04-02 09:13:33 -0400 (Wed, 02 Apr 2008)
New Revision: 7265
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/jsfprojects.meta
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java
Log:
JBIDE-1884
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/jsfprojects.meta
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/jsfprojects.meta 2008-04-02 13:12:09 UTC (rev 7264)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/jsfprojects.meta 2008-04-02 13:13:33 UTC (rev 7265)
@@ -74,8 +74,12 @@
<Editor name="Uneditable"/>
</XModelAttribute>
<XModelAttribute name="class name"/>
+ <XModelAttribute name="declaring class"/>
</XModelAttributes>
<XActionItem kind="list">
+ <XActionItem HandlerClassName="%OpenJavaSource%" ICON="action.empty"
+ PROPERTIES="attribute=declaring class;property=name"
+ displayName="Open" kind="action" name="Open"/>
<XActionItem ICON="action.copy" displayName="Copy" kind="list" name="CopyActions">
<XActionItem BaseActionName="Copy" HIDE="always"
HandlerClassName="%Copy%" ICON="action.copy" displayName="Copy"
@@ -99,15 +103,19 @@
</ICONS>
</XEntityRenderer>
<XModelAttributes>
+ <XModelAttribute default="property" loader="ElementType" name="element type">
+ <Editor name="Uneditable"/>
+ </XModelAttribute>
<XModelAttribute name="name" xmlname="NAME">
<Editor name="Uneditable"/>
</XModelAttribute>
<XModelAttribute name="class name"/>
- <XModelAttribute default="property" loader="ElementType" name="element type">
- <Editor name="Uneditable"/>
- </XModelAttribute>
+ <XModelAttribute name="declaring class"/>
</XModelAttributes>
<XActionItem kind="list">
+ <XActionItem HandlerClassName="%OpenJavaSource%" ICON="action.empty"
+ PROPERTIES="attribute=declaring class;property=name"
+ displayName="Open" kind="action" name="Open"/>
<XActionItem ICON="action.copy" displayName="Copy" kind="list" name="CopyActions">
<XActionItem BaseActionName="Copy" HIDE="always"
HandlerClassName="%Copy%" ICON="action.copy" displayName="Copy"
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java 2008-04-02 13:12:09 UTC (rev 7264)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java 2008-04-02 13:13:33 UTC (rev 7265)
@@ -91,9 +91,12 @@
XModelObject[] cs = getChildren();
for (int i = 0; i < cs.length; i++) map.put(cs[i].getPathPart(), cs[i]);
if(type != null) {
- IField[] fs = type.getFields();
+ IType _type = type;
+ while(_type != null) {
+ IField[] fs = _type.getFields();
if(fs != null) for (int i = 0; i < fs.length; i++) {
String n = fs[i].getElementName();
+ if(properties.contains(n)) continue;
JSFProjectBeanMember c = (JSFProjectBeanMember)map.get(n);
if(c != null && !c.getModelEntity().getName().equals("JSFProjectBeanProperty")) {
c.removeFromParent();
@@ -106,12 +109,13 @@
c.setType(beans.getType(typeName));
if(typeName == null) typeName = "";
c.setAttributeValue("class name", typeName);
+ c.setAttributeValue("declaring class", fs[i].getDeclaringType().getFullyQualifiedName());
} else {
c = createMember(n, fs[i], "JSFProjectBeanProperty");
}
properties.add(n);
}
- IMethod[] ms = type.getMethods();
+ IMethod[] ms = _type.getMethods();
if(ms != null) for (int i = 0; i < ms.length; i++) {
if(ms[i].isConstructor()) continue;
if(!Flags.isPublic(ms[i].getFlags())) continue;
@@ -141,11 +145,24 @@
if(typeName == null) typeName = "";
c.setAttributeValue("class name", typeName);
c.setMember(ms[i]);
+ c.setAttributeValue("declaring class", ms[i].getDeclaringType().getFullyQualifiedName());
} else if(!properties.contains(n)) {
- c = createMember(n, ms[i], entity);
+ c = createMember(n, ms[i], entity);
}
- if(isProperty) properties.add(n);
+ if(isProperty) {
+ properties.add(n);
+ } else {
+ //add it anyway
+ properties.add(n);
+ }
}
+
+ String sc = _type.getSuperclassName();
+ if(sc == null || sc.length() == 0 || "java.lang.Object".equals(sc)) break;
+ sc = EclipseJavaUtil.resolveType(_type, sc);
+ if(sc == null || sc.length() == 0 || "java.lang.Object".equals(sc)) break;
+ _type = beans.getType(sc);
+ }
} else if(beanList.length > 0) {
XModelObject[] ps = beanList[0].getChildren();
for (int i = 0; i < ps.length; i++) {
@@ -174,6 +191,7 @@
c.setBeans(beans);
String className = EclipseJavaUtil.getMemberTypeAsString(member);
c.setAttributeValue("class name", (className == null) ? "" : className);
+ c.setAttributeValue("declaring class", member.getDeclaringType().getFullyQualifiedName());
c.setType(beans.getType(className));
c.setMember(member);
if(isLoading) addChild_0(c); else addChild(c);
16 years, 1 month
JBoss Tools SVN: r7264 - trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/java/handlers.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-04-02 09:12:09 -0400 (Wed, 02 Apr 2008)
New Revision: 7264
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/java/handlers/OpenJavaSourceHandler.java
Log:
JBIDE-1884
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/java/handlers/OpenJavaSourceHandler.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/java/handlers/OpenJavaSourceHandler.java 2008-04-02 12:43:03 UTC (rev 7263)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/java/handlers/OpenJavaSourceHandler.java 2008-04-02 13:12:09 UTC (rev 7264)
@@ -35,7 +35,9 @@
}
protected String getType(XModelObject object) {
- return object.getAttributeValue(getAttribute());
+ String attr = getAttribute();
+ if(attr == null) return null;
+ return object.getAttributeValue(attr);
}
protected String getAttribute() {
@@ -46,6 +48,18 @@
if(!isEnabled(object)) return;
String type = getType(object);
type = type.replace('.', '/') + ".java";
+
+ if(p == null || p.getProperty("property") == null) {
+ String n = action.getProperty("property");
+ if(n != null) {
+ String v = object.getAttributeValue(n);
+ if(v != null) {
+ if(p == null) p = new Properties();
+ p.put("property", v);
+ }
+ }
+ }
+
try {
open(object.getModel(), type, p);
} catch (CoreException e) {
16 years, 1 month
JBoss Tools SVN: r7263 - trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2008-04-02 08:43:03 -0400 (Wed, 02 Apr 2008)
New Revision: 7263
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1917
http://jira.jboss.com/jira/browse/JBIDE-1947
http://jira.jboss.com/jira/browse/JBIDE-1918
http://jira.jboss.com/jira/browse/JBIDE-1492
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java 2008-04-02 12:43:03 UTC (rev 7263)
@@ -8,6 +8,7 @@
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMHTMLTextAreaElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -22,6 +23,9 @@
nsIDOMElement textArea = visualDocument
.createElement(HTML.TAG_TEXTAREA);
+ ((nsIDOMHTMLTextAreaElement) textArea
+ .queryInterface(nsIDOMHTMLTextAreaElement.NS_IDOMHTMLTEXTAREAELEMENT_IID))
+ .setReadOnly(true);
VpeCreationData creationData = new VpeCreationData(textArea);
@@ -32,11 +36,12 @@
copyAttribute(textArea, sourceElement, JSF.ATTR_COLS, HTML.ATTR_COLS);
VpeElementData elementData = new VpeElementData();
- nsIDOMNode text =null;
+ nsIDOMNode text = null;
if (sourceElement.hasAttribute(JSF.ATTR_VALUE)) {
Attr attr = sourceElement.getAttributeNode(JSF.ATTR_VALUE);
- text = visualDocument.createTextNode(sourceElement.getAttribute(JSF.ATTR_VALUE));
+ text = visualDocument.createTextNode(sourceElement
+ .getAttribute(JSF.ATTR_VALUE));
elementData.addAttributeData(new VpeAttributeData(attr, textArea,
true));
16 years, 1 month
JBoss Tools SVN: r7262 - in trunk: jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util and 7 other directories.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2008-04-02 03:28:48 -0400 (Wed, 02 Apr 2008)
New Revision: 7262
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputNumberSlider_old.css
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputbg.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/pos.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/sliderbg.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractRichFacesInputNumberTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSliderTemplate.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1917
http://jira.jboss.com/jira/browse/JBIDE-1947
http://jira.jboss.com/jira/browse/JBIDE-1918
http://jira.jboss.com/jira/browse/JBIDE-1492
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -14,19 +14,10 @@
import java.util.Map;
import java.util.Set;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.EditableTemplateAdapter;
import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsISelection;
import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* general class for jsf templates
@@ -82,115 +73,4 @@
}
- protected boolean handleCharacter(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
- if (elementMapping != null)
- return super.handleCharacter(pageContext, keyEvent);
- else
- return true;
- }
-
- protected boolean handleLeftDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
- if (elementMapping != null)
- return super.handleLeftDelete(pageContext, keyEvent);
- else
- return true;
-
- }
-
- protected boolean handleRightDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
- if (elementMapping != null)
- return super.handleRightDelete(pageContext, keyEvent);
- else
- return true;
- }
-
- @Override
- public void setSelection(VpePageContext pageContext, nsISelection selection) {
-
- nsIDOMNode focusedVisualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = pageContext.getDomMapping()
- .getNearElementMapping(focusedVisualNode);
-
- if (elementMapping != null)
- super.setSelection(pageContext, selection);
- else {
-
- VpeNodeMapping insertedMapping = pageContext.getDomMapping()
- .getNearNodeMappingAtVisualNode(focusedVisualNode);
-
- if (insertedMapping != null) {
-
- Node insertedNode = insertedMapping.getSourceNode();
-
- int offset = ((IDOMNode) insertedNode).getStartOffset();
-
- Node realNode = TemplateManagingUtil.getSourceNodeByPosition(
- pageContext, offset);
-
- VpeElementMapping mappingRealNode = pageContext.getDomMapping()
- .getNearElementMapping(realNode);
-
- if (mappingRealNode != null) {
-
- Node focusedNode = getFocusedNode(realNode, mappingRealNode
- .getElementData(), offset);
-
- setSourceSelection(pageContext, focusedNode, 0,
- getLengthNode(focusedNode));
-
- // visual selection block
-
- // get visual node
- focusedVisualNode = getVisualNode(pageContext, focusedNode,
- mappingRealNode.getElementData());
-
- // if not find
- if (focusedVisualNode == null)
- focusedVisualNode = mappingRealNode.getVisualElement();
-
- if (focusedVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
-
- focusedVisualNode = focusedVisualNode.getParentNode();
-
- pageContext
- .getVisualBuilder()
- .setSelectionRectangle(
- (nsIDOMElement) focusedVisualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
- }
-
- }
- }
- }
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -7,11 +7,15 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -67,11 +71,11 @@
Attr outputAttr = getOutputAttributeNode(sourceElement);
if (outputAttr != null) {
-
+
// prepare value
String newValue = prepareAttrValue(pageContext, sourceElement,
outputAttr);
-
+
// if escape then contents of value (or other attribute) is only
// text
if (!sourceElement.hasAttribute(JSF.ATTR_ESCAPE)
@@ -126,7 +130,7 @@
}
}
-
+
creationData.setElementData(elementData);
}
@@ -135,4 +139,101 @@
return ComponentUtil.getBundleValue(pageContext, attr);
}
+
+ @Override
+ public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping) {
+
+ // try get mapping
+ VpeNodeMapping tempMapping = pageContext.getDomMapping()
+ .getNearElementMapping(visualNode);
+
+ // if mapping is not null
+ if (tempMapping != null) {
+
+ return super.getTargetSourceNodeByVisualNode(pageContext,
+ visualNode, elementMapping);
+ }
+ // can be only for escape=false
+ else {
+
+ tempMapping = pageContext.getDomMapping()
+ .getNearNodeMappingAtVisualNode(visualNode);
+
+ if (tempMapping != null) {
+
+ Node insertedNode = tempMapping.getSourceNode();
+
+ return getTargetSourceNodeBySourcePosition(pageContext,
+ TemplateManagingUtil.getStartOffsetNode(insertedNode),
+ TemplateManagingUtil.getEndOffsetNode(insertedNode));
+
+ }
+ }
+
+ return elementMapping.getSourceNode();
+
+ }
+
+ @Override
+ public nsIDOMNode getTargetVisualNodeByVisualNode(
+ VpePageContext pageContext, nsIDOMNode visualNode,
+ VpeElementMapping elementMapping) {
+ // try get mapping
+ VpeNodeMapping tempMapping = pageContext.getDomMapping()
+ .getNearElementMapping(visualNode);
+
+ // if mapping is not null
+ if (tempMapping != null) {
+
+ return super.getTargetVisualNodeByVisualNode(pageContext,
+ visualNode, elementMapping);
+ }
+ // can be only for escape=false
+ else {
+
+ tempMapping = pageContext.getDomMapping()
+ .getNearNodeMappingAtVisualNode(visualNode);
+
+ if (tempMapping != null) {
+
+ Node insertedNode = tempMapping.getSourceNode();
+
+ Node sourceNode = getTargetSourceNodeBySourcePosition(
+ pageContext, TemplateManagingUtil
+ .getStartOffsetNode(insertedNode),
+ TemplateManagingUtil.getEndOffsetNode(insertedNode));
+ return getTargetVisualNodeBySourceNode(sourceNode,
+ elementMapping);
+
+ }
+ }
+
+ return elementMapping.getVisualNode();
+ }
+
+ @Override
+ protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
+ nsIDOMNode node) {
+ // TODO Auto-generated method stub
+ VpeElementMapping elementMapping = super.getElmentMapping(pageContext,
+ node);
+
+ if (elementMapping == null) {
+ VpeNodeMapping insertedMapping = pageContext.getDomMapping()
+ .getNearNodeMappingAtVisualNode(node);
+ if (insertedMapping != null) {
+ Node insertedNode = insertedMapping.getSourceNode();
+
+ int offset = TemplateManagingUtil
+ .getStartOffsetNode(insertedNode);
+ elementMapping = TemplateManagingUtil
+ .getElementMappingBySourceSelection(pageContext,
+ offset, offset);
+
+ }
+ }
+
+ return elementMapping;
+ }
}
Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextAreaTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -0,0 +1,62 @@
+package org.jboss.tools.jsf.vpe.jsf.template;
+
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class JsfInputTextAreaTemplate extends AbstractEditableJsfTemplate {
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ Element sourceElement = (Element) sourceNode;
+
+ nsIDOMElement textArea = visualDocument
+ .createElement(HTML.TAG_TEXTAREA);
+
+ VpeCreationData creationData = new VpeCreationData(textArea);
+
+ copyGeneralJsfAttributes(textArea, sourceElement);
+
+ copyAttribute(textArea, sourceElement, JSF.ATTR_DIR, HTML.ATTR_DIR);
+ copyAttribute(textArea, sourceElement, JSF.ATTR_ROWS, HTML.ATTR_ROWS);
+ copyAttribute(textArea, sourceElement, JSF.ATTR_COLS, HTML.ATTR_COLS);
+
+ VpeElementData elementData = new VpeElementData();
+ nsIDOMNode text =null;
+ if (sourceElement.hasAttribute(JSF.ATTR_VALUE)) {
+
+ Attr attr = sourceElement.getAttributeNode(JSF.ATTR_VALUE);
+ text = visualDocument.createTextNode(sourceElement.getAttribute(JSF.ATTR_VALUE));
+ elementData.addAttributeData(new VpeAttributeData(attr, textArea,
+ true));
+
+ } else {
+ text = visualDocument.createTextNode(""); //$NON-NLS-1$
+ elementData.addAttributeData(new VpeAttributeData(JSF.ATTR_VALUE,
+ textArea, true));
+
+ }
+ textArea.appendChild(text);
+ creationData.setElementData(elementData);
+
+ return creationData;
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
+}
Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfInputTextTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -0,0 +1,57 @@
+package org.jboss.tools.jsf.vpe.jsf.template;
+
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class JsfInputTextTemplate extends AbstractEditableJsfTemplate {
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ Element sourceElement = (Element) sourceNode;
+
+ nsIDOMElement input = visualDocument.createElement(HTML.TAG_INPUT);
+
+ VpeCreationData creationData = new VpeCreationData(input);
+
+ copyGeneralJsfAttributes(input, sourceElement);
+
+ copyAttribute(input, sourceElement, JSF.ATTR_VALUE, HTML.ATTR_VALUE);
+ copyAttribute(input, sourceElement, JSF.ATTR_SIZE, HTML.ATTR_SIZE);
+ copyAttribute(input, sourceElement, JSF.ATTR_DIR, HTML.ATTR_DIR);
+
+ VpeElementData elementData = new VpeElementData();
+ if (sourceElement.hasAttribute(JSF.ATTR_VALUE)) {
+
+ Attr attr = sourceElement.getAttributeNode(JSF.ATTR_VALUE);
+ elementData
+ .addAttributeData(new VpeAttributeData(attr, input, true));
+
+ } else {
+
+ elementData.addAttributeData(new VpeAttributeData(JSF.ATTR_VALUE,
+ input, true));
+
+ }
+ creationData.setElementData(elementData);
+
+ return creationData;
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
+}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -39,4 +39,10 @@
public static final String ATTR_STYLE_CLASS = "styleClass"; //$NON-NLS-1$
+ public static final String ATTR_SIZE = "size"; //$NON-NLS-1$
+
+ public static final String ATTR_ROWS = "rows"; //$NON-NLS-1$
+
+ public static final String ATTR_COLS = "cols"; //$NON-NLS-1$
+
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/templates/vpe-templates-jsf.xml 2008-04-02 07:28:48 UTC (rev 7262)
@@ -21,10 +21,10 @@
</vpe:tag>
<vpe:tag name="h:inputText" case-sensitive="yes">
- <vpe:template children="no" modify="no">
- <input type="text" value="{jsfvalue(@value)}"
+ <vpe:template children="no" modify="no" class="org.jboss.tools.jsf.vpe.jsf.template.JsfInputTextTemplate">
+ <!-- <input type="text" value="{jsfvalue(@value)}"
class="{@styleClass}" style="{@style}" title="{tagstring()}"
- size="{@size}" dir="{@dir}" />
+ size="{@size}" dir="{@dir}" /> -->
<vpe:resize>
<vpe:width width-attr="style.width" />
<vpe:height height-attr="style.height" />
@@ -47,11 +47,12 @@
</vpe:tag>
<vpe:tag name="h:inputTextarea" case-sensitive="yes">
- <vpe:template children="yes" modify="no">
- <textarea class="{@styleClass}" style="{@style}"
+ <vpe:template children="yes" modify="no" class="org.jboss.tools.jsf.vpe.jsf.template.JsfInputTextAreaTemplate">
+ <!-- <textarea class="{@styleClass}" style="{@style}"
rows="{@rows}" cols="{@cols}" title="{tagstring()}" dir="{@dir}">
- <vpe:value expr="{jsfvalue(@value)}" />
- </textarea>
+ <vpe:value expr="{jsfvalue(@value)}" />
+
+ </textarea>-->
<vpe:resize>
<vpe:width width-attr="style.width" />
<vpe:height height-attr="style.height" />
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputNumberSlider_old.css
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputNumberSlider_old.css 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputNumberSlider_old.css 2008-04-02 07:28:48 UTC (rev 7262)
@@ -1,90 +0,0 @@
-.minValueStyle {
- border-color: ;
- color: #000000;
- font-family: Arial, Verdana, sans-serif;
- font-size: 11px;
- line-height: 11px;
- border-left:1px solid #b0b0b0;
- padding: 0px 3px;
- text-align:left;
-}
-
-.maxValueStyle {
- border-color: ;
- color: #000000;
- font-family: Arial, Verdana, sans-serif;
- font-size: 11px;
- line-height: 11px;
- border-right: 1px solid #b0b0b0;
- padding: 0px 3px;
- text-align: right;
-}
-
-.inputStyleClass {
- border: 1px solid;
- padding: 0px 0px 0px 3px;
- margin-top: 0px;
- margin-bottom: 0px;
- background-position: left top;
- background-repeat: repeat-x;
- background-color:#ffffff;
- font-family:Arial, Verdana, sans-serif ;font-size:11px;
- color:#000000;
- border-color:#C4C0B9;
- border-bottom-color:#ffffff;
- border-right-color:#ffffff;
-}
-
-.cellForTableStyleClass {
- width:100%;
- padding-top:3px;
-}
-
-.dr-insldr-tip {
- border: 1px solid #E5973E;
- padding: 0px 2px;
- position: absolute;
- top: -17px;
- white-space: nowrap;
- font-family: Arial,Verdana,sans-serif;
- font-size: 11px;
-}
-.dr-insldr-handler {
- background-color:transparent;
- background-image: ;
- font-size:1px;
- height:8px;
- position:absolute;
- text-align:center;
- width:7px;
- z-index:1;
-}
-.dr-insldr-track {
- background-position:left top;
- background-repeat:repeat-x;
- font-size:1px;
- height:8px;
- vertical-align : bottom;
- background-color:#FFFFFF;
- background-image: ;
-}
-.manualInputFieldTableCellClass{
-vertical-align : bottom;
-}
-.innerTableStyle {
- border-color:;
- border:1px solid #b0b0b0;
- height:100%;
- width:100%;
-}
-.cell-with-picture {
- align: left;
- height: 4px;
- width: 7px;
-}
-.mainTableStyle{
-width :200px;
-}
-.empty-cell-style {
-font-size: 4px;
-}
\ No newline at end of file
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/inputbg.gif
===================================================================
(Binary files differ)
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/pos.gif
===================================================================
(Binary files differ)
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/inputNumberSlider/sliderbg.gif
===================================================================
(Binary files differ)
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractRichFacesInputNumberTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractRichFacesInputNumberTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/AbstractRichFacesInputNumberTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jsf.vpe.richfaces.template;
-
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-public abstract class AbstractRichFacesInputNumberTemplate extends AbstractRichFacesTemplate {
- /** INPUTSIZE_ATTRIBURE */
- final static private String INPUTSIZE_ATTRIBURE = "inputSize";
-
- /** INPUTCLASS_ATTRIBURE */
- final static private String INPUTCLASS_ATTRIBURE = "inputClass";
-
- /**
- *
- * @see com.exadel.vpe.editor.template.VpeAbstractTemplate#removeAttribute(com.exadel.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Element, org.w3c.dom.Document, org.w3c.dom.Node,
- * java.lang.Object, java.lang.String)
- */
- @Override
- public void removeAttribute(VpePageContext pageContext,
- Element sourceElement, nsIDOMDocument visualDocument, nsIDOMNode visualNode,
- Object data, String name) {
-
- super.removeAttribute(pageContext, sourceElement, visualDocument,
- visualNode, data, name);
-
- setAttribute(pageContext, sourceElement, visualDocument, visualNode,
- data, name, "");
- }
-
- /**
- * Return a input size
- * @param sourceNode a sourceNode
- * @return a input size
- */
- protected String getInputSize(Node sourceNode) {
- String returnValue = getDefaultInputSize();
- String tmp = getAttribute(INPUTSIZE_ATTRIBURE, sourceNode);
- if ( tmp.length() != 0 ) {
- returnValue = tmp;
- }
- return returnValue;
- }
-
- /**
- * Return a input class
- * @param sourceNode a sourceNode
- * @return a input class
- */
- public String getInputClass(Node sourceNode) {
- String returnValue = getDefaultInputClass();
- String tmp = getAttribute(INPUTCLASS_ATTRIBURE, sourceNode);
- if ( tmp.length() != 0 ) {
- returnValue = new StringBuffer().append(returnValue).append(" ").append(tmp).toString();
- }
- return returnValue;
- }
-
-
-
-
- public abstract String getDefaultInputSize();
-
- public abstract String getDefaultInputClass();
-
-
-}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/InputNumberSliderTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -22,14 +22,11 @@
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TextUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMHTMLInputElement;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMText;
-import org.mozilla.interfaces.nsISelection;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -81,16 +78,6 @@
private static final String INPUT_POSITION_ATTR = "inputPosition"; //$NON-NLS-1$
/**
- * "inputSize" attribute
- */
- private static final String INPUT_SIZE_ATTR = "inputSize"; //$NON-NLS-1$
-
- /**
- * "inputStyle" attribute
- */
- private static final String INPUT_STYLE_ATTR = "inputStyle"; //$NON-NLS-1$
-
- /**
* "minValue" attribute
*/
private static final String MIN_VALUE_ATTR = "minValue"; //$NON-NLS-1$
@@ -285,14 +272,14 @@
// create input field
nsIDOMElement inputField = visualDocument.createElement(HTML.TAG_INPUT);
- inputField.setAttribute(HTML.ATTR_TYPE, "text"); //$NON-NLS-1$
+ inputField.setAttribute(HTML.ATTR_TYPE, HTML.VALUE_TEXT_TYPE);
inputField.setAttribute(HTML.ATTR_SIZE, getNumberValue(sourceElement,
- INPUT_SIZE_ATTR, INPUT_SIZE_DEFAULT));
+ RichFaces.ATTR_INPUT_SIZE, INPUT_SIZE_DEFAULT));
inputField.setAttribute(HTML.ATTR_STYLE, ComponentUtil
.getBackgoundImgStyle(INPUT_BACKGROUND_IMAGE_PATH)
- + getAttribute(sourceElement, INPUT_STYLE_ATTR));
+ + getAttribute(sourceElement, RichFaces.ATTR_INPUT_STYLE));
VpeAttributeData attributeData;
@@ -327,7 +314,7 @@
nsIDOMHTMLInputElement iDOMInputElement = (nsIDOMHTMLInputElement) inputField
.queryInterface(nsIDOMHTMLInputElement.NS_IDOMHTMLINPUTELEMENT_IID);
- iDOMInputElement.setReadOnly(true);
+ iDOMInputElement.setReadOnly(false);
inputTd.appendChild(inputField);
@@ -593,149 +580,30 @@
return true;
}
- @Override
- protected boolean handleCharacter(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
+ /**
+ *
+ */
+ public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
+ // if element is not null
if (elementMapping != null) {
- VpeAttributeData attributeData = getAttributeData(pageContext,
- visualNode, elementMapping.getElementData());
+ // get attributeData
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
- if ((attributeData != null) && attributeData.isEditable()) {
+ // attributeData is found
+ if ((attributeData != null)
+ && (attributeData.getSourceAttr() != null)) {
+ return attributeData.getSourceAttr();
+ } else
+ return elementMapping.getSourceNode();
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- // get inserted string
- long charCode = keyEvent.getCharCode();
- char[] s = new char[1];
- s[0] = (char) charCode;
- String str = new String(s);
- if (TextUtil.containsKey(s[0])) {
- str = TextUtil.getValue(s[0]);
- }
-
- Node node = createAttribute((Element) elementMapping
- .getSourceNode(), attributeData.getAttributeName(),
- str);
-
- setSourceSelection(pageContext, node, 0, 0);
- return true;
- } else
- return super.handleCharacter(pageContext, keyEvent);
-
- }
-
}
- return false;
- }
-
- @Override
- protected boolean handleLeftDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
-
- // get selection
-
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping != null) {
-
- VpeAttributeData attributeData = getAttributeData(pageContext,
- visualNode, elementMapping.getElementData());
-
- if ((attributeData != null) && attributeData.isEditable()) {
-
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- Node node = createAttribute((Element) elementMapping
- .getSourceNode(), attributeData.getAttributeName(),
- ""); //$NON-NLS-1$
-
- setSourceSelection(pageContext, node, 0, 0);
- return true;
- } else
- return super.handleLeftDelete(pageContext, keyEvent);
-
- }
-
- }
- return false;
-
- }
-
- @Override
- protected boolean handleRightDelete(VpePageContext pageContext,
- nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
- // get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
-
- VpeElementMapping elementMapping = getElmentMapping(pageContext,
- visualNode);
-
- if (elementMapping != null) {
-
- VpeAttributeData attributeData = getAttributeData(pageContext,
- visualNode, elementMapping.getElementData());
-
- if ((attributeData != null) && attributeData.isEditable()) {
-
- if ((attributeData.getSourceAttr() == null)
- && (attributeData.getAttributeName() != null)) {
-
- Node node = createAttribute((Element) elementMapping
- .getSourceNode(), attributeData.getAttributeName(),
- ""); //$NON-NLS-1$
- setSourceSelection(pageContext, node, 0, 0);
-
- return true;
-
- } else
- return super.handleRightDelete(pageContext, keyEvent);
-
- }
-
- }
- return false;
-
- }
-
- /**
- *
- * @param sourceElement
- * @param attributeName
- * @param value
- */
- private Node createAttribute(Element sourceElement, String attributeName,
- String value) {
-
- if ((sourceElement != null) && (attributeName != null)) {
- sourceElement.setAttribute(attributeName, value != null ? value
- : ""); //$NON-NLS-1$
-
- return sourceElement.getAttributeNode(attributeName);
- }
return null;
}
+
}
\ No newline at end of file
Deleted: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSliderTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSliderTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSliderTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -1,785 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jsf.vpe.richfaces.template;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
-import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
-import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator;
-import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.template.VpeCreationData;
-import org.mozilla.interfaces.nsIDOMAttr;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMNodeList;
-import org.mozilla.interfaces.nsIDOMText;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * Template for input number slider control // TODO We should refactor this
- * class. There is a lot of reflection and a lot of direct work with mozzila.
- */
-public class RichFacesInputNumberSliderTemplate extends
- AbstractRichFacesInputNumberTemplate {
-
- private static final String CSS_FILE = "/inputNumberSlider/inputNumberSlider.css";
-
- private static final String MIN_VALUE_STALE_CLASS = "minValueStyle";
-
- private static final String MAX_VALUE_STALE_CLASS = "maxValueStyle";
-
- private static final String TABLE_INPUT_CELL_STYLE = "manualInputFieldTableCellClass";
-
- private static final String CELL_FOR_TABLE_STYLE = "cellForTableStyleClass";
-
- private static final String INNER_TABLE_STYLE = "innerTableStyle";
-
- final static private String HTML_INPUTSIZE_DEFAULT = "3";
-
- final static private String HTML_INPUTTYPE_HIDDEN = "hidden";
-
- final static private String HTML_INPUTTYPE_TEXT = "text";
-
- final static private String HTML_INPUTVALUE_DEFAULT = "50";
-
- final static private String IMAGE_SLIDER = "/inputNumberSlider/pos.gif";
-
- final static private String SLIDER_MAXVALUE_ATTR = "maxValue";
-
- final static private String SLIDER_MAXVALUE_DEFAULT = "100";
-
- final static private String SLIDER_MINVALUE_ATTR = "minValue";
-
- final static private String SLIDER_VALUE_ATTR = "value";
-
- final static private String SLIDER_MINVALUE_DEFAULT = "0";
-
- final static private String SLIDER_SHOWBOUNDARY_ATTR = "showBoundaryValues";
-
- final static private String SLIDER_SHOWINPUT_ATTR = "showInput";
-
- final static private String SLIDER_STEP_ATTR = "step";
-
- /** INPUT_STYLE_CLASS */
- private static final String INPUT_STYLE_CLASS = "inputStyleClass";
-
- /** */
- final private Map<String, Method> mapAttributeToMethod;
-
- final private static Class<?>[] defaultArgsMappedMethods = new Class<?>[2];
-
- static {
- defaultArgsMappedMethods[0] = nsIDOMElement.class;
- defaultArgsMappedMethods[1] = Element.class;
- }
-
- private boolean rightInputPosition = true;
-
- /**
- * Default constructor
- */
- public RichFacesInputNumberSliderTemplate() {
- mapAttributeToMethod = new HashMap<String, Method>();
-
- addMapAttibuteToMethod("value", "setInputValue");
- addMapAttibuteToMethod("inputSize", "setInputSize");
- addMapAttibuteToMethod("inputClass", "setInputClass");
- addMapAttibuteToMethod("inputStyle", "setInputStyle");
- addMapAttibuteToMethod("inputPosition", "setInputPosition");
- addMapAttibuteToMethod("maxlength", "setMaxlength");
- addMapAttibuteToMethod("showInput", "showInput");
- addMapAttibuteToMethod("showBoundaryValues", "showBoundaryValues");
- addMapAttibuteToMethod("maxValue", "setMaxValue");
- addMapAttibuteToMethod("minValue", "setMinValue");
- addMapAttibuteToMethod("width", "setWidth");
- addMapAttibuteToMethod("style", "setStyle");
- addMapAttibuteToMethod("class", "setClass");
- }
-
- /**
- *
- * @param methodName
- * @return
- */
- private Method getMethodByName(String methodName) {
- Class<?> clazz = this.getClass();
- Method m1 = null;
- try {
- m1 = clazz.getMethod(methodName, defaultArgsMappedMethods);
- } catch (SecurityException e) {
- RichFacesTemplatesActivator.getPluginLog().logError(
- "SecurityException: " + e.getMessage());
- } catch (NoSuchMethodException e) {
- RichFacesTemplatesActivator.getPluginLog().logWarning(
- "NoSuchMethodException: " + methodName + ":"
- + e.getMessage());
- }
-
- return m1;
- }
-
- /**
- *
- * @param attributeName
- * @param methodName
- */
- private void addMapAttibuteToMethod(String attributeName, String methodName) {
- Method method = getMethodByName(methodName);
-
- if (method != null) {
- mapAttributeToMethod.put(attributeName, method);
- }
- }
-
- /**
- * Creates a node of the visual tree on the node of the source tree. This
- * visual node should not have the parent node This visual node can have
- * child nodes.
- *
- * @param pageContext
- * Contains the information on edited page.
- * @param sourceNode
- * The current node of the source tree.
- * @param visualDocument
- * The document of the visual tree.
- * @return The information on the created node of the visual tree.
- */
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument) {
- setInputPosition(sourceNode);
-
- nsIDOMElement table1 = null;
- nsIDOMElement table1Tr1 = null;
- nsIDOMElement table1Tr1Td1 = null;
- nsIDOMText table1Tr1Td1Text = null;
- nsIDOMElement table1Tr1Td2 = null;
- nsIDOMText table1Tr1Td2Text = null;
- nsIDOMElement table1Tr1Td3 = null;
- nsIDOMElement table1Tr1Td3input = null;
- nsIDOMElement table1Tr2 = null;
- nsIDOMElement table1Tr2Td1 = null;
- nsIDOMElement table1Tr2Td1Table2 = null;
- nsIDOMElement table1Tr2Td1Table2Tr1 = null;
- nsIDOMElement table1Tr2Td1Table2Tr1Td = null;
- nsIDOMElement table1Tr2Td1Table2Tr1TdTable = null;
- nsIDOMElement table1Tr2Td1Table2Tr1TdTableTr = null;
-
- nsIDOMElement table1Tr2Td1Table2Tr1TdTableTrTd1 = null;
- nsIDOMElement table1Tr2Td1Table2Tr1TdTableTrTd2 = null;
- nsIDOMElement table1Tr2Td1Table2Tr1TdTableTrTd2Img = null;
- nsIDOMElement table1Tr2Td1Table2Tr1TdTableTrTd3 = null;
-
- // sets css link
- ComponentUtil.setCSSLink(pageContext, CSS_FILE, "inputNumberSlider");
-
- // create table1
- table1 = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- addBasicTableAttributes(table1);
-
- VpeCreationData creationData = new VpeCreationData(table1);
-
- // creates first row in table 1
- table1Tr1 = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
- table1Tr1Td1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr1Td1.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- MIN_VALUE_STALE_CLASS);
- table1Tr1Td1Text = visualDocument.createTextNode("0");
- table1Tr1Td2 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr1Td2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- MAX_VALUE_STALE_CLASS);
- table1Tr1Td2Text = visualDocument.createTextNode("100");
- table1Tr1Td3 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr1Td3.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- TABLE_INPUT_CELL_STYLE);
- table1Tr1Td3.setAttribute(HtmlComponentUtil.HTML_ROWSPAN_ATTR, "2");
- table1Tr1Td3input = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_INPUT);
-
- table1Tr1Td3input.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- /* INPUT_STYLE_CLASS+ */"-moz-user-modify:read-write");
-
-// nsIDOMAttr newVisualDOMAttribute = visualDocument
-// .createAttribute("value");
-// newVisualDOMAttribute.setValue("50");
-// table1Tr1Td3input.appendChild(newVisualDOMAttribute);
-
- // table1Tr1Td3input.setAttribute(HtmlComponentUtil.HTML_SIZE_ATTR,
- // "3");
- table1Tr1Td3input.setAttribute(HtmlComponentUtil.HTML_VALUE_ATTR,
- "50");
-
- creationData.setData(table1Tr1Td3input);
-
- String positionStyle = "margin-left: 10px;";
- if (!rightInputPosition) {
- positionStyle = "margin-right: 10px;";
- }
- table1Tr1Td3input.setAttribute("style", positionStyle
- + ComponentUtil
- .getBackgoundImgStyle("inputNumberSlider/inputbg.gif"));
-
- table1Tr2 = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
- table1Tr2Td1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr2Td1.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- CELL_FOR_TABLE_STYLE);
- table1Tr2Td1.setAttribute(HtmlComponentUtil.HTML_COLSPAN_ATTR, "2");
- table1Tr2Td1Table2 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- addBasicTableAttributes(table1Tr2Td1Table2);
-
- table1Tr2Td1Table2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- INNER_TABLE_STYLE);
- table1Tr2Td1Table2.setAttribute(
- HtmlComponentUtil.HTML_CELLPADDING_ATTR, "1");
- table1Tr2Td1Table2.setAttribute(
- HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
-
- table1Tr2Td1Table2Tr1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
-
- table1Tr2Td1Table2Tr1Td = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr2Td1Table2Tr1TdTable = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- table1Tr2Td1Table2Tr1TdTable.setAttribute(
- HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
- table1Tr2Td1Table2Tr1TdTable.setAttribute(
- HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
- table1Tr2Td1Table2Tr1TdTable.setAttribute(
- HtmlComponentUtil.HTML_BORDER_ATTR, "0");
-
- table1Tr2Td1Table2Tr1TdTableTr = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
-
- table1Tr2Td1Table2Tr1TdTableTrTd1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr2Td1Table2Tr1TdTableTrTd1.setAttribute(
- HtmlComponentUtil.HTML_CLASS_ATTR, "empty-cell-style");
-
- table1Tr2Td1Table2Tr1TdTableTrTd1.setAttribute("style", ComponentUtil
- .getBackgoundImgStyle("inputNumberSlider/sliderbg.gif"));
-
- table1Tr2Td1Table2Tr1TdTableTrTd1.setAttribute(
- HtmlComponentUtil.HTML_WIDTH_ATTR, "50%");
-
- table1Tr2Td1Table2Tr1TdTableTrTd2 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr2Td1Table2Tr1TdTableTrTd2.setAttribute(
- HtmlComponentUtil.HTML_CLASS_ATTR, "cell-with-picture");
-
- table1Tr2Td1Table2Tr1TdTableTrTd2.setAttribute("style", ComponentUtil
- .getBackgoundImgStyle("inputNumberSlider/inputbg.gif"));
-
- table1Tr2Td1Table2Tr1TdTableTrTd2Img = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_IMG);
- ComponentUtil
- .setImg(table1Tr2Td1Table2Tr1TdTableTrTd2Img, IMAGE_SLIDER);
-
- table1Tr2Td1Table2Tr1TdTableTrTd3 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- table1Tr2Td1Table2Tr1TdTableTrTd3.setAttribute(
- HtmlComponentUtil.HTML_CLASS_ATTR, "empty-cell-style");
-
- table1Tr2Td1Table2Tr1TdTableTrTd3.setAttribute("style", ComponentUtil
- .getBackgoundImgStyle("inputNumberSlider/sliderbg.gif"));
-
- table1Tr2Td1Table2Tr1TdTableTrTd3.setAttribute(
- HtmlComponentUtil.HTML_WIDTH_ATTR, "50%");
-
- table1.appendChild(table1Tr1);
- table1.appendChild(table1Tr2);
-
- if (rightInputPosition) {
- table1Tr1.appendChild(table1Tr1Td1);
- table1Tr1.appendChild(table1Tr1Td2);
- table1Tr1.appendChild(table1Tr1Td3);
- } else {
- table1Tr1.appendChild(table1Tr1Td3);
- table1Tr1.appendChild(table1Tr1Td1);
- table1Tr1.appendChild(table1Tr1Td2);
- }
-
- table1Tr2.appendChild(table1Tr2Td1);
- table1Tr1Td1.appendChild(table1Tr1Td1Text);
- table1Tr1Td2.appendChild(table1Tr1Td2Text);
-
- table1Tr1Td3.appendChild(table1Tr1Td3input);
-
- table1Tr2Td1.appendChild(table1Tr2Td1Table2);
- table1Tr2Td1Table2.appendChild(table1Tr2Td1Table2Tr1);
- table1Tr2Td1Table2Tr1.appendChild(table1Tr2Td1Table2Tr1Td);
- table1Tr2Td1Table2Tr1Td.appendChild(table1Tr2Td1Table2Tr1TdTable);
- table1Tr2Td1Table2Tr1TdTable
- .appendChild(table1Tr2Td1Table2Tr1TdTableTr);
- table1Tr2Td1Table2Tr1TdTableTr
- .appendChild(table1Tr2Td1Table2Tr1TdTableTrTd1);
- table1Tr2Td1Table2Tr1TdTableTr
- .appendChild(table1Tr2Td1Table2Tr1TdTableTrTd2);
- table1Tr2Td1Table2Tr1TdTableTr
- .appendChild(table1Tr2Td1Table2Tr1TdTableTrTd3);
- table1Tr2Td1Table2Tr1TdTableTrTd2
- .appendChild(table1Tr2Td1Table2Tr1TdTableTrTd2Img);
-
- //
- // set a default values
- //
-
- Object[] inPatams = new Object[2];
- inPatams[0] = table1;
- inPatams[1] = sourceNode;
-
- for (Map.Entry<String, Method> e : mapAttributeToMethod.entrySet()) {
- Method function = e.getValue();
- if (function != null) {
- try {
- function.invoke(this, inPatams);
- } catch (IllegalArgumentException e1) {
- RichFacesTemplatesActivator.getPluginLog().logWarning(
- "IllegalArgumentException: " + e.getKey() + ":"
- + e1.getMessage(), e1);
- } catch (IllegalAccessException e2) {
- RichFacesTemplatesActivator.getPluginLog().logWarning(
- "IllegalAccessException: " + e.getKey() + ":"
- + e2.getMessage(), e2);
- } catch (InvocationTargetException e3) {
- // RichFacesTemplatesActivator.getPluginLog().logWarning("InvocationTargetException:
- // " + e3.getMessage(), e3);
- }
- }
- }
-
- return creationData;
- }
-
- private void setInputPosition(Node sourceNode) {
- String position = getAttribute("inputPosition", sourceNode);
- rightInputPosition = !"left".equalsIgnoreCase(position);
- }
-
- /**
- *
- * @see com.exadel.vpe.editor.template.VpeAbstractTemplate#setAttribute(com.exadel.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Element, org.w3c.dom.Document, org.w3c.dom.Node,
- * java.lang.Object, java.lang.String, java.lang.String)
- */
- @Override
- public void setAttribute(VpePageContext pageContext, Element sourceElement,
- nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
- String name, String value) {
-
- Method function = mapAttributeToMethod.get(name);
- if (function != null) {
- Object[] inPatams = new Object[2];
- inPatams[0] = visualNode;
- inPatams[1] = sourceElement;
- try {
- function.invoke(this, inPatams);
- } catch (IllegalArgumentException e1) {
- RichFacesTemplatesActivator.getPluginLog().logWarning(
- "IllegalArgumentException: " + name + ":"
- + e1.getMessage());
- } catch (IllegalAccessException e2) {
- RichFacesTemplatesActivator.getPluginLog().logWarning(
- "IllegalAccessException: " + name + ":"
- + e2.getMessage());
- } catch (InvocationTargetException e3) {
- // RichFacesTemplatesActivator.getPluginLog().logWarning("InvocationTargetException:
- // " + name + ":"+ e3.getMessage() );
- }
- }
-
- nsIDOMElement visualtElement = (nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
- correctArrowPosition(sourceElement, visualtElement);
- }
-
- /**
- *
- */
- public String getDefaultInputSize() {
- return HTML_INPUTSIZE_DEFAULT;
- }
-
- /**
- *
- */
- public String getDefaultInputClass() {
- return INPUT_STYLE_CLASS;
- }
-
- /**
- * Sets some attributes which necessary for displaying table as tree
- *
- * @param tree
- */
- private void addBasicTableAttributes(nsIDOMElement table) {
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
- }
-
- /**
- *
- * @param visualNode
- * @return
- */
- private nsIDOMElement getInputElement(nsIDOMElement visualNode) {
- nsIDOMElement table = visualNode;
- nsIDOMNodeList tableList = table.getChildNodes();
- nsIDOMNode tr = tableList.item(0);
- nsIDOMNodeList trList = tr.getChildNodes();
- nsIDOMNode td1 = null;
- if (rightInputPosition) {
- td1 = trList.item(2);
- } else {
- td1 = trList.item(0);
- }
- nsIDOMNodeList td1List = td1.getChildNodes();
- nsIDOMNode input = td1List.item(0);
- nsIDOMElement inputElement = (nsIDOMElement) input
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- return inputElement;
- }
-
- /**
- *
- * @param visualNode
- * @return
- */
- private nsIDOMNode getMaxValueElement(nsIDOMElement visualNode) {
- nsIDOMElement table = visualNode;
- nsIDOMNodeList tableList = table.getChildNodes();
- nsIDOMNode tr = tableList.item(0);
- nsIDOMNodeList trList = tr.getChildNodes();
- nsIDOMNode td1 = trList.item(1);
- nsIDOMNodeList td1List = td1.getChildNodes();
- nsIDOMNode maxValue = td1List.item(0);
- return maxValue;
- }
-
- /**
- *
- * @param visualNode
- * @return
- */
- private nsIDOMNode getMinValueElement(nsIDOMElement visualNode) {
- nsIDOMElement table = visualNode;
- nsIDOMNodeList tableList = table.getChildNodes();
- nsIDOMNode tr = tableList.item(0);
- nsIDOMNodeList trList = tr.getChildNodes();
- nsIDOMNode td1 = trList.item(0);
- nsIDOMNodeList td1List = td1.getChildNodes();
- nsIDOMNode minValue = td1List.item(0);
- return minValue;
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void showInput(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (getAttribute(SLIDER_SHOWINPUT_ATTR, sourceNode).equalsIgnoreCase(
- "false")) {
- input.setAttribute(HtmlComponentUtil.HTML_TYPE_ATTR,
- HTML_INPUTTYPE_HIDDEN);
- } else {
- input.setAttribute(HtmlComponentUtil.HTML_TYPE_ATTR,
- HTML_INPUTTYPE_TEXT);
- }
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void showBoundaryValues(nsIDOMElement visualNode, Element sourceNode) {
- setMaxValue(visualNode, sourceNode);
- setMinValue(visualNode, sourceNode);
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setInputSize(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (input != null) {
- input.setAttribute("size", getInputSize(sourceNode));
- }
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setInputClass(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (input != null) {
- String tmp = getInputClass(sourceNode);
- input.setAttribute("class", tmp);
- }
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setMaxValue(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMNode maxValue = getMaxValueElement(visualNode);
- if (maxValue != null) {
- if (getAttribute(SLIDER_SHOWBOUNDARY_ATTR, sourceNode)
- .equalsIgnoreCase("false")) {
- maxValue.setNodeValue("");
- } else {
- String tmp = getAttribute(SLIDER_MAXVALUE_ATTR, sourceNode);
-
- if (tmp.length() == 0) {
- maxValue.setNodeValue(SLIDER_MAXVALUE_DEFAULT);
- } else {
- maxValue.setNodeValue(tmp);
- }
- }
- }
- correctArrowPosition(sourceNode, visualNode);
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setMinValue(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMNode minValue = getMinValueElement(visualNode);
- if (minValue != null) {
- if (getAttribute(SLIDER_SHOWBOUNDARY_ATTR, sourceNode)
- .equalsIgnoreCase("false")) {
- minValue.setNodeValue("");
- } else {
- String tmp = getAttribute(SLIDER_MINVALUE_ATTR, sourceNode);
- if (tmp.length() == 0) {
- minValue.setNodeValue(SLIDER_MINVALUE_DEFAULT);
- } else {
- minValue.setNodeValue(tmp);
- }
- }
- }
- correctArrowPosition(sourceNode, visualNode);
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setWidth(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement table = visualNode;
- String tmp = getAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, sourceNode);
- if (tmp.length() == 0) {
- tmp = parseStyleWidth(sourceNode);
- }
- if (tmp.length() == 0) {
- table.setAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, "200px;");
- } else {
- table.setAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, tmp);
- }
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setStyle(nsIDOMElement visualNode, Element sourceNode) {
- /*
- * Element table= visualNode; String tmp =
- * getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,sourceNode);
- */
-
- }
-
- /**
- * Corrects arrow position accordinlye max, min and inputValues
- *
- * @param sourceNode
- * @param visualElement
- */
- private void correctArrowPosition(Element sourceNode,
- nsIDOMElement visualElement) {
-
- String minValue = sourceNode.getAttribute(SLIDER_MINVALUE_ATTR);
- String maxValue = sourceNode.getAttribute(SLIDER_MAXVALUE_ATTR);
- String valueValue = sourceNode.getAttribute(SLIDER_VALUE_ATTR);
- String stepValue = sourceNode.getAttribute(SLIDER_STEP_ATTR);
- double min = 0;
- double max = 0;
- double value = 50;
- double step = 1;
- try {
- min = Integer.parseInt(minValue);
- } catch (NumberFormatException ex) {
- min = 0;
- }
- try {
- max = Integer.parseInt(maxValue);
- } catch (NumberFormatException ex) {
- max = 100;
- }
-
- try {
- value = Integer.parseInt(valueValue);
- } catch (NumberFormatException ex) {
- value = 50;
- }
- try {
- step = Integer.parseInt(stepValue);
- if (step < 1) {
- step = 1;
- }
- } catch (NumberFormatException ex) {
- step = 1;
- }
- double h1 = ((roundForStep(step, value) - min) / (max - min)) * 100;
- double h2 = 100 - h1;
-
- nsIDOMNodeList nodeList = visualElement.getChildNodes();
- nsIDOMNode node_01 = nodeList.item(1);
- nsIDOMNodeList nodeList_01 = node_01.getChildNodes();
- nsIDOMNode node_01_00 = nodeList_01.item(0);
- nsIDOMNodeList nodeList_01_00 = node_01_00.getChildNodes();
- nsIDOMNode node_01_00_00 = nodeList_01_00.item(0);
- nsIDOMNodeList nodeList_01_00_00 = node_01_00_00.getChildNodes();
- nsIDOMNode node_01_00_00_00 = nodeList_01_00_00.item(0);
- nsIDOMNodeList nodeList_01_00_00_00 = node_01_00_00_00.getChildNodes();
- nsIDOMNode node_01_00_00_00_00 = nodeList_01_00_00_00.item(0);
- nsIDOMNode node_01_00_00_00_02 = nodeList_01_00_00_00.item(2);
-
- nsIDOMElement table1Tr2Td1Table2Tr1Td1 = (nsIDOMElement) node_01_00_00_00_00
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
- table1Tr2Td1Table2Tr1Td1.setAttribute(
- HtmlComponentUtil.HTML_WIDTH_ATTR, (int) h1 + "%");
- if (node_01_00_00_00_02 != null) {
- nsIDOMElement table1Tr2Td1Table2Tr1Td2 = (nsIDOMElement) node_01_00_00_00_02
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- table1Tr2Td1Table2Tr1Td2.setAttribute(
- HtmlComponentUtil.HTML_WIDTH_ATTR, (int) h2 + "%");
- }
- }
-
- /**
- * Round result accordinly step
- *
- * @param step
- * @param value
- * @return
- */
- private double roundForStep(double step, double value) {
- return Math.round(value / step) * step;
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setClass(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement table = visualNode;
- String tmp = getAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, sourceNode);
- table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- new StringBuffer().append(tmp).toString());
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setInputValue(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (input != null) {
- String tmp = getAttribute("value", sourceNode);
- if (tmp.length() == 0) {
- // input.setAttribute("value", HTML_INPUTVALUE_DEFAULT);
- input.getAttributeNode("value").setNodeValue(
- HTML_INPUTVALUE_DEFAULT);
- } else {
- // input.setAttribute("value", tmp);
- input.getAttributeNode("value").setNodeValue(tmp);
- }
- }
- correctArrowPosition(sourceNode, visualNode);
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setInputStyle(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (input != null) {
- String tmp = getAttribute("inputStyle", sourceNode);
- String style = getAttribute("style", (Element) input);
- if (style != null) {
- input.setAttribute("style", tmp + style);
- } else {
- input.setAttribute("style", tmp);
- }
- }
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setInputPosition(nsIDOMElement visualNode, Element sourceNode) {
- }
-
- /**
- *
- * @param visualNode
- * @param sourceNode
- */
- public void setMaxlength(nsIDOMElement visualNode, Element sourceNode) {
- nsIDOMElement input = getInputElement(visualNode);
- if (input != null) {
- String tmp = getAttribute("maxlength", sourceNode);
- input.setAttribute("maxlength", tmp);
- }
- }
-
- @Override
- public boolean isRecreateAtAttrChange(VpePageContext pageContext,
- Element sourceElement, nsIDOMDocument visualDocument,
- nsIDOMElement visualNode, Object data, String name, String value) {
- return true;
- }
-
-}
\ No newline at end of file
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInputNumberSpinnerTemplate.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -7,232 +7,302 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jsf.vpe.richfaces.template;
-
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-
-/**
- * Template for input number spinner control
- */
-public class RichFacesInputNumberSpinnerTemplate extends AbstractRichFacesInputNumberTemplate {
-
- /** CSS_FILE_NAME */
- final static private String CSS_FILE_NAME = "inputNumberSpinner/inputNumberSpinner.css";
-
- /** IMAGE_NAME_UP */
- final static private String IMAGE_NAME_UP = "/inputNumberSpinner/up.gif";
-
- /** IMAGE_NAME_DOWN */
- final static private String IMAGE_NAME_DOWN = "/inputNumberSpinner/down.gif";
-
- /** DEFAULT_INPUT_SIZE */
- final static private String DEFAULT_INPUT_SIZE = "10";
-
- /** DEFAULT_INPUT_STYLE */
- final static private String DEFAULT_INPUT_STYLE = "ins-input";
-
-
- /** INPUTSTYLE_ATTRIBURE */
- final static private String INPUTSTYLE_ATTRIBURE = "inputStyle";
-
- /** INPUTVALUE_ATTRIBURE */
- final static private String INPUTVALUE_ATTRIBURE = "value";
-
-
- /**
- * Creates a node of the visual tree on the node of the source tree. This
- * visual node should not have the parent node This visual node can have
- * child nodes.
- *
- * @param pageContext
- * Contains the information on edited page.
- * @param sourceNode
- * The current node of the source tree.
- * @param visualDocument
- * The document of the visual tree.
- * @return The information on the created node of the visual tree.
- */
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
-
- // Set a css for this element
- ComponentUtil.setCSSLink(pageContext, CSS_FILE_NAME,
- "richFacesInputNumberSpinner");
-
- nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0px");
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
-
- nsIDOMElement row = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
-
- // create input element
- nsIDOMElement cellInput = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
- cellInput.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "ins-dr-spnr-e");
- cellInput.setAttribute("valign", "top");
- cellInput.appendChild(createInputElement(visualDocument, sourceNode));
- row.appendChild(cellInput);
-
-
- // create arrows cell
- nsIDOMElement cellArrows = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
- cellArrows.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-spnr-b");
- cellArrows.setAttribute("valign", "middle");
- cellArrows.appendChild(createArrowsElement(visualDocument, sourceNode));
- row.appendChild(cellArrows);
-
- table.appendChild(row);
-
- String tmp = getAttribute("style", sourceNode);
- table.setAttribute("style", tmp);
-
+
+/**
+ * Template for input number spinner control
+ */
+public class RichFacesInputNumberSpinnerTemplate extends
+/* AbstractRichFacesInputNumberTemplate */AbstractEditableRichFacesTemplate {
+
+ /** CSS_FILE_NAME */
+ final static private String CSS_FILE_NAME = "inputNumberSpinner/inputNumberSpinner.css"; //$NON-NLS-1$
+
+ /** IMAGE_NAME_UP */
+ final static private String IMAGE_NAME_UP = "/inputNumberSpinner/up.gif"; //$NON-NLS-1$
+
+ /** IMAGE_NAME_DOWN */
+ final static private String IMAGE_NAME_DOWN = "/inputNumberSpinner/down.gif"; //$NON-NLS-1$
+
+ /** DEFAULT_INPUT_SIZE */
+ final static private String DEFAULT_INPUT_SIZE = "10"; //$NON-NLS-1$
+
+ /** DEFAULT_INPUT_STYLE */
+ final static private String DEFAULT_INPUT_STYLE = "ins-input"; //$NON-NLS-1$
+
+ final static private String ZERO_STRING = "0"; //$NON-NLS-1$
+
+ /**
+ * Creates a node of the visual tree on the node of the source tree. This
+ * visual node should not have the parent node This visual node can have
+ * child nodes.
+ *
+ * @param pageContext
+ * Contains the information on edited page.
+ * @param sourceNode
+ * The current node of the source tree.
+ * @param visualDocument
+ * The document of the visual tree.
+ * @return The information on the created node of the visual tree.
+ */
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+
+ // Set a css for this element
+ ComponentUtil.setCSSLink(pageContext, CSS_FILE_NAME,
+ "richFacesInputNumberSpinner"); //$NON-NLS-1$
+
+ Element sourceElement = (Element) sourceNode;
+
+ nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE);
+ table.setAttribute(HTML.ATTR_BORDER, ZERO_STRING);
+ table.setAttribute(HTML.ATTR_CELLPADDING, ZERO_STRING);
+ table.setAttribute(HTML.ATTR_CELLSPACING, ZERO_STRING);
+
+ VpeElementData elementData = new VpeElementData();
+
+ nsIDOMElement row = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TR);
+
+ // create input element
+ nsIDOMElement cellInput = visualDocument.createElement(HTML.TAG_TD);
+ cellInput.setAttribute(HTML.ATTR_CLASS, "ins-dr-spnr-e"); //$NON-NLS-1$
+ cellInput.setAttribute(HTML.ATTR_VALIGN, HTML.VALUE_TOP_VALIGN);
+ cellInput.appendChild(createInputElement(visualDocument, sourceElement,
+ elementData));
+ row.appendChild(cellInput);
+
+ // create arrows cell
+ nsIDOMElement cellArrows = visualDocument.createElement(HTML.TAG_TD);
+ cellArrows.setAttribute(HTML.ATTR_CLASS, "dr-spnr-b"); //$NON-NLS-1$
+ cellArrows.setAttribute(HTML.ATTR_VALIGN, HTML.VALUE_MIDDLE_VALIGN);
+ cellArrows.appendChild(createArrowsElement(visualDocument, sourceNode));
+ row.appendChild(cellArrows);
+
+ table.appendChild(row);
+
+ String tmp = getAttribute(sourceElement, RichFaces.ATTR_STYLE);
+ table.setAttribute(HTML.ATTR_STYLE, tmp);
+
// Create return variable contain template
- VpeCreationData creationData = new VpeCreationData(table);
-
- return creationData;
- }
-
- /**
- * Create a HTML-part containg arrows elements
- * @param visualDocument The current node of the source tree.
- * @param sourceNode The document of the visual tree.
- * @return a HTML-part containg arrows elements
- */
- private nsIDOMElement createArrowsElement(nsIDOMDocument visualDocument, Node sourceNode) {
- nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
-
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
-
- nsIDOMElement rowUp = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
- nsIDOMElement cellUp = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
-
- nsIDOMElement imageUpElement = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_INPUT);
-
- ComponentUtil.setImg(imageUpElement, IMAGE_NAME_UP);
-
- imageUpElement.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
- imageUpElement.setAttribute("type", "image");
- imageUpElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-spnr-bn");
-
- cellUp.appendChild(imageUpElement);
- rowUp.appendChild(cellUp);
- table.appendChild(rowUp);
-
- nsIDOMElement rowDown = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
- nsIDOMElement cellDown = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
-
- nsIDOMElement imageDownElement = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_INPUT);
-
- ComponentUtil.setImg(imageDownElement, IMAGE_NAME_DOWN);
-
- imageDownElement.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
- imageDownElement.setAttribute("type", "image");
- imageDownElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-spnr-bn");
- cellDown.appendChild(imageDownElement);
- rowDown.appendChild(cellDown);
- table.appendChild(rowDown);
-
- return table;
- }
-
-
- /**
- * Create a HTML-part containg input element
- * @param visualDocument The current node of the source tree.
- * @param sourceNode The document of the visual tree.
- * @return a HTML-part containg input element
- */
- private nsIDOMElement createInputElement(nsIDOMDocument visualDocument, Node sourceNode) {
- nsIDOMElement inputElement = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_INPUT);
-
- inputElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- getInputClass(sourceNode));
-
- inputElement.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- getInputStyle(sourceNode));
-
- inputElement.setAttribute("type", "text");
-
- inputElement.setAttribute("size", getInputSize(sourceNode));
- inputElement.setAttribute("value", getInputValue(sourceNode));
-
- return inputElement;
- }
-
-
- /**
- * Return a input value
- * @param sourceNode a sourceNode
- * @return a input value
- */
- private String getInputValue(Node sourceNode) {
- String returnValue = getAttribute(INPUTVALUE_ATTRIBURE, sourceNode);
- return returnValue;
- }
-
- /**
- * Return a input style
- * @param sourceNode a sourceNode
- * @return a input style
- */
- private String getInputStyle(Node sourceNode) {
- String returnValue = getAttribute(INPUTSTYLE_ATTRIBURE, sourceNode);
- return returnValue;
- }
-
- /**
- *
- * @see com.exadel.vpe.editor.template.VpeAbstractTemplate#setAttribute(com.exadel.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Element, org.w3c.dom.Document, org.w3c.dom.Node,
- * java.lang.Object, java.lang.String, java.lang.String)
- */
+ VpeCreationData creationData = new VpeCreationData(table);
+
+ creationData.setElementData(elementData);
+
+ return creationData;
+ }
+
+ /**
+ * Create a HTML-part containg arrows elements
+ *
+ * @param visualDocument
+ * The current node of the source tree.
+ * @param sourceNode
+ * The document of the visual tree.
+ * @return a HTML-part containg arrows elements
+ */
+ private nsIDOMElement createArrowsElement(nsIDOMDocument visualDocument,
+ Node sourceNode) {
+ nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE);
+
+ table.setAttribute(HTML.ATTR_BORDER, ZERO_STRING);
+ table.setAttribute(HTML.ATTR_CELLPADDING, ZERO_STRING);
+ table.setAttribute(HTML.ATTR_CELLSPACING, ZERO_STRING);
+
+ nsIDOMElement rowUp = visualDocument.createElement(HTML.TAG_TR);
+ nsIDOMElement cellUp = visualDocument.createElement(HTML.TAG_TD);
+
+ nsIDOMElement imageUpElement = visualDocument
+ .createElement(HTML.TAG_INPUT);
+
+ ComponentUtil.setImg(imageUpElement, IMAGE_NAME_UP);
+
+ imageUpElement.setAttribute(HTML.ATTR_BORDER, ZERO_STRING);
+ imageUpElement.setAttribute(HTML.ATTR_TYPE, HTML.VALUE_IMAGE_TYPE);
+ imageUpElement.setAttribute(HTML.ATTR_CLASS, "dr-spnr-bn"); //$NON-NLS-1$
+
+ cellUp.appendChild(imageUpElement);
+ rowUp.appendChild(cellUp);
+ table.appendChild(rowUp);
+
+ nsIDOMElement rowDown = visualDocument.createElement(HTML.TAG_TR);
+ nsIDOMElement cellDown = visualDocument.createElement(HTML.TAG_TD);
+
+ nsIDOMElement imageDownElement = visualDocument
+ .createElement(HTML.TAG_INPUT);
+
+ ComponentUtil.setImg(imageDownElement, IMAGE_NAME_DOWN);
+
+ imageDownElement.setAttribute(HTML.ATTR_BORDER, ZERO_STRING);
+ imageDownElement.setAttribute(HTML.ATTR_TYPE, HTML.VALUE_IMAGE_TYPE);
+ imageDownElement.setAttribute(HTML.ATTR_CLASS, "dr-spnr-bn"); //$NON-NLS-1$
+ cellDown.appendChild(imageDownElement);
+ rowDown.appendChild(cellDown);
+ table.appendChild(rowDown);
+
+ return table;
+ }
+
+ /**
+ * Create a HTML-part containg input element
+ *
+ * @param visualDocument
+ * The current node of the source tree.
+ * @param sourceNode
+ * The document of the visual tree.
+ * @param elementData
+ * @return a HTML-part containg input element
+ */
+ private nsIDOMElement createInputElement(nsIDOMDocument visualDocument,
+ Element sourceElement, VpeElementData elementData) {
+ nsIDOMElement inputElement = visualDocument
+ .createElement(HTML.TAG_INPUT);
+
+ inputElement
+ .setAttribute(HTML.ATTR_CLASS, getInputClass(sourceElement));
+
+ inputElement
+ .setAttribute(HTML.ATTR_STYLE, getInputStyle(sourceElement));
+
+ inputElement.setAttribute(HTML.ATTR_TYPE, HTML.VALUE_TEXT_TYPE);
+
+ inputElement.setAttribute(HTML.ATTR_SIZE, getInputSize(sourceElement));
+ inputElement
+ .setAttribute(HTML.ATTR_VALUE, getInputValue(sourceElement));
+
+ if ((sourceElement).hasAttribute(RichFaces.ATTR_VALUE)) {
+ elementData.addAttributeData(new VpeAttributeData(sourceElement
+ .getAttributeNode(RichFaces.ATTR_VALUE), inputElement, true));
+ } else {
+ elementData.addAttributeData(new VpeAttributeData(
+ RichFaces.ATTR_VALUE, inputElement, true));
+ }
+
+ return inputElement;
+ }
+
+ /**
+ * Return a input value
+ *
+ * @param sourceNode
+ * a sourceNode
+ * @return a input value
+ */
+ private String getInputValue(Element sourceElement) {
+ String returnValue = getAttribute(sourceElement, RichFaces.ATTR_VALUE);
+ return returnValue;
+ }
+
+ /**
+ * Return a input style
+ *
+ * @param sourceNode
+ * a sourceNode
+ * @return a input style
+ */
+ private String getInputStyle(Element sourceElement) {
+ String returnValue = getAttribute(sourceElement,
+ RichFaces.ATTR_INPUT_STYLE);
+ return returnValue;
+ }
+
+ /**
+ * Return a input size
+ *
+ * @param sourceNode
+ * a sourceNode
+ * @return a input size
+ */
+ protected String getInputSize(Element sourceElement) {
+ String returnValue = getDefaultInputSize();
+ String tmp = getAttribute(sourceElement, RichFaces.ATTR_INPUT_SIZE);
+ if (tmp.length() != 0) {
+ returnValue = tmp;
+ }
+ return returnValue;
+ }
+
+ /**
+ * Return a input class
+ *
+ * @param sourceNode
+ * a sourceNode
+ * @return a input class
+ */
+ public String getInputClass(Element sourceElement) {
+ String returnValue = getDefaultInputClass();
+ String tmp = getAttribute(sourceElement, RichFaces.ATTR_INPUT_CLASS);
+ if (tmp.length() != 0) {
+ returnValue = new StringBuffer().append(returnValue).append(" ") //$NON-NLS-1$
+ .append(tmp).toString();
+ }
+ return returnValue;
+ }
+
+ /**
+ *
+ * @see com.exadel.vpe.editor.template.VpeAbstractTemplate#setAttribute(com.exadel.vpe.editor.context.VpePageContext,
+ * org.w3c.dom.Element, org.w3c.dom.Document, org.w3c.dom.Node,
+ * java.lang.Object, java.lang.String, java.lang.String)
+ */
@Override
- public void setAttribute(VpePageContext pageContext, Element sourceElement, nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name, String value) {
- // 1. Call super method
- super.setAttribute(pageContext, sourceElement, visualDocument, visualNode, data, name, value);
-
- nsIDOMElement table = (nsIDOMElement) visualNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- nsIDOMNodeList listTable = table.getChildNodes();
- nsIDOMNode nodeTr = listTable.item(0);
- nsIDOMNodeList listTr = nodeTr.getChildNodes();
- nsIDOMNode nodeTd = listTr.item(0);
-
- nsIDOMNodeList listTd = nodeTd.getChildNodes();
- nsIDOMNode entry0 = listTd.item(0);
-
- nsIDOMElement inputElement = (nsIDOMElement) entry0.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
- inputElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, getInputClass(sourceElement));
-
- inputElement.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, getInputStyle(sourceElement));
-
- inputElement.setAttribute(HtmlComponentUtil.HTML_SIZE_ATTR, getInputSize(sourceElement));
- inputElement.setAttribute("value", getInputValue(sourceElement));
-
- // 3. Set a style for main container
- String strStyle = getAttribute("style", sourceElement);
- table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, strStyle);
- }
-
-
-
- public String getDefaultInputSize() {
- return DEFAULT_INPUT_SIZE;
- }
-
- public String getDefaultInputClass() {
- return DEFAULT_INPUT_STYLE;
+ public void setAttribute(VpePageContext pageContext, Element sourceElement,
+ nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
+ String name, String value) {
+ // 1. Call super method
+ super.setAttribute(pageContext, sourceElement, visualDocument,
+ visualNode, data, name, value);
+
+ nsIDOMElement table = (nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ nsIDOMNodeList listTable = table.getChildNodes();
+ nsIDOMNode nodeTr = listTable.item(0);
+ nsIDOMNodeList listTr = nodeTr.getChildNodes();
+ nsIDOMNode nodeTd = listTr.item(0);
+
+ nsIDOMNodeList listTd = nodeTd.getChildNodes();
+ nsIDOMNode entry0 = listTd.item(0);
+
+ nsIDOMElement inputElement = (nsIDOMElement) entry0
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ inputElement
+ .setAttribute(HTML.ATTR_CLASS, getInputClass(sourceElement));
+
+ inputElement
+ .setAttribute(HTML.ATTR_STYLE, getInputStyle(sourceElement));
+
+ inputElement.setAttribute(HTML.ATTR_SIZE, getInputSize(sourceElement));
+ inputElement
+ .setAttribute(HTML.ATTR_VALUE, getInputValue(sourceElement));
+
+ // 3. Set a style for main container
+ String strStyle = getAttribute(sourceElement, RichFaces.ATTR_STYLE);
+ table.setAttribute(HTML.ATTR_STYLE, strStyle);
}
-}
+ public String getDefaultInputSize() {
+ return DEFAULT_INPUT_SIZE;
+ }
+
+ public String getDefaultInputClass() {
+ return DEFAULT_INPUT_STYLE;
+ }
+
+}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -24,5 +24,8 @@
public static final String ATTR_STYLE = "style"; //$NON-NLS-1$
public static final String ATTR_WIDTH = "width"; //$NON-NLS-1$
public static final String ATTR_VALUE = "value"; //$NON-NLS-1$
+ public static final String ATTR_INPUT_SIZE = "inputSize"; //$NON-NLS-1$
+ public static final String ATTR_INPUT_CLASS = "inputClass"; //$NON-NLS-1$
+ public static final String ATTR_INPUT_STYLE = "inputStyle"; //$NON-NLS-1$
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -135,7 +135,6 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
-import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
@@ -151,6 +150,7 @@
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMMutationEvent;
import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.interfaces.nsISelection;
import org.mozilla.interfaces.nsISelectionListener;
import org.mozilla.interfaces.nsISupports;
@@ -553,7 +553,7 @@
anchorPosition);
if (template instanceof ITemplateSelectionManager) {
- ((ITemplateSelectionManager) template).setVisualSelectionBySource(
+ ((ITemplateSelectionManager) template).setSelectionBySource(
pageContext, visualSelectionController, focusPosition,
anchorPosition);
return;
@@ -756,26 +756,43 @@
if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
- nsIDOMElement visualDragElement = selectionBuilder.getDragElement(mouseEvent);
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- System.out.println("<<< mouseDown targetNode: " + visualNode.getNodeName() + " (" + visualNode + ") selectedElement: " + (visualDragElement != null ? visualDragElement.getNodeName() + " (" + visualDragElement + ")" : null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
+
mouseDownSelectionFlag = false;
- if (visualDragElement != null) {
+ VpeTemplate template = TemplateManagingUtil
+ .getTemplateByVisualSelection(pageContext, VisualDomUtil
+ .getTargetNode(mouseEvent));
+
+ if (template instanceof ITemplateSelectionManager) {
+
+ ((ITemplateSelectionManager) template).setSelectionByMouse(
+ pageContext, visualSelectionController, mouseEvent);
- //we shouldn't change selection when we click on <input type="text" /> element,
- //because if we change after resizing the input element lost selection
-// if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.getNodeName())&&
-// HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.getAttribute(HTML.ATTR_TYPE))
-// &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null)) {
+ mouseDownSelectionFlag = true;
+
+ }
+ else {
+ nsIDOMElement visualDragElement = selectionBuilder.getDragElement(mouseEvent);
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ System.out.println("<<< mouseDown targetNode: " + visualNode.getNodeName() + " (" + visualNode + ") selectedElement: " + (visualDragElement != null ? visualDragElement.getNodeName() + " (" + visualDragElement + ")" : null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+
- selectionBuilder.setVisualElementSelection(visualDragElement);
- mouseDownSelectionFlag = true;
-// }
- } else {
- selectionBuilder.setCaretAtMouse(mouseEvent);
+ if (visualDragElement != null) {
+
+ //we shouldn't change selection when we click on <input type="text" /> element,
+ //because if we change after resizing the input element lost selection
+ // if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.getNodeName())&&
+ // HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.getAttribute(HTML.ATTR_TYPE))
+ // &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null)) {
+
+ selectionBuilder.setVisualElementSelection(visualDragElement);
+ mouseDownSelectionFlag = true;
+ // }
+ } else {
+ selectionBuilder.setCaretAtMouse(mouseEvent);
+ }
}
switcher.stopActiveEditor();
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -75,7 +75,7 @@
VpeTemplate vpeTemplate = TemplateManagingUtil
.getTemplateByVisualSelection(visualBuilder.getPageContext(),
- selection.getFocusNode());
+ TemplateManagingUtil.getSelectedNode(selection));
if (vpeTemplate instanceof ITemplateSelectionManager) {
((ITemplateSelectionManager) vpeTemplate).setSelection(
visualBuilder.getPageContext(), selection);
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -38,6 +38,7 @@
import org.jboss.tools.vpe.editor.template.ITemplateNodesManager;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -251,22 +252,20 @@
}
boolean openBundleEditors(nsIDOMNode visualNode) {
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if (sourceNode != null && sourceNode.getNodeType() == Node.ELEMENT_NODE) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceNode);
- if (elementMapping != null) {
+ VpeElementMapping elementMapping = TemplateManagingUtil
+ .getElementMappingByVisualSelection(pageContext, visualNode);
+ if (elementMapping != null) {
- VpeTemplate template = elementMapping.getTemplate();
+ VpeTemplate template = elementMapping.getTemplate();
- // if template implements VpeTemplateNodesManager interface
- if (template instanceof ITemplateNodesManager) {
- return ((ITemplateNodesManager) template).openBundle(
- pageContext, visualNode, elementMapping.getElementData());
- } else {
- template.openBundleEditors(pageContext,
- (Element) sourceNode, elementMapping.getData());
- }
+ // if template implements VpeTemplateNodesManager interface
+ if (template instanceof ITemplateNodesManager) {
+ return ((ITemplateNodesManager) template).openBundle(
+ pageContext, visualNode, elementMapping);
+ } else {
+ template.openBundleEditors(pageContext,
+ (Element) elementMapping.getSourceNode(),
+ elementMapping.getData());
}
}
return false;
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -1623,24 +1623,6 @@
public boolean isTextEditable(nsIDOMNode visualNode) {
-
- // get VpeNodeMapping
- VpeNodeMapping nodeMapping = domMapping
- .getNearNodeMapping(visualNode);
-
- // if it is element mapping
- if (nodeMapping instanceof VpeElementMapping) {
- // get template
- VpeTemplate template = ((VpeElementMapping) nodeMapping)
- .getTemplate();
- // if template implements VpeTemplateAttributesManager
- if (template instanceof ITemplateNodesManager)
- return ((ITemplateNodesManager) template).isNodeEditable(
- pageContext, visualNode,
- ((VpeElementMapping) nodeMapping).getElementData());
-
- }
-
if (visualNode != null) {
nsIDOMNode parent = visualNode.getParentNode();
if (parent != null
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/EditableTemplateAdapter.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -12,18 +12,20 @@
import java.util.List;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.swt.graphics.Point;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
+import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMKeyEvent;
+import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMNSUIEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsISelection;
import org.mozilla.interfaces.nsISelectionController;
@@ -48,23 +50,15 @@
implements ITemplateKeyEventHandler, ITemplateNodesManager,
ITemplateSelectionManager {
- /**
- * name of "view" tag
- */
- private static final String VIEW_TAGNAME = "view"; //$NON-NLS-1$
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- /**
- * name of "locale" attribute
- */
- private static final String LOCALE_ATTRNAME = "locale"; //$NON-NLS-1$
-
/*
* (non-Javadoc)
*
* @see org.jboss.tools.vpe.editor.template.VpeTemplateKeyEventHandler#handleKeyPress(org.jboss.tools.vpe.editor.context.VpePageContext,
* org.mozilla.interfaces.nsIDOMKeyEvent)
*/
- public boolean handleKeyPress(VpePageContext pageContext,
+ final public boolean handleKeyPress(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
long keyCode = keyEvent.getKeyCode();
@@ -146,11 +140,8 @@
protected boolean handleCharacter(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
// get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
+ nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
@@ -162,17 +153,35 @@
VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, elementData)) {
+ if (isNodeEditable(visualNode, elementData)) {
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
+
+ Node node;
+ Point selectedRange;
// get source node
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ if ((attributeData.getSourceAttr() == null)
+ && (attributeData.getAttributeName() != null)) {
+ node = createAttribute(
+ (Element) elementMapping.getSourceNode(), attributeData
+ .getAttributeName(), EMPTY_STRING);
+ selectedRange = new Point(0, 0);
+ } else {
+
+ node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
+ elementMapping);
+ selectedRange = getSelectionRange(TemplateManagingUtil
+ .getCurrentSelection(pageContext));
+ }
+
if (node == null)
return false;
// get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
- int anchorOffset = selection.getAnchorOffset();
+ int focusOffset = selectedRange.x;
+ int anchorOffset = selectedRange.x + selectedRange.y;
// initialization offset and length selected string
int startOffset = 0;
@@ -206,7 +215,8 @@
node.setNodeValue(newValue);
// set selection
- setSourceSelection(pageContext, node, startOffset + 1, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ startOffset + 1, 0);
}
return true;
@@ -241,11 +251,9 @@
*/
protected boolean handleRightDelete(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
// get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
+ nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
@@ -257,18 +265,37 @@
VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, elementData)) {
+ if (isNodeEditable(visualNode, elementData)) {
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
+
+ Node node;
+ Point selectedRange;
// get source node
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ if ((attributeData.getSourceAttr() == null)
+ && (attributeData.getAttributeName() != null)) {
+ node = createAttribute(
+ (Element) elementMapping.getSourceNode(), attributeData
+ .getAttributeName(), EMPTY_STRING);
+ selectedRange = new Point(0, 0);
+ } else {
+
+ node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
+ elementMapping);
+ selectedRange = getSelectionRange(TemplateManagingUtil
+ .getCurrentSelection(pageContext));
+ }
+
if (node == null)
return false;
// get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
- int anchorOffset = selection.getAnchorOffset();
+ int focusOffset = selectedRange.x;
+ int anchorOffset = selectedRange.x + selectedRange.y;
+
// initialization offset and length selected string
int startOffset = 0;
int length = 0;
@@ -279,7 +306,8 @@
// if offset is end of text will do nothing
if (focusOffset == node.getNodeValue().length()) {
- setSourceSelection(pageContext, node, focusOffset, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ focusOffset, 0);
return true;
}
@@ -306,7 +334,8 @@
node.setNodeValue(newValue);
// set new selection
- setSourceSelection(pageContext, node, startOffset, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ startOffset, 0);
}
@@ -327,13 +356,9 @@
protected boolean handleLeftDelete(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
// get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
+ nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
- // if node editable
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
@@ -344,18 +369,36 @@
VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, elementData)) {
+ if (isNodeEditable(visualNode, elementData)) {
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
+
+ Node node;
+ Point selectedRange;
// get source node
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ if ((attributeData.getSourceAttr() == null)
+ && (attributeData.getAttributeName() != null)) {
+ node = createAttribute(
+ (Element) elementMapping.getSourceNode(), attributeData
+ .getAttributeName(), EMPTY_STRING);
+ selectedRange = new Point(0, 0);
+ } else {
+
+ node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
+ elementMapping);
+ selectedRange = getSelectionRange(TemplateManagingUtil
+ .getCurrentSelection(pageContext));
+ }
if (node == null)
return false;
// get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
- int anchorOffset = selection.getAnchorOffset();
+ int focusOffset = selectedRange.x;
+ int anchorOffset = selectedRange.x + selectedRange.y;
+
// initialization offset and length selected string
int startOffset = 0;
int length = 0;
@@ -366,7 +409,8 @@
// if offset is start of text then will do nothing
if (focusOffset == 0) {
- setSourceSelection(pageContext, node, 0, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ 0, 0);
return true;
}
// set start offset to previous character
@@ -393,7 +437,8 @@
node.setNodeValue(newValue);
// set new selection
- setSourceSelection(pageContext, node, startOffset, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ startOffset, 0);
}
@@ -462,11 +507,8 @@
protected boolean handleRight(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
// get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
+ nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
@@ -478,21 +520,27 @@
VpeElementData elementData = elementMapping.getElementData();
// get source node
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ Node node = getTargetSourceNodeByVisualNode(pageContext, visualNode,
+ elementMapping);
if (node == null)
return false;
// get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
+ Point selectedRange = getSelectionRange(TemplateManagingUtil
+ .getCurrentSelection(pageContext));
+ int focusOffset = selectedRange.x;
+
// if node editable
- if (isNodeEditable(pageContext, visualNode, elementData)) {
+ if (isNodeEditable(visualNode, elementData)) {
if (focusOffset != node.getNodeValue().length()) {
- setSourceSelection(pageContext, node, focusOffset + 1, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ focusOffset + 1, 0);
} else
- setSourceSelection(pageContext, node, focusOffset, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ focusOffset, 0);
}
return true;
@@ -528,11 +576,8 @@
protected boolean handleLeft(VpePageContext pageContext,
nsIDOMKeyEvent keyEvent) {
- // get selection
- nsISelection selection = getCurrentSelection(pageContext);
-
// get visual node which is focused
- nsIDOMNode visualNode = selection.getFocusNode();
+ nsIDOMNode visualNode = getCurrentSelectedVisualNode(pageContext);
VpeElementMapping elementMapping = getElmentMapping(pageContext,
visualNode);
@@ -544,21 +589,27 @@
VpeElementData elementData = elementMapping.getElementData();
// if node editable
- if (isNodeEditable(pageContext, visualNode, elementData)) {
+ if (isNodeEditable(visualNode, elementData)) {
// get source node
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ Node node = getTargetSourceNodeByVisualNode(pageContext,
+ visualNode, elementMapping);
if (node == null)
return false;
// get focus and anchor offsets
- int focusOffset = selection.getFocusOffset();
+ Point selectedRange = getSelectionRange(TemplateManagingUtil
+ .getCurrentSelection(pageContext));
+ int focusOffset = selectedRange.x;
+
if (focusOffset != 0) {
- setSourceSelection(pageContext, node, focusOffset - 1, 0);
+ TemplateManagingUtil.setSourceSelection(pageContext, node,
+ focusOffset - 1, 0);
} else {
- setSourceSelection(pageContext, node, 0, 0);
+ TemplateManagingUtil
+ .setSourceSelection(pageContext, node, 0, 0);
}
}
return true;
@@ -587,428 +638,542 @@
* @param elementData
* @return
*/
- protected VpeAttributeData getAttributeData(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData) {
+ public boolean isNodeEditable(nsIDOMNode visualNode,
+ VpeElementData elementData) {
- // if input data is correct
- if ((visualNode != null) && (elementData != null)
- && (elementData.getAttributesData() != null)) {
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementData);
- List<VpeAttributeData> attributesMapping = elementData
- .getAttributesData();
+ if (attributeData != null)
+ return attributeData.isEditable();
- for (VpeAttributeData attributeData : attributesMapping) {
-
- // if visual nodes equals
- if (visualNode.equals(attributeData.getVisualAttr()))
- return attributeData;
- }
- }
-
- return null;
-
+ return false;
}
/**
*
- * @param pageContext
- * @param node
- * @param elementData
- * @return
*/
- protected VpeAttributeData getAttributeData(VpePageContext pageContext,
- Node node, VpeElementData elementData) {
+ public boolean isNodeEditable(Node node, VpeElementData elementData) {
- // if input data is correct
- if ((node != null) && (elementData != null)
- && (elementData.getAttributesData() != null)) {
+ VpeAttributeData attributeData = getAttributeData(node, elementData);
- List<VpeAttributeData> attributesMapping = elementData
- .getAttributesData();
-
- for (VpeAttributeData attributeData : attributesMapping) {
-
- // if source nodes equals
- if (node.equals(attributeData.getSourceAttr()))
- return attributeData;
- }
+ if (attributeData != null) {
+ return attributeData.isEditable();
}
- return null;
-
+ return false;
}
/*
* (non-Javadoc)
*
- * @see org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager#getSourceNode(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.mozilla.interfaces.nsIDOMNode)
+ * @see org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * org.mozilla.interfaces.nsISelection)
*/
- public Node getSourceNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData) {
+ final public void setSelection(VpePageContext pageContext,
+ nsISelection selection) {
- // get attribute data
- VpeAttributeData attributeData = getAttributeData(pageContext,
- visualNode, elementData);
+ nsIDOMNode selectedVisualNode = TemplateManagingUtil
+ .getSelectedNode(selection);
- if (attributeData != null)
- return attributeData.getSourceAttr();
+ if (selectedVisualNode == null)
+ return;
- return null;
- }
+ VpeElementMapping elementMapping = getElmentMapping(pageContext,
+ selectedVisualNode);
- /**
- *
- * @param pageContext
- * @param node
- * @param elementData
- * @return
- */
- public nsIDOMNode getVisualNode(VpePageContext pageContext, Node node,
- VpeElementData elementData) {
+ // get target visual node
+ nsIDOMNode targetVisualNode = getTargetVisualNodeByVisualNode(
+ pageContext, selectedVisualNode, elementMapping);
- VpeAttributeData attributeData = getAttributeData(pageContext, node,
- elementData);
- if (attributeData != null)
- return attributeData.getVisualAttr();
+ // get target souce node
+ Node targetSourceNode = getTargetSourceNodeByVisualNode(pageContext,
+ selectedVisualNode, elementMapping);
- return null;
- }
+ int focusOffset;
+ int length;
- /**
- *
- * @param pageContext
- * @param visualNode
- * @param elementData
- * @return
- */
- public boolean isNodeEditable(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData) {
+ if (isNodeEditable(targetVisualNode, elementMapping.getElementData())) {
- VpeAttributeData attributeData = getAttributeData(pageContext,
- visualNode, elementData);
+ Point range = getSelectionRange(selection);
- if (attributeData != null)
- return attributeData.isEditable();
+ focusOffset = range.x;
+ length = range.y;
- return false;
+ } else {
+
+ focusOffset = 0;
+ length = TemplateManagingUtil.getLengthNode(targetSourceNode);
+
+ }
+
+ // set source selection
+// TemplateManagingUtil.setSourceSelection(pageContext, targetSourceNode,
+// focusOffset, length);
+
+ setSelectionRange(selection,
+ targetVisualNode, new Point(focusOffset, length));
+
+ // check for text node
+ if (targetVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
+ targetVisualNode = targetVisualNode.getParentNode();
+
+ // paint visual selection
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) targetVisualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
+
}
- /**
+ /*
+ * (non-Javadoc)
*
+ * @see org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelectionBySource(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * org.jboss.tools.vpe.editor.selection.VpeSelectionController, int,
+ * int)
*/
- public boolean isNodeEditable(VpePageContext pageContext, Node node,
- VpeElementData elementData) {
+ final public void setSelectionBySource(VpePageContext pageContext,
+ VpeSelectionController selectionController, int focus, int anchor) {
- VpeAttributeData attributeData = getAttributeData(pageContext, node,
- elementData);
+ // get element mapping
+ VpeElementMapping elementMapping = TemplateManagingUtil
+ .getElementMappingBySourceSelection(pageContext, focus, anchor);
- if (attributeData != null) {
- return attributeData.isEditable();
+ // get focused attribute
+ Node focusNode = getTargetSourceNodeBySourcePosition(pageContext,
+ focus, anchor);
+
+ int visualFocus = 0;
+ int visualAnchor = 0;
+
+ if (isNodeEditable(focusNode, elementMapping.getElementData())) {
+
+ String text = focusNode.getNodeValue();
+ int start = TemplateManagingUtil.getStartOffsetNode(focusNode);
+ focus = focus - start;
+ anchor = anchor - start;
+ visualFocus = TextUtil.visualInnerPosition(text, focus);
+ visualAnchor = TextUtil.visualInnerPosition(text, anchor);
+
}
- return false;
- }
- /**
- *
- * @param pageContext
- * @param node
- * @param offset
- * @param length
- */
- protected void setSourceSelection(VpePageContext pageContext, Node node,
- int offset, int length) {
+ nsIDOMNode visualNode = getTargetVisualNodeBySourceNode(focusNode,
+ elementMapping);
- int start = getStartOffsetNode(node);
+ setSelectionRange(selectionController
+ .getSelection(nsISelectionController.SELECTION_NORMAL),
+ visualNode, new Point(visualFocus, visualAnchor - visualFocus));
- pageContext.getSourceBuilder().getStructuredTextViewer()
- .setSelectedRange(start + offset, length);
- pageContext.getSourceBuilder().getStructuredTextViewer().revealRange(
- start + offset, length);
+ // check for text node
+ if (visualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE) {
+ visualNode = visualNode.getParentNode();
+ }
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
}
/*
* (non-Javadoc)
*
- * @see org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.mozilla.interfaces.nsISelection)
+ * @see org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setSelectionByMouse(org.mozilla.interfaces.nsIDOMMouseEvent)
*/
- public void setSelection(VpePageContext pageContext, nsISelection selection) {
+ final public void setSelectionByMouse(VpePageContext pageContext,
+ VpeSelectionController selectionController,
+ nsIDOMMouseEvent mouseEvent) {
- nsIDOMNode focusedVisualNode = selection.getFocusNode();
+ // get visual node by event
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (focusedVisualNode == null)
- return;
+ // get element mapping
+ VpeElementMapping elementMapping = getElmentMapping(pageContext,
+ visualNode);
- VpeElementMapping elementMapping = pageContext.getDomMapping()
- .getNearElementMapping(focusedVisualNode);
if (elementMapping == null)
return;
- int focusOffset;
- int length;
+ Node targetSourceNode = getTargetSourceNodeByVisualNode(pageContext,
+ visualNode, elementMapping);
- VpeAttributeData attributeData = getAttributeData(pageContext,
- focusedVisualNode, elementMapping.getElementData());
+ nsIDOMNode targetVisualNode = getTargetVisualNodeByVisualNode(
+ pageContext, visualNode, elementMapping);
- boolean isEditable = isNodeEditable(pageContext, focusedVisualNode,
- elementMapping.getElementData());
+ // get nsIDOMNSUIEvent event
+ nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent) mouseEvent
+ .queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
- Node focusedSourceNode;
- if (attributeData == null) {
+ int selectionOffset;
+ int selectionLength;
- focusedSourceNode = elementMapping.getSourceNode();
- focusedVisualNode = elementMapping.getVisualNode();
+ if (isNodeEditable(targetVisualNode, elementMapping.getElementData())) {
+ selectionOffset = nsuiEvent.getRangeOffset();
+ selectionLength = 0;
+ } else {
- focusOffset = 0;
- length = 0;
+ selectionOffset = 0;
+ selectionLength = TemplateManagingUtil
+ .getLengthNode(targetSourceNode);
- } else {
+ }
- focusedSourceNode = getSourceNode(pageContext, focusedVisualNode,
- elementMapping.getElementData());
+ TemplateManagingUtil.setSourceSelection(pageContext, targetSourceNode, selectionOffset, selectionLength);
+
+ setSelectionRange(selectionController
+ .getSelection(nsISelectionController.SELECTION_NORMAL),
+ targetVisualNode, new Point(selectionOffset, selectionLength));
- if (focusedSourceNode == null)
- focusedSourceNode = elementMapping.getSourceNode();
+ // check for text node
+ if (targetVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE) {
+ targetVisualNode = targetVisualNode.getParentNode();
+ }
- if (isEditable) {
+ // paint selection rectangle
+ pageContext.getVisualBuilder().setSelectionRectangle(
+ (nsIDOMElement) targetVisualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
- focusOffset = selection.getFocusOffset();
- length = selection.getAnchorOffset() - focusOffset;
+ }
- } else {
+ /**
+ *
+ */
+ public boolean openBundle(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping) {
- focusOffset = 0;
- length = getLengthNode(focusedSourceNode);
- }
+ VpeAttributeData attributeData = getAttributeData(
+ getTargetVisualNodeByVisualNode(pageContext, visualNode,
+ elementMapping), elementMapping.getElementData());
+ // so as nsIDOMMouseEvent doesn't give simple selected nsIDOMText as
+ // target, but nsiSelection can give simple "text"
+ // TODO may be, there is a better way to get selected simple nsIDOMText
+ if (attributeData == null) {
+
+ // get visual node which is focused
+ nsIDOMNode tempNode = getCurrentSelectedVisualNode(pageContext);
+ attributeData = getAttributeData(getTargetVisualNodeByVisualNode(
+ pageContext, tempNode, elementMapping), elementMapping
+ .getElementData());
+
}
- setSourceSelection(pageContext, focusedSourceNode, focusOffset, length);
+ if ((attributeData == null) || (attributeData.getSourceAttr() == null))
+ return false;
- if (focusedVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
- focusedVisualNode = focusedVisualNode.getParentNode();
+ return pageContext.getBundle().openBundle(
+ attributeData.getSourceAttr().getNodeValue(),
+ TemplateManagingUtil.getPageLocale(pageContext, attributeData
+ .getSourceAttr()));
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) focusedVisualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
-
}
/*
* (non-Javadoc)
*
- * @see org.jboss.tools.vpe.editor.template.ITemplateSelectionManager#setVisualSelectionBySource(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * @see org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetSourceNodeBySourcePosition(org.jboss.tools.vpe.editor.context.VpePageContext,
* int, int)
*/
- public void setVisualSelectionBySource(VpePageContext pageContext,
- VpeSelectionController selectionController, int focus, int anchor) {
+ public Node getTargetSourceNodeBySourcePosition(VpePageContext pageContext,
+ int focusPosition, int anchorPosition) {
- // get source node
- Node sourceNode = TemplateManagingUtil.getSourceNodeByPosition(
- pageContext, focus);
+ // get element mapping by position
+ VpeElementMapping elementMapping = TemplateManagingUtil
+ .getElementMappingBySourceSelection(pageContext, focusPosition,
+ anchorPosition);
- // get element mapping
- VpeElementMapping elementMapping = pageContext.getDomMapping()
- .getNearElementMapping(sourceNode);
+ // find focus attribute by position
+ Node focusAttribute = findElementAttributeByPosition(elementMapping
+ .getElementData(), focusPosition);
- // get focused attribute
- Node focusNode = getFocusedNode(sourceNode, elementMapping
- .getElementData(), focus);
+ // fond anchor attribute by position
+ Node anchorAttribute = findElementAttributeByPosition(elementMapping
+ .getElementData(), anchorPosition);
- Node anchorNode = getFocusedNode(sourceNode, elementMapping
- .getElementData(), anchor);
+ // if anchor and focus attributes are equal return focused attribute
+ if (focusAttribute == anchorAttribute)
+ return focusAttribute;
- int visualFocus = 0;
- int visualAnchor = 0;
- nsIDOMNode visualNode = null;
- if ((focusNode == anchorNode)
- && isNodeEditable(pageContext, focusNode, elementMapping
- .getElementData())) {
+ // else return all element
+ return elementMapping.getSourceNode();
+ }
- visualNode = getVisualNode(pageContext, focusNode, elementMapping
- .getElementData());
- if (visualNode != null) {
- String text = focusNode.getNodeValue();
- int start = getStartOffsetNode(focusNode);
- focus = focus - start;
- anchor = anchor - start;
- visualFocus = TextUtil.visualInnerPosition(text, focus);
- visualAnchor = TextUtil.visualInnerPosition(text, anchor);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetVisualNodeBySourceNode(org.w3c.dom.Node,
+ * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
+ */
+ public nsIDOMNode getTargetVisualNodeBySourceNode(Node sourceNode,
+ VpeElementMapping elementMapping) {
+ // if element is not null
+ if (elementMapping != null) {
+
+ // get attributeData
+ VpeAttributeData attributeData = getAttributeData(sourceNode,
+ elementMapping.getElementData());
+
+ // attributeData is found
+ if (attributeData != null)
+ return attributeData.getVisualAttr();
+ else
+ return elementMapping.getVisualNode();
+
}
- if (visualNode == null) {
- visualNode = elementMapping.getVisualNode();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetVisualNodeByVisualNode(org.mozilla.interfaces.nsIDOMNode,
+ * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
+ */
+ public nsIDOMNode getTargetVisualNodeByVisualNode(
+ VpePageContext pageContext, nsIDOMNode visualNode,
+ VpeElementMapping elementMapping) {
+
+ // if element is not null
+ if (elementMapping != null) {
+
+ // get attributeData
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
+
+ // attributeData is found
+ if (attributeData != null)
+ return attributeData.getVisualAttr();
+ else
+ return elementMapping.getVisualNode();
+
}
- nsISelection selection = selectionController
- .getSelection(nsISelectionController.SELECTION_NORMAL);
- if (visualNode.getNodeType() == nsIDOMNode.TEXT_NODE) {
- selection.collapse(visualNode, visualFocus);
+ return null;
- // if(visualFocus!=visualAnchor)
- // selection.extend(visualNode, visualAnchor );
- }
- else {
- selection.collapse(visualNode, 0);
- }
- if (visualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE) {
- visualNode = visualNode.getParentNode();
- }
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
}
/*
* (non-Javadoc)
*
- * @see org.jboss.tools.vpe.editor.template.VpeTemplateNodesManager#getFocusedNode(org.w3c.dom.Node,
- * int)
+ * @see org.jboss.tools.vpe.editor.template.ITemplateNodesManager#getTargetSourceNodeByVisualNode(org.mozilla.interfaces.nsIDOMNode,
+ * org.jboss.tools.vpe.editor.mapping.VpeElementMapping)
*/
- public Node getFocusedNode(Node sourceNode, VpeElementData elementData,
- int offset) {
+ public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping) {
+ // if element is not null
+ if (elementMapping != null) {
+
+ // get attributeData
+ VpeAttributeData attributeData = getAttributeData(visualNode,
+ elementMapping.getElementData());
+
+ // attributeData is found
+ if ((attributeData != null)
+ && (attributeData.getSourceAttr() != null))
+ return attributeData.getSourceAttr();
+ else
+ return elementMapping.getSourceNode();
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ *
+ * @param elementData
+ * @param offset
+ * @return
+ */
+ private Node findElementAttributeByPosition(VpeElementData elementData,
+ int position) {
+
+ // if data are correct
if ((elementData != null) && (elementData.getAttributesData() != null)) {
List<VpeAttributeData> attributesMapping = elementData
.getAttributesData();
+ // for each defined attribute
for (VpeAttributeData attributeData : attributesMapping) {
- if ((offset >= (getStartOffsetNode(attributeData
- .getSourceAttr())))
- && (offset <= (getEndOffsetNode(attributeData
- .getSourceAttr()))))
+ // if position is in attribute's bound
+ if ((position >= (TemplateManagingUtil
+ .getStartOffsetNode(attributeData.getSourceAttr())))
+ && (position <= (TemplateManagingUtil
+ .getEndOffsetNode(attributeData.getSourceAttr()))))
return attributeData.getSourceAttr();
}
}
- return sourceNode;
+ return null;
}
/**
- * get start offset of node
*
- * @param node
+ * @param pageContext
+ * @param visualNode
+ * @param elementData
* @return
*/
- protected int getStartOffsetNode(Node node) {
+ protected VpeAttributeData getAttributeData(nsIDOMNode visualNode,
+ VpeElementData elementData) {
- if (node instanceof IDOMAttr) {
- return ((IDOMAttr) node).getValueRegionStartOffset() + 1;
- } else if (node instanceof IndexedRegion) {
- return ((IndexedRegion) node).getStartOffset();
+ // if input data is correct
+ if ((visualNode != null) && (elementData != null)
+ && (elementData.getAttributesData() != null)) {
+
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
+
+ for (VpeAttributeData attributeData : attributesMapping) {
+
+ // if visual nodes equals
+ if (visualNode.equals(attributeData.getVisualAttr()))
+ return attributeData;
+ }
}
- return 0;
+
+ return null;
+
}
/**
*
+ * @param pageContext
* @param node
+ * @param elementData
* @return
*/
- protected int getLengthNode(Node node) {
+ protected VpeAttributeData getAttributeData(Node node,
+ VpeElementData elementData) {
- if (node instanceof IDOMAttr) {
- return ((IDOMAttr) node).getValueSource().length();
- } else if (node instanceof IndexedRegion) {
- return ((IndexedRegion) node).getEndOffset()
- - ((IndexedRegion) node).getStartOffset();
+ // if input data is correct
+ if ((node != null) && (elementData != null)
+ && (elementData.getAttributesData() != null)) {
+
+ List<VpeAttributeData> attributesMapping = elementData
+ .getAttributesData();
+
+ for (VpeAttributeData attributeData : attributesMapping) {
+
+ // if source nodes equals
+ if (node.equals(attributeData.getSourceAttr()))
+ return attributeData;
+ }
}
- return 0;
+ return null;
+
}
/**
- * get end offset of node
*
+ * @param pageContext
* @param node
* @return
*/
- protected int getEndOffsetNode(Node node) {
+ protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
+ nsIDOMNode node) {
- if (node instanceof IndexedRegion) {
- return ((IndexedRegion) node).getEndOffset();
- }
- return 0;
+ return pageContext.getDomMapping().getNearElementMapping(node);
+
}
/**
*
+ * @param pageContext
+ * @return
*/
- public boolean openBundle(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData) {
+ protected nsIDOMNode getCurrentSelectedVisualNode(VpePageContext pageContext) {
- Node node = getSourceNode(pageContext, visualNode, elementData);
+ nsISelection selection = TemplateManagingUtil
+ .getCurrentSelection(pageContext);
- // so as nsIDOMMouseEvent doesn't give simple selected nsIDOMText as
- // target, but nsiSelection can give simple "text"
- // TODO may be, there is a better way to get selected simple nsIDOMText
- if (node == null) {
+ if (selection.getFocusNode() != null)
+ return TemplateManagingUtil.getSelectedNode(selection);
+ else
+ return TemplateManagingUtil.getLastSelectedVisualNode(pageContext);
- // get selection
- nsISelection selection = pageContext.getEditPart().getController()
- .getXulRunnerEditor().getSelection();
+ }
- // get visual node which is focused
- nsIDOMNode tempNode = selection.getFocusNode();
+ /**
+ *
+ * @param pageContext
+ * @return
+ */
+ protected Point getSelectionRange(nsISelection selection) {
- node = getSourceNode(pageContext, tempNode, elementData);
+ nsIDOMNode focusedNode = TemplateManagingUtil
+ .getSelectedNode(selection);
- }
+ Point range = new Point(0, 0);
- if (node == null)
- return false;
+ if (focusedNode != null) {
+ if ((HTML.TAG_INPUT.equalsIgnoreCase(focusedNode.getLocalName()))
+ || (HTML.TAG_TEXTAREA.equalsIgnoreCase(focusedNode
+ .getLocalName()))) {
- return pageContext.getBundle().openBundle(node.getNodeValue(),
- getPageLocale(pageContext, node));
+ range = TemplateManagingUtil
+ .getSelectionRangeFromInputElement(focusedNode);
+ } else {
+ range.x = selection.getFocusOffset();
+ range.y = selection.getAnchorOffset()
+ - selection.getFocusOffset();
+
+ }
+ }
+ return range;
}
/**
*
- * @param pageContext
- * @param sourceElement
- * @return
+ * @param selection
+ * @param node
+ * @param range
*/
- private String getPageLocale(VpePageContext pageContext, Node sourceNode) {
+ protected void setSelectionRange(nsISelection selection, nsIDOMNode node,
+ Point range) {
- while (sourceNode != null) {
+ selection.removeAllRanges();
+ if (node.getNodeType() == nsIDOMNode.TEXT_NODE) {
+ selection.collapse(node, range.x);
- if (VIEW_TAGNAME.equals(sourceNode.getLocalName())) {
- break;
+ // if(visualFocus!=visualAnchor)
+ // selection.extend(visualNode, visualAnchor );
+ } else {
+
+ if ((HTML.TAG_INPUT.equalsIgnoreCase(node.getLocalName()))
+ || (HTML.TAG_TEXTAREA.equalsIgnoreCase(node.getLocalName()))) {
+ TemplateManagingUtil.setSelectionRangeInInputElement(node,
+ range);
+
}
- sourceNode = sourceNode.getParentNode();
+ selection.collapse(node, 0);
}
- if ((sourceNode == null) || !(sourceNode instanceof Element)
- || !(((Element) sourceNode).hasAttribute(LOCALE_ATTRNAME)))
- return null;
-
- String locale = ((Element) sourceNode).getAttribute(LOCALE_ATTRNAME);
-
- return locale;
-
}
/**
*
- * @param pageContext
- * @param node
- * @return
+ * @param sourceElement
+ * @param attributeName
+ * @param value
*/
- protected VpeElementMapping getElmentMapping(VpePageContext pageContext,
- nsIDOMNode node) {
+ protected Node createAttribute(Element sourceElement, String attributeName,
+ String value) {
- return pageContext.getDomMapping().getNearElementMapping(node);
+ if ((sourceElement != null) && (attributeName != null)) {
+ sourceElement.setAttribute(attributeName, value != null ? value
+ : ""); //$NON-NLS-1$
- }
+ return sourceElement.getAttributeNode(attributeName);
+ }
+ return null;
- protected nsISelection getCurrentSelection(VpePageContext pageContext) {
- return pageContext.getEditPart().getController().getXulRunnerEditor()
- .getSelection();
}
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateNodesManager.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -12,6 +12,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Node;
@@ -31,8 +32,8 @@
*
* @return true if selected attribute is editable
*/
- public boolean isNodeEditable(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData);
+ public boolean isNodeEditable(nsIDOMNode visualNode,
+ VpeElementData elementData);
/**
*
@@ -41,41 +42,21 @@
* @param elementData
* @return
*/
- public boolean isNodeEditable(VpePageContext pageContext, Node node,
- VpeElementData elementData);
+ public boolean isNodeEditable(Node node, VpeElementData elementData);
- /**
- * get visual element of attribute from source element
- *
- * @param pageContext
- * @param attr
- * @param data
- * @return
- */
- public nsIDOMNode getVisualNode(VpePageContext pageContext, Node node,
- VpeElementData elementData);
+ public nsIDOMNode getTargetVisualNodeBySourceNode(Node sourceNode,
+ VpeElementMapping elementMapping);
- /**
- * get source element of attribute from visual element
- *
- * @param pageContext
- * @param visualNode
- * @param data
- * @return
- */
- public Node getSourceNode(VpePageContext pageContext,
- nsIDOMNode visualNode, VpeElementData elementData);
+ public nsIDOMNode getTargetVisualNodeByVisualNode(
+ VpePageContext pageContext, nsIDOMNode visualNode,
+ VpeElementMapping elementMapping);
- /**
- * get sourceNode by offset
- *
- * @param sourceNode
- * @param offset
- * @return
- */
- public Node getFocusedNode(Node sourceNode, VpeElementData elementData,
- int offset);
+ public Node getTargetSourceNodeByVisualNode(VpePageContext pageContext,
+ nsIDOMNode visualNode, VpeElementMapping elementMapping);
+ public Node getTargetSourceNodeBySourcePosition(VpePageContext pageContext,
+ int focusOffset, int anchorOffset);
+
/**
* open bundle
*
@@ -84,5 +65,5 @@
* @return
*/
boolean openBundle(VpePageContext pageContext, nsIDOMNode visualNode,
- VpeElementData elementData);
+ VpeElementMapping elementMapping);
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ITemplateSelectionManager.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -12,6 +12,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
+import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsISelection;
/**
@@ -36,7 +37,18 @@
* @param pageContext
* @return true if visual element was selected
*/
- public void setVisualSelectionBySource(VpePageContext pageContext,
+ public void setSelectionBySource(VpePageContext pageContext,
VpeSelectionController selectionController, int focus, int anchor);
+ /**
+ * set selection by mouse
+ *
+ * @param visualSelectionController
+ *
+ * @param mouseEvent
+ */
+ public void setSelectionByMouse(VpePageContext pageContext,
+ VpeSelectionController selectionController,
+ nsIDOMMouseEvent mouseEvent);
+
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -17,69 +17,77 @@
*/
public final class HTML {
- private HTML() {
- }
+ private HTML() {
+ }
- public static final String TAG_HTML = "HTML"; //$NON-NLS-1$
- public static final String TAG_HEAD = "HEAD"; //$NON-NLS-1$
- public static final String TAG_BODY = "BODY"; //$NON-NLS-1$
- public static final String TAG_IMG = "IMG"; //$NON-NLS-1$
- public static final String TAG_LINK = "LINK"; //$NON-NLS-1$
- public static final String TAG_SELECT = "SELECT"; //$NON-NLS-1$
- public static final String TAG_OPTION = "OPTION"; //$NON-NLS-1$
- public static final String TAG_STYLE = "STYLE"; //$NON-NLS-1$
- public static final String TAG_TABLE = "TABLE"; //$NON-NLS-1$
- public static final String TAG_TBODY = "TBODY"; //$NON-NLS-1$
- public static final String TAG_THEAD = "THEAD"; //$NON-NLS-1$
- public static final String TAG_TFOOT = "TFOOT"; //$NON-NLS-1$
- public static final String TAG_CAPTION = "CAPTION"; //$NON-NLS-1$
- public static final String TAG_TH = "TH"; //$NON-NLS-1$
- public static final String TAG_TR = "TR"; //$NON-NLS-1$
- public static final String TAG_TD = "TD"; //$NON-NLS-1$
- public static final String TAG_DL = "DL"; //$NON-NLS-1$
- public static final String TAG_DT = "DT"; //$NON-NLS-1$
- public static final String TAG_COL = "COL"; //$NON-NLS-1$
- public static final String TAG_COLS = "COLS"; //$NON-NLS-1$
- public static final String TAG_COLGROUP = "COLGROUP"; //$NON-NLS-1$
- public static final String TAG_BR = "BR"; //$NON-NLS-1$
- public static final String TAG_LI = "LI"; //$NON-NLS-1$
- public static final String TAG_DIV = "DIV"; //$NON-NLS-1$
- public static final String TAG_SPAN = "SPAN"; //$NON-NLS-1$
- public static final String TAG_P = "P"; //$NON-NLS-1$
- public static final String TAG_TEXTAREA = "TEXTAREA"; //$NON-NLS-1$
- public static final String TAG_INPUT = "INPUT"; //$NON-NLS-1$
- public static final String TAG_BUTTON = "BUTTON"; //$NON-NLS-1$
- public static final String TAG_OL = "OL"; //$NON-NLS-1$
- public static final String TAG_UL = "UL"; //$NON-NLS-1$
- public static final String TAG_CODE = "CODE"; //$NON-NLS-1$
- public static final String TAG_PRE = "PRE"; //$NON-NLS-1$
- public static final String TAG_B = "B"; //$NON-NLS-1$
- public static final String TAG_I = "I"; //$NON-NLS-1$
- public static final String TAG_U = "U"; //$NON-NLS-1$
- public static final String TAG_LABEL = "LABEL"; //$NON-NLS-1$
- public static final String TAG_A = "A"; //$NON-NLS-1$
- public static final String TAG_H1 = "H1"; //$NON-NLS-1$
-
- public static final String ATTR_ID = "ID"; //$NON-NLS-1$
- public static final String ATTR_TYPE = "TYPE"; //$NON-NLS-1$
- public static final String ATTR_TEXT = "TEXT"; //$NON-NLS-1$
- public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
- public static final String ATTR_TITLE = "TITLE"; //$NON-NLS-1$
- public static final String ATTR_NAME = "NAME"; //$NON-NLS-1$
- public static final String ATTR_VALUE = "VALUE"; //$NON-NLS-1$
- public static final String ATTR_STYLE = "style"; //$NON-NLS-1$
- public static final String ATTR_SIZE = "size"; //$NON-NLS-1$
- public static final String ATTR_MULTIPLE = "MULTIPLE"; //$NON-NLS-1$
- public static final String ATTR_COLSPAN = "colspan"; //$NON-NLS-1$
- public static final String ATTR_CELLSPACING = "cellspacing"; //$NON-NLS-1$
- public static final String ATTR_CELLPADDING = "cellpadding"; //$NON-NLS-1$
- public static final String ATTR_WIDTH = "WIDTH"; //$NON-NLS-1$
- public static final String ATTR_HEIGHT = "HEIGHT"; //$NON-NLS-1$
- public static final String ATTR_BORDER = "border"; //$NON-NLS-1$
- public static final String ATTR_FOR = "FOR"; //$NON-NLS-1$
- public static final String ATTR_DIR = "dir"; //$NON-NLS-1$
- public static final String ATTR_DISABLED = "disabled"; //$NON-NLS-1$
- public static final String ATTR_FRAME = "frame"; //$NON-NLS-1$
- public static final String ATTR_ROWSPAN = "rowspan"; //$NON-NLS-1$
-
+ public static final String TAG_HTML = "HTML"; //$NON-NLS-1$
+ public static final String TAG_HEAD = "HEAD"; //$NON-NLS-1$
+ public static final String TAG_BODY = "BODY"; //$NON-NLS-1$
+ public static final String TAG_IMG = "IMG"; //$NON-NLS-1$
+ public static final String TAG_LINK = "LINK"; //$NON-NLS-1$
+ public static final String TAG_SELECT = "SELECT"; //$NON-NLS-1$
+ public static final String TAG_OPTION = "OPTION"; //$NON-NLS-1$
+ public static final String TAG_STYLE = "STYLE"; //$NON-NLS-1$
+ public static final String TAG_TABLE = "TABLE"; //$NON-NLS-1$
+ public static final String TAG_TBODY = "TBODY"; //$NON-NLS-1$
+ public static final String TAG_THEAD = "THEAD"; //$NON-NLS-1$
+ public static final String TAG_TFOOT = "TFOOT"; //$NON-NLS-1$
+ public static final String TAG_CAPTION = "CAPTION"; //$NON-NLS-1$
+ public static final String TAG_TH = "TH"; //$NON-NLS-1$
+ public static final String TAG_TR = "TR"; //$NON-NLS-1$
+ public static final String TAG_TD = "TD"; //$NON-NLS-1$
+ public static final String TAG_DL = "DL"; //$NON-NLS-1$
+ public static final String TAG_DT = "DT"; //$NON-NLS-1$
+ public static final String TAG_COL = "COL"; //$NON-NLS-1$
+ public static final String TAG_COLS = "COLS"; //$NON-NLS-1$
+ public static final String TAG_COLGROUP = "COLGROUP"; //$NON-NLS-1$
+ public static final String TAG_BR = "BR"; //$NON-NLS-1$
+ public static final String TAG_LI = "LI"; //$NON-NLS-1$
+ public static final String TAG_DIV = "DIV"; //$NON-NLS-1$
+ public static final String TAG_SPAN = "SPAN"; //$NON-NLS-1$
+ public static final String TAG_P = "P"; //$NON-NLS-1$
+ public static final String TAG_TEXTAREA = "TEXTAREA"; //$NON-NLS-1$
+ public static final String TAG_INPUT = "INPUT"; //$NON-NLS-1$
+ public static final String TAG_BUTTON = "BUTTON"; //$NON-NLS-1$
+ public static final String TAG_OL = "OL"; //$NON-NLS-1$
+ public static final String TAG_UL = "UL"; //$NON-NLS-1$
+ public static final String TAG_CODE = "CODE"; //$NON-NLS-1$
+ public static final String TAG_PRE = "PRE"; //$NON-NLS-1$
+ public static final String TAG_B = "B"; //$NON-NLS-1$
+ public static final String TAG_I = "I"; //$NON-NLS-1$
+ public static final String TAG_U = "U"; //$NON-NLS-1$
+ public static final String TAG_LABEL = "LABEL"; //$NON-NLS-1$
+ public static final String TAG_A = "A"; //$NON-NLS-1$
+ public static final String TAG_H1 = "H1"; //$NON-NLS-1$
+
+ public static final String ATTR_ID = "ID"; //$NON-NLS-1$
+ public static final String ATTR_TYPE = "TYPE"; //$NON-NLS-1$
+ public static final String ATTR_TEXT = "TEXT"; //$NON-NLS-1$
+ public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+ public static final String ATTR_TITLE = "TITLE"; //$NON-NLS-1$
+ public static final String ATTR_NAME = "NAME"; //$NON-NLS-1$
+ public static final String ATTR_VALUE = "VALUE"; //$NON-NLS-1$
+ public static final String ATTR_STYLE = "style"; //$NON-NLS-1$
+ public static final String ATTR_SIZE = "size"; //$NON-NLS-1$
+ public static final String ATTR_MULTIPLE = "MULTIPLE"; //$NON-NLS-1$
+ public static final String ATTR_COLSPAN = "colspan"; //$NON-NLS-1$
+ public static final String ATTR_CELLSPACING = "cellspacing"; //$NON-NLS-1$
+ public static final String ATTR_CELLPADDING = "cellpadding"; //$NON-NLS-1$
+ public static final String ATTR_WIDTH = "WIDTH"; //$NON-NLS-1$
+ public static final String ATTR_HEIGHT = "HEIGHT"; //$NON-NLS-1$
+ public static final String ATTR_BORDER = "border"; //$NON-NLS-1$
+ public static final String ATTR_FOR = "FOR"; //$NON-NLS-1$
+ public static final String ATTR_DIR = "dir"; //$NON-NLS-1$
+ public static final String ATTR_DISABLED = "disabled"; //$NON-NLS-1$
+ public static final String ATTR_FRAME = "frame"; //$NON-NLS-1$
+ public static final String ATTR_ROWSPAN = "rowspan"; //$NON-NLS-1$
+ public static final String ATTR_ROWS = "rows"; //$NON-NLS-1$
+ public static final String ATTR_COLS = "cols"; //$NON-NLS-1$
+ public static final String ATTR_VALIGN = "valign"; //$NON-NLS-1$
+
+ public static final String VALUE_TOP_VALIGN = "top"; //$NON-NLS-1$
+ public static final String VALUE_MIDDLE_VALIGN = "middle"; //$NON-NLS-1$
+ public static final String VALUE_TEXT_TYPE = "text"; //$NON-NLS-1$
+ public static final String VALUE_IMAGE_TYPE = "image"; //$NON-NLS-1$
+
}
\ No newline at end of file
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java 2008-04-02 07:23:47 UTC (rev 7261)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TemplateManagingUtil.java 2008-04-02 07:28:48 UTC (rev 7262)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.util;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.vpe.editor.context.VpePageContext;
@@ -17,12 +20,26 @@
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNSHTMLInputElement;
+import org.mozilla.interfaces.nsIDOMNSHTMLTextAreaElement;
import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsISelection;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class TemplateManagingUtil {
/**
+ * name of "view" tag
+ */
+ private static final String VIEW_TAGNAME = "view"; //$NON-NLS-1$
+
+ /**
+ * name of "locale" attribute
+ */
+ private static final String LOCALE_ATTRNAME = "locale"; //$NON-NLS-1$
+
+ /**
* get template of selected element
*
* @param pageContext
@@ -31,47 +48,73 @@
public static VpeTemplate getTemplateByVisualSelection(
VpePageContext pageContext, nsIDOMNode selectedNode) {
// get element mapping
-// VpeElementMapping elementMapping = pageContext.getDomMapping()
-// .getNearElementMapping(getVisualSelectedNode(pageContext));
- VpeElementMapping elementMapping = pageContext.getDomMapping()
- .getNearElementMapping(selectedNode);
+ VpeElementMapping elementMapping = getElementMappingByVisualSelection(
+ pageContext, selectedNode);
+
if (elementMapping != null)
return elementMapping.getTemplate();
- // next code is necessary for get template some jsf elements (which have
- // escape="false" attribute). It's necessary for the current
- // implementation of escape="false" attribute's process.
- // When or if the implementation of escape="false" attribute's process
- // will changed, you will must review next code
+ return null;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param selectedNode
+ */
+ public static VpeElementMapping getElementMappingByVisualSelection(
+ VpePageContext pageContext, nsIDOMNode selectedNode) {
+
+ // get element mapping
+ VpeElementMapping elementMapping = pageContext.getDomMapping()
+ .getNearElementMapping(selectedNode);
+
+ if (elementMapping != null)
+ return elementMapping;
+
+ /*
+ * next code is necessary for get template some jsf elements (which have
+ * escape="false" attribute). It's necessary for the current
+ * implementation of escape="false" attribute's process. When or if the
+ * implementation of escape="false" attribute's process will changed,
+ * you will must review next code
+ */
VpeNodeMapping nodeMapping = pageContext.getDomMapping()
- .getNearNodeMapping(getVisualSelectedNode(pageContext));
+ .getNearNodeMapping(getLastSelectedVisualNode(pageContext));
if (nodeMapping != null) {
- // get node. This node is not ascribe (may be) to DOM model of page,
- // because "value" attribute is parsed (if escape ="false")
- // separately and is built in vpe. But it has correct offset
- // information
+ /*
+ * get node. This node is not ascribe (may be) to DOM model of page,
+ * because "value" attribute is parsed (if escape ="false")
+ * separately and is built in vpe. But it has correct offset
+ * information
+ */
IDOMNode mappingNode = (IDOMNode) nodeMapping.getSourceNode();
+ // get document
+ IDOMDocument sourceDocument = getSourceDocument(pageContext);
+
// get source node by ofsset
- Node sourceNode = getSourceNodeByPosition(pageContext, mappingNode
- .getStartOffset());
+ Node sourceNode = getSourceNodeByPosition(sourceDocument,
+ mappingNode.getStartOffset());
// find elementMapping by source node
if (sourceNode != null) {
VpeElementMapping mapping = pageContext.getDomMapping()
.getNearElementMapping(sourceNode);
if (mapping != null)
- return mapping.getTemplate();
+ return mapping;
}
}
return null;
+
}
/**
+ * get template by source Selection
*
* @param pageContext
* @param focus
@@ -81,24 +124,108 @@
public static VpeTemplate getTemplateBySourceSelection(
VpePageContext pageContext, int focus, int anchor) {
+ VpeElementMapping elementMapping = getElementMappingBySourceSelection(
+ pageContext, focus, anchor);
+
+ if (elementMapping != null)
+ return elementMapping.getTemplate();
+
+ return null;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param selectedRange
+ * @return
+ */
+ public static VpeElementMapping getElementMappingBySourceSelection(
+ VpePageContext pageContext, Point selectedRange) {
+
+ return getElementMappingBySourceSelection(pageContext, selectedRange.x,
+ selectedRange.x + selectedRange.y);
+ }
+
+ /**
+ * get element mapping by source Selection
+ *
+ * @param pageContext
+ * @param focus
+ * @param anchor
+ * @return
+ */
+ public static VpeElementMapping getElementMappingBySourceSelection(
+ VpePageContext pageContext, int focus, int anchor) {
+
+ // get document
+ IDOMDocument sourceDocument = getSourceDocument(pageContext);
+
+ /*
+ * implementation of IDOMModel's method getIndexedRegion(...) has one
+ * feature : if cursor is situated at the border of elements then this
+ * method return next element. For example ... <h:inputText ../><h:outputText/>... -
+ * if cursor will be situated at the right border of "h:inputText"
+ * element then getIndexedRegion() return "h:outputText" element. So for
+ * focus position we choose smaller value
+ */
+
+ if (anchor < focus) {
+ focus = anchor;
+ anchor = focus;
+ }
+
// get source node by offset
- Node focusNode = getSourceNodeByPosition(pageContext, focus);
+ Node focusNode = getSourceNodeByPosition(sourceDocument, focus);
+
// if focus node also contain anchor point (selected only 1 element)
- if ((focusNode != null)
- && (anchor <= ((IDOMNode) focusNode).getEndOffset())
- && (anchor >= ((IDOMNode) focusNode).getStartOffset())) {
+ if ((focusNode != null) && isNodeContainPosition(focusNode, anchor)) {
+ return pageContext.getDomMapping().getNearElementMapping(focusNode);
+
+ }
+ return null;
+
+ }
+
+ /**
+ * get element mapping by source Selection
+ *
+ * @param pageContext
+ * @param focus
+ * @param anchor
+ * @return
+ */
+ public static VpeElementMapping getElementMappingBySourcePosition(
+ VpePageContext pageContext, int focus) {
+
+ // get document
+ IDOMDocument sourceDocument = getSourceDocument(pageContext);
+
+ // get source node by offset
+ Node focusNode = getSourceNodeByPosition(sourceDocument, focus);
+
+ // if focus node also contain anchor point (selected only 1 element)
+ if ((focusNode != null)) {
+
VpeElementMapping elementMapping = pageContext.getDomMapping()
.getNearElementMapping(focusNode);
- if (elementMapping != null)
- return elementMapping.getTemplate();
+ return elementMapping;
}
return null;
}
+ private static boolean isNodeContainPosition(Node node, int position) {
+
+ if ((((IDOMNode) node).getStartOffset() <= position)
+ && (((IDOMNode) node).getEndOffset() >= position))
+ return true;
+
+ return false;
+ }
+
/**
* get source node by position
*
@@ -106,29 +233,202 @@
* @param position
* @return
*/
- public static Node getSourceNodeByPosition(VpePageContext pageContext,
+ private static Node getSourceNodeByPosition(IDOMDocument document,
int position) {
- // get document
- IDOMDocument document = (IDOMDocument) pageContext.getSourceBuilder()
- .getSourceDocument();
-
// get source node by position
- return (Node) document.getModel().getIndexedRegion(position);
+ IDOMNode node = (IDOMNode) document.getModel().getIndexedRegion(
+ position);
+ return node;
}
+ private static IDOMDocument getSourceDocument(VpePageContext pageContext) {
+
+ return (IDOMDocument) pageContext.getSourceBuilder()
+ .getSourceDocument();
+ }
+
/**
* get selected element
*
* @param pageContext
* @return
*/
- private static nsIDOMElement getVisualSelectedNode(
+ public static nsIDOMElement getLastSelectedVisualNode(
VpePageContext pageContext) {
return pageContext.getEditPart().getController().getXulRunnerEditor()
.getLastSelectedElement();
}
+ /**
+ *
+ * @param selection
+ * @return
+ */
+ public static nsIDOMNode getSelectedNode(nsISelection selection) {
+
+ if (selection.getFocusNode() != null) {
+ if ((selection.getFocusNode().getNodeType() != nsIDOMNode.TEXT_NODE)
+ && (selection.getFocusOffset() != 0)) {
+
+ return selection.getFocusNode().getChildNodes().item(
+ selection.getFocusOffset() - 1);
+ } else
+ return selection.getFocusNode();
+
+ }
+ return null;
+ }
+
+ /**
+ * get start offset of node
+ *
+ * @param node
+ * @return
+ */
+ public static int getStartOffsetNode(Node node) {
+
+ if (node instanceof IDOMAttr) {
+ return ((IDOMAttr) node).getValueRegionStartOffset() + 1;
+ } else if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getStartOffset();
+ }
+ return 0;
+ }
+
+ /**
+ *
+ * @param node
+ * @return
+ */
+ public static int getLengthNode(Node node) {
+
+ if (node instanceof IDOMAttr) {
+ return ((IDOMAttr) node).getValueSource().length();
+ } else if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getEndOffset()
+ - ((IndexedRegion) node).getStartOffset();
+ }
+ return 0;
+ }
+
+ /**
+ * get end offset of node
+ *
+ * @param node
+ * @return
+ */
+ public static int getEndOffsetNode(Node node) {
+
+ if (node instanceof IndexedRegion) {
+ return ((IndexedRegion) node).getEndOffset();
+ }
+ return 0;
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param node
+ * @param offset
+ * @param length
+ */
+ public static void setSourceSelection(VpePageContext pageContext,
+ Node node, int offset, int length) {
+
+ int start = getStartOffsetNode(node);
+
+ pageContext.getSourceBuilder().getStructuredTextViewer()
+ .setSelectedRange(start + offset, length);
+ pageContext.getSourceBuilder().getStructuredTextViewer().revealRange(
+ start + offset, length);
+
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @return
+ */
+ public static nsISelection getCurrentSelection(VpePageContext pageContext) {
+ return pageContext.getEditPart().getController().getXulRunnerEditor()
+ .getSelection();
+ }
+
+ /**
+ *
+ * @param pageContext
+ * @param sourceElement
+ * @return
+ */
+ public static String getPageLocale(VpePageContext pageContext,
+ Node sourceNode) {
+
+ while (sourceNode != null) {
+
+ if (VIEW_TAGNAME.equals(sourceNode.getLocalName())) {
+ break;
+ }
+ sourceNode = sourceNode.getParentNode();
+ }
+
+ if ((sourceNode == null) || !(sourceNode instanceof Element)
+ || !(((Element) sourceNode).hasAttribute(LOCALE_ATTRNAME)))
+ return null;
+
+ String locale = ((Element) sourceNode).getAttribute(LOCALE_ATTRNAME);
+
+ return locale;
+
+ }
+
+ public static Point getSelectionRangeFromInputElement(nsIDOMNode node) {
+
+ Point range = new Point(0, 0);
+
+ if (node != null)
+ if (HTML.TAG_INPUT.equalsIgnoreCase(node.getLocalName())) {
+
+ nsIDOMNSHTMLInputElement inputElement = (nsIDOMNSHTMLInputElement) node
+ .queryInterface(nsIDOMNSHTMLInputElement.NS_IDOMNSHTMLINPUTELEMENT_IID);
+
+ range.x = inputElement.getSelectionStart();
+ range.y = inputElement.getSelectionEnd()
+ - inputElement.getSelectionStart();
+ } else if (HTML.TAG_TEXTAREA.equalsIgnoreCase(node.getLocalName())) {
+
+ nsIDOMNSHTMLTextAreaElement textAreaElement = (nsIDOMNSHTMLTextAreaElement) node
+ .queryInterface(nsIDOMNSHTMLTextAreaElement.NS_IDOMNSHTMLTEXTAREAELEMENT_IID);
+ range.x = textAreaElement.getSelectionStart();
+ range.y = textAreaElement.getSelectionEnd()
+ - textAreaElement.getSelectionStart();
+
+ }
+
+ return range;
+
+ }
+
+ /**
+ *
+ * @param node
+ * @param range
+ */
+ public static void setSelectionRangeInInputElement(nsIDOMNode node,
+ Point range) {
+
+ if ((node != null) && (range != null))
+ if (HTML.TAG_INPUT.equalsIgnoreCase(node.getLocalName())) {
+ nsIDOMNSHTMLInputElement inputElement = (nsIDOMNSHTMLInputElement) node
+ .queryInterface(nsIDOMNSHTMLInputElement.NS_IDOMNSHTMLINPUTELEMENT_IID);
+ inputElement.setSelectionRange(range.x, range.x + range.y);
+ } else if (HTML.TAG_TEXTAREA.equalsIgnoreCase(node.getLocalName())) {
+ nsIDOMNSHTMLTextAreaElement textAreaElement = (nsIDOMNSHTMLTextAreaElement) node
+ .queryInterface(nsIDOMNSHTMLTextAreaElement.NS_IDOMNSHTMLTEXTAREAELEMENT_IID);
+ textAreaElement.setSelectionRange(range.x, range.x + range.y);
+ }
+ }
+
}
16 years, 1 month
JBoss Tools SVN: r7261 - in trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor: toolbar and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2008-04-02 03:23:47 -0400 (Wed, 02 Apr 2008)
New Revision: 7261
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
Log:
add dispose listeners for toolItems
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-04-01 18:54:51 UTC (rev 7260)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2008-04-02 07:23:47 UTC (rev 7261)
@@ -20,6 +20,8 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
@@ -292,10 +294,22 @@
}
}
- private ToolItem createToolItem(ToolBar parent, int type, String image, String toolTipText) {
+ private ToolItem createToolItem(ToolBar parent, int type, String image,
+ String toolTipText) {
ToolItem item = new ToolItem(parent, type);
- item.setImage(ImageDescriptor.createFromFile(MozillaEditor.class, image).createImage());
+ item.setImage(ImageDescriptor
+ .createFromFile(MozillaEditor.class, image).createImage());
item.setToolTipText(toolTipText);
+
+ // add dispose listener
+ item.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ // dispose tollitem's image
+ ((ToolItem) e.widget).getImage().dispose();
+
+ }
+ });
return item;
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2008-04-01 18:54:51 UTC (rev 7260)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2008-04-02 07:23:47 UTC (rev 7261)
@@ -15,6 +15,8 @@
import org.eclipse.compare.Splitter;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
@@ -151,6 +153,7 @@
button.setImage(ImageDescriptor.createFromFile(MozillaEditor.class, "icons/arrow.gif").createImage()); //$NON-NLS-1$
button.setToolTipText(VpeUIMessages.MENU);
button.addListener(SWT.Selection, new Listener() {
+
public void handleEvent(Event event) {
Rectangle bounds = button.getBounds();
Point point = btnBar.toDisplay( bounds.x + 15, bounds.y + 12);
@@ -158,7 +161,17 @@
menu.setVisible(true);
}
});
+
+ // add dispose listener
+ button.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ // dispose tollitem's image
+ ((ToolItem) e.widget).getImage().dispose();
+
+ }
+ });
+
return btnBar;
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2008-04-01 18:54:51 UTC (rev 7260)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2008-04-02 07:23:47 UTC (rev 7261)
@@ -15,6 +15,8 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
@@ -52,7 +54,17 @@
ToolItem item = new ToolItem(parent, type);
item.setImage(ImageDescriptor.createFromFile(MozillaEditor.class, image).createImage());
item.setToolTipText(toolTipText);
+
+ // add dispose listener
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ // dispose tollitem's image
+ ((ToolItem) e.widget).getImage().dispose();
+
+ }
+ });
+
return item;
}
16 years, 1 month