269895 and 269897
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.pagedesigner/META-INF/MANIFEST.MF
index 2595429..888f7c5 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/META-INF/MANIFEST.MF
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-SymbolicName: org.eclipse.jst.pagedesigner;singleton:=true
Bundle-Name: %pluginName
-Bundle-Version: 1.1.1.qualifier
+Bundle-Version: 1.1.2.qualifier
Bundle-Activator: org.eclipse.jst.pagedesigner.PDPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -116,6 +116,7 @@
org.eclipse.jst.pagedesigner.ui.common.sash;x-internal:=true,
org.eclipse.jst.pagedesigner.ui.dialogfields;x-internal:=true,
org.eclipse.jst.pagedesigner.ui.dialogs;x-internal:=true,
+ org.eclipse.jst.pagedesigner.ui.preferences;x-internal:=true,
org.eclipse.jst.pagedesigner.utils;x-internal:=true,
org.eclipse.jst.pagedesigner.validation.caret;x-internal:=true,
org.eclipse.jst.pagedesigner.viewer;x-internal:=true
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml b/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
index f8907af..9de8e55 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/plugin.xml
@@ -202,4 +202,10 @@
<propertyCategory></propertyCategory>
</propertyContributor>
</extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.jst.pagedesigner.ui.preferences.PDPreferences">
+ </initializer>
+ </extension>
</plugin>
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java
index ade2b79..3b03710 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/ConverterUtil.java
@@ -15,6 +15,7 @@
import org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.dtmanager.DTManager;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
import org.w3c.dom.Attr;
@@ -86,14 +87,14 @@
/**
* @param document
* @param text
- * @return the descripton element in the document containing text
+ * @return the description element in the document containing text
*/
public static Element createDescriptionElement(IDOMDocument document,
String text) {
if (document == null) {
return null;
}
- Element span = document.createElement(IHTMLConstants.TAG_SPAN); //$NON-NLS-1$
+ Element span = document.createElement(IHTMLConstants.TAG_SPAN);
span.setAttribute(
"style", "color:gray;font-style:italic;font-size:normal;"); //$NON-NLS-1$ //$NON-NLS-2$
if (text == null) {
@@ -104,4 +105,68 @@
}
return span;
}
+
+ /**
+ * Method to find the resulting converted tag containing a given
+ * source element. The converted element that will be
+ * the parent tag is returned so the caller can then determine
+ * if the parent is part of a table, header, body, footer, row,
+ * cell, or some other element.
+ *
+ * @param srcElem the source element to test.
+ * @param childElem a child of the source element (used by a
+ * recursive call to handle special case where
+ * it was moved up a level to the child model
+ * list of the grandparent).
+ * @return a converted element of the type that will contain the
+ * source element.
+ */
+ static Node findConvertedParentElement(Element srcElem, Element childElem) {
+ Node parent = srcElem.getParentNode();
+ if ((parent == null) || !(parent instanceof Element)) {
+ return null;
+ }
+
+ String name = parent.getNodeName();
+ if (IHTMLConstants.TAG_HTML.equalsIgnoreCase(name)
+ || IHTMLConstants.TAG_BODY.equalsIgnoreCase(name)) {
+ return null;
+ }
+
+ ITagConverter converter = createTagConverter((Element) parent);
+ if (!converter.isVisualByHTML()) {
+ return null;
+ }
+
+ converter.convertRefresh(null);
+ ConvertPosition position = null;
+ if (childElem != null) {
+ // If a child node (grand child of current parent) was
+ // passed in, check for its position. It may have been
+ // moved up a level to child model list of the current
+ // parent. In JSF this is done with a header or
+ // footer facet tag in a column tag for a dataTable.
+ position = converter.getChildVisualPosition(childElem);
+ }
+ if (position == null) {
+ position = converter.getChildVisualPosition(srcElem);
+ }
+ if (position != null) {
+ // return the node that will contain the visual
+ // child and then the caller can check to see if this
+ // element is table mark-up.
+ return position.getParentNode();
+ }
+
+ // The current source element is not in the child model
+ // list for the converted parent so recurse to next
+ // ancestor and pass source element to see if it has been
+ // moved up a level as child model of the grandparent.
+ return findConvertedParentElement((Element) parent, srcElem);
+ }
+
+ private static ITagConverter createTagConverter(Element ele) {
+ return DTManager.getInstance().getTagConverter(ele,
+ IConverterFactory.MODE_DESIGNER, null);
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java
index 7050685..e0a2af2 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/converter/DefaultUnknownTagConverter.java
@@ -11,8 +11,10 @@
*******************************************************************************/
package org.eclipse.jst.pagedesigner.converter;
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.utils.DOMUtil;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.Text;
/**
@@ -23,6 +25,10 @@
*/
public class DefaultUnknownTagConverter extends AbstractTagConverter {
+ private static final int NO_ELEMENT = 0;
+ private static final int TABLE_ELEMENT = 1;
+ private static final int TABLE_ROW_ELEMENT = 2;
+
/**
* @param host
* @param mode
@@ -39,33 +45,113 @@
*/
protected Element doConvertRefresh() {
Element hostEle = this.getHostElement();
- Element divEle = createElement("div");
- String style = DOMUtil.getAttributeIgnoreCase(hostEle, "style");
+
+ // Test to see if the src element is contained in an
+ // element that renders as a table. If so, render this
+ // element accordingly as content in the table.
+ // This is done to address the use case where tags
+ // (such as JSTL) are used in collaboration within HTML
+ // tables. The CSS layout for tables does not handle
+ // invalid HTML so this change tries to produce valid
+ // HTML. If the table layout code gets updated to handle
+ // invalid HTML tables, then this code can be removed.
+ // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=253974
+ Node containingElement = ConverterUtil.findConvertedParentElement(hostEle, null);
+ String name = null;
+ if (containingElement != null) {
+ name = containingElement.getNodeName();
+ }
+ if (name != null) {
+ if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(name)
+ || IHTMLConstants.TAG_TBODY.equalsIgnoreCase(name)
+ || IHTMLConstants.TAG_TFOOT.equalsIgnoreCase(name)) {
+ // this element is contained in a table, tbody or tfoot
+ return renderAsTableRow(hostEle, false, TABLE_ELEMENT);
+ } else if (IHTMLConstants.TAG_THEAD.equalsIgnoreCase(name)) {
+ // this element is contained in a thead
+ return renderAsTableRow(hostEle, true, TABLE_ELEMENT);
+ } else if (IHTMLConstants.TAG_TR.equalsIgnoreCase(name)) {
+ // this element is contained in a tr
+ return renderAsTableCell(hostEle, false, TABLE_ROW_ELEMENT);
+ }
+ }
+
+ // Otherwise, use the default rendering for an unknown tag
+ return renderDefault(hostEle, NO_ELEMENT);
+ }
+
+ private Element renderDefault(Element hostEle, int tableElement) {
+ // rendering for host element not contained in a table
+ Element divEle = createElement("div"); //$NON-NLS-1$
+ String style = DOMUtil.getAttributeIgnoreCase(hostEle, "style"); //$NON-NLS-1$
if (style == null) {
- style = "";
+ style = ""; //$NON-NLS-1$
}
- if (style.length() > 0 && !style.endsWith(";")) {
- style += ";";
+ if (style.length() > 0 && !style.endsWith(";")) { //$NON-NLS-1$
+ style += ";"; //$NON-NLS-1$
}
- style += "border: none; padding: 0; margin: 0";
- divEle.setAttribute("style", style);
- Element div2 = createElement("span");
- String border = isPreviewMode() ? "border-style: solid;border-width: 1px" : "border:none";
- div2.setAttribute("style", "background-color: white;"+border+";color:gray");
+ style += "border: none; padding: 0; margin: 0"; //$NON-NLS-1$
+ divEle.setAttribute("style", style); //$NON-NLS-1$
+ Element div2 = createElement("span"); //$NON-NLS-1$
+ String border = isPreviewMode() ? "border-style: solid;border-width: 1px" : "border:none"; //$NON-NLS-1$ //$NON-NLS-2$
+ div2.setAttribute("style", "background-color: white;"+border+";color:gray"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Text txt = createText(hostEle.getTagName());
div2.appendChild(txt);
divEle.appendChild(div2);
- Element div3 = createElement("div");
- div3.setAttribute("style", "margin: 0; padding: 0");
- divEle.appendChild(div3);
+ Element childContainer = null;
+ switch (tableElement) {
+ case TABLE_ELEMENT:
+ childContainer = createElement(IHTMLConstants.TAG_TABLE);
+ copyChildren(getHostElement(), childContainer);
+ break;
+ case TABLE_ROW_ELEMENT:
+ childContainer = createElement(IHTMLConstants.TAG_TABLE);
+ Element trElem = createElement(IHTMLConstants.TAG_TR);
+ childContainer.appendChild(trElem);
+ copyChildren(getHostElement(), trElem);
+ break;
+ case NO_ELEMENT:
+ default:
+ childContainer = createElement("div"); //$NON-NLS-1$
+ childContainer.setAttribute("style", "margin: 0; padding: 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ copyChildren(getHostElement(), childContainer);
+ break;
+ }
- copyChildren(getHostElement(), div3);
+ divEle.appendChild(childContainer);
+
return divEle;
}
/*
+ * Creates a table row, and adds either a table cell (data
+ * or a header depending on the boolean flag).
+ */
+ private Element renderAsTableRow(Element hostEle, boolean isHeader, int tableElement) {
+ Element trElem = createElement(IHTMLConstants.TAG_TR);
+ Element tdElem = renderAsTableCell(hostEle, isHeader, tableElement);
+ trElem.appendChild(tdElem);
+ return trElem;
+ }
+
+ /*
+ * Creates a table cell, as either data or a header depending
+ * on the boolean flag.
+ */
+ private Element renderAsTableCell(Element hostEle, boolean isHeader, int tableElement) {
+ Element tdElem = null;
+ if (isHeader) {
+ tdElem = createElement(IHTMLConstants.TAG_TH);
+ } else {
+ tdElem = createElement(IHTMLConstants.TAG_TD);
+ }
+ tdElem.appendChild(renderDefault(hostEle, tableElement));
+ return tdElem;
+ }
+
+ /*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.converter.ITagConverter#isMultiLevel()
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
index 7f530f5..2a24e73 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
@@ -29,6 +29,7 @@
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.gef.ui.views.palette.PaletteViewerPage;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.IPostSelectionProvider;
@@ -50,6 +51,8 @@
import org.eclipse.jst.pagedesigner.tools.RangeSelectionTool;
import org.eclipse.jst.pagedesigner.ui.common.PartActivationHandler;
import org.eclipse.jst.pagedesigner.ui.common.sash.SashEditorPart;
+import org.eclipse.jst.pagedesigner.ui.preferences.PDPreferences;
+import org.eclipse.jst.pagedesigner.utils.EditorUtil;
import org.eclipse.jst.pagedesigner.utils.PreviewUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
@@ -255,7 +258,11 @@
};
int sashIndex = addPage(_sashEditorPart, getEditorInput());
- setPageText(sashIndex, PDPlugin.getResourceString("HTMLEditor.Design"));
+ // Set the sash editor mode from the stored file property
+ // or the default preference
+ initDesignerMode();
+
+ setPageText(sashIndex, PDPlugin.getResourceString("HTMLEditor.Design")); //$NON-NLS-1$
// the update's critical, to get viewer selection manager and
// highlighting to work
@@ -296,12 +303,12 @@
// // IEditorPart, page switches will indicate
// // a "null" active editor when the design page is made active
setPageText(designPageIndex, PDPlugin
- .getResourceString("HTMLEditor.Design"));
+ .getResourceString("HTMLEditor.Design")); //$NON-NLS-1$
// add source page
int sourcePageIndex = addPage(_textEditor, getEditorInput());
setPageText(sourcePageIndex, PDPlugin
- .getResourceString("HTMLEditor.Source"));
+ .getResourceString("HTMLEditor.Source")); //$NON-NLS-1$
// the update's critical, to get viewer selection manager and
// highlighting to work
_textEditor.update();
@@ -540,10 +547,10 @@
_log.error("Error.HTMLEditor.0", ce); //$NON-NLS-1$
}
}
- throw new PartInitException("Resource " + input.getName()
- + " does not exist.");
+ throw new PartInitException("Resource " + input.getName() //$NON-NLS-1$
+ + " does not exist."); //$NON-NLS-1$
}
- throw new PartInitException("Editor could not be open on "
+ throw new PartInitException("Editor could not be open on " //$NON-NLS-1$
+ input.getName());
}
} else if (input instanceof IStorageEditorInput) {
@@ -552,7 +559,7 @@
contents = ((IStorageEditorInput) input).getStorage()
.getContents();
if (contents == null) {
- throw new PartInitException("Editor could not be open on "
+ throw new PartInitException("Editor could not be open on " //$NON-NLS-1$
+ input.getName());
}
} catch (CoreException noStorageExc) {
@@ -745,7 +752,7 @@
// enable our editor context
IContextService contextService = (IContextService) getSite()
.getService(IContextService.class);
- contextService.activateContext("org.eclipse.jst.pagedesigner.editorContext");
+ contextService.activateContext("org.eclipse.jst.pagedesigner.editorContext"); //$NON-NLS-1$
} catch (Exception e) {
// Error in editor initialization
@@ -1037,7 +1044,7 @@
* @param mode
*/
public void setDesignerMode(int mode) {
- if (_sashEditorPart != null) {
+ if (_sashEditorPart != null && _mode != mode) {
switch (mode) {
case MODE_SASH_HORIZONTAL:
_sashEditorPart.setOrientation(SWT.HORIZONTAL);
@@ -1052,10 +1059,40 @@
default:
_sashEditorPart.setOrientation(SWT.VERTICAL);
}
+ if (getEditorInput() != null) {
+ EditorUtil.setEditorInputDesignModeProperty(getEditorInput(), String.valueOf(mode));
+ }
}
this._mode = mode;
}
+ /*
+ * Set the sash editor mode from the stored file property
+ * or the default preference.
+ */
+ private void initDesignerMode() {
+ int preferredMode = MODE_SASH_VERTICAL;
+
+ // If the user has already selected a mode for the file, use it.
+ String prop = null;
+ if (getEditorInput() != null) {
+ prop = EditorUtil.getEditorInputDesignModeProperty(getEditorInput());
+ }
+ if (prop != null) {
+ try {
+ preferredMode = Integer.parseInt(prop);
+ } catch (NumberFormatException e) {
+ // do nothing;
+ }
+ } else {
+ // Otherwise, get the default mode from preferences.
+ IPreferenceStore pStore = PDPlugin.getDefault().getPreferenceStore();
+ preferredMode = pStore.getInt(PDPreferences.SASH_EDITOR_MODE_PREF);
+ }
+
+ setDesignerMode(preferredMode);
+ }
+
/**
* @return the current design mode
*/
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/preferences/PDPreferences.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/preferences/PDPreferences.java
new file mode 100644
index 0000000..5f2c64a
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/preferences/PDPreferences.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.ui.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.editors.HTMLEditor;
+
+/**
+ * Utility class for handling preferences related to the Web Page Editor plug-in.
+ * <br>
+ * <p><b>Provisional API - subject to change</b></p>
+ */
+public class PDPreferences extends AbstractPreferenceInitializer {
+
+ /**
+ * Preference used to set modes for the page designer when displayed
+ * in a sash editor.
+ */
+ public static final String SASH_EDITOR_MODE_PREF =
+ PDPreferences.class.getName() + ".sash_editor_mode"; //$NON-NLS-1$
+
+ private static IPreferenceStore getPreferenceStore() {
+ return PDPlugin.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ public void initializeDefaultPreferences() {
+ // Set default HTML editor split vertical (i.e. with top and bottom pane)
+ IPreferenceStore store = getPreferenceStore();
+ store.setDefault(SASH_EDITOR_MODE_PREF, HTMLEditor.MODE_SASH_VERTICAL);
+ }
+}
\ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/utils/EditorUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/utils/EditorUtil.java
new file mode 100644
index 0000000..a0fabf8
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/utils/EditorUtil.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.utils;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.ide.ResourceUtil;
+
+/**
+ * Utility class for Editor related information.
+ * <br>
+ * <p><b>Provisional API - subject to change</b></p>
+ */
+public class EditorUtil {
+
+ private static final String PROPERTY_QUALIFIER = "org.eclipse.jst.pagedesigner"; //$NON-NLS-1$
+ private static final String PERSIST_PROPERTY_NAME_DESIGNER_MODE = "DesignMode"; //$NON-NLS-1$
+ private static final QualifiedName PERSIST_PROPERTY_KEY_DESIGNER_MODE =
+ new QualifiedName(PROPERTY_QUALIFIER, PERSIST_PROPERTY_NAME_DESIGNER_MODE);
+
+ /**
+ * Find the design mode property for the file resource of the
+ * editor input. If found, then return the property value,
+ * otherwise return null.
+ *
+ * @param editorInput
+ * @return user selected design mode for the editor input file
+ */
+ public static String getEditorInputDesignModeProperty(IEditorInput editorInput) {
+ String dmProperty = null;
+ if (editorInput != null) {
+ IResource res = ResourceUtil.getResource(editorInput);
+ if (res != null) {
+ try {
+ dmProperty = res.getPersistentProperty(PERSIST_PROPERTY_KEY_DESIGNER_MODE);
+ } catch (CoreException e) {
+ // do nothing;
+ }
+ }
+ }
+
+ return dmProperty;
+ }
+
+ /**
+ * Save the design mode property for the file resource of the
+ * editor input. If the supplied mode is <code>null</code>,
+ * the persistent property is removed from this resource.
+ *
+ * @param editorInput
+ * @param mode user selected design mode to be saved
+ */
+ public static void setEditorInputDesignModeProperty(IEditorInput editorInput, String mode) {
+ if (editorInput != null) {
+ IResource res = ResourceUtil.getResource(editorInput);
+ if (res != null) {
+ try {
+ res.setPersistentProperty(PERSIST_PROPERTY_KEY_DESIGNER_MODE, mode);
+ } catch (CoreException e) {
+ // do nothing;
+ }
+ }
+ }
+ }
+}