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:
042: package org.netbeans.modules.vmd.palette;
043:
044: import java.io.IOException;
045: import java.io.InputStream;
046: import java.util.Properties;
047: import org.netbeans.modules.vmd.api.model.Debug;
048: import org.openide.filesystems.FileAttributeEvent;
049: import org.openide.filesystems.FileChangeListener;
050: import org.openide.filesystems.FileEvent;
051: import org.openide.filesystems.FileObject;
052: import org.openide.filesystems.FileRenameEvent;
053: import org.openide.loaders.DataObjectExistsException;
054: import org.openide.loaders.MultiDataObject;
055: import org.openide.nodes.Node;
056: import org.openide.util.WeakListeners;
057:
058: /**
059: *
060: * @author Anton Chechel
061: */
062: public class PaletteItemDataObject extends MultiDataObject implements
063: FileChangeListener {
064: private String producerID;
065: private String displayName;
066: private String toolTip;
067: private String icon;
068: private String bigIcon;
069:
070: public PaletteItemDataObject(FileObject fileObject,
071: PaletteItemDataLoader loader)
072: throws DataObjectExistsException, IOException {
073: super (fileObject, loader);
074:
075: FileChangeListener fileChangeListener = WeakListeners.create(
076: FileChangeListener.class, this , fileObject);
077: fileObject.addFileChangeListener(fileChangeListener);
078:
079: readProperties(fileObject);
080: }
081:
082: @Override
083: protected Node createNodeDelegate() {
084: return new PaletteItemDataNode(this );
085: }
086:
087: private void readProperties(FileObject pf) throws IOException {
088: Properties props = new Properties();
089: InputStream is = null;
090: try {
091: is = pf.getInputStream();
092: props.load(is);
093: } finally {
094: if (is != null) {
095: try {
096: is.close();
097: } catch (IOException e) {
098: Debug.warning(e.toString());
099: }
100: }
101: }
102: producerID = props.getProperty("producerID"); // NOI18N
103: displayName = props.getProperty("displayName"); // NOI18N
104: toolTip = props.getProperty("toolTip"); // NOI18N
105: icon = props.getProperty("icon"); // NOI18N
106: if (icon != null && icon.length() == 0) {
107: icon = null;
108: }
109: bigIcon = props.getProperty("bigIcon"); // NOI18N
110: if (bigIcon != null && bigIcon.length() == 0) {
111: bigIcon = null;
112: }
113: }
114:
115: String getProducerID() {
116: return producerID;
117: }
118:
119: String getDisplayName() {
120: return displayName;
121: }
122:
123: String getToolTip() {
124: return toolTip;
125: }
126:
127: String getIcon() {
128: return icon;
129: }
130:
131: String getBigIcon() {
132: return bigIcon;
133: }
134:
135: String getProjectType() {
136: String path = getPrimaryFile().getPath();
137: return path.substring(0, path.indexOf('/')); // NOI18N
138: }
139:
140: public void fileFolderCreated(FileEvent fe) {
141: }
142:
143: public void fileDataCreated(FileEvent fe) {
144: }
145:
146: public void fileChanged(FileEvent fe) {
147: try {
148: readProperties(fe.getFile());
149: } catch (IOException ex) {
150: Debug.warning(ex);
151: }
152: }
153:
154: public void fileDeleted(FileEvent fe) {
155: }
156:
157: public void fileRenamed(FileRenameEvent fe) {
158: }
159:
160: public void fileAttributeChanged(FileAttributeEvent fe) {
161: }
162: }
|