ada.editor/src/org/netbeans/modules/ada/editor/AdaDataNode.java
author Andrea Lucarelli <raster@netbeans.org>
Sun, 22 Aug 2010 23:37:11 +0200
branchrelease68
changeset 16367 d2820c029d3a
permissions -rw-r--r--
Add JVM compiler support.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
     5  *
     6  * The contents of this file are subject to the terms of either the GNU
     7  * General Public License Version 2 only ("GPL") or the Common
     8  * Development and Distribution License("CDDL") (collectively, the
     9  * "License"). You may not use this file except in compliance with the
    10  * License. You can obtain a copy of the License at
    11  * http://www.netbeans.org/cddl-gplv2.html
    12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    13  * specific language governing permissions and limitations under the
    14  * License.  When distributing the software, include this License Header
    15  * Notice in each file and include the License file at
    16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    17  * particular file as subject to the "Classpath" exception as provided
    18  * by Sun in the GPL Version 2 section of the License file that
    19  * accompanied this code. If applicable, add the following below the
    20  * License Header, with the fields enclosed by brackets [] replaced by
    21  * your own identifying information:
    22  * "Portions Copyrighted [year] [name of copyright owner]"
    23  *
    24  * If you wish your version of this file to be governed by only the CDDL
    25  * or only the GPL Version 2, indicate your decision by adding
    26  * "[Contributor] elects to include this software in this distribution
    27  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    28  * single choice of license, a recipient has the option to distribute
    29  * your version of this file under either the CDDL, the GPL Version 2 or
    30  * to extend the choice of license to its licensees as provided above.
    31  * However, if you add GPL Version 2 code and therefore, elected the GPL
    32  * Version 2 license, then the option applies only if the new code is
    33  * made subject to such option by the copyright holder.
    34  *
    35  * Contributor(s):
    36  *
    37  * Portions Copyrighted 2009 Sun Microsystems, Inc.
    38  */
    39 package org.netbeans.modules.ada.editor;
    40 
    41 import java.awt.Image;
    42 import java.text.DateFormat;
    43 import org.openide.filesystems.FileAttributeEvent;
    44 import org.openide.filesystems.FileChangeListener;
    45 import org.openide.filesystems.FileEvent;
    46 import org.openide.filesystems.FileRenameEvent;
    47 import org.openide.loaders.DataNode;
    48 import org.openide.loaders.DataObject;
    49 import org.openide.nodes.FilterNode.Children;
    50 import org.openide.util.ImageUtilities;
    51 import org.openide.util.Lookup;
    52 
    53 /**
    54  *
    55  * @author Andrea Lucarelli
    56  */
    57 public class AdaDataNode extends DataNode implements FileChangeListener {
    58 
    59     private static final String ADS_ICON = "/org/netbeans/modules/ada/editor/resources/icons/ads-16.png";
    60     private static final String ADB_ICON = "/org/netbeans/modules/ada/editor/resources/icons/adb-16.png";
    61     private static final String ADA_SPEC_ICON = "/org/netbeans/modules/ada/editor/resources/icons/ada-spec-16.png";
    62     private static final String ADA_BODY_ICON = "/org/netbeans/modules/ada/editor/resources/icons/ada-body-16.png";
    63     private AdaDataObject obj;
    64     private String displayName;
    65     private String tooltip;
    66     private Image icon;
    67 
    68     public AdaDataNode(AdaDataObject obj) {
    69         super(obj, Children.LEAF);
    70         this.obj = obj;
    71     }
    72 
    73     public AdaDataNode(DataObject obj, Lookup lookup) {
    74         super(obj, Children.LEAF, lookup);
    75         //Add file change listener to the FileObject:
    76         //obj.getPrimaryFile().addFileChangeListener(this);
    77         //Set default icon:
    78         if (obj.getPrimaryFile().getExt().equalsIgnoreCase("ads")) {
    79             setIconBaseWithExtension(ADS_ICON);
    80             icon = ImageUtilities.loadImage(ADS_ICON);
    81         } else if (obj.getPrimaryFile().getExt().equalsIgnoreCase("adb")) {
    82             setIconBaseWithExtension(ADB_ICON);
    83             icon = ImageUtilities.loadImage(ADB_ICON);
    84         } else {
    85             // TODO: manage the contents for set the icon
    86             setIconBaseWithExtension(ADA_SPEC_ICON);
    87             icon = ImageUtilities.loadImage(ADA_SPEC_ICON);
    88         }
    89 
    90         //Set default tooltip:
    91         tooltip = obj.getPrimaryFile().getNameExt();
    92         setShortDescription (tooltip);
    93     }
    94 
    95     @Override
    96     public String getDisplayName() {
    97         if (null != displayName) {
    98             return displayName;
    99         }
   100         return super.getDisplayName();
   101     }
   102 
   103     @Override
   104     public String getShortDescription() {
   105         if (null != tooltip) {
   106             return tooltip;
   107         }
   108         return super.getShortDescription();
   109     }
   110 
   111     @Override
   112     public Image getIcon(int arg0) {
   113         if (null != icon) {
   114             return icon;
   115         }
   116         return super.getIcon(arg0);
   117     }
   118 
   119     //When the file changes...
   120     @Override
   121     public void fileChanged(FileEvent arg0) {
   122 
   123         //Get the milliseconds and format it:
   124         long mills = System.currentTimeMillis();
   125         DateFormat dateFormatter = DateFormat.getDateTimeInstance(
   126                 DateFormat.LONG,
   127                 DateFormat.LONG);
   128         String formatted = dateFormatter.format(mills);
   129 
   130         //Save the current display name:
   131         String oldDisplayName = displayName;
   132 
   133         //Save the current tooltip:
   134         String oldShortDescription = tooltip;
   135 
   136         //Set the new display name:
   137         displayName = "Change (" + formatted + ")";
   138 
   139         //Set the new tooltip:
   140         tooltip = formatted;
   141 
   142         //Fire change events on the node,
   143         //which will immediately refresh it with the new values:
   144         fireDisplayNameChange(oldDisplayName, displayName);
   145         fireShortDescriptionChange(oldShortDescription, tooltip);
   146         fireIconChange();
   147     }
   148 
   149     @Override
   150     public void fileFolderCreated(FileEvent arg0) {
   151     }
   152 
   153     @Override
   154     public void fileDataCreated(FileEvent arg0) {
   155     }
   156 
   157     @Override
   158     public void fileDeleted(FileEvent arg0) {
   159     }
   160 
   161     @Override
   162     public void fileRenamed(FileRenameEvent arg0) {
   163     }
   164 
   165     @Override
   166     public void fileAttributeChanged(FileAttributeEvent arg0) {
   167     }
   168 }