#99442 Factoring out JSF document modifications.
1.1 --- a/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/JsfSupportUtilities.java Fri Mar 30 16:52:28 2007 +0000
1.2 +++ b/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/JsfSupportUtilities.java Fri Mar 30 16:56:37 2007 +0000
1.3 @@ -102,4 +102,13 @@
1.4 public static void updateLocalStyleValuesForElement(Element e, StyleData[] setStyleData, StyleData[] removeStyleData) {
1.5 Util.updateLocalStyleValuesForElement(e, setStyleData, removeStyleData);
1.6 }
1.7 +
1.8 + public static boolean setStyleAttribute(Element componentRootElement, String attribute, int value) {
1.9 + MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
1.10 + if (markupDesignBean == null) {
1.11 + return false;
1.12 + }
1.13 + return Util.setDesignProperty(markupDesignBean, attribute, value);
1.14 + }
1.15 +
1.16 }
2.1 --- a/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/text/Bundle.properties Fri Mar 30 16:52:28 2007 +0000
2.2 +++ b/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/text/Bundle.properties Fri Mar 30 16:56:37 2007 +0000
2.3 @@ -22,4 +22,4 @@
2.4 LBL_MoveComponents=Move Components
2.5 LBL_BringToFront=Bring To Front
2.6 LBL_SendToBack=Send To Back
2.7 -
2.8 +LBL_ResizeComponent=Resize Component
3.1 --- a/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/text/DomDocumentImpl.java Fri Mar 30 16:52:28 2007 +0000
3.2 +++ b/visualweb.designer.jsf/src/org/netbeans/modules/visualweb/designer/jsf/text/DomDocumentImpl.java Fri Mar 30 16:56:37 2007 +0000
3.3 @@ -39,6 +39,7 @@
3.4 import org.netbeans.modules.visualweb.api.designer.cssengine.StyleData;
3.5 import org.netbeans.modules.visualweb.api.designer.markup.MarkupService;
3.6 import org.netbeans.modules.visualweb.api.designer.cssengine.XhtmlCss;
3.7 +import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
3.8 import org.netbeans.modules.visualweb.designer.html.HtmlTag;
3.9 import org.netbeans.modules.visualweb.designer.jsf.JsfForm;
3.10 import org.netbeans.modules.visualweb.designer.jsf.JsfSupportUtilities;
3.11 @@ -2306,5 +2307,135 @@
3.12 jsfForm.writeUnlock(writeLock);
3.13 }
3.14 }
3.15 -
3.16 +
3.17 + // XXX Moved from designer/../GridHandler.
3.18 + /** Resize the given component to new dimensions.
3.19 + * Note that the x,y position might change too, for example, when
3.20 + * you resize the component by dragging a selection handle on the
3.21 + * top or left edges of the component.
3.22 + *
3.23 + * <p>
3.24 + * @param editor The editor containing the resized component
3.25 + * @param component Component being resized
3.26 + * @param element The DOM element for the component
3.27 + * @param newX The left edge of the component after resize
3.28 + * @param xMoved True iff the left edge position changed during the resize
3.29 + * @param newY The top edge of the component after resize
3.30 + * @param yMoved True iff the top edge position moved during the resize
3.31 + * @param newWidth The new width after resize
3.32 + * @param newHeight The new height after resize
3.33 + * @param box Box being resized
3.34 + * @param snapDisabled If true, skip snapping
3.35 + * @todo Should I use floating point coordinates instead?
3.36 + */
3.37 +// public void resize(DesignerPane editor, Element componentRootElement, /*MarkupDesignBean bean,*/ int newX, boolean xMoved,
3.38 +// int newY, boolean yMoved, int newWidth, boolean widthChanged, int newHeight,
3.39 +// boolean heightChanged, CssBox box, boolean snapDisabled) {
3.40 + public void resizeComponent(Designer designer, Element componentRootElement, /*MarkupDesignBean bean,*/ int newX, boolean xMoved,
3.41 + int newY, boolean yMoved, int newWidth, boolean widthChanged, int newHeight,
3.42 + boolean heightChanged, Box box, boolean snapEnabled) {
3.43 + // Locate a grid layout parent
3.44 +// Document doc = editor.getDocument();
3.45 +// WebForm webform = doc.getWebForm();
3.46 +// WebForm webform = editor.getWebForm();
3.47 +
3.48 + int x = newX;
3.49 + int y = newY;
3.50 +
3.51 + if (snapEnabled) {
3.52 +// x = snapX(newX, box.getPositionedBy());
3.53 +// y = snapY(newY, box.getPositionedBy());
3.54 + x = designer.snapX(newX, box.getPositionedBy());
3.55 + y = designer.snapY(newY, box.getPositionedBy());
3.56 + }
3.57 +
3.58 + Element element = box.getElement();
3.59 +
3.60 + if (element == null) {
3.61 +// element = bean.getElement();
3.62 + element = componentRootElement;
3.63 + }
3.64 +
3.65 + boolean absolute = isAbsolutelyPositioned(element);
3.66 +
3.67 +// UndoEvent undoEvent = webform.getModel().writeLock(NbBundle.getMessage(GridHandler.class, "ResizeComponent")); // NOI18N
3.68 +// HtmlDomProvider.WriteLock writeLock = webform.writeLock(NbBundle.getMessage(GridHandler.class, "ResizeComponent")); // NOI18N
3.69 + HtmlDomProvider.WriteLock writeLock = jsfForm.writeLock(NbBundle.getMessage(DomDocumentImpl.class, "LBL_ResizeComponent")); // NOI18N
3.70 + // Gotta set width and height attributes!
3.71 + try {
3.72 +// doc.writeLock(NbBundle.getMessage(GridHandler.class, "ResizeComponent")); // NOI18N
3.73 +
3.74 + // prevent multiple updates for the same element - only need a single refresh
3.75 +// webform.getDomSynchronizer().setUpdatesSuspended(bean, true);
3.76 +// webform.setUpdatesSuspended(componentRootElement, true);
3.77 + jsfForm.setUpdatesSuspended(componentRootElement, true);
3.78 +
3.79 + List<StyleData> set = new ArrayList<StyleData>(5);
3.80 + List<StyleData> remove = new ArrayList<StyleData>(3);
3.81 +
3.82 + if (absolute && (xMoved || yMoved)) {
3.83 +// set.add(new StyleData(XhtmlCss.POSITION_INDEX, CssConstants.CSS_ABSOLUTE_VALUE));
3.84 + set.add(new StyleData(XhtmlCss.POSITION_INDEX, CssProvider.getValueService().getAbsoluteValue()));
3.85 +
3.86 +// CssBox parentBox = box.getParent();
3.87 + Box parentBox = box.getParent();
3.88 +
3.89 + if (xMoved) {
3.90 + set.add(getHorizontalCssSetting(x, newWidth, box, parentBox, element));
3.91 + }
3.92 +
3.93 + if (yMoved) {
3.94 + set.add(getVerticalCssSetting(y, newHeight, box, parentBox, element));
3.95 + }
3.96 + }
3.97 +
3.98 + if (widthChanged) {
3.99 +// if (!DndHandler.setDesignProperty(bean, HtmlAttribute.WIDTH, newWidth, webform)) {
3.100 +// if (!WebForm.getHtmlDomProviderService().setDesignProperty(bean, HtmlAttribute.WIDTH, newWidth)) {
3.101 +// if (!WebForm.getHtmlDomProviderService().setStyleAttribute(componentRootElement, HtmlAttribute.WIDTH, newWidth)) {
3.102 + if (!JsfSupportUtilities.setStyleAttribute(componentRootElement, HtmlAttribute.WIDTH, newWidth)) {
3.103 + set.add(new StyleData(XhtmlCss.WIDTH_INDEX, Integer.toString(newWidth) + "px")); // NOI18N
3.104 + } else {
3.105 + // Ensure that we don't have a conflict
3.106 + remove.add(new StyleData(XhtmlCss.WIDTH_INDEX));
3.107 + }
3.108 + }
3.109 +
3.110 + if (heightChanged) {
3.111 +// if (!DndHandler.setDesignProperty(bean, HtmlAttribute.HEIGHT, newHeight, webform)) {
3.112 +// if (!WebForm.getHtmlDomProviderService().setDesignProperty(bean, HtmlAttribute.HEIGHT, newHeight)) {
3.113 + if (!JsfSupportUtilities.setStyleAttribute(componentRootElement, HtmlAttribute.HEIGHT, newHeight)) {
3.114 + set.add(new StyleData(XhtmlCss.HEIGHT_INDEX, Integer.toString(newHeight) + "px")); // NOI18N
3.115 + } else {
3.116 + // Ensure that we don't have a conflict
3.117 + remove.add(new StyleData(XhtmlCss.HEIGHT_INDEX));
3.118 + }
3.119 + }
3.120 +
3.121 +// XhtmlCssEngine engine = webform.getMarkup().getCssEngine();
3.122 +
3.123 +// <removing design bean manipulation in engine>
3.124 +// engine.updateLocalStyleValues((RaveElement)element, set, remove);
3.125 +// ====
3.126 +// Util.updateLocalStyleValuesForElement(element,
3.127 +// (StyleData[])set.toArray(new StyleData[set.size()]),
3.128 +// (StyleData[])remove.toArray(new StyleData[remove.size()]));
3.129 +// WebForm.getHtmlDomProviderService().updateLocalStyleValuesForElement(element,
3.130 +// set.toArray(new StyleData[set.size()]),
3.131 +// remove.toArray(new StyleData[remove.size()]));
3.132 + JsfSupportUtilities.updateLocalStyleValuesForElement(element,
3.133 + set.toArray(new StyleData[set.size()]),
3.134 + remove.toArray(new StyleData[remove.size()]));
3.135 +// </removing design bean manipulation in engine>
3.136 + } finally {
3.137 +// webform.getDomSynchronizer().setUpdatesSuspended(bean, false);
3.138 +// webform.setUpdatesSuspended(componentRootElement, false);
3.139 + jsfForm.setUpdatesSuspended(componentRootElement, false);
3.140 +// doc.writeUnlock();
3.141 +// webform.getModel().writeUnlock(undoEvent);
3.142 +// webform.writeUnlock(writeLock);
3.143 + jsfForm.writeUnlock(writeLock);
3.144 + }
3.145 + }
3.146 +
3.147 }
4.1 --- a/visualweb.designer/src/org/netbeans/modules/visualweb/api/designer/Designer.java Fri Mar 30 16:52:28 2007 +0000
4.2 +++ b/visualweb.designer/src/org/netbeans/modules/visualweb/api/designer/Designer.java Fri Mar 30 16:56:37 2007 +0000
4.3 @@ -57,6 +57,8 @@
4.4
4.5 public void selectComponent(Element componentRootElement);
4.6 public int getSelectedCount();
4.7 + /** Gets selected componets (component root elements). */
4.8 + public Element[] getSelectedComponents();
4.9
4.10 public enum Alignment {
4.11 SNAP_TO_GRID,
4.12 @@ -76,6 +78,8 @@
4.13 /** Representing the individual box. Providing accessors (getters) only! */
4.14 public interface Box {
4.15 public Element getComponentRootElement();
4.16 + public Element getElement();
4.17 +
4.18 public Box getParent();
4.19 public Box[] getChildren();
4.20
5.1 --- a/visualweb.designer/src/org/netbeans/modules/visualweb/designer/Resizer.java Fri Mar 30 16:52:28 2007 +0000
5.2 +++ b/visualweb.designer/src/org/netbeans/modules/visualweb/designer/Resizer.java Fri Mar 30 16:56:37 2007 +0000
5.3 @@ -220,8 +220,10 @@
5.4
5.5 // gm.resize(pane, component, r.x, origX != r.x, r.y, origY != r.y, r.width,
5.6 // resizeHorizontally, r.height, resizeVertically, box, snapDisabled);
5.7 - gm.resize(pane, componentRootElement, r.x, origX != r.x, r.y, origY != r.y, r.width,
5.8 - resizeHorizontally, r.height, resizeVertically, box, snapDisabled);
5.9 +// gm.resize(pane, componentRootElement, r.x, origX != r.x, r.y, origY != r.y, r.width,
5.10 +// resizeHorizontally, r.height, resizeVertically, box, snapDisabled);
5.11 + webform.getDomDocument().resizeComponent(webform, componentRootElement, r.x, origX != r.x, r.y, origY != r.y, r.width,
5.12 + resizeHorizontally, r.height, resizeVertically, box, !snapDisabled);
5.13 }
5.14
5.15 /*
6.1 --- a/visualweb.designer/src/org/netbeans/modules/visualweb/designer/WebForm.java Fri Mar 30 16:52:28 2007 +0000
6.2 +++ b/visualweb.designer/src/org/netbeans/modules/visualweb/designer/WebForm.java Fri Mar 30 16:56:37 2007 +0000
6.3 @@ -2107,7 +2107,11 @@
6.4 public int getSelectedCount() {
6.5 return getSelection().getNumSelected();
6.6 }
6.7 -
6.8 +
6.9 + public Element[] getSelectedComponents() {
6.10 + return getSelection().getSelectedComponentRootElements();
6.11 + }
6.12 +
6.13 public void snapToGrid() {
6.14 getGridHandler().snapToGrid();
6.15 }