001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.io;
042:
043: import org.netbeans.api.project.Project;
044: import org.netbeans.core.spi.multiview.MultiViewElementCallback;
045: import org.netbeans.modules.vmd.api.io.ActiveViewSupport;
046: import org.netbeans.modules.vmd.api.io.DataObjectContext;
047: import org.netbeans.modules.vmd.api.io.DesignDocumentAwareness;
048: import org.netbeans.modules.vmd.api.io.ProjectUtils;
049: import org.netbeans.modules.vmd.api.io.providers.DocumentSerializer;
050: import org.netbeans.modules.vmd.api.io.providers.IOSupport;
051: import org.openide.loaders.DataObject;
052: import org.openide.text.CloneableEditorSupport;
053:
054: import java.lang.ref.WeakReference;
055: import java.util.HashMap;
056:
057: /**
058: * @author David Kaspar
059: */
060: public class DataObjectContextImpl implements DataObjectContext {
061:
062: private static final String PROJECT_TYPE_VMD_UNKNOWN = "#vmd-unknown-project-type"; // NOI18N
063:
064: public transient static final HashMap<String, WeakReference<Project>> projectID2project = new HashMap<String, WeakReference<Project>>();
065:
066: private static final long serialVersionUID = -1;
067:
068: private DataObject dataObject;
069: private transient volatile boolean initialized;
070: private transient String projectID;
071: private transient String projectType;
072:
073: static {
074: ActiveViewSupport.getDefault();
075: }
076:
077: public DataObjectContextImpl() {
078: }
079:
080: public DataObjectContextImpl(DataObject dataObject) {
081: this ();
082: assert dataObject != null;
083: this .dataObject = dataObject;
084: }
085:
086: private void initialize() {
087: synchronized (this ) {
088: if (initialized)
089: return;
090: projectID = ProjectUtils.getProjectID(ProjectUtils
091: .getProject(this ));
092: DocumentSerializer documentSerializer = IOSupport
093: .getDocumentSerializer(dataObject);
094: projectType = documentSerializer.getProjectType();
095: if (projectType == null)
096: projectType = PROJECT_TYPE_VMD_UNKNOWN;
097: initialized = true;
098: }
099: }
100:
101: public String getProjectID() {
102: initialize();
103: return projectID;
104: }
105:
106: public String getProjectType() {
107: initialize();
108: return projectType;
109: }
110:
111: public DataObject getDataObject() {
112: return dataObject;
113: }
114:
115: public CloneableEditorSupport getCloneableEditorSupport() {
116: return IOSupport.getCloneableEditorSupport(dataObject);
117: }
118:
119: public void notifyModified() {
120: IOSupport.getDataObjectInteface(dataObject)
121: .notifyEditorSupportModified();
122: }
123:
124: public void updateFromMultiViewElementCallback(
125: MultiViewElementCallback callback) {
126: }
127:
128: public void addDesignDocumentAwareness(
129: DesignDocumentAwareness listener) {
130: IOSupport.getDocumentSerializer(dataObject)
131: .addDesignDocumentAwareness(listener);
132: }
133:
134: public void removeDesignDocumentAwareness(
135: DesignDocumentAwareness listener) {
136: IOSupport.getDocumentSerializer(dataObject)
137: .removeDesignDocumentAwareness(listener);
138: }
139:
140: public void forceSave() {
141: IOSupport.getDocumentSerializer(dataObject).saveDocument();
142: }
143:
144: }
|