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