1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.netbeans.modules.office.loader; 25 26 import java.awt.datatransfer.Transferable; 27 import java.util.List; 28 import java.io.*; 29 30 import org.openide.loaders.*; 31 import org.openide.nodes.*; 32 import org.openide.util.NbBundle; 33 import org.openide.filesystems.*; 34 35 import org.openoffice.netbeans.modules.office.actions.OfficeDocumentCookie; 36 import org.openoffice.netbeans.modules.office.nodes.OfficeDocumentChildren; 37 38 /** A node to represent this object. 39 * 40 * @author tomaso 41 */ 42 public class OfficeDocumentDataNode extends DataNode { 43 OfficeDocumentDataNode(OfficeDocumentDataObject obj)44 public OfficeDocumentDataNode(OfficeDocumentDataObject obj) { 45 // this(obj, Children.LEAF); 46 this(obj, new OfficeDocumentChildren((OfficeDocumentCookie) 47 obj.getCookie(OfficeDocumentCookie.class))); 48 } 49 OfficeDocumentDataNode(OfficeDocumentDataObject obj, Children ch)50 public OfficeDocumentDataNode(OfficeDocumentDataObject obj, Children ch) { 51 super(obj, ch); 52 setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon"); 53 } 54 getOfficeDocumentDataObject()55 protected OfficeDocumentDataObject getOfficeDocumentDataObject() { 56 return (OfficeDocumentDataObject)getDataObject(); 57 } 58 59 // Allow for pasting of Script Parcels to Office Documents createPasteTypes(Transferable t, List ls)60 protected void createPasteTypes(Transferable t, List ls) { 61 Node[] copies = NodeTransfer.nodes(t, NodeTransfer.COPY); 62 63 if (copies != null) { 64 for (int i = 0; i < copies.length; i++) { 65 if (copies[i] instanceof ParcelDataNode) { 66 File source = FileUtil.toFile(((ParcelDataNode)copies[i]).getDataObject().getPrimaryFile()); 67 File target = FileUtil.toFile(getDataObject().getPrimaryFile()); 68 69 if (source.exists() && source.canRead() && 70 target.exists() && target.canWrite()) { 71 ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)copies[i], target, false)); 72 } 73 } 74 } 75 } 76 77 Node[] moves = NodeTransfer.nodes(t, NodeTransfer.MOVE); 78 if (moves != null) { 79 for (int i = 0; i < moves.length; i++) { 80 if (moves[i] instanceof ParcelDataNode) { 81 File source = FileUtil.toFile(((ParcelDataNode)moves[i]).getDataObject().getPrimaryFile()); 82 File target = FileUtil.toFile(getDataObject().getPrimaryFile()); 83 84 if (source.exists() && source.canRead() && 85 target.exists() && target.canWrite()) { 86 ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)moves[i], target, true)); 87 } 88 } 89 } 90 } 91 92 // Also try superclass, but give it lower priority: 93 super.createPasteTypes(t, ls); 94 } 95 96 /* Example of adding Executor / Debugger / Arguments to node: 97 protected Sheet createSheet() { 98 Sheet sheet = super.createSheet(); 99 Sheet.Set set = sheet.get(ExecSupport.PROP_EXECUTION); 100 if (set == null) { 101 set = new Sheet.Set(); 102 set.setName(ExecSupport.PROP_EXECUTION); 103 set.setDisplayName(NbBundle.getMessage(OfficeDocumentDataNode.class, "LBL_DataNode_exec_sheet")); 104 set.setShortDescription(NbBundle.getMessage(OfficeDocumentDataNode.class, "HINT_DataNode_exec_sheet")); 105 } 106 ((ExecSupport)getCookie(ExecSupport.class)).addProperties(set); 107 // Maybe: 108 ((CompilerSupport)getCookie(CompilerSupport.class)).addProperties(set); 109 sheet.put(set); 110 return sheet; 111 } 112 */ 113 114 // Don't use getDefaultAction(); just make that first in the data loader's getActions list 115 116 } 117