001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.visualweb.navigation;
029:
030: import java.awt.EventQueue;
031: import java.lang.ref.WeakReference;
032: import java.util.logging.Logger;
033: import org.netbeans.modules.visualweb.insync.Model;
034: import org.netbeans.modules.visualweb.insync.ModelSetListener;
035: import org.netbeans.modules.visualweb.insync.models.FacesModel;
036:
037: /**
038: *
039: * @author joelle
040: */
041: public class FacesModelSetListener implements ModelSetListener {
042:
043: private static Logger LOGGER = Logger
044: .getLogger(FacesModelSetListener.class.getName());
045:
046: public FacesModelSetListener(VWPContentModel vwpContentModel) {
047: setVwpContentModel(vwpContentModel);
048: }
049:
050: public void modelAdded(Model model) {
051: LOGGER.finest("Model Added()");
052: //DO NOTHING
053: }
054:
055: public void modelChanged(final Model myModel) {
056: final VWPContentModel vwpContentModel = getVwpContentModel();
057: if (myModel != null && vwpContentModel != null) {
058: FacesModel facesModel = vwpContentModel.getFacesModel();
059: LOGGER.finest("Model Changed()");
060: if ((myModel.equals(facesModel))
061: || (myModel.getFile().getExt().equals("jspf") && getVwpContentModel()
062: .isKnownFragementModel(facesModel,
063: facesModel.getRootBean(), myModel))) {
064: EventQueue.invokeLater(new Runnable() {
065:
066: public void run() {
067: vwpContentModel.updateModel();
068: }
069: });
070: }
071: } else {
072: LOGGER.fine("Values of one of the model is null:");
073: LOGGER.fine("VWPContentModel: " + vwpContentModel);
074: LOGGER.fine("MyModel (passed in): " + myModel);
075: }
076: }
077:
078: public void modelRemoved(Model model) {
079: LOGGER.finest("Model Removed()");
080: //DO NOTHING
081: }
082:
083: public void modelProjectChanged() {
084: LOGGER.finest("Model Project Changed()");
085: //DO NOTHING
086: }
087:
088: private WeakReference<VWPContentModel> refVWPContentModel;
089:
090: private VWPContentModel getVwpContentModel() {
091: VWPContentModel vwpContentModel = null;
092: if (refVWPContentModel != null) {
093: vwpContentModel = refVWPContentModel.get();
094: }
095: return vwpContentModel;
096: }
097:
098: private void setVwpContentModel(VWPContentModel vwpContentModel) {
099: refVWPContentModel = new WeakReference<VWPContentModel>(
100: vwpContentModel);
101: }
102: }
|