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.io.*;
27 import java.awt.datatransfer.Transferable;
28 import java.util.zip.*;
29 
30 import org.openide.loaders.*;
31 import org.openide.nodes.*;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.NbBundle;
34 import org.openide.util.datatransfer.*;
35 import org.openide.ErrorManager;
36 import org.openide.windows.OutputWriter;
37 
38 import org.openoffice.netbeans.modules.office.actions.ParcelCookie;
39 
40 /** A node to represent this object.
41  *
42  * @author tomaso
43  */
44 public class ParcelDataNode extends DataNode {
45 
ParcelDataNode(ParcelDataObject obj)46     public ParcelDataNode(ParcelDataObject obj) {
47         this(obj, Children.LEAF);
48     }
49 
ParcelDataNode(ParcelDataObject obj, Children ch)50     public ParcelDataNode(ParcelDataObject obj, Children ch) {
51         super(obj, ch);
52         setIconBase("/org/openoffice/netbeans/modules/office/resources/ParcelIcon");
53     }
54 
getParcelDataObject()55     protected ParcelDataObject getParcelDataObject() {
56         return (ParcelDataObject)getDataObject();
57     }
58 
59     public static class ParcelPasteType extends PasteType {
60         ParcelDataNode sourceParcel = null;
61         File targetDocument = null;
62         boolean isCut = false;
63 
ParcelPasteType(ParcelDataNode sourceParcel, File targetDocument, boolean isCut)64         public ParcelPasteType(ParcelDataNode sourceParcel,
65             File targetDocument, boolean isCut) {
66             this.sourceParcel = sourceParcel;
67             this.targetDocument = targetDocument;
68             this.isCut = isCut;
69         }
70 
paste()71         public Transferable paste() {
72             ParcelCookie parcelCookie =
73                 (ParcelCookie)sourceParcel.getCookie(ParcelCookie.class);
74             parcelCookie.deploy(targetDocument);
75 
76             if (isCut == true) {
77                 FileObject fo = sourceParcel.getDataObject().getPrimaryFile();
78                 try {
79                     fo.delete();
80                 }
81                 catch (IOException ioe) {}
82                 return ExTransferable.EMPTY;
83             }
84             else {
85                 return null;
86             }
87         }
88     }
89 
90     /* Example of adding Executor / Debugger / Arguments to node:
91     protected Sheet createSheet() {
92         Sheet sheet = super.createSheet();
93         Sheet.Set set = sheet.get(ExecSupport.PROP_EXECUTION);
94         if (set == null) {
95             set = new Sheet.Set();
96             set.setName(ExecSupport.PROP_EXECUTION);
97             set.setDisplayName(NbBundle.getMessage(ParcelDataNode.class, "LBL_DataNode_exec_sheet"));
98             set.setShortDescription(NbBundle.getMessage(ParcelDataNode.class, "HINT_DataNode_exec_sheet"));
99         }
100         ((ExecSupport)getCookie(ExecSupport.class)).addProperties(set);
101         // Maybe:
102         ((CompilerSupport)getCookie(CompilerSupport.class)).addProperties(set);
103         sheet.put(set);
104         return sheet;
105     }
106      */
107 
108     // Don't use getDefaultAction(); just make that first in the data loader's getActions list
109 
110 }
111