Freemarker support no longer needs to have a DataObject after recent changes in the platform.
authorJan Lahoda <jlahoda@netbeans.org>
Wed, 16 Nov 2011 14:17:11 +0100
changeset 176700373deb937e9
parent 17669 da3d5aa94b77
child 17672 4c1a55e30094
Freemarker support no longer needs to have a DataObject after recent changes in the platform.
freemarker/manifest.mf
freemarker/nbproject/project.xml
freemarker/src/org/netbeans/modules/freemarker/FreeMarkerKit.java
freemarker/src/org/netbeans/modules/freemarker/MimeTypes.java
freemarker/src/org/netbeans/modules/freemarker/TopLevelFreeMarkerTokenId.java
freemarker/src/org/netbeans/modules/freemarker/layer.xml
freemarker/src/org/netbeans/modules/freemarker/loader/Bundle.properties
freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataLoader.java
freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataLoaderBeanInfo.java
freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataNode.java
freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataObject.java
     1.1 --- a/freemarker/manifest.mf	Fri Nov 11 10:35:39 2011 +0100
     1.2 +++ b/freemarker/manifest.mf	Wed Nov 16 14:17:11 2011 +0100
     1.3 @@ -2,8 +2,5 @@
     1.4  OpenIDE-Module: org.netbeans.modules.freemarker
     1.5  OpenIDE-Module-Layer: org/netbeans/modules/freemarker/layer.xml
     1.6  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/freemarker/Bundle.properties
     1.7 -OpenIDE-Module-Specification-Version: 1.1
     1.8 +OpenIDE-Module-Specification-Version: 1.2
     1.9  
    1.10 -Name: org/netbeans/modules/freemarker/loader/FreemarkerDataLoader.class
    1.11 -OpenIDE-Module-Class: Loader
    1.12 -
     2.1 --- a/freemarker/nbproject/project.xml	Fri Nov 11 10:35:39 2011 +0100
     2.2 +++ b/freemarker/nbproject/project.xml	Wed Nov 16 14:17:11 2011 +0100
     2.3 @@ -24,6 +24,15 @@
     2.4                      </run-dependency>
     2.5                  </dependency>
     2.6                  <dependency>
     2.7 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
     2.8 +                    <build-prerequisite/>
     2.9 +                    <compile-dependency/>
    2.10 +                    <run-dependency>
    2.11 +                        <release-version>1</release-version>
    2.12 +                        <specification-version>1.52</specification-version>
    2.13 +                    </run-dependency>
    2.14 +                </dependency>
    2.15 +                <dependency>
    2.16                      <code-name-base>org.netbeans.modules.lexer</code-name-base>
    2.17                      <build-prerequisite/>
    2.18                      <compile-dependency/>
    2.19 @@ -55,6 +64,14 @@
    2.20                      <run-dependency/>
    2.21                  </dependency>
    2.22                  <dependency>
    2.23 +                    <code-name-base>org.openide.modules</code-name-base>
    2.24 +                    <build-prerequisite/>
    2.25 +                    <compile-dependency/>
    2.26 +                    <run-dependency>
    2.27 +                        <specification-version>7.27</specification-version>
    2.28 +                    </run-dependency>
    2.29 +                </dependency>
    2.30 +                <dependency>
    2.31                      <code-name-base>org.openide.nodes</code-name-base>
    2.32                      <build-prerequisite/>
    2.33                      <compile-dependency/>
     3.1 --- a/freemarker/src/org/netbeans/modules/freemarker/FreeMarkerKit.java	Fri Nov 11 10:35:39 2011 +0100
     3.2 +++ b/freemarker/src/org/netbeans/modules/freemarker/FreeMarkerKit.java	Wed Nov 16 14:17:11 2011 +0100
     3.3 @@ -1,7 +1,7 @@
     3.4  /*
     3.5   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6   *
     3.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     3.8 + * Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.
     3.9   *
    3.10   * The contents of this file are subject to the terms of either the GNU
    3.11   * General Public License Version 2 only ("GPL") or the Common
    3.12 @@ -41,7 +41,10 @@
    3.13  
    3.14  package org.netbeans.modules.freemarker;
    3.15  
    3.16 +import javax.swing.text.Document;
    3.17 +import org.netbeans.api.lexer.InputAttributes;
    3.18  import org.netbeans.modules.editor.NbEditorKit;
    3.19 +import org.netbeans.modules.freemarker.MimeTypes.FutureMimeType;
    3.20  
    3.21  /**
    3.22  * Java editor kit with appropriate document
    3.23 @@ -59,4 +62,16 @@
    3.24          return MimeTypes.FREEMARKER_TOP_LEVEL;
    3.25      }
    3.26  
    3.27 +    @Override
    3.28 +    public Document createDefaultDocument() {
    3.29 +        final Document doc = super.createDefaultDocument();
    3.30 +        InputAttributes ia = new InputAttributes();
    3.31 +
    3.32 +        doc.putProperty(InputAttributes.class, ia);
    3.33 +
    3.34 +        ia.setValue(TopLevelFreeMarkerTokenId.language(), MimeTypes.MIME_TYPE_PROPERTY, new FutureMimeType(doc), true);
    3.35 +        
    3.36 +        return doc;
    3.37 +    }
    3.38 +
    3.39  }
     4.1 --- a/freemarker/src/org/netbeans/modules/freemarker/MimeTypes.java	Fri Nov 11 10:35:39 2011 +0100
     4.2 +++ b/freemarker/src/org/netbeans/modules/freemarker/MimeTypes.java	Wed Nov 16 14:17:11 2011 +0100
     4.3 @@ -1,7 +1,7 @@
     4.4  /*
     4.5   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6   * 
     4.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     4.8 + * Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.
     4.9   * 
    4.10   * The contents of this file are subject to the terms of either the GNU
    4.11   * General Public License Version 2 only ("GPL") or the Common
    4.12 @@ -38,6 +38,10 @@
    4.13   */
    4.14  
    4.15  package org.netbeans.modules.freemarker;
    4.16 +
    4.17 +import java.util.concurrent.atomic.AtomicReference;
    4.18 +import javax.swing.text.Document;
    4.19 +import org.netbeans.modules.editor.NbEditorUtilities;
    4.20  import org.openide.filesystems.FileObject;
    4.21  import org.openide.filesystems.FileUtil;
    4.22  
    4.23 @@ -47,9 +51,9 @@
    4.24   */
    4.25  public class MimeTypes {
    4.26  
    4.27 -    private static final String FREEMARKER_TOP_LEVEL_FRAGMENT = "x-freemarker-tl"; // NOI18N
    4.28 +    private static final String FREEMARKER_TOP_LEVEL_FRAGMENT = "x-freemarker"; // NOI18N
    4.29      public static final String FREEMARKER_TOP_LEVEL = "text/" + FREEMARKER_TOP_LEVEL_FRAGMENT; // NOI18N
    4.30 -    public static final String FREEMARKER = "text/x-freemarker"; // NOI18N
    4.31 +    public static final String FREEMARKER = "text/x-freemarker-inner"; // NOI18N
    4.32      public static final String MIME_TYPE_PROPERTY = "mimeType"; // NOI18N
    4.33              
    4.34      public static String prepareCompoundMimeType(FileObject file) {
    4.35 @@ -64,14 +68,26 @@
    4.36          return "text/" + fileMTFragment + "+" + FREEMARKER_TOP_LEVEL_FRAGMENT; // NOI18N
    4.37      }
    4.38  
    4.39 -    public static String getEmbeddedMimeType(String mimeType) {
    4.40 -        if (mimeType.startsWith("text/") && mimeType.endsWith("+" + FREEMARKER_TOP_LEVEL_FRAGMENT)) { // NOI18N
    4.41 -            return mimeType.substring(0, mimeType.length() - ("+" + FREEMARKER_TOP_LEVEL_FRAGMENT).length()); // NOI18N
    4.42 -        } else {
    4.43 -            return "text/plain"; // NOI18N
    4.44 +    public static class FutureMimeType {
    4.45 +        private final Document doc;
    4.46 +        private final AtomicReference<String> mimeType = new AtomicReference<String>();
    4.47 +        public FutureMimeType(Document doc) {
    4.48 +            this.doc = doc;
    4.49 +        }
    4.50 +        public String get() {
    4.51 +            String r = mimeType.get();
    4.52 +
    4.53 +            if (r != null) return r;
    4.54 +
    4.55 +            FileObject file = NbEditorUtilities.getFileObject(doc);
    4.56 +            String mt = file != null ? FileUtil.getMIMEType(file) : "text/plain";
    4.57 +
    4.58 +            mimeType.compareAndSet(null, mt);
    4.59 +
    4.60 +            return mt;
    4.61          }
    4.62      }
    4.63 -
    4.64 +    
    4.65      private MimeTypes() {
    4.66      }
    4.67  }
     5.1 --- a/freemarker/src/org/netbeans/modules/freemarker/TopLevelFreeMarkerTokenId.java	Fri Nov 11 10:35:39 2011 +0100
     5.2 +++ b/freemarker/src/org/netbeans/modules/freemarker/TopLevelFreeMarkerTokenId.java	Wed Nov 16 14:17:11 2011 +0100
     5.3 @@ -45,6 +45,8 @@
     5.4  import org.netbeans.api.lexer.LanguagePath;
     5.5  import org.netbeans.api.lexer.Token;
     5.6  import org.netbeans.api.lexer.TokenId;
     5.7 +import org.netbeans.modules.freemarker.MimeTypes.FutureMimeType;
     5.8 +import org.netbeans.spi.lexer.EmbeddingPresence;
     5.9  import org.netbeans.spi.lexer.LanguageEmbedding;
    5.10  import org.netbeans.spi.lexer.LanguageHierarchy;
    5.11  import org.netbeans.spi.lexer.Lexer;
    5.12 @@ -95,8 +97,8 @@
    5.13                      if (inputAttributes != null) {
    5.14                          Object value = inputAttributes.getValue(languagePath, MimeTypes.MIME_TYPE_PROPERTY);
    5.15  
    5.16 -                        if (value instanceof String) {
    5.17 -                            embeddedMimeType = MimeTypes.getEmbeddedMimeType((String) value);
    5.18 +                        if (value instanceof FutureMimeType) {
    5.19 +                            embeddedMimeType = ((FutureMimeType) value).get();
    5.20                          }
    5.21                      }
    5.22                      
    5.23 @@ -122,6 +124,11 @@
    5.24              }
    5.25          }
    5.26  
    5.27 +        @Override
    5.28 +        protected EmbeddingPresence embeddingPresence(TopLevelFreeMarkerTokenId id) {
    5.29 +            return EmbeddingPresence.ALWAYS_QUERY;
    5.30 +        }
    5.31 +
    5.32      }.language();
    5.33      
    5.34      public static Language<TopLevelFreeMarkerTokenId> language() {
     6.1 --- a/freemarker/src/org/netbeans/modules/freemarker/layer.xml	Fri Nov 11 10:35:39 2011 +0100
     6.2 +++ b/freemarker/src/org/netbeans/modules/freemarker/layer.xml	Wed Nov 16 14:17:11 2011 +0100
     6.3 @@ -44,7 +44,7 @@
     6.4  <filesystem>
     6.5      <folder name="Editors">
     6.6          <folder name="text">
     6.7 -            <folder name="x-freemarker-tl">
     6.8 +            <folder name="x-freemarker">
     6.9                  <file name="language.instance">
    6.10                      <attr name="instanceCreate" methodvalue="org.netbeans.modules.freemarker.TopLevelFreeMarkerTokenId.language"/>
    6.11                      <attr name="instanceOf" stringvalue="org.netbeans.api.lexer.Language"/>
    6.12 @@ -65,7 +65,7 @@
    6.13      </folder>
    6.14      <folder name="Loaders">
    6.15          <folder name="text">
    6.16 -            <folder name="x-freemarker-tl">
    6.17 +            <folder name="x-freemarker">
    6.18                  <folder name="Actions">
    6.19                      <file name="org-openide-actions-CopyAction.shadow">
    6.20                          <attr name="originalFile" stringvalue="Actions/Edit/org-openide-actions-CopyAction.instance"/>
     7.1 --- a/freemarker/src/org/netbeans/modules/freemarker/loader/Bundle.properties	Fri Nov 11 10:35:39 2011 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,39 +0,0 @@
     7.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.5 -#
     7.6 -# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     7.7 -#
     7.8 -# The contents of this file are subject to the terms of either the GNU
     7.9 -# General Public License Version 2 only ("GPL") or the Common
    7.10 -# Development and Distribution License("CDDL") (collectively, the
    7.11 -# "License"). You may not use this file except in compliance with the
    7.12 -# License. You can obtain a copy of the License at
    7.13 -# http://www.netbeans.org/cddl-gplv2.html
    7.14 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.15 -# specific language governing permissions and limitations under the
    7.16 -# License.  When distributing the software, include this License Header
    7.17 -# Notice in each file and include the License file at
    7.18 -# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    7.19 -# particular file as subject to the "Classpath" exception as provided
    7.20 -# by Sun in the GPL Version 2 section of the License file that
    7.21 -# accompanied this code. If applicable, add the following below the
    7.22 -# License Header, with the fields enclosed by brackets [] replaced by
    7.23 -# your own identifying information:
    7.24 -# "Portions Copyrighted [year] [name of copyright owner]"
    7.25 -#
    7.26 -# Contributor(s):
    7.27 -#
    7.28 -# The Original Software is NetBeans. The Initial Developer of the Original
    7.29 -# Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    7.30 -# Microsystems, Inc. All Rights Reserved.
    7.31 -#
    7.32 -# If you wish your version of this file to be governed by only the CDDL
    7.33 -# or only the GPL Version 2, indicate your decision by adding
    7.34 -# "[Contributor] elects to include this software in this distribution
    7.35 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
    7.36 -# single choice of license, a recipient has the option to distribute
    7.37 -# your version of this file under either the CDDL, the GPL Version 2 or
    7.38 -# to extend the choice of license to its licensees as provided above.
    7.39 -# However, if you add GPL Version 2 code and therefore, elected the GPL
    7.40 -# Version 2 license, then the option applies only if the new code is
    7.41 -# made subject to such option by the copyright holder.
    7.42 -LBL_Freemarker_loader_name=Freemarker Files
     8.1 --- a/freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataLoader.java	Fri Nov 11 10:35:39 2011 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,82 +0,0 @@
     8.4 -/*
     8.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 - * 
     8.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     8.8 - * 
     8.9 - * The contents of this file are subject to the terms of either the GNU
    8.10 - * General Public License Version 2 only ("GPL") or the Common
    8.11 - * Development and Distribution License("CDDL") (collectively, the
    8.12 - * "License"). You may not use this file except in compliance with the
    8.13 - * License. You can obtain a copy of the License at
    8.14 - * http://www.netbeans.org/cddl-gplv2.html
    8.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.16 - * specific language governing permissions and limitations under the
    8.17 - * License.  When distributing the software, include this License Header
    8.18 - * Notice in each file and include the License file at
    8.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    8.20 - * particular file as subject to the "Classpath" exception as provided
    8.21 - * by Sun in the GPL Version 2 section of the License file that
    8.22 - * accompanied this code. If applicable, add the following below the
    8.23 - * License Header, with the fields enclosed by brackets [] replaced by
    8.24 - * your own identifying information:
    8.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    8.26 - * 
    8.27 - * If you wish your version of this file to be governed by only the CDDL
    8.28 - * or only the GPL Version 2, indicate your decision by adding
    8.29 - * "[Contributor] elects to include this software in this distribution
    8.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    8.31 - * single choice of license, a recipient has the option to distribute
    8.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    8.33 - * to extend the choice of license to its licensees as provided above.
    8.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    8.35 - * Version 2 license, then the option applies only if the new code is
    8.36 - * made subject to such option by the copyright holder.
    8.37 - * 
    8.38 - * Contributor(s):
    8.39 - * 
    8.40 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
    8.41 - */
    8.42 -package org.netbeans.modules.freemarker.loader;
    8.43 -
    8.44 -import java.io.IOException;
    8.45 -import org.netbeans.modules.freemarker.MimeTypes;
    8.46 -import org.openide.filesystems.FileObject;
    8.47 -import org.openide.loaders.DataObjectExistsException;
    8.48 -import org.openide.loaders.MultiDataObject;
    8.49 -import org.openide.loaders.UniFileLoader;
    8.50 -import org.openide.util.NbBundle;
    8.51 -
    8.52 -public class FreemarkerDataLoader extends UniFileLoader {
    8.53 -
    8.54 -    private static final long serialVersionUID = 1L;
    8.55 -
    8.56 -    public FreemarkerDataLoader() {
    8.57 -        super("org.netbeans.modules.freemarker.loader.FreemarkerDataObject"); // NOI18N
    8.58 -    }
    8.59 -
    8.60 -    @Override
    8.61 -    protected String defaultDisplayName() {
    8.62 -        return NbBundle.getMessage(FreemarkerDataLoader.class, "LBL_Freemarker_loader_name");
    8.63 -    }
    8.64 -
    8.65 -    @Override
    8.66 -    protected FileObject findPrimaryFile(FileObject fo) {
    8.67 -        Object attr = fo.getAttribute("javax.script.ScriptEngine"); // NOI18N
    8.68 -        
    8.69 -        if (attr == null || !(attr instanceof String)) {
    8.70 -            return null;
    8.71 -        }
    8.72 -        
    8.73 -        return fo;
    8.74 -    }
    8.75 -
    8.76 -    protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
    8.77 -        return new FreemarkerDataObject(primaryFile, this);
    8.78 -    }
    8.79 -
    8.80 -    @Override
    8.81 -    protected String actionsContext() {
    8.82 -        return "Loaders/" + MimeTypes.FREEMARKER_TOP_LEVEL + "/Actions";
    8.83 -    }
    8.84 -
    8.85 -}
     9.1 --- a/freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataLoaderBeanInfo.java	Fri Nov 11 10:35:39 2011 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,63 +0,0 @@
     9.4 -/*
     9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     9.6 - * 
     9.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     9.8 - * 
     9.9 - * The contents of this file are subject to the terms of either the GNU
    9.10 - * General Public License Version 2 only ("GPL") or the Common
    9.11 - * Development and Distribution License("CDDL") (collectively, the
    9.12 - * "License"). You may not use this file except in compliance with the
    9.13 - * License. You can obtain a copy of the License at
    9.14 - * http://www.netbeans.org/cddl-gplv2.html
    9.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    9.16 - * specific language governing permissions and limitations under the
    9.17 - * License.  When distributing the software, include this License Header
    9.18 - * Notice in each file and include the License file at
    9.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    9.20 - * particular file as subject to the "Classpath" exception as provided
    9.21 - * by Sun in the GPL Version 2 section of the License file that
    9.22 - * accompanied this code. If applicable, add the following below the
    9.23 - * License Header, with the fields enclosed by brackets [] replaced by
    9.24 - * your own identifying information:
    9.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    9.26 - * 
    9.27 - * If you wish your version of this file to be governed by only the CDDL
    9.28 - * or only the GPL Version 2, indicate your decision by adding
    9.29 - * "[Contributor] elects to include this software in this distribution
    9.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    9.31 - * single choice of license, a recipient has the option to distribute
    9.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    9.33 - * to extend the choice of license to its licensees as provided above.
    9.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    9.35 - * Version 2 license, then the option applies only if the new code is
    9.36 - * made subject to such option by the copyright holder.
    9.37 - * 
    9.38 - * Contributor(s):
    9.39 - * 
    9.40 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
    9.41 - */
    9.42 -package org.netbeans.modules.freemarker.loader;
    9.43 -
    9.44 -import java.awt.Image;
    9.45 -import java.beans.BeanInfo;
    9.46 -import java.beans.IntrospectionException;
    9.47 -import java.beans.Introspector;
    9.48 -import java.beans.SimpleBeanInfo;
    9.49 -import org.openide.loaders.UniFileLoader;
    9.50 -
    9.51 -public class FreemarkerDataLoaderBeanInfo extends SimpleBeanInfo {
    9.52 -    @Override
    9.53 -    public BeanInfo[] getAdditionalBeanInfo() {
    9.54 -        try {
    9.55 -            return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    9.56 -        } catch (IntrospectionException e) {
    9.57 -            throw new AssertionError(e);
    9.58 -        }
    9.59 -    }
    9.60 -
    9.61 -    @Override
    9.62 -    public Image getIcon(int type) {
    9.63 -        return super.getIcon(type); // TODO add a custom icon here: Utilities.loadImage(..., true)
    9.64 -
    9.65 -    }
    9.66 -}
    10.1 --- a/freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataNode.java	Fri Nov 11 10:35:39 2011 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,70 +0,0 @@
    10.4 -/*
    10.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 - * 
    10.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    10.8 - * 
    10.9 - * The contents of this file are subject to the terms of either the GNU
   10.10 - * General Public License Version 2 only ("GPL") or the Common
   10.11 - * Development and Distribution License("CDDL") (collectively, the
   10.12 - * "License"). You may not use this file except in compliance with the
   10.13 - * License. You can obtain a copy of the License at
   10.14 - * http://www.netbeans.org/cddl-gplv2.html
   10.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   10.16 - * specific language governing permissions and limitations under the
   10.17 - * License.  When distributing the software, include this License Header
   10.18 - * Notice in each file and include the License file at
   10.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   10.20 - * particular file as subject to the "Classpath" exception as provided
   10.21 - * by Sun in the GPL Version 2 section of the License file that
   10.22 - * accompanied this code. If applicable, add the following below the
   10.23 - * License Header, with the fields enclosed by brackets [] replaced by
   10.24 - * your own identifying information:
   10.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   10.26 - * 
   10.27 - * If you wish your version of this file to be governed by only the CDDL
   10.28 - * or only the GPL Version 2, indicate your decision by adding
   10.29 - * "[Contributor] elects to include this software in this distribution
   10.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   10.31 - * single choice of license, a recipient has the option to distribute
   10.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   10.33 - * to extend the choice of license to its licensees as provided above.
   10.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   10.35 - * Version 2 license, then the option applies only if the new code is
   10.36 - * made subject to such option by the copyright holder.
   10.37 - * 
   10.38 - * Contributor(s):
   10.39 - * 
   10.40 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
   10.41 - */
   10.42 -package org.netbeans.modules.freemarker.loader;
   10.43 -
   10.44 -import org.openide.loaders.DataNode;
   10.45 -import org.openide.nodes.Children;
   10.46 -import org.openide.util.Lookup;
   10.47 -
   10.48 -public class FreemarkerDataNode extends DataNode {
   10.49 -    private static final String IMAGE_ICON_BASE = "SET/PATH/TO/ICON/HERE";
   10.50 -
   10.51 -    public FreemarkerDataNode(FreemarkerDataObject obj) {
   10.52 -        super(obj, Children.LEAF);
   10.53 -//        setIconBaseWithExtension(IMAGE_ICON_BASE);
   10.54 -    }
   10.55 -
   10.56 -    FreemarkerDataNode(FreemarkerDataObject obj, Lookup lookup) {
   10.57 -        super(obj, Children.LEAF, lookup);
   10.58 -//        setIconBaseWithExtension(IMAGE_ICON_BASE);
   10.59 -    }
   10.60 -
   10.61 -//    /** Creates a property sheet. */
   10.62 -//    @Override
   10.63 -//    protected Sheet createSheet() {
   10.64 -//        Sheet s = super.createSheet();
   10.65 -//        Sheet.Set ss = s.get(Sheet.PROPERTIES);
   10.66 -//        if (ss == null) {
   10.67 -//            ss = Sheet.createPropertiesSet();
   10.68 -//            s.put(ss);
   10.69 -//        }
   10.70 -//        // TODO add some relevant properties: ss.put(...)
   10.71 -//        return s;
   10.72 -//    }
   10.73 -}
    11.1 --- a/freemarker/src/org/netbeans/modules/freemarker/loader/FreemarkerDataObject.java	Fri Nov 11 10:35:39 2011 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,208 +0,0 @@
    11.4 -/*
    11.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    11.6 - * 
    11.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    11.8 - * 
    11.9 - * The contents of this file are subject to the terms of either the GNU
   11.10 - * General Public License Version 2 only ("GPL") or the Common
   11.11 - * Development and Distribution License("CDDL") (collectively, the
   11.12 - * "License"). You may not use this file except in compliance with the
   11.13 - * License. You can obtain a copy of the License at
   11.14 - * http://www.netbeans.org/cddl-gplv2.html
   11.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   11.16 - * specific language governing permissions and limitations under the
   11.17 - * License.  When distributing the software, include this License Header
   11.18 - * Notice in each file and include the License file at
   11.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   11.20 - * particular file as subject to the "Classpath" exception as provided
   11.21 - * by Sun in the GPL Version 2 section of the License file that
   11.22 - * accompanied this code. If applicable, add the following below the
   11.23 - * License Header, with the fields enclosed by brackets [] replaced by
   11.24 - * your own identifying information:
   11.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   11.26 - * 
   11.27 - * If you wish your version of this file to be governed by only the CDDL
   11.28 - * or only the GPL Version 2, indicate your decision by adding
   11.29 - * "[Contributor] elects to include this software in this distribution
   11.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   11.31 - * single choice of license, a recipient has the option to distribute
   11.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   11.33 - * to extend the choice of license to its licensees as provided above.
   11.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   11.35 - * Version 2 license, then the option applies only if the new code is
   11.36 - * made subject to such option by the copyright holder.
   11.37 - * 
   11.38 - * Contributor(s):
   11.39 - * 
   11.40 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
   11.41 - */
   11.42 -package org.netbeans.modules.freemarker.loader;
   11.43 -
   11.44 -import java.io.IOException;
   11.45 -import javax.swing.text.EditorKit;
   11.46 -import javax.swing.text.StyledDocument;
   11.47 -import org.netbeans.api.lexer.InputAttributes;
   11.48 -import org.netbeans.api.lexer.LanguagePath;
   11.49 -import org.netbeans.modules.freemarker.TopLevelFreeMarkerTokenId;
   11.50 -import org.netbeans.modules.freemarker.MimeTypes;
   11.51 -import org.openide.cookies.CloseCookie;
   11.52 -import org.openide.cookies.EditCookie;
   11.53 -import org.openide.cookies.EditorCookie;
   11.54 -import org.openide.cookies.OpenCookie;
   11.55 -import org.openide.cookies.PrintCookie;
   11.56 -import org.openide.cookies.SaveCookie;
   11.57 -import org.openide.filesystems.FileLock;
   11.58 -import org.openide.filesystems.FileObject;
   11.59 -import org.openide.loaders.DataObject;
   11.60 -import org.openide.loaders.DataObjectExistsException;
   11.61 -import org.openide.loaders.MultiDataObject;
   11.62 -import org.openide.nodes.CookieSet;
   11.63 -import org.openide.nodes.Node;
   11.64 -import org.openide.nodes.Node.Cookie;
   11.65 -import org.openide.text.CloneableEditorSupport;
   11.66 -import org.openide.util.Lookup;
   11.67 -import org.openide.text.DataEditorSupport;
   11.68 -import org.openide.windows.CloneableOpenSupport;
   11.69 -
   11.70 -public class FreemarkerDataObject extends MultiDataObject {
   11.71 -    public FreemarkerDataObject(FileObject pf, FreemarkerDataLoader loader) throws DataObjectExistsException, IOException {
   11.72 -        super(pf, loader);
   11.73 -        CookieSet cookies = getCookieSet();
   11.74 -        CloneableEditorSupport des = new SimpleES(this, getPrimaryEntry(), cookies);
   11.75 -        des.setMIMEType(MimeTypes.prepareCompoundMimeType(pf));
   11.76 -        cookies.add((Node.Cookie) des);
   11.77 -    }
   11.78 -    
   11.79 -
   11.80 -    @Override
   11.81 -    protected Node createNodeDelegate() {
   11.82 -        return new FreemarkerDataNode(this, getLookup());
   11.83 -    }
   11.84 -
   11.85 -    @Override
   11.86 -    public Lookup getLookup() {
   11.87 -        return getCookieSet().getLookup();
   11.88 -    }
   11.89 -
   11.90 -
   11.91 -    private static final class SimpleES extends DataEditorSupport
   11.92 -            implements OpenCookie, EditCookie, EditorCookie.Observable, PrintCookie, CloseCookie {
   11.93 -        /** SaveCookie for this support instance. The cookie is adding/removing 
   11.94 -         * data object's cookie set depending on if modification flag was set/unset. */
   11.95 -        private final SaveCookie saveCookie = new SaveCookie() {
   11.96 -            /** Implements <code>SaveCookie</code> interface. */
   11.97 -            public void save() throws IOException {
   11.98 -                SimpleES.this.saveDocument();
   11.99 -            }
  11.100 -        };
  11.101 -
  11.102 -        private CookieSet set;
  11.103 -
  11.104 -        /** Constructor. 
  11.105 -         * @param obj data object to work on
  11.106 -         * @param set set to add/remove save cookie from
  11.107 -         */
  11.108 -        SimpleES(DataObject obj, MultiDataObject.Entry entry, CookieSet set) {
  11.109 -            super(obj, new Environment(obj, entry));
  11.110 -            this.set = set;
  11.111 -        }
  11.112 -
  11.113 -        /** 
  11.114 -         * Overrides superclass method. Adds adding of save cookie if the document has been marked modified.
  11.115 -         * @return true if the environment accepted being marked as modified
  11.116 -         *    or false if it has refused and the document should remain unmodified
  11.117 -         */
  11.118 -        @Override
  11.119 -        protected boolean notifyModified() {
  11.120 -            if (!super.notifyModified()) {
  11.121 -                return false;
  11.122 -            }
  11.123 -
  11.124 -            addSaveCookie();
  11.125 -
  11.126 -            return true;
  11.127 -        }
  11.128 -
  11.129 -        /** Overrides superclass method. Adds removing of save cookie. */
  11.130 -        @Override
  11.131 -        protected void notifyUnmodified() {
  11.132 -            super.notifyUnmodified();
  11.133 -
  11.134 -            removeSaveCookie();
  11.135 -        }
  11.136 -
  11.137 -        @Override
  11.138 -        protected StyledDocument createStyledDocument(EditorKit kit) {
  11.139 -            StyledDocument result = super.createStyledDocument(kit);
  11.140 -            InputAttributes attributes = new InputAttributes();
  11.141 -            
  11.142 -            attributes.setValue(LanguagePath.get(TopLevelFreeMarkerTokenId.language()),
  11.143 -                                MimeTypes.MIME_TYPE_PROPERTY,
  11.144 -                                result.getProperty(MimeTypes.MIME_TYPE_PROPERTY),
  11.145 -                                true);
  11.146 -            
  11.147 -            result.putProperty(InputAttributes.class, attributes);
  11.148 -            
  11.149 -            return result;
  11.150 -        }
  11.151 -
  11.152 -        /** Helper method. Adds save cookie to the data object. */
  11.153 -        private void addSaveCookie() {
  11.154 -            DataObject obj = getDataObject();
  11.155 -
  11.156 -            // Adds save cookie to the data object.
  11.157 -            if (obj.getCookie(SaveCookie.class) == null) {
  11.158 -                set.add(saveCookie);
  11.159 -                obj.setModified(true);
  11.160 -            }
  11.161 -        }
  11.162 -
  11.163 -        /** Helper method. Removes save cookie from the data object. */
  11.164 -        private void removeSaveCookie() {
  11.165 -            DataObject obj = getDataObject();
  11.166 -
  11.167 -            // Remove save cookie from the data object.
  11.168 -            Cookie cookie = obj.getCookie(SaveCookie.class);
  11.169 -
  11.170 -            if (cookie != null && cookie.equals(saveCookie)) {
  11.171 -                set.remove(saveCookie);
  11.172 -                obj.setModified(false);
  11.173 -            }
  11.174 -        }
  11.175 -        /** Nested class. Environment for this support. Extends
  11.176 -         * <code>DataEditorSupport.Env</code> abstract class.
  11.177 -         */
  11.178 -        private static class Environment extends DataEditorSupport.Env {
  11.179 -            private static final long serialVersionUID = 5451434321155443431L;
  11.180 -
  11.181 -            private MultiDataObject.Entry entry;
  11.182 -
  11.183 -            /** Constructor. */
  11.184 -            public Environment(DataObject obj, MultiDataObject.Entry entry) {
  11.185 -                super(obj);
  11.186 -                this.entry = entry;
  11.187 -            }
  11.188 -
  11.189 -            /** Implements abstract superclass method. */
  11.190 -            protected FileObject getFile() {
  11.191 -                return entry.getFile();
  11.192 -            }
  11.193 -
  11.194 -            /** Implements abstract superclass method.*/
  11.195 -            protected FileLock takeLock() throws IOException {
  11.196 -                return entry.takeLock();
  11.197 -            }
  11.198 -
  11.199 -            /** 
  11.200 -             * Overrides superclass method.
  11.201 -             * @return text editor support (instance of enclosing class)
  11.202 -             */
  11.203 -            @Override
  11.204 -            public CloneableOpenSupport findCloneableOpenSupport() {
  11.205 -                return getDataObject().getCookie(SimpleES.class);
  11.206 -            }
  11.207 -        } // End of nested Environment class.
  11.208 -
  11.209 -    }
  11.210 -    
  11.211 -}