001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.designer.jsf.action;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import org.netbeans.modules.visualweb.api.designer.Designer;
047: import org.netbeans.modules.visualweb.api.designer.Designer.Box;
048: import org.netbeans.modules.visualweb.designer.jsf.JsfForm;
049: import org.netbeans.modules.visualweb.designer.jsf.JsfSupportUtilities;
050: import org.openide.util.NbBundle;
051: import org.w3c.dom.Element;
052:
053: /**
054: * Action bringing the comp to the front.
055: *
056: * @author Peter Zavadsky
057: * @author Tor Norbye (old functionality implementation -> performAction impl)
058: */
059: public class BringToFrontAction extends AbstractComponentAction {
060:
061: /** Creates a new instance of BringToFrontAction */
062: public BringToFrontAction() {
063: }
064:
065: protected String getDisplayName(Element[] componentRootElements) {
066: return NbBundle.getMessage(BringToFrontAction.class,
067: "LBL_BringToFrontAction");
068: }
069:
070: protected String getIconBase(Element[] componentRootElements) {
071: return null;
072: }
073:
074: protected boolean isEnabled(Element[] componentRootElements) {
075: if (componentRootElements.length == 0) {
076: return false;
077: }
078:
079: Element componentRootElement = componentRootElements[0];
080: // WebForm webform = WebForm.findWebFormForElement(componentRootElement);
081: // if (webform == null) {
082: // return false;
083: // }
084: JsfForm jsfForm = JsfForm.findJsfForm(componentRootElement);
085: if (jsfForm == null) {
086: return false;
087: }
088:
089: // return !LiveUnit.isTrayBean(designBean) && FacesSupport.isFormBean(webform, designBean.getBeanParent());
090: // return !WebForm.getDomProviderService().isTrayComponent(componentRootElement)
091: // && webform.isFormComponent(WebForm.getDomProviderService().getParentComponent(componentRootElement));
092: return !JsfSupportUtilities
093: .isTrayComponent(componentRootElement)
094: && jsfForm.isFormComponent(JsfSupportUtilities
095: .getParentComponent(componentRootElement));
096: }
097:
098: protected void performAction(Element[] componentRootElements) {
099: if (componentRootElements.length == 0) {
100: return;
101: }
102:
103: Element componentRootElement = componentRootElements[0];
104: // WebForm webform = WebForm.findWebFormForElement(componentRootElement);
105: // if (webform == null) {
106: // return;
107: // }
108: JsfForm jsfForm = JsfForm.findJsfForm(componentRootElement);
109: if (jsfForm == null) {
110: return;
111: }
112:
113: // bringToFront(webform);
114: bringToFront(jsfForm);
115: }
116:
117: // private static void bringToFront(WebForm webform) {
118: private static void bringToFront(JsfForm jsfForm) {
119: Designer[] designers = JsfForm.findDesigners(jsfForm);
120: Designer designer = designers.length > 0 ? designers[0] : null;
121: if (designer == null) {
122: return;
123: }
124:
125: // SelectionManager sm = webform.getSelection();
126: //// ModelViewMapper mapper = webform.getMapper();
127: //
128: // if (!sm.isSelectionEmpty()) {
129: // List<CssBox> list = new ArrayList<CssBox>(sm.getNumSelected());
130: //// Iterator it = sm.iterator();
131: ////
132: //// while (it.hasNext()) {
133: //// DesignBean bean = (DesignBean)it.next();
134: // for (Element componentRootElement : sm.getSelectedComponentRootElements()) {
135: //// DesignBean bean = WebForm.getDomProviderService().getMarkupDesignBeanForElement(componentRootElement);
136: //// CssBox box = mapper.findBox(bean);
137: // CssBox box = ModelViewMapper.findBoxForComponentRootElement(webform.getPane().getPageBox(), componentRootElement);
138: //
139: // if (box != null) {
140: // list.add(box);
141: // }
142: // }
143: //
144: //// GridHandler.getInstance().front(webform, list);
145: //// webform.getGridHandler().front(webform, list);
146: //// webform.getGridHandler().front(webform, list.toArray(new CssBox[list.size()]));
147: // webform.getDomDocument().frontComponents(list.toArray(new CssBox[list.size()]));
148: // }
149: Element[] selectedComponents = designer.getSelectedComponents();
150: if (selectedComponents.length > 0) {
151: List<Box> selectedBoxes = new ArrayList<Box>();
152: for (Element selectedComponent : selectedComponents) {
153: Box box = designer
154: .findBoxForComponentRootElement(selectedComponent);
155: if (box != null) {
156: selectedBoxes.add(box);
157: }
158: }
159: jsfForm.getDomDocumentImpl().frontComponents(
160: selectedBoxes
161: .toArray(new Box[selectedBoxes.size()]));
162: }
163: }
164:
165: }
|