0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.visualweb.designer.jsf;
0043:
0044: import java.awt.datatransfer.UnsupportedFlavorException;
0045: import org.netbeans.modules.visualweb.designer.jsf.palette.PaletteControllerFactory;
0046: import org.netbeans.modules.visualweb.api.designer.Designer;
0047: import org.netbeans.modules.visualweb.api.designer.DesignerFactory;
0048: import org.netbeans.modules.visualweb.api.designer.DomProvider;
0049: import com.sun.rave.designtime.DesignBean;
0050: import com.sun.rave.designtime.DesignContext;
0051: import com.sun.rave.designtime.DesignEvent;
0052: import com.sun.rave.designtime.DesignProject;
0053: import com.sun.rave.designtime.DesignProperty;
0054: import com.sun.rave.designtime.DisplayItem;
0055: import com.sun.rave.designtime.Position;
0056: import com.sun.rave.designtime.Result;
0057: import com.sun.rave.designtime.event.DesignContextListener;
0058: import com.sun.rave.designtime.event.DesignProjectListener;
0059: import com.sun.rave.designtime.markup.MarkupDesignBean;
0060: import com.sun.rave.designtime.markup.MarkupPosition;
0061: import java.awt.EventQueue;
0062: import java.awt.datatransfer.DataFlavor;
0063: import java.awt.datatransfer.Transferable;
0064: import org.netbeans.modules.visualweb.designer.jsf.text.DomDocumentImpl;
0065: import org.netbeans.modules.visualweb.insync.live.LiveUnit;
0066: import org.netbeans.modules.visualweb.insync.markup.MarkupUnit;
0067: import org.netbeans.modules.visualweb.insync.models.FacesModel;
0068: import org.netbeans.modules.visualweb.insync.models.FacesModelSet;
0069:
0070: import java.io.IOException;
0071: import java.net.URL;
0072: import java.util.ArrayList;
0073: import java.util.HashSet;
0074: import java.util.Iterator;
0075: import java.util.List;
0076: import java.util.Map;
0077: import java.util.Set;
0078: import java.util.WeakHashMap;
0079: import java.util.concurrent.locks.ReadWriteLock;
0080: import java.util.concurrent.locks.ReentrantReadWriteLock;
0081: import java.util.logging.Level;
0082: import java.util.logging.Logger;
0083: import javax.swing.JComponent;
0084:
0085: import org.netbeans.api.project.FileOwnerQuery;
0086: import org.netbeans.api.project.Project;
0087: import org.netbeans.core.spi.multiview.MultiViewElement;
0088: import org.netbeans.modules.visualweb.api.designer.markup.MarkupService;
0089: import org.netbeans.modules.visualweb.api.designtime.idebridge.DesigntimeIdeBridgeProvider;
0090: import org.netbeans.modules.visualweb.designer.html.HtmlTag;
0091: import org.netbeans.modules.visualweb.designer.jsf.ui.ErrorPanelImpl;
0092: import org.netbeans.modules.visualweb.designer.jsf.ui.JsfMultiViewElement;
0093: import org.netbeans.modules.visualweb.designer.jsf.ui.NotAvailableMultiViewElement;
0094: import org.netbeans.modules.visualweb.designer.jsf.ui.RenderErrorPanelImpl;
0095: import org.netbeans.modules.visualweb.insync.ModelSet;
0096: import org.netbeans.modules.visualweb.insync.ModelSetsListener;
0097: import org.netbeans.modules.visualweb.insync.ResultHandler;
0098: import org.netbeans.modules.visualweb.insync.UndoEvent;
0099: import org.netbeans.modules.visualweb.insync.Unit;
0100: import org.netbeans.modules.visualweb.insync.Util;
0101: import org.netbeans.modules.visualweb.insync.faces.FacesBean;
0102: import org.netbeans.modules.visualweb.insync.faces.FacesPageUnit;
0103: import org.netbeans.modules.visualweb.insync.faces.MarkupBean;
0104: import org.netbeans.modules.visualweb.insync.java.JavaUnit;
0105: import org.netbeans.spi.palette.PaletteController;
0106: import org.openide.awt.UndoRedo;
0107: import org.openide.cookies.EditorCookie;
0108: import org.openide.cookies.LineCookie;
0109: import org.openide.filesystems.FileObject;
0110: import org.openide.filesystems.URLMapper;
0111: import org.openide.loaders.DataObject;
0112: import org.openide.loaders.DataObjectNotFoundException;
0113: import org.openide.text.Line;
0114: import org.openide.util.Exceptions;
0115: import org.openide.util.WeakListeners;
0116: import org.openide.util.WeakSet;
0117: import org.w3c.dom.Document;
0118: import org.w3c.dom.DocumentFragment;
0119: import org.w3c.dom.Element;
0120: import org.w3c.dom.Node;
0121:
0122: /**
0123: * Represents JSF form. Something like WebForm before, but only the JSF specific part of it.
0124: * TODO Factor out the maintaining of the maps into JsfFormManager.
0125: *
0126: * @author Peter Zavadsky
0127: * @author Tor Norbye (the original code copied from the old WebForm)
0128: */
0129: public class JsfForm {
0130:
0131: // /** Weak <code>Map</code> between <code>FacesModel</code> and <code>JsfForm</code>. */
0132: // private static final Map<FacesModel, JsfForm> facesModel2jsfForm = new WeakHashMap<FacesModel, JsfForm>();
0133: private static final Set<JsfForm> jsfForms = new WeakSet<JsfForm>();
0134:
0135: // /** Weak <code>Map</code> between <code>JsfForm</code> and <code>Designer</code>. */
0136: // private static final Map<JsfForm, Set<Designer>> jsfForm2designerSet = new WeakHashMap<JsfForm, Set<Designer>>();
0137: private final Set<Designer> designers = new WeakSet<Designer>();
0138:
0139: // /** Weak <code>Marp</code> between <code>Designer</code> and <code>JsfMultiViewElement</code>. */
0140: // private static final Map<Designer, JsfMultiViewElement> designer2jsfMultiViewElement = new WeakHashMap<Designer, JsfMultiViewElement>();
0141: private static final Set<JsfMultiViewElement> jsfMultiViewElements = new WeakSet<JsfMultiViewElement>();
0142:
0143: /** Maps weakly <code>DesignProject</code> to <code>JsfDesignProjectListener</code>. */
0144: private static final Map<DesignProject, JsfDesignProjectListener> designProject2jsfDesignProjectListener = new WeakHashMap<DesignProject, JsfDesignProjectListener>();
0145:
0146: private static final ReadWriteLock jsfFormsLock = new ReentrantReadWriteLock();
0147:
0148: private static final ReadWriteLock jsfMultiViewElementsLock = new ReentrantReadWriteLock();
0149:
0150: private static final ReadWriteLock designersLock = new ReentrantReadWriteLock();
0151:
0152: private static final ReadWriteLock designProject2jsfDesignProjectListenersLock = new ReentrantReadWriteLock();
0153:
0154: /** <code>FacesModel</code> associated with this JSF form. */
0155: private FacesModel facesModel;
0156:
0157: // /** <code>Designer</code> associated with this JSF form. */
0158: // private final Designer designer;
0159:
0160: private DomSynchronizer domSynchronizer;
0161:
0162: // private DesignContext designContext;
0163:
0164: // private final PropertyChangeListener dataObjectListener = new DataObjectPropertyChangeListener(this);
0165:
0166: private/*final*/DesignContextListener designContextListener /*= new JsfDesignContextListener(this)*/;
0167:
0168: private/*final*/boolean isFragment;
0169: private/*final*/boolean isPortlet;
0170:
0171: // private final EventListenerList listenerList = new EventListenerList();
0172:
0173: private/*final*/PaletteController paletteController;
0174:
0175: private final DomProvider domProvider = new DomProviderImpl(this );
0176:
0177: // XXX Bad (old style) error handling.
0178: private Exception renderFailureException;
0179: // XXX Bad (old style) error handling.
0180: private MarkupDesignBean renderFailureComponent;
0181: // XXX Bad (old style) error handling.
0182: private boolean renderFailureShown;
0183:
0184: private final DomDocumentImpl domDocumentImpl = new DomDocumentImpl(
0185: this );
0186:
0187: // XXX Caching external jsf forms.
0188: private final ExternalDomProviderCache externalDomProviderCache = new ExternalDomProviderCache();
0189:
0190: // XXX Moved from the designer/../WebForm.
0191: // XXX For fragments, this represents the assigned context page.
0192: private JsfForm contextJsfForm;
0193:
0194: /** XXX Virutal forms support painting. */
0195: private boolean virtualFormsSupportEnabled;
0196: /** XXX Ajax transactions support painting. */
0197: private boolean ajaxTransactionsSupportEnabled;
0198:
0199: private final DndSupport dndSupport = new DndSupport(this );
0200:
0201: private final ReadWriteLock facesModelLock = new ReentrantReadWriteLock();
0202:
0203: /** Creates a new instance of JsfForm */
0204: private JsfForm(FacesModel facesModel, DataObject dataObject) {
0205: // if (facesModel == null) {
0206: // throw new NullPointerException("FacesModel may not be null!"); // NOI18N
0207: // }
0208:
0209: // if (facesModel.getLiveUnit() == null) {
0210: // log(new NullPointerException("Invalid FacesModel, it has null LiveUnit, facesModel=" + facesModel)); // NOI18N
0211: // }
0212:
0213: // associateFacesModel(dataObject.getPrimaryFile());
0214: // synchronized (facesModel2jsfForm) {
0215: // synchronized (jsfForms) {
0216: // this.facesModel = facesModel;
0217: // }
0218: setFacesModel(facesModel);
0219:
0220: init(dataObject);
0221: if (isValid()) {
0222: init();
0223: }
0224: }
0225:
0226: private void init(DataObject dataObject) {
0227: // XXX This needs to be moved to insync.
0228: initFragmentProperty(dataObject);
0229:
0230: initPaletteController(dataObject);
0231: }
0232:
0233: private void init() {
0234: // XXX This needs to be moved to insync.
0235: initPortletProperty();
0236:
0237: initListening();
0238: }
0239:
0240: private void initFragmentProperty(DataObject dataObject) {
0241: // Set isFragment/isPortlet fields.
0242: FileObject fo = dataObject.getPrimaryFile();
0243: this .isFragment = "jspf".equals(fo.getExt()); // NOI18N
0244: }
0245:
0246: private void initPortletProperty() {
0247: // XXX This needs to be moved to insync.
0248: if (getFacesModel().getFacesModelSet() != null) {
0249: isPortlet = getFacesModel().getFacesModelSet()
0250: .getFacesContainer().isPortletContainer();
0251: } else {
0252: isPortlet = false;
0253: }
0254: }
0255:
0256: private void initPaletteController(DataObject jspDataObject) {
0257: Project project = FileOwnerQuery.getOwner(jspDataObject
0258: .getPrimaryFile());
0259: if (project == null) {
0260: log(new NullPointerException(
0261: "There is no project found for DataObject, jspDataObject="
0262: + jspDataObject)); // NOI18N
0263: }
0264: paletteController = PaletteControllerFactory.getDefault()
0265: .createJsfPaletteController(project);
0266: }
0267:
0268: private void initListening() {
0269: // // Set listening.
0270: // dataObject.addPropertyChangeListener(WeakListeners.propertyChange(dataObjectListener, dataObject));
0271: initDesignProjectListening();
0272: updateDnDListening();
0273: }
0274:
0275: private void setFacesModel(FacesModel facesModel) {
0276: // synchronized (jsfForms) {
0277: facesModelLock.writeLock().lock();
0278: try {
0279: this .facesModel = facesModel;
0280: } finally {
0281: facesModelLock.writeLock().unlock();
0282: }
0283: }
0284:
0285: private static FacesModel getFacesModel(FileObject fileObject) {
0286: FacesModelSet facesModelSet = FacesModelSet
0287: .getInstance(fileObject);
0288: if (facesModelSet != null) {
0289: return facesModelSet.getFacesModel(fileObject);
0290: }
0291: return null;
0292: }
0293:
0294: private static FacesModel getFacesModel(DataObject dataObject) {
0295: if (dataObject == null) {
0296: throw new NullPointerException(
0297: "DataObject may not be null!"); // NOI18N
0298: }
0299:
0300: return getFacesModel(dataObject.getPrimaryFile());
0301: }
0302:
0303: // XXX TEMP to try out.
0304: private static boolean LOAD_MODEL_SYNCHRONOUSLY = Boolean
0305: .getBoolean("vwp.designer.jsf.loadModelSync"); // NOI18N
0306:
0307: public static JsfForm getJsfForm(final DataObject dataObject) {
0308: if (dataObject == null) {
0309: return null;
0310: }
0311:
0312: FacesModel facesModel;
0313: if (LOAD_MODEL_SYNCHRONOUSLY) {
0314: facesModel = getFacesModel(dataObject);
0315: if (facesModel == null) {
0316: if (!dataObject.isTemplate()) {
0317: log(new IllegalArgumentException(
0318: "There is no FacesModel available for non-template dataObject="
0319: + dataObject)); // NOI18N
0320: }
0321: return null;
0322: }
0323: } else {
0324: // XXX TODO Here should be a method which immediatelly returns FacesModel if it is already created.
0325: facesModel = FacesModelSet
0326: .getFacesModelIfAvailable(dataObject
0327: .getPrimaryFile());
0328: }
0329:
0330: JsfForm jsfForm;
0331: // synchronized (facesModel2jsfForm) {
0332: // synchronized (jsfForms) {
0333: // jsfForm = facesModel2jsfForm.get(facesModel);
0334: jsfForm = findJsfFormForFacesModel(facesModel);
0335: if (jsfForm == null) {
0336: jsfFormsLock.writeLock().lock();
0337: try {
0338: jsfForm = new JsfForm(facesModel, dataObject);
0339: // facesModel2jsfForm.put(facesModel, jsfForm);
0340: jsfForms.add(jsfForm);
0341: } finally {
0342: jsfFormsLock.writeLock().unlock();
0343: }
0344: }
0345:
0346: // // XXX FacesModel was not loaded yet, request it now.
0347: // if (facesModel == null) {
0348: // loadFacesModelForJsfForm(jsfForm, dataObject);
0349: // }
0350:
0351: return jsfForm;
0352: }
0353:
0354: public static boolean tryFacesModelForJsfForm(JsfForm jsfForm,
0355: DataObject dataObject) {
0356: if (FacesModelSet.getFacesModelIfAvailable(dataObject
0357: .getPrimaryFile()) == null) {
0358: return false;
0359: } else {
0360: FacesModel facesModel = jsfForm.loadFacesModel(dataObject);
0361: if (facesModel == null) {
0362: return false;
0363: }
0364: jsfForm.setFacesModel(facesModel);
0365: jsfForm.init();
0366: return true;
0367: }
0368: }
0369:
0370: public static void loadFacesModelForJsfForm(final JsfForm jsfForm,
0371: final DataObject dataObject) {
0372: ModelSet.addModelSetsListener(new ModelSetsListener() {
0373: public void modelSetAdded(ModelSet modelSet) {
0374: Project project = modelSet.getProject();
0375: FileObject fileObject = dataObject.getPrimaryFile();
0376: Project jsfProject = FileOwnerQuery
0377: .getOwner(fileObject);
0378: if (project == jsfProject) {
0379: FacesModel facesModel = jsfForm
0380: .loadFacesModel(dataObject);
0381: if (facesModel != null) {
0382: jsfForm.setFacesModel(facesModel);
0383: EventQueue.invokeLater(new Runnable() {
0384: public void run() {
0385: jsfForm.init();
0386: jsfForm.notifyViewsModelLoaded();
0387: }
0388: });
0389: }
0390:
0391: ModelSet.removeModelSetsListener(this );
0392: }
0393: }
0394:
0395: public void modelSetRemoved(ModelSet modelSet) {
0396: }
0397: });
0398: FacesModelSet.startModeling(dataObject.getPrimaryFile());
0399: }
0400:
0401: // XXX Revise, the need for this method is suspicious.
0402: public static JsfForm findJsfFormForDomProvider(
0403: DomProvider domProvider) {
0404: if (!(domProvider instanceof DomProviderImpl)) {
0405: return null;
0406: }
0407:
0408: return ((DomProviderImpl) domProvider).getJsfForm();
0409: }
0410:
0411: // public static Designer createDesigner(DataObject jsfJspDataObject) {
0412: // JsfForm jsfForm = JsfForm.getJsfForm(jsfJspDataObject);
0413: // if (jsfForm == null) {
0414: // return null;
0415: // }
0416: //
0417: // return createDesigner(jsfForm);
0418: // }
0419:
0420: public/*private*/static Designer[] findDesigners(JsfForm jsfForm) {
0421: // Set<Designer> designerSet;
0422: // synchronized (jsfForm2designerSet) {
0423: // designerSet = jsfForm2designerSet.get(jsfForm);
0424: // }
0425: // if (designerSet != null) {
0426: // // XXX To be sure there are not lost some weak refs.
0427: // designerSet = new HashSet<Designer>(designerSet);
0428: // }
0429: // return designerSet == null ? new Designer[0] : designerSet.toArray(new Designer[designerSet.size()]);
0430: return jsfForm == null ? new Designer[0] : jsfForm
0431: .getDesigners();
0432: }
0433:
0434: // private static Designer createDesigner(JsfForm jsfForm) {
0435: // // TODO There should be always created new designer.
0436: // Designer designer;
0437: //// synchronized (jsfForm2designerSet) {
0438: //// Set<Designer> designerSet = jsfForm2designerSet.get(jsfForm);
0439: //// if (designerSet == null) {
0440: //// designerSet = new WeakSet<Designer>();
0441: //// }
0442: //
0443: // designer = DesignerFactory.createDesigner(jsfForm.getDomProvider());
0444: //// designerSet.add(designer);
0445: //// jsfForm2designerSet.put(jsfForm, designerSet);
0446: // jsfForm.addDesigner(designer);
0447: //// }
0448: // return designer;
0449: // }
0450: Designer createDesigner() {
0451: Designer designer = DesignerFactory.createDesigner(domProvider);
0452: addDesigner(designer);
0453: return designer;
0454: }
0455:
0456: public static JsfMultiViewElement[] getJsfMultiViewElements() {
0457: Set<JsfMultiViewElement> jsfMEs;
0458: // synchronized (jsfMultiViewElements) {
0459: jsfMultiViewElementsLock.readLock().lock();
0460: try {
0461: jsfMEs = new HashSet<JsfMultiViewElement>(
0462: jsfMultiViewElements);
0463: } finally {
0464: jsfMultiViewElementsLock.readLock().unlock();
0465: }
0466: // #126861 Possible null inside the weak set.
0467: if (jsfMEs.contains(null)) {
0468: jsfMEs.remove(null);
0469: }
0470: return jsfMEs.toArray(new JsfMultiViewElement[jsfMEs.size()]);
0471: }
0472:
0473: private static JsfMultiViewElement[] findJsfMultiViewElements(
0474: JsfForm jsfForm) {
0475: // Designer[] designers = findDesigners(jsfForm);
0476: if (jsfForm == null) {
0477: return new JsfMultiViewElement[0];
0478: }
0479:
0480: Set<JsfMultiViewElement> multiViewElements;
0481: // synchronized (designer2jsfMultiViewElement) {
0482: // synchronized (jsfMultiViewElements) {
0483: // for (Designer designer : designers) {
0484: // JsfMultiViewElement jsfMultiViewElement = designer2jsfMultiViewElement.get(designer);
0485: // if (jsfMultiViewElement != null) {
0486: // jsfMultiViewElements.add(jsfMultiViewElement);
0487: // }
0488: // }
0489: jsfMultiViewElementsLock.readLock().lock();
0490: try {
0491: multiViewElements = new HashSet<JsfMultiViewElement>(
0492: jsfMultiViewElements);
0493: } finally {
0494: jsfMultiViewElementsLock.readLock().unlock();
0495: }
0496: for (Iterator<JsfMultiViewElement> it = multiViewElements
0497: .iterator(); it.hasNext();) {
0498: JsfMultiViewElement multiViewElement = it.next();
0499: if (multiViewElement.getJsfForm() != jsfForm) {
0500: it.remove();
0501: }
0502: }
0503: return multiViewElements
0504: .toArray(new JsfMultiViewElement[multiViewElements
0505: .size()]);
0506: }
0507:
0508: static MultiViewElement createMultiViewElement(JsfForm jsfForm,
0509: Designer designer, DataObject jspDataObject) {
0510: if (jsfForm == null || designer == null) {
0511: return new NotAvailableMultiViewElement();
0512: }
0513:
0514: JsfMultiViewElement jsfMultiViewElement = new JsfMultiViewElement(
0515: jsfForm, designer, jspDataObject);
0516: // synchronized (designer2jsfMultiViewElement) {
0517: // designer2jsfMultiViewElement.put(designer, jsfMultiViewElement);
0518: // }
0519: // synchronized (jsfMultiViewElements) {
0520: jsfMultiViewElementsLock.writeLock().lock();
0521: try {
0522: jsfMultiViewElements.add(jsfMultiViewElement);
0523: } finally {
0524: jsfMultiViewElementsLock.writeLock().unlock();
0525: }
0526: return jsfMultiViewElement;
0527: }
0528:
0529: public static JsfMultiViewElement findJsfMultiViewElementForDesigner(
0530: Designer designer) {
0531: if (designer == null) {
0532: return null;
0533: }
0534: // synchronized (designer2jsfMultiViewElement) {
0535: // return designer2jsfMultiViewElement.get(designer);
0536: // }
0537: Set<JsfMultiViewElement> multiViewElements;
0538: // synchronized (jsfMultiViewElements) {
0539: jsfMultiViewElementsLock.readLock().lock();
0540: try {
0541: multiViewElements = new HashSet<JsfMultiViewElement>(
0542: jsfMultiViewElements);
0543: } finally {
0544: jsfMultiViewElementsLock.readLock().unlock();
0545: }
0546:
0547: for (JsfMultiViewElement multiViewElement : multiViewElements) {
0548: if (multiViewElement.getDesigner() == designer) {
0549: return multiViewElement;
0550: }
0551: }
0552: return null;
0553: }
0554:
0555: static Designer[] getDesigners(JsfForm jsfForm) {
0556: if (jsfForm == null) {
0557: return new Designer[0];
0558: }
0559: Designer[] designers = findDesigners(jsfForm);
0560: if (designers.length == 0) {
0561: // Designer designer = createDesigner(jsfForm);
0562: Designer designer = jsfForm.createDesigner();
0563: return new Designer[] { designer };
0564: }
0565: return designers;
0566: }
0567:
0568: static Designer[] getDesignersForDataObject(
0569: DataObject jsfJspDataObject) {
0570: JsfForm jsfForm = getJsfForm(jsfJspDataObject);
0571: if (jsfForm == null) {
0572: return new Designer[0];
0573: }
0574: // Designer[] designers = findDesigners(jsfForm);
0575: // if (designers.length == 0) {
0576: // Designer designer = createDesigner(jsfForm);
0577: // return new Designer[] {designer};
0578: // }
0579: // return designers;
0580: return getDesigners(jsfForm);
0581: }
0582:
0583: // static Designer[] findDesignersForFileObject(FileObject jsfJspFileObject) {
0584: // JsfForm jsfForm = findJsfForm(jsfJspFileObject);
0585: // if (jsfForm == null) {
0586: // return new Designer[0];
0587: // }
0588: // return findDesigners(jsfForm);
0589: // }
0590:
0591: static Designer[] findDesignersForDesignContext(
0592: DesignContext designContext) {
0593: JsfForm jsfForm = findJsfForm(designContext);
0594: if (jsfForm == null) {
0595: return new Designer[0];
0596: }
0597: return findDesigners(jsfForm);
0598: }
0599:
0600: static Designer[] findDesignersForElement(Element element) {
0601: JsfForm jsfForm = findJsfForm(element);
0602: if (jsfForm == null) {
0603: return new Designer[0];
0604: }
0605: return findDesigners(jsfForm);
0606: }
0607:
0608: static Designer[] findDesignersForDocument(Document document) {
0609: MarkupUnit markupUnit = MarkupUnit
0610: .getMarkupUnitForDocument(document);
0611: if (markupUnit == null) {
0612: return new Designer[0];
0613: }
0614: return findDesignersForFileObject(markupUnit.getFileObject());
0615: }
0616:
0617: private static Designer[] findDesignersForFileObject(
0618: FileObject fileObject) {
0619: JsfForm jsfForm = findJsfForm(fileObject);
0620: if (jsfForm == null) {
0621: return new Designer[0];
0622: }
0623: return findDesigners(jsfForm);
0624: }
0625:
0626: static JsfForm findJsfForm(DataObject dataObject) {
0627: if (dataObject == null) {
0628: return null;
0629: }
0630:
0631: FacesModel facesModel = getFacesModel(dataObject);
0632: if (facesModel == null) {
0633: return null;
0634: }
0635: return findJsfFormForFacesModel(facesModel);
0636: }
0637:
0638: // static JsfForm findJsfForm(FacesModel facesModel) {
0639: // return findJsfForm(facesModel);
0640: // }
0641:
0642: /*private*/static JsfForm findJsfForm(FileObject fileObject) {
0643: if (fileObject == null) {
0644: return null;
0645: }
0646:
0647: FacesModel facesModel = getFacesModel(fileObject);
0648: if (facesModel == null) {
0649: return null;
0650: }
0651: return findJsfFormForFacesModel(facesModel);
0652: }
0653:
0654: /*private*/public static JsfForm findJsfForm(
0655: DesignContext designContext) {
0656: if (designContext == null) {
0657: return null;
0658: }
0659:
0660: FacesModel facesModel = ((LiveUnit) designContext).getModel();
0661: if (facesModel == null) {
0662: return null;
0663: }
0664: return findJsfFormForFacesModel(facesModel);
0665: }
0666:
0667: public/*private*/static JsfForm findJsfForm(Element element) {
0668: MarkupDesignBean markupDesignBean = MarkupUnit
0669: .getMarkupDesignBeanForElement(element);
0670: if (markupDesignBean == null) {
0671: return null;
0672: }
0673: DesignContext designContext = markupDesignBean
0674: .getDesignContext();
0675: return findJsfForm(designContext);
0676: }
0677:
0678: /*private*/static JsfForm findJsfFormForFacesModel(
0679: FacesModel facesModel) {
0680: if (facesModel == null) {
0681: return null;
0682: }
0683: // synchronized (facesModel2jsfForm) {
0684: // return facesModel2jsfForm.get(facesModel);
0685: // }
0686: Set<JsfForm> forms;
0687: // synchronized (jsfForms) {
0688: jsfFormsLock.readLock().lock();
0689: try {
0690: forms = new HashSet<JsfForm>(jsfForms);
0691: } finally {
0692: jsfFormsLock.readLock().unlock();
0693: }
0694: for (JsfForm jsfForm : forms) {
0695: if (jsfForm != null
0696: && jsfForm.getFacesModel() == facesModel) {
0697: return jsfForm;
0698: }
0699: }
0700: return null;
0701: }
0702:
0703: // DomProvider getDomProvider() {
0704: // return domProvider;
0705: // }
0706:
0707: // static boolean hasDomProvider(DataObject dataObject) {
0708: // if (dataObject == null) {
0709: // return false;
0710: // }
0711: //
0712: // FacesModel facesModel = getFacesModel(dataObject);
0713: // return hasJsfForm(facesModel);
0714: // }
0715: //
0716: // private static boolean hasJsfForm(FacesModel facesModel) {
0717: // synchronized (facesModel2jsfForm) {
0718: // return facesModel2jsfForm.containsKey(facesModel);
0719: // }
0720: // }
0721:
0722: // static boolean hasJsfForm(DataObject dataObject) {
0723: // FacesModel facesModel = getFacesModel(dataObject);
0724: // synchronized (facesModel2jsfForm) {
0725: // // XXX Also check whether this model is still valid (in the FacesModelSet).
0726: // return facesModel2jsfForm.containsKey(facesModel);
0727: // }
0728: // }
0729:
0730: // static Designer findDesignerForDesignContext(DesignContext designContext) {
0731: // FacesModel facesModel = ((LiveUnit)designContext).getModel();
0732: //
0733: // JsfForm jsfForm;
0734: // synchronized (facesModel2jsfForm) {
0735: // jsfForm = facesModel2jsfForm.get(facesModel);
0736: // }
0737: // return jsfForm == null ? null : jsfForm.getDesigner();
0738: // }
0739: //
0740: // static Designer findDesignerForFileObject(FileObject fo) {
0741: // FacesModel facesModel = getFacesModelForFileObject(fo);
0742: //
0743: // JsfForm jsfForm;
0744: // synchronized (facesModel2jsfForm) {
0745: // jsfForm = facesModel2jsfForm.get(facesModel);
0746: // }
0747: // return jsfForm == null ? null : jsfForm.getDesigner();
0748: // }
0749: //
0750: //
0751: // /** XXX */
0752: // Designer getDesigner() {
0753: // return designer;
0754: // }
0755:
0756: // private static void removeJsfFormForDataObject(DataObject dobj) {
0757: // synchronized (dataObject2jsfForm) {
0758: // dataObject2jsfForm.remove(dobj);
0759: // }
0760: // }
0761:
0762: private void initDesignProjectListening() {
0763: LiveUnit liveUnit = getFacesModel().getLiveUnit();
0764: if (liveUnit == null) {
0765: log(new NullPointerException(
0766: "Invalid FacesModel, it has null LiveUnit, facesModel="
0767: + getFacesModel())); // NOI18N
0768: return;
0769: }
0770: DesignProject designProject = liveUnit.getProject();
0771: if (designProject == null) {
0772: // Log issue?
0773: return;
0774: }
0775: JsfDesignProjectListener jsfDesignProjectListener;
0776: // synchronized (designProject2jsfDesignProjectListener) {
0777: designProject2jsfDesignProjectListenersLock.readLock().lock();
0778: try {
0779: jsfDesignProjectListener = designProject2jsfDesignProjectListener
0780: .get(designProject);
0781: } finally {
0782: designProject2jsfDesignProjectListenersLock.readLock()
0783: .unlock();
0784: }
0785: if (jsfDesignProjectListener == null) {
0786: designProject2jsfDesignProjectListenersLock.writeLock()
0787: .lock();
0788: try {
0789: jsfDesignProjectListener = new JsfDesignProjectListener();
0790: designProject
0791: .addDesignProjectListener(WeakListeners
0792: .create(DesignProjectListener.class,
0793: jsfDesignProjectListener,
0794: designProject));
0795: designProject2jsfDesignProjectListener.put(
0796: designProject, jsfDesignProjectListener);
0797: } finally {
0798: designProject2jsfDesignProjectListenersLock.writeLock()
0799: .lock();
0800: }
0801: }
0802: }
0803:
0804: private void updateDnDListening() {
0805: getDndSupport().updateDndListening();
0806: }
0807:
0808: // public MultiViewElement getDesignerMultiViewElement() {
0809: // JComponent component = designer.getDesignerComponent();
0810: // if (component instanceof MultiViewElement) {
0811: // return (MultiViewElement)component;
0812: // } else {
0813: // ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
0814: // new IllegalStateException("Component is not of MultiViewElement type, component=" + component)); // NOI18N
0815: // return null;
0816: // }
0817: // }
0818:
0819: // private void associateFacesModel(FileObject fo) {
0820: // facesModel = FacesModel.getInstance(fo);
0821: //
0822: // if (facesModel == null) {
0823: // throw new IllegalArgumentException("Specified file is not JSF form, fo=" + fo); // NOI18N
0824: // }
0825: //
0826: //// init(fo);
0827: // }
0828:
0829: // private void replaceFacesModel(FileObject oldFo, FileObject newFo) {
0830: // if (oldFo != null) {
0831: //// designer.destroyDesigner();
0832: // // XXX There would be weak listeners needed.
0833: // getDomSynchronizer().unregisterDomListeners();
0834: // }
0835: // // XXX Force new DomSynchronizer.
0836: // domSynchronizer = null;
0837: //
0838: // if (newFo != null) {
0839: //// associateFacesModel(newFo);
0840: //
0841: //// FacesModel newModel = FacesModel.getInstance(newFo);
0842: // FacesModel newModel = getFacesModel(newFo);
0843: // if (newModel == null) {
0844: // throw new IllegalArgumentException("Null FacesModel for FileObject, fo=" + newFo); // NOI18N
0845: // }
0846: ////// synchronized (facesModel2jsfForm) {
0847: //// synchronized (jsfForms) {
0848: ////// facesModel2jsfForm.remove(this.facesModel);
0849: //// this.facesModel = newModel;
0850: ////// facesModel2jsfForm.put(this.facesModel, this);
0851: //// }
0852: // setFacesModel(newModel);
0853: //
0854: // updateDnDListening();
0855: //
0856: // getDomSynchronizer().requestRefresh();
0857: // }
0858: // }
0859:
0860: private FacesModel getFacesModel() {
0861: // synchronized (jsfForms) {
0862: facesModelLock.readLock().lock();
0863: try {
0864: return facesModel;
0865: } finally {
0866: facesModelLock.readLock().unlock();
0867: }
0868: }
0869:
0870: // public Document getJspDom() {
0871: //// return InSyncServiceProvider.get().getJspDomForMarkupFile(getFacesModel().getMarkupFile());
0872: // return getFacesModel().getJspDom();
0873: // }
0874:
0875: // >> Impl of DomProvider
0876: // public Document getHtmlDom() {
0877: //// return InSyncServiceProvider.get().getHtmlDomForMarkupFile(getFacesModel().getMarkupFile());
0878: // return getFacesModel().getHtmlDom();
0879: // }
0880:
0881: // public DocumentFragment getHtmlDocumentFragment() {
0882: //// return InSyncServiceProvider.get().getHtmlDomFragmentForDocument(getHtmlDom());
0883: // return getFacesModel().getHtmlDomFragment();
0884: // }
0885:
0886: // public Element getHtmlBody() {
0887: //// return InSyncServiceProvider.get().getHtmlBodyForMarkupFile(getFacesModel().getMarkupFile());
0888: // return getFacesModel().getHtmlBody();
0889: // }
0890:
0891: void setUpdatesSuspended(MarkupDesignBean markupDesignBean,
0892: boolean suspend) {
0893: getDomSynchronizer().setUpdatesSuspended(markupDesignBean,
0894: suspend);
0895: }
0896:
0897: // boolean isRefreshPending() {
0898: // return getDomSynchronizer().isRefreshPending();
0899: // }
0900:
0901: // private void attachContext(DesignContext designContext) {
0902: ////// getDomSynchronizer().attachContext(context);
0903: //// if (this.designContext == designContext) {
0904: //// return;
0905: //// }
0906: ////
0907: //// detachContext();
0908: //// this.designContext = designContext;
0909: ////
0910: //// if (designContext != null) {
0911: //// designContext.addDesignContextListener(designContextListener);
0912: //// }
0913: // updateDesignContextListening(designContext);
0914: // }
0915:
0916: private void updateDesignContextListening(
0917: DesignContext designContext) {
0918: // XXX By reassigning removing the previous listening -> weak listeners.
0919: designContextListener = new JsfDesignContextListener(this );
0920: designContext
0921: .addDesignContextListener((DesignContextListener) WeakListeners
0922: .create(DesignContextListener.class,
0923: designContextListener, designContext));
0924: }
0925:
0926: // public void detachContext() {
0927: //// // XXX Do not recreate the synchronizer (causes errors).
0928: //// if (domSynchronizer != null) {
0929: //// getDomSynchronizer().detachContext();
0930: //// }
0931: // if (designContext != null) {
0932: // designContext.removeDesignContextListener(designContextListener);
0933: // }
0934: //
0935: // designContext = null;
0936: // }
0937:
0938: DocumentFragment createSourceFragment(MarkupDesignBean bean) {
0939: return getDomSynchronizer().createSourceFragment(bean);
0940: }
0941:
0942: void requestChange(MarkupDesignBean bean) {
0943: getDomSynchronizer().requestChange(bean);
0944: }
0945:
0946: void beanChanged(MarkupDesignBean bean) {
0947: getDomSynchronizer().beanChanged(bean);
0948: }
0949:
0950: void requestTextUpdate(MarkupDesignBean bean) {
0951: getDomSynchronizer().requestTextUpdate(bean);
0952: }
0953:
0954: // << Impl of DomProvider
0955:
0956: //////
0957: // XXX See DomSynchronizer
0958: void modelChanged() {
0959: // designer.modelChanged();
0960: // fireModelChanged();
0961: notifyViewsModelChanged();
0962: }
0963:
0964: // void nodeChanged(Node rendered, Node parent) {
0965: //// designer.nodeChanged(rendered, parent, wasMove);
0966: //// fireNodeChanged(rendered, parent, wasMove);
0967: // notifyViewsNodeChanged(rendered, parent, null);
0968: // }
0969:
0970: void nodeChanged(Node rendered, Node parent,
0971: Element[] changedElements) {
0972: // designer.nodeChanged(rendered, parent, wasMove);
0973: // fireNodeChanged(rendered, parent, wasMove);
0974: notifyViewsNodeChanged(rendered, parent, changedElements);
0975: }
0976:
0977: void nodeRemoved(Node previouslyRendered, Node parent) {
0978: // designer.nodeRemoved(previouslyRendered, parent);
0979: // fireNodeRemoved(previouslyRendered, parent);
0980: notifyViewsNodeRemoved(previouslyRendered, parent);
0981: }
0982:
0983: void nodeInserted(Node rendered, Node parent) {
0984: // designer.nodeInserted(rendered, parent);
0985: // fireNodeInserted(rendered, parent);
0986: notifyViewsNodeInserted(rendered, parent);
0987: }
0988:
0989: // XXX Moved from designer/../WebForm.
0990: /** XXX Moved from FacesSupport. Updates erros in the corresponding component.
0991: * TODO Usage of this after renderHtml call is very suspicious, revise. */
0992: public void updateErrorsInComponent() {
0993: // designer.updateErrorsInComponent();
0994: // fireUpdateErrorsInComponent();
0995:
0996: // FileObject markupFile = getModel().getMarkupFile();
0997: //// <missing designtime api>
0998: //// Exception renderFailure = facesunit.getRenderFailure();
0999: //// MarkupDesignBean renderFailureComponent =
1000: //// (MarkupDesignBean)facesunit.getRenderFailureComponent();
1001: //// ====
1002: // Exception renderFailure = InSyncService.getProvider().getRenderFailure(markupFile);
1003:
1004: // Exception renderFailure = domProvider.getRenderFailure();
1005: //// MarkupDesignBean renderFailureComponent = (MarkupDesignBean)InSyncService.getProvider().getRenderFailureComponent(markupFile);
1006: // MarkupDesignBean renderFailureComponent = domProvider.getRenderFailureMarkupDesignBean();
1007: //
1008: //// </missing designtime api>
1009: //
1010: // setRenderFailedValues(renderFailureComponent, renderFailure);
1011: updateRenderFailureValues();
1012:
1013: // if (renderFailure == null) {
1014: if (!hasRenderFailure()) {
1015: // Since we had a successful render now, we should remember this such
1016: // that if a rendering error happens again, we will show the errorpanel
1017: setRenderFailureShown(false);
1018: }
1019:
1020: // XXX #6472138 Put into AWT.
1021: updateComponentForErrors();
1022: }
1023:
1024: private void updateComponentForErrors() {
1025: if (EventQueue.isDispatchThread()) {
1026: doUpdateComponentForErrors();
1027: } else {
1028: EventQueue.invokeLater(new Runnable() {
1029: public void run() {
1030: doUpdateComponentForErrors();
1031: }
1032: });
1033: }
1034: }
1035:
1036: private void doUpdateComponentForErrors() {
1037: // if (getTopComponent().isShowing()) {
1038: // // In case some kind of rendering error happened
1039: // // Ugh... I need to track this differently!
1040: // getTopComponent().updateErrors();
1041: // }
1042: // domProvider.tcUpdateErrors(this);
1043: notifyViewsUpdateErrors();
1044: }
1045:
1046: void updateGridMode() {
1047: // designer.updateGridMode();
1048: // fireUpdateGridMode(isGridMode());
1049: notifyViewsGridModeUpdated(isGridMode());
1050: }
1051:
1052: public boolean isGridMode() {
1053: // Element body = getHtmlBody();
1054: //
1055: // if (body == null) {
1056: // return false;
1057: // }
1058: //
1059: //// Value val = CssLookup.getValue(b, XhtmlCss.RAVELAYOUT_INDEX);
1060: // CssValue cssValue = CssProvider.getEngineService().getComputedValueForElement(body, XhtmlCss.RAVELAYOUT_INDEX);
1061: //
1062: //// return val == CssValueConstants.GRID_VALUE;
1063: // return CssProvider.getValueService().isGridValue(cssValue);
1064: return Util.isGridMode(getFacesModel());
1065: }
1066:
1067: void documentReplaced() {
1068: // designer.documentReplaced();
1069: // fireDocumentReplaced();
1070: notifyViewsDocumentReplaced();
1071: }
1072:
1073: void showDropMatch(Element componentRootElement,
1074: Element regionElement, int dropType) {
1075: notifyViewsShowDropMatch(componentRootElement, regionElement,
1076: dropType);
1077: }
1078:
1079: void clearDropMatch() {
1080: notifyViewsClearDropMatch();
1081: }
1082:
1083: void selectComponent(Element componentRootElement) {
1084: notifyViewsSelectComponent(componentRootElement);
1085: }
1086:
1087: void inlineEditComponents(Element[] componentRootElements) {
1088: notifyViewsInlineEditComponents(componentRootElements);
1089: }
1090:
1091: // public void clearHtml() {
1092: //// InSyncServiceProvider.get().clearHtmlForMarkupFile(getFacesModel().getMarkupFile());
1093: // getFacesModel().clearHtml();
1094: // }
1095: // XXX
1096: //////
1097:
1098: private DomSynchronizer getDomSynchronizer() {
1099: if (domSynchronizer == null) {
1100: domSynchronizer = new DomSynchronizer(this );
1101: }
1102: return domSynchronizer;
1103: }
1104:
1105: FacesDndSupport.UpdateSuspender getUpdateSuspender() {
1106: return getDomSynchronizer();
1107: }
1108:
1109: //////
1110: // XXX See DomProvider interface.
1111: void requestRefresh() {
1112: getDomSynchronizer().requestRefresh();
1113: }
1114:
1115: public void refreshModelWithExternals(boolean deep) {
1116: JsfForm[] externals = findExternals();
1117: for (JsfForm jsfForm : externals) {
1118: jsfForm.refreshModel(deep);
1119: }
1120:
1121: refreshModel(deep);
1122: }
1123:
1124: private JsfForm[] findExternals() {
1125: Designer[] designers = findDesigners(this );
1126: if (designers.length == 0) {
1127: return new JsfForm[0];
1128: }
1129: Designer designer = designers[0];
1130: DomProvider[] domProviders = designer.getExternalDomProviders();
1131: List<JsfForm> externals = new ArrayList<JsfForm>();
1132: for (DomProvider domProvider : domProviders) {
1133: JsfForm external = findJsfFormForDomProvider(domProvider);
1134: if (external == null) {
1135: continue;
1136: }
1137: if (external == this ) {
1138: // Skip this one.
1139: continue;
1140: }
1141: externals.add(external);
1142: }
1143: return externals.toArray(new JsfForm[externals.size()]);
1144: }
1145:
1146: public void refreshModel(boolean deep) {
1147: getFacesModel().refreshAndSyncNonPageBeans(deep);
1148: // XXX Moved from designer/../WebForm.
1149: externalDomProviderCache.flush();
1150:
1151: // fireModelRefreshed();
1152: notifyViewsModelRefreshed();
1153: }
1154:
1155: public void refreshProject() {
1156: // XXX Moved from designer/DesignerTopComp#componentShowing.
1157: Project project = getFacesModel().getProject();
1158: // XXX uh oh, what if I refresh THIS project but not other projects.... and
1159: // you edit stylesheets from different projects? Notagood! Do I really need to
1160: // refresh ALL projects?
1161: if (project != null) {
1162: RefreshServiceImpl.refreshProject(project, false);
1163:
1164: // Prevent refreshing all for every update since a refresh could be
1165: // sort of expensive. (It doesn't actually update layout on all pages,
1166: // but does scan the entire project for pages and clears associated caches
1167: // etc.
1168: }
1169: }
1170:
1171: // public void destroyDomSynchronizer() {
1172: // // XXX Revise.
1173: // if (domSynchronizer != null) {
1174: // getDomSynchronizer().destroy();
1175: // }
1176: // domSynchronizer = null;
1177: // }
1178: // XXX
1179: //////
1180:
1181: // public boolean editEventHandlerForDesignBean(DesignBean designBean) {
1182: // if (designBean == null) {
1183: //// webform.getModel().openDefaultHandler(component);
1184: // getFacesModel().openDefaultHandler();
1185: // return false;
1186: // } else {
1187: // // See if it's an XHTML element; if so just show it in
1188: // // the JSP source
1189: //// if (FacesSupport.isXhtmlComponent(component)) {
1190: // if (isXhtmlComponent(designBean)) {
1191: //// MarkupBean mb = FacesSupport.getMarkupBean(component);
1192: // MarkupBean mb = Util.getMarkupBean(designBean);
1193: //
1194: //// MarkupUnit unit = webform.getMarkup();
1195: // MarkupUnit unit = getFacesModel().getMarkupUnit();
1196: // // <markup_separation>
1197: //// Util.show(null, unit.getFileObject(),
1198: //// unit.computeLine((RaveElement)mb.getElement()), 0, true);
1199: // // ====
1200: //// MarkupService.show(unit.getFileObject(), unit.computeLine((RaveElement)mb.getElement()), 0, true);
1201: // showLineAt(unit.getFileObject(), unit.computeLine(mb.getElement()), 0);
1202: // // </markup_separation>
1203: // } else {
1204: //// webform.getModel().openDefaultHandler(component);
1205: // getFacesModel().openDefaultHandler(designBean);
1206: // }
1207: //
1208: // return true;
1209: // }
1210: // }
1211:
1212: // // XXX Copied from DesignerActions.
1213: // /** Return true iff the given DesignBean is an XHTML markup "component" */
1214: // private static boolean isXhtmlComponent(DesignBean bean) {
1215: //// MarkupBean mb = FacesSupport.getMarkupBean(bean);
1216: // MarkupBean mb = Util.getMarkupBean(bean);
1217: //
1218: // return (mb != null) && !(mb instanceof FacesBean);
1219: // }
1220: //
1221: // // XXX Copied from MarkupUtilities.
1222: // // XXX Copied from DesignerActions.
1223: // private static void showLineAt(FileObject fo, int lineno, int column) {
1224: // DataObject dobj;
1225: // try {
1226: // dobj = DataObject.find(fo);
1227: // }
1228: // catch (DataObjectNotFoundException ex) {
1229: // ErrorManager.getDefault().notify(ex);
1230: // return;
1231: // }
1232: //
1233: // // Try to open doc before showing the line. This SHOULD not be
1234: // // necessary, except without this the IDE hangs in its attempt
1235: // // to open the file when the file in question is a CSS file.
1236: // // Probably a bug in the xml/css module's editorsupport code.
1237: // // This has the negative effect of first flashing the top
1238: // // of the file before showing the destination line, so
1239: // // this operation is made conditional so only clients who
1240: // // actually need it need to use it.
1241: // EditorCookie ec = (EditorCookie)dobj.getCookie(EditorCookie.class);
1242: // if (ec != null) {
1243: // try {
1244: // ec.openDocument(); // ensure that it has been opened - REDUNDANT?
1245: // //ec.open();
1246: // }
1247: // catch (IOException ex) {
1248: // ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
1249: // }
1250: // }
1251: //
1252: // LineCookie lc = (LineCookie)dobj.getCookie(LineCookie.class);
1253: // if (lc != null) {
1254: // Line.Set ls = lc.getLineSet();
1255: // if (ls != null) {
1256: // // -1: convert line numbers to be zero-based
1257: // Line line = ls.getCurrent(lineno-1);
1258: // // TODO - pass in a column too?
1259: // line.show(Line.SHOW_GOTO, column);
1260: // }
1261: // }
1262: // }
1263:
1264: public String toString() {
1265: return super .toString() + "[facesModel=" + getFacesModel()
1266: + "]"; // NOI18N
1267: }
1268:
1269: // >>> DnD
1270: // public DataFlavor getImportFlavor(DataFlavor[] flavors) {
1271: // return FacesDnDSupport.getImportFlavor(flavors);
1272: // }
1273:
1274: // public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
1275: // return getFacesModel().getDnDSupport().canImport(comp, transferFlavors);
1276: // }
1277:
1278: // public DesignBean[] pasteBeans(Transferable t, DesignBean parent, MarkupPosition pos, Point location, DomProvider.CoordinateTranslator coordinateTranslator) {
1279: // return getFacesModel().getDnDSupport().pasteBeans(t, parent, pos, location, new CoordinateTranslatorImpl(coordinateTranslator), getDomSynchronizer());
1280: // }
1281:
1282: // public void importData(JComponent comp, Transferable t, Object transferData, Dimension dimension, omProvider.Location location, DomProvider.CoordinateTranslator coordinateTranslator, int dropAction) {
1283: // getFacesModel().getDnDSupport().importData(comp, t, transferData, dimension, new LocationImpl(location), new CoordinateTranslatorImpl(coordinateTranslator), getDomSynchronizer(), dropAction);
1284: // }
1285:
1286: // public DesignBean findHtmlContainer(DesignBean parent) {
1287: // return Util.findHtmlContainer(parent);
1288: // }
1289:
1290: // public String[] getClassNames(DisplayItem[] displayItems) {
1291: // return getFacesModel().getDnDSupport().getClasses(displayItems);
1292: // }
1293:
1294: // public boolean importBean(DisplayItem[] items, DesignBean origParent, int nodePos, String facet, List createdBeans, DomProvider.Location location, DomProvider.CoordinateTranslator coordinateTranslator)
1295: // throws IOException {
1296: // return getFacesModel().getDnDSupport().importBean(items, origParent, nodePos, facet, createdBeans, new LocationImpl(location), new CoordinateTranslatorImpl(coordinateTranslator), getDomSynchronizer());
1297: // }
1298:
1299: // public MarkupPosition getDefaultPositionUnderParent(DesignBean parent) {
1300: // return FacesDnDSupport.getDefaultMarkupPositionUnderParent(parent, getFacesModel());
1301: // }
1302:
1303: // public int computeActions(DesignBean droppee, Transferable transferable, boolean searchUp, int nodePos) {
1304: // return getFacesModel().getDnDSupport().computeActions(droppee, transferable, searchUp, nodePos);
1305: // }
1306:
1307: // public DesignBean findParent(String className, DesignBean droppee, Node parentNode, boolean searchUp) {
1308: // return Util.findParent(className, droppee, parentNode, searchUp, getFacesModel());
1309: // }
1310:
1311: // public int processLinks(Element origElement, Class[] classes, List beans, boolean selectFirst, boolean handleLinks, boolean showLinkTarget) {
1312: // return getFacesModel().getDnDSupport().processLinks(origElement, classes, beans, selectFirst, handleLinks, showLinkTarget, getDomSynchronizer());
1313: // }
1314:
1315: // public boolean setDesignProperty(DesignBean bean, String attribute, int length) {
1316: // return Util.setDesignProperty(bean, attribute, length);
1317: // }
1318:
1319: // <<< DnD
1320:
1321: // public void removeForDataObject(DataObject dobj) {
1322: // removeJsfFormForDataObject(dobj);
1323: // }
1324:
1325: public boolean isFragment() {
1326: return isFragment;
1327: }
1328:
1329: public boolean isPortlet() {
1330: return isPortlet;
1331: }
1332:
1333: // public DataObject getJspDataObject() {
1334: // FileObject file = getFacesModel().getMarkupFile();
1335: //
1336: // try {
1337: // return DataObject.find(file);
1338: // } catch (DataObjectNotFoundException dnfe) {
1339: // ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, dnfe);
1340: //
1341: // return null;
1342: // }
1343: // }
1344:
1345: // void addDomProviderListener(DomProvider.DomProviderListener l) {
1346: // listenerList.add(DomProvider.DomProviderListener.class, l);
1347: // }
1348: //
1349: // void removeDomProviderListener(DomProvider.DomProviderListener l) {
1350: // listenerList.remove(DomProvider.DomProviderListener.class, l);
1351: // }
1352:
1353: // private DomProvider.DomProviderListener[] getDomProviderListeners() {
1354: // // Guaranteed to return a non-null array
1355: // Object[] listeners = listenerList.getListenerList();
1356: //
1357: // List<DomProvider.DomProviderListener> dDomProviderListeners = new ArrayList<DomProvider.DomProviderListener>();
1358: // // Process the listeners last to first, notifying
1359: // // those that are interested in this event
1360: // for (int i = listeners.length-2; i>=0; i-=2) {
1361: // if (listeners[i] == DomProvider.DomProviderListener.class) {
1362: // domProviderListeners.add((DomProvider.DomProviderListener)listeners[i+1]);
1363: // }
1364: // }
1365: // return domProviderListeners.toArray(new DomProvider.DomProviderListener[domProviderListeners.size()]);
1366: // }
1367:
1368: // private void fireModelChanged() {
1369: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1370: // for (DomProvider.DomProviderListener listener : listeners) {
1371: // listener.modelChanged();
1372: // }
1373: // }
1374: private void notifyViewsModelChanged() {
1375: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1376: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1377: jsfMultiViewElement.modelChanged();
1378: }
1379: }
1380:
1381: // private void fireModelRefreshed() {
1382: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1383: // for (DomProvider.DomProviderListener listener : listeners) {
1384: // listener.modelRefreshed();
1385: // }
1386: // }
1387: private void notifyViewsModelRefreshed() {
1388: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1389: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1390: jsfMultiViewElement.modelRefreshed();
1391: }
1392: }
1393:
1394: // private void fireNodeChanged(Node rendered, Node parent, boolean wasMove) {
1395: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1396: // for (DomProvider.DomProviderListener listener : listeners) {
1397: // listener.nodeChanged(rendered, parent, wasMove);
1398: // }
1399: // }
1400: private void notifyViewsNodeChanged(Node node, Node parent,
1401: Element[] changedElements) {
1402: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1403: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1404: jsfMultiViewElement.nodeChanged(node, parent,
1405: changedElements);
1406: }
1407: }
1408:
1409: // private void fireNodeRemoved(Node previouslyRendered, Node parent) {
1410: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1411: // for (DomProvider.DomProviderListener listener : listeners) {
1412: // listener.nodeRemoved(previouslyRendered, parent);
1413: // }
1414: // }
1415: private void notifyViewsNodeRemoved(Node node, Node parent) {
1416: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1417: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1418: jsfMultiViewElement.nodeRemoved(node, parent);
1419: }
1420: }
1421:
1422: // private void fireNodeInserted(Node rendered, Node parent) {
1423: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1424: // for (DomProvider.DomProviderListener listener : listeners) {
1425: // listener.nodeInserted(rendered, parent);
1426: // }
1427: // }
1428: private void notifyViewsNodeInserted(Node node, Node parent) {
1429: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1430: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1431: jsfMultiViewElement.nodeInserted(node, parent);
1432: }
1433: }
1434:
1435: // private void fireUpdateErrorsInComponent() {
1436: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1437: // for (DomProvider.DomProviderListener listener : listeners) {
1438: // listener.updateErrorsInComponent();
1439: // }
1440: // }
1441:
1442: // private void fireUpdateGridMode(boolean gridMode) {
1443: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1444: // for (DomProvider.DomProviderListener listener : listeners) {
1445: // listener.gridModeUpdated(gridMode);
1446: // }
1447: // }
1448: private void notifyViewsGridModeUpdated(boolean gridMode) {
1449: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1450: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1451: jsfMultiViewElement.gridModeUpdated(gridMode);
1452: }
1453: }
1454:
1455: // private void fireDocumentReplaced() {
1456: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1457: // for (DomProvider.DomProviderListener listener : listeners) {
1458: // listener.documentReplaced();
1459: // }
1460: // }
1461: private void notifyViewsDocumentReplaced() {
1462: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1463: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1464: jsfMultiViewElement.documentReplaced();
1465: }
1466: }
1467:
1468: // void fireShowDropMatch(Element componentRootElement, Element regionElement, int dropType) {
1469: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1470: // for (DomProvider.DomProviderListener listener : listeners) {
1471: // listener.showDropMatch(componentRootElement, regionElement, dropType);
1472: // }
1473: // }
1474: private void notifyViewsShowDropMatch(Element componentRootElement,
1475: Element regionElement, int dropType) {
1476: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1477: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1478: jsfMultiViewElement.showDropMatch(componentRootElement,
1479: regionElement, dropType);
1480: }
1481: }
1482:
1483: // void fireClearDropMatch() {
1484: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1485: // for (DomProvider.DomProviderListener listener : listeners) {
1486: // listener.clearDropMatch();
1487: // }
1488: // }
1489: private void notifyViewsClearDropMatch() {
1490: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1491: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1492: jsfMultiViewElement.clearDropMatch();
1493: }
1494: }
1495:
1496: // void fireSelect(DesignBean designBean) {
1497: // Element componentRootElement = JsfSupportUtilities.getComponentRootElementForDesignBean(designBean);
1498: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1499: // for (DomProvider.DomProviderListener listener : listeners) {
1500: //// listener.select(designBean);
1501: // listener.select(componentRootElement);
1502: // }
1503: // }
1504: private void notifyViewsSelectComponent(Element componentRootElement) {
1505: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1506: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1507: jsfMultiViewElement.selectComponent(componentRootElement);
1508: }
1509: }
1510:
1511: // private void fireRefreshForm(boolean deep) {
1512: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1513: // for (DomProvider.DomProviderListener listener : listeners) {
1514: // listener.refreshForm(deep);
1515: // }
1516: // }
1517:
1518: // void fireInlineEdit(DesignBean[] designBeans) {
1519: // List<Element> componentRootElements = new ArrayList<Element>();
1520: // for (DesignBean designBean : designBeans) {
1521: // Element componentRootElement = JsfSupportUtilities.getComponentRootElementForDesignBean(designBean);
1522: // if (componentRootElement != null) {
1523: // componentRootElements.add(componentRootElement);
1524: // }
1525: // }
1526: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1527: // for (DomProvider.DomProviderListener listener : listeners) {
1528: //// listener.inlineEdit(designBeans);
1529: // listener.inlineEdit(componentRootElements.toArray(new Element[componentRootElements.size()]));
1530: // }
1531: // }
1532: private void notifyViewsInlineEditComponents(
1533: Element[] componentRootElements) {
1534: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
1535: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1536: jsfMultiViewElement
1537: .inlineEditComponents(componentRootElements);
1538: }
1539: }
1540:
1541: // private void fireDesignContextActivated(DesignContext designContext) {
1542: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1543: // for (DomProvider.DomProviderListener listener : listeners) {
1544: // listener.designContextActivated(designContext);
1545: // }
1546: // }
1547:
1548: // private void fireDesignContextDeactivated(DesignContext designContext) {
1549: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1550: // for (DomProvider.DomProviderListener listener : listeners) {
1551: // listener.designContextDeactivated(designContext);
1552: // }
1553: // }
1554:
1555: private void notifyViewsUpdateErrors() {
1556: JsfMultiViewElement[] jsfMultiViewElements = JsfForm
1557: .findJsfMultiViewElements(this );
1558: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1559: jsfMultiViewElement.updateErrors();
1560: }
1561: }
1562:
1563: private void notifyViewsDesignContextGenerationChanged() {
1564: JsfMultiViewElement[] jsfMultiViewElements = JsfForm
1565: .findJsfMultiViewElements(this );
1566: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
1567: jsfMultiViewElement.designContextGenerationChanged();
1568: }
1569: }
1570:
1571: // XXX Hack to skip firing events if the generation is the same. Old code moved from designer.
1572: private long generationSeen = 0L;
1573:
1574: private void designContextChanged(DesignContext designContext) {
1575: long currentGeneration;
1576: if (designContext instanceof LiveUnit) {
1577: currentGeneration = ((LiveUnit) designContext)
1578: .getContextGeneration();
1579: } else {
1580: currentGeneration = 0L;
1581: }
1582:
1583: if (currentGeneration == generationSeen) {
1584: // XXX Skip event firing.
1585: return;
1586: }
1587: generationSeen = currentGeneration;
1588:
1589: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1590: // for (DomProvider.DomProviderListener listener : listeners) {
1591: //// listener.designContextChanged(designContext);
1592: // listener.designContextGenerationChanged();
1593: // }
1594: notifyViewsDesignContextGenerationChanged();
1595: }
1596:
1597: // private void fireDesignBeanCreated(DesignBean designBean) {
1598: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1599: // for (DomProvider.DomProviderListener listener : listeners) {
1600: // listener.designBeanCreated(designBean);
1601: // }
1602: // }
1603:
1604: // private void fireDesignBeanDeleted(DesignBean designBean) {
1605: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1606: // for (DomProvider.DomProviderListener listener : listeners) {
1607: // listener.designBeanDeleted(designBean);
1608: // }
1609: // }
1610:
1611: // private void fireDesignBeanMoved(DesignBean designBean, DesignBean designBean0, Position position) {
1612: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1613: // for (DomProvider.DomProviderListener listener : listeners) {
1614: // listener.designBeanMoved(designBean, designBean0, position);
1615: // }
1616: // }
1617:
1618: // private void fireDesignBeanContextActivated(DesignBean designBean) {
1619: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1620: // for (DomProvider.DomProviderListener listener : listeners) {
1621: // listener.designBeanContextActivated(designBean);
1622: // }
1623: // }
1624:
1625: // private void fireDesignBeanContextDeactivated(DesignBean designBean) {
1626: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1627: // for (DomProvider.DomProviderListener listener : listeners) {
1628: // listener.designBeanContextDeactivated(designBean);
1629: // }
1630: // }
1631:
1632: // private void fireDesignBeanNameChanged(DesignBean designBean, String string) {
1633: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1634: // for (DomProvider.DomProviderListener listener : listeners) {
1635: // listener.designBeanNameChanged(designBean, string);
1636: // }
1637: // }
1638:
1639: // private void fireDesignBeanChanged(DesignBean designBean) {
1640: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1641: // for (DomProvider.DomProviderListener listener : listeners) {
1642: // listener.designBeanChanged(designBean);
1643: // }
1644: // }
1645:
1646: // private void fireDesignPropertyChanged(DesignProperty designProperty, Object object) {
1647: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1648: // for (DomProvider.DomProviderListener listener : listeners) {
1649: // listener.designPropertyChanged(designProperty, object);
1650: // }
1651: // }
1652:
1653: // private void fireDesignEventChanged(DesignEvent designEvent) {
1654: // DomProvider.DomProviderListener[] listeners = getDomProviderListeners();
1655: // for (DomProvider.DomProviderListener listener : listeners) {
1656: // listener.designEventChanged(designEvent);
1657: // }
1658: // }
1659:
1660: // public URL getBaseUrl() {
1661: // MarkupUnit markupUnit = getFacesModel().getMarkupUnit();
1662: // if (markupUnit == null) {
1663: // // #6457856 NPE
1664: // return null;
1665: // }
1666: // return markupUnit.getBase();
1667: // }
1668:
1669: // public URL resolveUrl(String urlString) {
1670: //// return InSyncServiceProvider.get().resolveUrl(getBaseUrl(), getJspDom(), urlString);
1671: // return Util.resolveUrl(getBaseUrl(), getJspDom(), urlString);
1672: // }
1673:
1674: // public DocumentFragment renderHtmlForMarkupDesignBean(MarkupDesignBean markupDesignBean) {
1675: // return FacesPageUnit.renderHtml(getFacesModel(), markupDesignBean);
1676: // }
1677:
1678: // public Exception getRenderFailure() {
1679: // FacesPageUnit facesPageUnit = getFacesModel().getFacesUnit();
1680: // if (facesPageUnit == null) {
1681: // return null;
1682: // }
1683: // return facesPageUnit.getRenderFailure();
1684: // }
1685:
1686: // public MarkupDesignBean getRenderFailureMarkupDesignBean() {
1687: // FacesPageUnit facesPageUnit = getFacesModel().getFacesUnit();
1688: // if (facesPageUnit == null) {
1689: // return null;
1690: // }
1691: // DesignBean designBean = facesPageUnit.getRenderFailureComponent();
1692: // if (designBean instanceof MarkupDesignBean) {
1693: // return (MarkupDesignBean)designBean;
1694: // } else {
1695: // return null;
1696: // }
1697: // }
1698:
1699: // public List<FileObject> getWebPageFileObjectsInThisProject() {
1700: //// return InSyncServiceProvider.get().getWebPages(getFacesModel().getProject(), true, false);
1701: // return Util.getWebPages(getFacesModel().getProject(), true, false);
1702: // }
1703:
1704: public PaletteController getPaletteController() {
1705: return paletteController;
1706: }
1707:
1708: // public boolean isBraveheartPage() {
1709: // return Util.isBraveheartPage(getJspDom());
1710: // }
1711:
1712: // public boolean isWoodstockPage() {
1713: // return Util.isWoodstockPage(getJspDom());
1714: // }
1715:
1716: static void refreshDesignersInProject(Project project) {
1717: JsfForm[] jsfForms = findJsfFormsForProject(project);
1718: for (JsfForm jsfForm : jsfForms) {
1719: jsfForm.refreshProject();
1720: }
1721: }
1722:
1723: private static JsfForm[] findJsfFormsForProject(Project project) {
1724: if (project == null) {
1725: return new JsfForm[0];
1726: }
1727: List<JsfForm> projectJsfForms = new ArrayList<JsfForm>();
1728: Set<JsfForm> allJsfForms;
1729: // synchronized (jsfForm2designerSet) {
1730: // allJsfForms = jsfForm2designerSet.keySet();
1731: // }
1732: // synchronized (jsfForms) {
1733: jsfFormsLock.readLock().lock();
1734: try {
1735: allJsfForms = new HashSet<JsfForm>(jsfForms);
1736: } finally {
1737: jsfFormsLock.readLock().unlock();
1738: }
1739: for (JsfForm jsfForm : allJsfForms) {
1740: if (project == jsfForm.getFacesModel().getProject()
1741: && !projectJsfForms.contains(jsfForm)) {
1742: projectJsfForms.add(jsfForm);
1743: }
1744: }
1745: return projectJsfForms.toArray(new JsfForm[projectJsfForms
1746: .size()]);
1747: }
1748:
1749: private void updateRenderFailureValues() {
1750: Exception failure = getRenderFailure();
1751: MarkupDesignBean renderFailureComponent = getRenderFailureMarkupDesignBean();
1752: setRenderFailureValues(renderFailureComponent, failure);
1753: }
1754:
1755: private/*public*/Exception getRenderFailure() {
1756: FacesPageUnit facesPageUnit = getFacesModel().getFacesUnit();
1757: if (facesPageUnit == null) {
1758: return null;
1759: }
1760: return facesPageUnit.getRenderFailure();
1761: }
1762:
1763: private/*public*/MarkupDesignBean getRenderFailureMarkupDesignBean() {
1764: FacesPageUnit facesPageUnit = getFacesModel().getFacesUnit();
1765: if (facesPageUnit == null) {
1766: return null;
1767: }
1768: DesignBean designBean = facesPageUnit
1769: .getRenderFailureComponent();
1770: if (designBean instanceof MarkupDesignBean) {
1771: return (MarkupDesignBean) designBean;
1772: } else {
1773: return null;
1774: }
1775: }
1776:
1777: private void setRenderFailureValues(
1778: MarkupDesignBean renderFailureComponent,
1779: Exception renderFailureException) {
1780: this .renderFailureComponent = renderFailureComponent;
1781: this .renderFailureException = renderFailureException;
1782: }
1783:
1784: private boolean hasRenderFailure() {
1785: return getRenderFailureException() != null;
1786: }
1787:
1788: Exception getRenderFailureException() {
1789: return renderFailureException;
1790: }
1791:
1792: MarkupDesignBean getRenderFailureComponent() {
1793: return renderFailureComponent;
1794: }
1795:
1796: DndSupport getDndSupport() {
1797: return dndSupport;
1798: }
1799:
1800: FacesModel.JsfSupport getJsfSupport() {
1801: // XXX
1802: return getDndSupport();
1803: }
1804:
1805: public Element getHtmlBody() {
1806: // return domProvider.getHtmlBody();
1807: return getHtmlBody(true);
1808: }
1809:
1810: // XXX Side effect, updating errors, old code.
1811: public Element getHtmlBody(boolean updateErrors) {
1812: // XXX Model should be valid always.
1813: if (!isModelValid()) {
1814: return null;
1815: }
1816:
1817: Element body = getFacesModel().getHtmlBody();
1818:
1819: // XXX #6472138 FIXME Is this correct here?
1820: if (updateErrors) {
1821: updateErrorsInComponent();
1822: }
1823: return body;
1824: }
1825:
1826: public Document getJspDom() {
1827: // return domProvider.getJspDom();
1828: return getFacesModel().getJspDom();
1829: }
1830:
1831: public Document getHtmlDom() {
1832: // return domProvider.getHtmlDom();
1833: return getFacesModel().getHtmlDom();
1834: }
1835:
1836: public Element createComponent(String className, Node parent,
1837: Node before) {
1838: // return domProvider.createComponent(className, parent, before);
1839: DesignBean designBean = createBean(className, parent, before);
1840: return designBean instanceof MarkupDesignBean ? ((MarkupDesignBean) designBean)
1841: .getElement()
1842: : null;
1843: }
1844:
1845: // XXX Copy also in insync/FacesDnDSupport.
1846: /*public*/private DesignBean createBean(String className,
1847: Node parent, Node before) {
1848: MarkupPosition pos = new MarkupPosition(parent, before);
1849: DesignBean parentBean = /*FacesSupport.*/Util
1850: .findParentBean(parent);
1851: LiveUnit unit = getFacesModel().getLiveUnit();
1852: return unit.createBean(className, parentBean, pos);
1853: }
1854:
1855: public boolean moveComponent(Element componentRootElement,
1856: Node parentNode, Node before) {
1857: // return domProvider.moveComponent(componentRootElement, parentNode, before);
1858: MarkupDesignBean bean = MarkupUnit
1859: .getMarkupDesignBeanForElement(componentRootElement);
1860: if (bean == null) {
1861: return false;
1862: }
1863:
1864: // LiveUnit lu = getFacesModel().getLiveUnit();
1865: LiveUnit lu = getLiveUnit();
1866: MarkupPosition markupPos = new MarkupPosition(parentNode,
1867: before);
1868: DesignBean parentBean = null;
1869: Node e = parentNode;
1870:
1871: while (e != null) {
1872: // if (e instanceof RaveElement) {
1873: // parentBean = ((RaveElement)e).getDesignBean();
1874: if (e instanceof Element) {
1875: // parentBean = InSyncService.getProvider().getMarkupDesignBeanForElement((Element)e);
1876: parentBean = MarkupUnit
1877: .getMarkupDesignBeanForElement((Element) e);
1878:
1879: if (parentBean != null) {
1880: break;
1881: }
1882: }
1883:
1884: e = e.getParentNode();
1885: }
1886:
1887: if (bean == parentBean) {
1888: return false;
1889: }
1890:
1891: return lu.moveBean(bean, parentBean, markupPos);
1892: }
1893:
1894: public boolean isInlineEditing() {
1895: Designer[] designers = findDesigners(this );
1896: for (Designer designer : designers) {
1897: if (designer.isInlineEditing()) {
1898: return true;
1899: }
1900: }
1901:
1902: return false;
1903: }
1904:
1905: // public WriteLock writeLock(String message) {
1906: // return domProvider.writeLock(message);
1907: // }
1908: //
1909: // public void writeUnlock(WriteLock writeLock) {
1910: // domProvider.writeUnlock(writeLock);
1911: // }
1912: public UndoEvent writeLock(String message) {
1913: return getFacesModel().writeLock(message);
1914: }
1915:
1916: public void writeUnlock(UndoEvent writeLock) {
1917: getFacesModel().writeUnlock(writeLock);
1918: }
1919:
1920: // public void deleteComponent(Element componentRootElement) {
1921: // domProvider.deleteComponent(componentRootElement);
1922: // }
1923:
1924: public DomDocumentImpl getDomDocumentImpl() {
1925: return domDocumentImpl;
1926: }
1927:
1928: public boolean isModelInSync() {
1929: if (isValid()) {
1930: FacesModel facesModel = getFacesModel();
1931: if (facesModel == null) {
1932: return false;
1933: }
1934: MarkupUnit markupUnit = facesModel.getMarkupUnit();
1935: if (markupUnit == null) {
1936: return false;
1937: }
1938: if (markupUnit.getState() == Unit.State.SOURCEDIRTY) {
1939: return false;
1940: }
1941: JavaUnit javaUnit = facesModel.getJavaUnit();
1942: if (javaUnit == null) {
1943: return false;
1944: }
1945: if (javaUnit.getState() == Unit.State.SOURCEDIRTY) {
1946: return false;
1947: } else {
1948: return true;
1949: }
1950: }
1951: return false;
1952: }
1953:
1954: public/*private*/void syncModel() {
1955: // domProvider.syncModel();
1956: if (isValid()) {
1957: getFacesModel().sync();
1958: }
1959: }
1960:
1961: public void setModelActivated(boolean activated) {
1962: // domProvider.setModelActivated(activated);
1963: getFacesModel().setActivated(activated);
1964: }
1965:
1966: boolean isModelValid() {
1967: // XXX
1968: FacesModel facesModel = getFacesModel();
1969: if (facesModel == null) {
1970: // XXX #115851 Possible NPE. It means, this was called during loading.
1971: return false;
1972: }
1973: MarkupUnit markupUnit = facesModel.getMarkupUnit();
1974: if (markupUnit == null) {
1975: return false;
1976: }
1977: return facesModel.isValid();
1978: }
1979:
1980: public boolean isModelBusted() {
1981: // return domProvider.isModelBusted();
1982: return getFacesModel().isBusted();
1983: }
1984:
1985: public/*private*/void clearHtml() {
1986: // domProvider.clearHtml();
1987: getFacesModel().clearHtml();
1988: }
1989:
1990: public DataObject getJspDataObject() {
1991: // return domProvider.getJspDataObject();
1992: FileObject file = getMarkupFile();
1993:
1994: try {
1995: return DataObject.find(file);
1996: } catch (DataObjectNotFoundException ex) {
1997: log(ex);
1998:
1999: return null;
2000: }
2001: }
2002:
2003: public void deleteDesignBean(DesignBean designBean) {
2004: getFacesModel().getLiveUnit().deleteBean(designBean);
2005: }
2006:
2007: public void setUpdatesSuspended(Element componentRootElement,
2008: boolean suspend) {
2009: // domProvider.setUpdatesSuspended(componentRootElement, suspend);
2010: MarkupDesignBean markupDesignBean = MarkupUnit
2011: .getMarkupDesignBeanForElement(componentRootElement);
2012: setUpdatesSuspended(markupDesignBean, suspend);
2013: }
2014:
2015: public boolean isWriteLocked() {
2016: return getFacesModel().isWriteLocked();
2017: }
2018:
2019: public void snapToGrid(Designer designer) {
2020: getDomDocumentImpl().snapToGrid(designer);
2021: }
2022:
2023: public void align(Designer designer, Alignment alignment) {
2024: getDomDocumentImpl().align(designer, alignment);
2025: }
2026:
2027: /** Alignments. */
2028: public enum Alignment {
2029: SNAP_TO_GRID, TOP, MIDDLE, BOTTOM, LEFT, CENTER, RIGHT
2030: } // End of Alignment.
2031:
2032: private static final DataFlavor FLAVOR_DISPLAY_ITEM = new DataFlavor(
2033: DataFlavor.javaJVMLocalObjectMimeType + "; class="
2034: + DisplayItem.class.getName(), // NOI18N
2035: "RAVE_PALETTE_ITEM"); // TODO get rid of such name.
2036:
2037: public boolean canPasteTransferable(
2038: Element[] selectedComponentElements, Transferable trans) {
2039: // return domProvider.canPasteTransferable(trans);
2040: if (trans != null) {
2041: DataFlavor[] df = trans.getTransferDataFlavors();
2042: int n = 0;
2043:
2044: if (df != null) {
2045: n = df.length;
2046: }
2047:
2048: for (int i = 0; i < n; i++) {
2049: DataFlavor flavor = df[i];
2050:
2051: // // XXX TODO Get rid of this dep, you can specify your own data flavor
2052: // // which can match, there will be created new data flavors avoiding
2053: // // usage of .
2054: // if (FLAVOR_DISPLAY_ITEM.equals(flavor)
2055: // || (flavor.getRepresentationClass() == String.class)
2056: // || flavor.getMimeType().startsWith("application/x-creator-")) { // NOI18N
2057: // // Yes!
2058: // return true;
2059: // }
2060: // XXX TODO Get rid of this dep, you can specify your own data flavor
2061: // which can match, there will be created new data flavors avoiding
2062: // usage of .
2063: if (FLAVOR_DISPLAY_ITEM.equals(flavor)
2064: || (flavor.getRepresentationClass() == String.class)) {
2065: // Yes!
2066: return true;
2067: } else if (flavor.getMimeType().startsWith(
2068: "application/x-creator-")) { // NOI18N
2069: // XXX #94718 There is API needed (from designtime/insync).
2070: FacesModel facesModel = getFacesModel();
2071: if (facesModel == null) {
2072: return false;
2073: }
2074: LiveUnit liveUnit = facesModel.getLiveUnit();
2075: if (liveUnit == null) {
2076: return false;
2077: }
2078: DesignBean selectedBean = getPrimarySelectedBean(selectedComponentElements);
2079: if (selectedBean == null) {
2080: DesignBean defaultParentBean = getDefaultParentBean();
2081: selectedBean = defaultParentBean;
2082: }
2083: if (selectedBean == null) {
2084: // Log?
2085: return false;
2086: }
2087: try {
2088: Object transferData = trans
2089: .getTransferData(flavor);
2090: if (transferData instanceof LiveUnit.ClipImage) {
2091: LiveUnit.ClipImage clipImage = (LiveUnit.ClipImage) transferData;
2092: String[] types = clipImage.getTypes();
2093: for (String className : types) {
2094: if (liveUnit.canCreateBean(className,
2095: selectedBean, null)) {
2096: return true;
2097: }
2098: }
2099: }
2100: } catch (UnsupportedFlavorException ex) {
2101: Exceptions.printStackTrace(ex);
2102: } catch (IOException ex) {
2103: Exceptions.printStackTrace(ex);
2104: }
2105: }
2106: }
2107: }
2108: return false;
2109: }
2110:
2111: private MarkupDesignBean getPrimarySelectedBean(
2112: Element[] selectedComponentElements) {
2113: for (Element componentRootElement : selectedComponentElements) {
2114: MarkupDesignBean markupDesignBean = MarkupUnit
2115: .getMarkupDesignBeanForElement(componentRootElement);
2116: if (markupDesignBean != null) {
2117: return markupDesignBean;
2118: }
2119: }
2120: return null;
2121: }
2122:
2123: public UndoRedo getUndoManager() {
2124: // return domProvider.getUndoManager();
2125: return getFacesModel().getUndoManager();
2126: }
2127:
2128: public int computeActions(Element componentRootElement,
2129: Transferable transferable) {
2130: // return domProvider.computeActions(componentRootElement, transferable);
2131: MarkupDesignBean droppee = MarkupUnit
2132: .getMarkupDesignBeanForElement(componentRootElement);
2133: return getDndSupport().computeActions(droppee, transferable);
2134: }
2135:
2136: public void attachContext() {
2137: // domProvider.attachContext();
2138: DesignContext context = getFacesModel().getLiveUnit();
2139: if (context != null) {
2140: // attachContext(context);
2141: updateDesignContextListening(context);
2142: }
2143: }
2144:
2145: public boolean hasRenderingErrors() {
2146: // return domProvider.hasRenderingErrors();
2147: return getRenderFailureComponent() != null;
2148: }
2149:
2150: public JComponent getErrorPanel(
2151: ErrorPanelCallback errorPanelCallback) {
2152: // return (JComponent)domProvider.getErrorPanel(errorPanelCallback);
2153: FacesModel facesModel = getFacesModel();
2154: if (facesModel.isBusted()) {
2155: return new ErrorPanelImpl(facesModel, facesModel
2156: .getErrors(), errorPanelCallback);
2157: } else {
2158: return new RenderErrorPanelImpl(this , errorPanelCallback,
2159: new RenderErrorPanelImpl.RenderFailureProvider() {
2160: public Exception getRenderFailureException() {
2161: return JsfForm.this
2162: .getRenderFailureException();
2163: }
2164:
2165: public MarkupDesignBean getRenderFailureComponent() {
2166: return JsfForm.this
2167: .getRenderFailureComponent();
2168: }
2169: });
2170: }
2171: }
2172:
2173: // XXX
2174: public interface ErrorPanel {
2175: public void updateErrors();
2176: } // End of ErrorPanel.
2177:
2178: // XXX Hack for the impls. Ged rid of this.
2179: public interface ErrorPanelCallback {
2180: public void updateTopComponentForErrors();
2181:
2182: public void setRenderFailureShown(boolean shown);
2183:
2184: // public Exception getRenderFailure();
2185: // public MarkupDesignBean getRenderFailureComponent();
2186: public void handleRefresh(boolean showErrors);
2187: } // End of ErrorPanelCallback.
2188:
2189: public boolean isSourceDirty() {
2190: // return domProvider.isSourceDirty();
2191: MarkupUnit markupUnit = getFacesModel().getMarkupUnit();
2192: if (markupUnit != null) {
2193: return markupUnit.getState() == Unit.State.SOURCEDIRTY;
2194: } else {
2195: // XXX #6478973 Model could be corrupted, until #6480764 is fixed.
2196: log(new IllegalStateException(
2197: "The FacesModel is corrupted, its markup unit is null, facesModel="
2198: + getFacesModel())); // NOI18N
2199: }
2200: return false;
2201: }
2202:
2203: public void dumpHtmlMarkupForNode(org.openide.nodes.Node node) {
2204: // domProvider.dumpHtmlMarkupForNode(node);
2205: DesignBean designBean = node.getLookup().lookup(
2206: DesignBean.class);
2207: if (designBean instanceof MarkupDesignBean) {
2208: MarkupDesignBean markupDesignBean = (MarkupDesignBean) designBean;
2209: Element sourceElement = markupDesignBean.getElement();
2210: Element renderedElement = MarkupService
2211: .getRenderedElementForElement(sourceElement);
2212: if (renderedElement == null
2213: || sourceElement == renderedElement) {
2214: log("Markup design bean not renderable, markup design bean="
2215: + markupDesignBean); // NOI18N
2216: dumpHtmlMarkupDesignBeanHtml();
2217: return;
2218: }
2219: log("Rendered markup design bean=" + markupDesignBean // NOI18N
2220: + "\n" + Util.getHtmlStream(renderedElement)); // NOI18N
2221: } else {
2222: log("Design bean not renderable, design bean=" + designBean); // NOI18N
2223: dumpHtmlMarkupDesignBeanHtml();
2224: }
2225: }
2226:
2227: private void dumpHtmlMarkupDesignBeanHtml() {
2228: DocumentFragment df = getHtmlDomFragment();
2229: Element html = Util.findDescendant(HtmlTag.HTML.name, df);
2230: if (html == null) {
2231: html = getHtmlBody(false);
2232: }
2233: log("Rendered html element markup design bean="
2234: + MarkupUnit.getMarkupDesignBeanForElement(html) + "\n"
2235: + Util.getHtmlStream(html)); // NOI18N
2236: }
2237:
2238: private DocumentFragment getHtmlDomFragment() {
2239: // return domProvider.getHtmlDocumentFragment();
2240: return getFacesModel().getHtmlDomFragment();
2241: }
2242:
2243: /*private*/MarkupDesignBean getDefaultParentBean() {
2244: // return domProvider.getDefaultParentComponent();
2245: // LiveUnit liveUnit = getFacesModel().getLiveUnit();
2246: LiveUnit liveUnit = getLiveUnit();
2247: if (liveUnit != null) {
2248: // MarkupBean bean = getFacesModel().getFacesUnit().getDefaultParent();
2249: MarkupBean bean = getFacesPageUnit().getDefaultParent();
2250:
2251: if (bean != null) {
2252: DesignBean designBean = liveUnit.getDesignBean(bean);
2253: if (designBean instanceof MarkupDesignBean) {
2254: return (MarkupDesignBean) designBean;
2255: }
2256: }
2257: }
2258: return null;
2259: }
2260:
2261: public Element getDefaultParentComponent() {
2262: MarkupDesignBean markupDesignBean = getDefaultParentBean();
2263: return markupDesignBean == null ? null
2264: : JsfSupportUtilities
2265: .getComponentRootElementForMarkupDesignBean(markupDesignBean);
2266: }
2267:
2268: // private Element findDefaultParentComponent() {
2269: // Element bodyElement = getHtmlBody(false);
2270: // if (isFragment()) {
2271: // Element fSubViewElement = Util.findDescendant(HtmlTag.FSUBVIEW.name, bodyElement);
2272: // return fSubViewElement == null ? bodyElement : fSubViewElement;
2273: // } else {
2274: // return bodyElement;
2275: // }
2276: // }
2277:
2278: public Transferable copyComponents(Element[] componentRootElements) {
2279: // return domProvider.copyComponents(componentRootElements);
2280: List<DesignBean> beans = new ArrayList<DesignBean>();
2281: for (Element componentRootElement : componentRootElements) {
2282: DesignBean bean = MarkupUnit
2283: .getMarkupDesignBeanForElement(componentRootElement);
2284: if (bean != null) {
2285: beans.add(bean);
2286: }
2287: }
2288: LiveUnit liveUnit = getFacesModel().getLiveUnit();
2289: return liveUnit.copyBeans(beans.toArray(new DesignBean[beans
2290: .size()]));
2291: }
2292:
2293: public void deleteComponents(Element[] componentRootElements) {
2294: getDomDocumentImpl().deleteComponents(componentRootElements);
2295: }
2296:
2297: // public boolean canDropDesignBeansAtNode(DesignBean[] designBeans, Node node) {
2298: // DesignBean parent = null;
2299: // while (node != null) {
2300: //// if (curr instanceof RaveElement) {
2301: //// parent = ((RaveElement)curr).getDesignBean();
2302: // if (node instanceof Element) {
2303: //// parent = InSyncService.getProvider().getMarkupDesignBeanForElement((Element)curr);
2304: //// parent = WebForm.getDomProviderService().getMarkupDesignBeanForElement((Element)curr);
2305: // parent = MarkupUnit.getMarkupDesignBeanForElement((Element)node);
2306: //
2307: // if (parent != null) {
2308: // break;
2309: // }
2310: // }
2311: //
2312: // node = node.getParentNode();
2313: // }
2314: //
2315: // if (parent == null) {
2316: // return true;
2317: // }
2318: //
2319: // // See if ALL the beans being dragged can be dropped here
2320: //// LiveUnit unit = webform.getModel().getLiveUnit();
2321: // LiveUnit unit = getFacesModel().getLiveUnit();
2322: //
2323: //// for (int i = 0, n = beans.size(); i < n; i++) {
2324: //// DesignBean bean = (DesignBean)beans.get(i);
2325: // for (DesignBean bean : designBeans) {
2326: // String className = bean.getInstance().getClass().getName();
2327: //
2328: // if (!unit.canCreateBean(className, parent, null)) {
2329: // return false;
2330: // }
2331: //
2332: // // Ensure that we're not trying to drop a html bean on a
2333: // // renders-children parent
2334: // boolean isHtmlBean = className.startsWith(HtmlBean.PACKAGE);
2335: //
2336: // if (isHtmlBean) {
2337: // // We can't drop anywhere below a "renders children" JSF
2338: // // component
2339: //// if (parent != FacesSupport.findHtmlContainer(webform, parent)) {
2340: //// if (parent != webform.findHtmlContainer(parent)) {
2341: // if (parent != Util.findHtmlContainer(parent)) {
2342: // return false;
2343: // }
2344: // }
2345: // }
2346: //
2347: // return true;
2348: // }
2349:
2350: // public boolean handleMouseClickForElement(Element element, int clickCount) {
2351: // MarkupMouseRegion region = findRegion(element);
2352: //
2353: // if ((region != null) && region.isClickable()) {
2354: // Result r = region.regionClicked(clickCount);
2355: // ResultHandler.handleResult(r, getFacesModel());
2356: // // #6353410 If there was performed click on the region
2357: // // then do not perform other actions on the same click.
2358: // return true;
2359: // }
2360: // return false;
2361: // }
2362:
2363: // // XXX Moved from FacesSupport.
2364: // /** Locate the closest mouse region to the given element */
2365: // private static MarkupMouseRegion findRegion(Element element) {
2366: // while (element != null) {
2367: //// if (element.getMarkupMouseRegion() != null) {
2368: //// return element.getMarkupMouseRegion();
2369: //// }
2370: //// MarkupMouseRegion region = InSyncService.getProvider().getMarkupMouseRegionForElement(element);
2371: // MarkupMouseRegion region = FacesPageUnit.getMarkupMouseRegionForElement(element);
2372: // if (region != null) {
2373: // return region;
2374: // }
2375: //
2376: // if (element.getParentNode() instanceof Element) {
2377: // element = (Element)element.getParentNode();
2378: // } else {
2379: // break;
2380: // }
2381: // }
2382: //
2383: // return null;
2384: // }
2385:
2386: // private static class DataObjectPropertyChangeListener implements PropertyChangeListener {
2387: //
2388: // private final JsfForm jsfForm;
2389: //
2390: // public DataObjectPropertyChangeListener(JsfForm jsfForm) {
2391: // this.jsfForm = jsfForm;
2392: // }
2393: //
2394: // public void propertyChange(final PropertyChangeEvent evt) {
2395: // // Immediately wipe out the paint box
2396: // if (evt.getPropertyName().equals(DataObject.PROP_PRIMARY_FILE)) {
2397: //// if ((getPane() != null) && (getPane().getPaneUI() != null)) {
2398: //// getPane().getPaneUI().setPageBox(null);
2399: //// }
2400: //
2401: ///*//NB6.0
2402: // // Reconfigure the data object: throw away the old model
2403: // // and find the new model associated with the new file object.
2404: //// InSyncServiceProvider.get().doOutsideOfRefactoringSession(new Runnable() {
2405: // MdrInSyncSynchronizer.get().doOutsideOfRefactoringSession(new Runnable() {
2406: // public void run() {
2407: // */
2408: // // Do the stuff on UI thread as some stuff gets updated that requires to be on UI thread
2409: // SwingUtilities.invokeLater(new Runnable() {
2410: // public void run() {
2411: // jsfForm.replaceFacesModel((FileObject)evt.getOldValue(), (FileObject)evt.getNewValue());
2412: // }
2413: // });
2414: ///* }
2415: // });
2416: ////*/
2417: // }
2418: // }
2419: // } // End of DataObjectPropertyChangeListener.
2420:
2421: private static class JsfDesignContextListener implements
2422: DesignContextListener {
2423:
2424: private final JsfForm jsfForm;
2425:
2426: public JsfDesignContextListener(JsfForm jsfForm) {
2427: this .jsfForm = jsfForm;
2428: }
2429:
2430: public void contextActivated(DesignContext designContext) {
2431: jsfForm.getDomSynchronizer()
2432: .contextActivated(designContext);
2433: // jsfForm.designer.contextActivated(designContext);
2434: // jsfForm.fireDesignContextActivated(designContext);
2435: }
2436:
2437: public void contextDeactivated(DesignContext designContext) {
2438: jsfForm.getDomSynchronizer().contextDeactivated(
2439: designContext);
2440: // jsfForm.designer.contextDeactivated(designContext);
2441: // jsfForm.fireDesignContextDeactivated(designContext);
2442: }
2443:
2444: public void contextChanged(DesignContext designContext) {
2445: jsfForm.getDomSynchronizer().contextChanged(designContext);
2446: // jsfForm.designer.contextChanged(designContext);
2447: jsfForm.designContextChanged(designContext);
2448: }
2449:
2450: public void beanCreated(DesignBean designBean) {
2451: jsfForm.getDomSynchronizer().beanCreated(designBean);
2452: // jsfForm.designer.beanCreated(designBean);
2453: // jsfForm.fireDesignBeanCreated(designBean);
2454: }
2455:
2456: public void beanDeleted(DesignBean designBean) {
2457: jsfForm.getDomSynchronizer().beanDeleted(designBean);
2458: // jsfForm.designer.beanDeleted(designBean);
2459: // jsfForm.fireDesignBeanDeleted(designBean);
2460: }
2461:
2462: public void beanMoved(DesignBean designBean,
2463: DesignBean designBean0, Position position) {
2464: jsfForm.getDomSynchronizer().beanMoved(designBean,
2465: designBean0, position);
2466: // jsfForm.designer.beanMoved(designBean, designBean0, position);
2467: // jsfForm.fireDesignBeanMoved(designBean, designBean0, position);
2468: }
2469:
2470: public void beanContextActivated(DesignBean designBean) {
2471: jsfForm.getDomSynchronizer().beanContextActivated(
2472: designBean);
2473: // jsfForm.designer.beanContextActivated(designBean);
2474: // jsfForm.fireDesignBeanContextActivated(designBean);
2475: }
2476:
2477: public void beanContextDeactivated(DesignBean designBean) {
2478: jsfForm.getDomSynchronizer().beanContextDeactivated(
2479: designBean);
2480: // jsfForm.designer.beanContextDeactivated(designBean);
2481: // jsfForm.fireDesignBeanContextDeactivated(designBean);
2482: }
2483:
2484: public void instanceNameChanged(DesignBean designBean,
2485: String string) {
2486: jsfForm.getDomSynchronizer().instanceNameChanged(
2487: designBean, string);
2488: // jsfForm.designer.instanceNameChanged(designBean, string);
2489: // jsfForm.fireDesignBeanNameChanged(designBean, string);
2490: }
2491:
2492: public void beanChanged(DesignBean designBean) {
2493: jsfForm.getDomSynchronizer().beanChanged(designBean);
2494: // jsfForm.designer.beanChanged(designBean);
2495: // jsfForm.fireDesignBeanChanged(designBean);
2496: }
2497:
2498: public void propertyChanged(DesignProperty designProperty,
2499: Object object) {
2500: jsfForm.getDomSynchronizer().propertyChanged(
2501: designProperty, object);
2502: // jsfForm.designer.propertyChanged(designProperty, object);
2503: // jsfForm.fireDesignPropertyChanged(designProperty, object);
2504: }
2505:
2506: public void eventChanged(DesignEvent designEvent) {
2507: jsfForm.getDomSynchronizer().eventChanged(designEvent);
2508: // jsfForm.designer.eventChanged(designEvent);
2509: // jsfForm.fireDesignEventChanged(designEvent);
2510: }
2511: } // End of JsfDesignContextListener.
2512:
2513: // private static class CoordinateTranslatorImpl implements FacesDnDSupport.CoordinateTranslator {
2514: // private final DomProvider.CoordinateTranslator coordinateTranslator;
2515: //
2516: // public CoordinateTranslatorImpl(DomProvider.CoordinateTranslator coordinateTranslator) {
2517: // this.coordinateTranslator = coordinateTranslator;
2518: // }
2519: //
2520: // public Point translateCoordinates(Element parent, int x, int y) {
2521: // return coordinateTranslator.translateCoordinates(parent, x, y);
2522: // }
2523: //
2524: // public int snapX(int x) {
2525: // return coordinateTranslator.snapX(x);
2526: // }
2527: //
2528: // public int snapY(int y) {
2529: // return coordinateTranslator.snapY(y);
2530: // }
2531: // } // End of CoordinateTranslatorImpl.
2532:
2533: // private static class LocationImpl implements FacesDnDSupport.Location {
2534: // private final DomProvider.Location location;
2535: //
2536: //
2537: // public LocationImpl(DomProvider.Location location) {
2538: // this.location = location;
2539: // }
2540: //
2541: //
2542: // public DesignBean getDroppee() {
2543: // return location.droppee;
2544: // }
2545: //
2546: // public String getFacet() {
2547: // return location.facet;
2548: // }
2549: //
2550: // public Element getDroppeeElement() {
2551: // return location.droppeeElement;
2552: // }
2553: //
2554: // public MarkupPosition getPos() {
2555: // return location.pos;
2556: // }
2557: //
2558: // public Point getCoordinates() {
2559: // return location.coordinates;
2560: // }
2561: //
2562: // public Dimension getSize() {
2563: // return location.size;
2564: // }
2565: // } // End of LocationImpl.
2566:
2567: public boolean hasCachedExternalFrames() {
2568: return externalDomProviderCache.size() > 0;
2569: }
2570:
2571: Designer[] getExternalDesigners(URL url) {
2572: JsfForm external = findExternalForm(url);
2573:
2574: if (external == null) {
2575: return new Designer[0];
2576: }
2577:
2578: // XXX Side-effect. Moved from the designer.
2579: if (!hasRecursiveContextJsfForm(external)) {
2580: external.setContextJsfForm(this );
2581: }
2582:
2583: // Designer[] designers = findDesigners(external);
2584: // if (designers.length == 0) {
2585: // Designer designer = createDesigner(external);
2586: // return new Designer[] {designer};
2587: // }
2588: // return designers;
2589: return getDesigners(external);
2590: }
2591:
2592: // XXX Copied/modified from designer/../ExternalDocumentBox.
2593: private JsfForm findExternalForm(URL url) {
2594: // DocumentCache cache = webform.getDocument().getFrameBoxCache();
2595: // DocumentCache cache = webform.getFrameBoxCache();
2596: ExternalDomProviderCache cache = externalDomProviderCache;
2597:
2598: JsfForm frameForm = cache.get(url);
2599: if (frameForm != null) {
2600: // XXX #110845 Retrieve valid forms only!
2601: if (frameForm.isModelValid()) {
2602: return frameForm;
2603: } else {
2604: // FIXME This means the kept invalid forms are memory leaks.
2605: cache.remove(url);
2606: }
2607: }
2608:
2609: // According to HTML4.01 section 16.5: "The contents of the
2610: // IFRAME element, on the other hand, should only be displayed
2611: // by user agents that do not support frames or are configured
2612: // not to display frames."
2613: // Thus, we don't walk the children array; instead, we
2614: // fetch the url document and display that instead
2615: if (url == null) {
2616: return null;
2617: }
2618:
2619: FileObject fo = URLMapper.findFileObject(url);
2620:
2621: if (fo != null) {
2622: frameForm = loadPage(fo);
2623: }
2624:
2625: if (frameForm == null) {
2626: frameForm = loadPage(url);
2627: }
2628:
2629: // if ((frameForm != null) && (frameForm != WebForm.EXTERNAL)) {
2630: if (frameForm != null) {
2631: cache.put(url, frameForm);
2632: }
2633:
2634: // // Set the cell renderer pane if necessary
2635: // if ((frameForm != null) && (frameForm.getRenderPane() == null)) {
2636: // frameForm.setRenderPane(webform.getRenderPane());
2637: // }
2638:
2639: return frameForm;
2640: }
2641:
2642: private static JsfForm loadPage(URL url) {
2643: //Log.err.log("URL box loading not yet implemented");
2644: // return WebForm.EXTERNAL;
2645: return null;
2646:
2647: // /*
2648: // // Compute document base for the other document
2649: // // try {
2650: // // url = new URL(getBase(), href);
2651: // // } catch (MalformedURLException mfe) {
2652: // // try {
2653: // // ErrorManager.getDefault().notify(mfe);
2654: // // url = new URL(href);
2655: // // } catch (MalformedURLException mfe2) {
2656: // // ErrorManager.getDefault().notify(mfe);
2657: // // url = null;
2658: // // }
2659: // // }
2660: // // if (url != null) {
2661: // StringBuffer sb = new StringBuffer();
2662: // try {
2663: // InputStream uis = url.openStream();
2664: // Reader r = new BufferedReader(new InputStreamReader(uis));
2665: // int c;
2666: // while ((c = r.read()) != -1) {
2667: // sb.append((char)c);
2668: // }
2669: // } catch (IOException ioe) {
2670: // ErrorManager.getDefault().notify(ioe);
2671: // return false;
2672: // }
2673: // String str = sb.toString();
2674: //
2675: // // Construct a document containing the string buffer
2676: // StringContent content = new StringContent(str.length()+5);
2677: // try {
2678: // content.insertString(0, str);
2679: // } catch (Exception e) {
2680: // ErrorManager.getDefault().notify(e);
2681: // return false;
2682: // }
2683: // AbstractDocument adoc = new PlainDocument(content);
2684: // DataObject dobj = null;
2685: // String filename = url.toString(); // only used for diagnostic messages, right?
2686: //
2687: // MarkupUnit markup = new MarkupUnit(dobj, adoc, filename, MarkupUnit.ALLOW_XML);
2688: // markup.sync();
2689: // //if (!markup.getState().equals(markup.getState().CLEAN)) {
2690: // if (!markup.getState().equals(Unit.State.CLEAN)) {
2691: // return false;
2692: // }
2693: //
2694: // CellRendererPane renderPane = webform.getPane().getRenderPane();
2695: // Log.err.log("FrameBox initialization for external urls not yet done");
2696: // */
2697: // /* XXX Not yet implemented
2698: // frameForm = new WebForm(markup, renderPane);
2699: // DesignerPane pane = null;
2700: // Document document = new Document(frameForm);
2701: // frameForm.setDocument(document);
2702: // return success;
2703: // */
2704: }
2705:
2706: private static JsfForm loadPage(FileObject fobj) {
2707: DataObject dobj = null;
2708:
2709: try {
2710: dobj = DataObject.find(fobj);
2711: } catch (DataObjectNotFoundException ex) {
2712: return null;
2713: }
2714:
2715: /*
2716: // Wrapper which handles errors
2717: LiveFacesCookie c = LiveFacesCookie.getInstanceFor(dobj);
2718: if (c == null) {
2719: ErrorManager.getDefault().log("Data object " + dobj + " ain't got no insync cookie!");
2720: return false;
2721: }
2722: FacesModel model = getDocument().getWebForm().getModel();
2723: model.syncFromDoc();
2724: if (model.getMarkup().getState().isInvalid()) {
2725: return false;
2726: }
2727: markup = model.getMarkup();
2728: */
2729:
2730: // XXX Does this work for a form which is not yet open?
2731: // WebForm frameForm = WebForm.findWebForm(dobj);
2732: // WebForm frameForm = WebForm.getDesignersWebFormForDataObject(dobj);
2733: JsfForm frameForm = getJsfForm(dobj);
2734:
2735: // if ((frameForm != null) && (frameForm.getModel() != null)) {
2736: // frameForm.getModel().sync();
2737: if (frameForm != null) {
2738: frameForm.syncModel();
2739: }
2740:
2741: return frameForm;
2742: }
2743:
2744: // XXX Moved from designer/../WebForm.
2745: /** Get the context page for this fragment. This method should only return non-null
2746: * for page fragments. The context page is a page which provides a "style context" for
2747: * the fragment. Typically, the page is one of the pages which includes the page fragment,
2748: * but that's not strictly necessary. The key thing is that the page fragment will pick
2749: * up stylesheets etc. defined in the head of the context page.
2750: * @return A context page for the fragment
2751: */
2752: JsfForm getContextJsfForm() {
2753: // if (isFragment && (contextPage == null)) {
2754: if (isFragment() && (contextJsfForm == null)) {
2755: // Find a page
2756: Iterator it =
2757: // DesignerService.getDefault().getWebPages(getProject(), true, false).iterator();
2758: // InSyncService.getProvider().getWebPages(getProject(), true, false).iterator();
2759: // domProvider.getWebPageFileObjectsInThisProject().iterator();
2760: Util.getWebPages(getFacesModel().getProject(), true, false)
2761: .iterator();
2762:
2763: while (it.hasNext()) {
2764: FileObject fo = (FileObject) it.next();
2765:
2766: try {
2767: DataObject dobj = DataObject.find(fo);
2768:
2769: // XXX Very suspicious, how come that context page is any random page
2770: // whitin project?? What actually the context page is good for?
2771: // It seems it is a wrong architecture.
2772: // if (isWebFormDataObject(dobj)) {
2773: if (JsfSupportUtilities.isWebFormDataObject(dobj)) {
2774: // contextJsfForm = getWebFormForDataObject(dobj);
2775: contextJsfForm = getJsfForm(dobj);
2776: break;
2777: }
2778: } catch (DataObjectNotFoundException ex) {
2779: log(ex);
2780: }
2781: }
2782: }
2783:
2784: return contextJsfForm;
2785: }
2786:
2787: // XXX Moved from designer/../WebForm.
2788: /** Set the associated context page for this page fragment. (Only allowed on
2789: * page fragments.)
2790: * @see getContextPage()
2791: */
2792: private void setContextJsfForm(JsfForm contextJsfForm) {
2793: // assert isFragment;
2794: if (!isFragment()) {
2795: return;
2796: }
2797:
2798: // XXX Context page notion from fragment should be removed.
2799: if (this .contextJsfForm != contextJsfForm && isValid()) {
2800: // Force refresh such that the style links are recomputed
2801: clearHtml();
2802: }
2803:
2804: this .contextJsfForm = contextJsfForm;
2805: }
2806:
2807: private boolean hasRecursiveContextJsfForm(JsfForm contextJsfForm) {
2808: if (contextJsfForm == null) {
2809: return false;
2810: }
2811: JsfForm jsf = this ;
2812: while (jsf != null) {
2813: JsfForm context = jsf.getContextJsfForm();
2814: if (context == contextJsfForm) {
2815: return true;
2816: }
2817: jsf = context;
2818: }
2819: return false;
2820: }
2821:
2822: public boolean isBraveheartPage() {
2823: return Util.isBraveheartPage(getJspDom());
2824: }
2825:
2826: public boolean isWoodstockPage() {
2827: return Util.isWoodstockPage(getJspDom());
2828: }
2829:
2830: public void setRenderFailureShown(boolean shown) {
2831: renderFailureShown = shown;
2832: }
2833:
2834: public boolean isRenderFailureShown() {
2835: return renderFailureShown;
2836: }
2837:
2838: public boolean editEventHandlerForComponent(
2839: Element componentRootElement) {
2840: DesignBean designBean = MarkupUnit
2841: .getMarkupDesignBeanForElement(componentRootElement);
2842: if (designBean == null) {
2843: // webform.getModel().openDefaultHandler(component);
2844: getFacesModel().openDefaultHandler();
2845: return false;
2846: } else {
2847: // See if it's an XHTML element; if so just show it in
2848: // the JSP source
2849: // if (FacesSupport.isXhtmlComponent(component)) {
2850: if (isXhtmlComponent(designBean)) {
2851: // MarkupBean mb = FacesSupport.getMarkupBean(component);
2852: MarkupBean mb = Util.getMarkupBean(designBean);
2853:
2854: // MarkupUnit unit = webform.getMarkup();
2855: MarkupUnit unit = getFacesModel().getMarkupUnit();
2856: // <markup_separation>
2857: // Util.show(null, unit.getFileObject(),
2858: // unit.computeLine((RaveElement)mb.getElement()), 0, true);
2859: // ====
2860: // MarkupService.show(unit.getFileObject(), unit.computeLine((RaveElement)mb.getElement()), 0, true);
2861: showLineAt(unit.getFileObject(), unit.computeLine(mb
2862: .getElement()), 0);
2863: // </markup_separation>
2864: } else {
2865: // webform.getModel().openDefaultHandler(component);
2866: getFacesModel().openDefaultHandler(designBean);
2867: }
2868:
2869: return true;
2870: }
2871: }
2872:
2873: /** Return true iff the given DesignBean is an XHTML markup "component" */
2874: private static boolean isXhtmlComponent(DesignBean bean) {
2875: // MarkupBean mb = FacesSupport.getMarkupBean(bean);
2876: MarkupBean mb = Util.getMarkupBean(bean);
2877:
2878: return (mb != null) && !(mb instanceof FacesBean);
2879: }
2880:
2881: // XXX Copied from DesignerActions.
2882: private static void showLineAt(FileObject fo, int lineno, int column) {
2883: DataObject dobj;
2884: try {
2885: dobj = DataObject.find(fo);
2886: } catch (DataObjectNotFoundException ex) {
2887: log(ex);
2888: return;
2889: }
2890:
2891: // Try to open doc before showing the line. This SHOULD not be
2892: // necessary, except without this the IDE hangs in its attempt
2893: // to open the file when the file in question is a CSS file.
2894: // Probably a bug in the xml/css module's editorsupport code.
2895: // This has the negative effect of first flashing the top
2896: // of the file before showing the destination line, so
2897: // this operation is made conditional so only clients who
2898: // actually need it need to use it.
2899: EditorCookie ec = (EditorCookie) dobj
2900: .getCookie(EditorCookie.class);
2901: if (ec != null) {
2902: try {
2903: ec.openDocument(); // ensure that it has been opened - REDUNDANT?
2904: //ec.open();
2905: } catch (IOException ex) {
2906: log(ex);
2907: return;
2908: }
2909: }
2910:
2911: LineCookie lc = (LineCookie) dobj.getCookie(LineCookie.class);
2912: if (lc != null) {
2913: Line.Set ls = lc.getLineSet();
2914: if (ls != null) {
2915: // -1: convert line numbers to be zero-based
2916: Line line = ls.getCurrent(lineno - 1);
2917: // TODO - pass in a column too?
2918: line.show(Line.SHOW_GOTO, column);
2919: }
2920: }
2921: }
2922:
2923: private Designer[] getDesigners() {
2924: Set<Designer> ds;
2925: // synchronized (designers) {
2926: designersLock.readLock().lock();
2927: try {
2928: ds = new HashSet<Designer>(designers);
2929: } finally {
2930: designersLock.readLock().unlock();
2931: }
2932: return ds.toArray(new Designer[ds.size()]);
2933: }
2934:
2935: private void addDesigner(Designer designer) {
2936: // synchronized (designers) {
2937: designersLock.writeLock().lock();
2938: try {
2939: designers.add(designer);
2940: } finally {
2941: designersLock.writeLock().unlock();
2942: }
2943: }
2944:
2945: public boolean isRenderedNode(Node node) {
2946: if (node == null) {
2947: return false;
2948: }
2949:
2950: return node.getOwnerDocument() == getHtmlDom();
2951: }
2952:
2953: public void setVirtualFormsSupportEnabled(boolean enabled) {
2954: virtualFormsSupportEnabled = enabled;
2955:
2956: // TODO fire model event and in handler repaint the component.
2957: tcRepaint();
2958: }
2959:
2960: public boolean isVirtualFormsSupportEnabled() {
2961: return virtualFormsSupportEnabled;
2962: }
2963:
2964: public void setAjaxTransactionsSupportEnabled(boolean enabled) {
2965: ajaxTransactionsSupportEnabled = enabled;
2966:
2967: // TODO fire model event and in handler repaint the component.
2968: tcRepaint();
2969: }
2970:
2971: public boolean isAjaxTransactionsSupportEnabled() {
2972: return ajaxTransactionsSupportEnabled;
2973: }
2974:
2975: public void tcRepaint() {
2976: Designer[] designers = findDesigners(this );
2977:
2978: for (Designer designer : designers) {
2979: JsfMultiViewElement jsfMultiViewElement = findJsfMultiViewElementForDesigner(designer);
2980: if (jsfMultiViewElement == null) {
2981: continue;
2982: }
2983: jsfMultiViewElement.getJsfTopComponent().repaint();
2984: }
2985: }
2986:
2987: /** XXX #101837 Closing the component when facesModel goes away. */
2988: private static class JsfDesignProjectListener implements
2989: DesignProjectListener {
2990: public void contextOpened(DesignContext designContext) {
2991: // No op.
2992: }
2993:
2994: public void contextClosed(DesignContext designContext) {
2995: JsfForm jsfForm = JsfForm.findJsfForm(designContext);
2996: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(jsfForm);
2997: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
2998: jsfMultiViewElement.closeMultiView();
2999: }
3000: }
3001: } // End of DesignProjectListener.
3002:
3003: DocumentFragment renderMarkupDesignBean(
3004: MarkupDesignBean markupDesignBean) {
3005: return renderMarkupDesignBean(markupDesignBean, true);
3006: }
3007:
3008: DocumentFragment renderMarkupDesignBean(
3009: MarkupDesignBean markupDesignBean, boolean markRendered) {
3010: return FacesPageUnit.renderHtml(getFacesModel(),
3011: markupDesignBean, markRendered);
3012: }
3013:
3014: LiveUnit getLiveUnit() {
3015: return getFacesModel().getLiveUnit();
3016: }
3017:
3018: Project getProject() {
3019: return getFacesModel().getProject();
3020: }
3021:
3022: FileObject getMarkupFile() {
3023: return getFacesModel().getMarkupFile();
3024: }
3025:
3026: FacesPageUnit getFacesPageUnit() {
3027: return getFacesModel().getFacesUnit();
3028: }
3029:
3030: void customizeCreation(DesignBean[] designBeans) {
3031: Util.customizeCreation(designBeans, getFacesModel());
3032: }
3033:
3034: void designBeanCreated(DesignBean designBean) {
3035: getFacesModel().beanCreated(designBean);
3036: }
3037:
3038: public void handleResult(Result result) {
3039: ResultHandler.handleResult(result, getFacesModel());
3040: }
3041:
3042: void linkDesignBeans(DesignBean droppee, DesignBean lb) {
3043: getFacesModel().linkBeans(droppee, lb);
3044: }
3045:
3046: DesignBean findParent(String className, DesignBean droppee,
3047: Node parentNode, boolean searchUp) {
3048: return Util.findParent(className, droppee, parentNode,
3049: searchUp, getFacesModel());
3050: }
3051:
3052: public boolean isFormComponent(Element componentRootElement) {
3053: MarkupDesignBean bean = MarkupUnit
3054: .getMarkupDesignBeanForElement(componentRootElement);
3055: if (bean == null) {
3056: return false;
3057: }
3058: // return Util.isFormBean(getFacesModel(), bean);
3059: return isFormDesignBean(bean);
3060: }
3061:
3062: boolean isFormDesignBean(DesignBean designBean) {
3063: return Util.isFormBean(getFacesModel(), designBean);
3064: }
3065:
3066: MarkupUnit getMarkupUnit() {
3067: return getFacesModel().getMarkupUnit();
3068: }
3069:
3070: public org.openide.nodes.Node getRootBeanNode() {
3071: FacesModel facesModel = getFacesModel();
3072: DesignBean rootBean = facesModel.getRootBean();
3073: if (rootBean == null) {
3074: // XXX If the model is busted then it is supposed to be OK, there is an error, see e.g. #6478860.
3075: if (!facesModel.isBusted()) {
3076: log(new IllegalStateException(
3077: "Invalid FacesModel, it is not busted and its root design bean is null, facesModel="
3078: + facesModel)); // NOI18N
3079: }
3080: return null;
3081: } else {
3082: return DesigntimeIdeBridgeProvider.getDefault()
3083: .getNodeRepresentation(rootBean);
3084: }
3085: }
3086:
3087: private static void log(Throwable ex) {
3088: Logger logger = getLogger();
3089: logger.log(Level.INFO, null, ex);
3090: }
3091:
3092: private static void log(String message) {
3093: Logger logger = getLogger();
3094: logger.log(Level.INFO, message);
3095: }
3096:
3097: private static void notify(Throwable ex) {
3098: Logger logger = getLogger();
3099: logger.log(Level.SEVERE, null, ex);
3100: }
3101:
3102: private static Logger getLogger() {
3103: return Logger.getLogger(JsfForm.class.getName());
3104: }
3105:
3106: public boolean isValid() {
3107: return getFacesModel() != null;
3108: }
3109:
3110: private FacesModel loadFacesModel(final DataObject dataObject) {
3111: FacesModel facesModel;
3112: try {
3113: facesModel = getFacesModel(dataObject);
3114: // XXX FacesModel throws runtime exceptions, which is wrong.
3115: } catch (Exception ex) {
3116: loadingFailed(new IllegalStateException(
3117: "FacesModel was not loaded for DataObject, dataObject="
3118: + dataObject, ex));
3119: return null;
3120: }
3121: if (facesModel == null) {
3122: loadingFailed(new NullPointerException(
3123: "No FacesModel for DataObject, dataObject="
3124: + dataObject));
3125: return null;
3126: }
3127: return facesModel;
3128: }
3129:
3130: private void loadingFailed(Exception ex) {
3131: notify(ex);
3132: EventQueue.invokeLater(new Runnable() {
3133: public void run() {
3134: notifyViewsModelLoadingFailed();
3135: }
3136: });
3137: }
3138:
3139: private void notifyViewsModelLoaded() {
3140: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
3141: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
3142: jsfMultiViewElement.modelLoaded();
3143: }
3144: }
3145:
3146: private void notifyViewsModelLoadingFailed() {
3147: JsfMultiViewElement[] jsfMultiViewElements = findJsfMultiViewElements(this );
3148: for (JsfMultiViewElement jsfMultiViewElement : jsfMultiViewElements) {
3149: jsfMultiViewElement.closeMultiView();
3150: }
3151: }
3152:
3153: }
|