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 org.openide.actions.*;
27  import org.openide.cookies.*;
28  import org.openide.filesystems.*;
29  import org.openide.loaders.*;
30  import org.openide.nodes.*;
31  import org.openide.util.HelpCtx;
32  
33  import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorEditorSupport;
34  import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserSupport;
35  
36  /** Represents a ParcelDescriptor object in the Repository.
37   *
38   * @author tomaso
39   */
40  public class ParcelDescriptorDataObject extends MultiDataObject {
41  
42      private boolean canParse = false;
43  
ParcelDescriptorDataObject(FileObject pf, ParcelDescriptorDataLoader loader)44      public ParcelDescriptorDataObject(FileObject pf, ParcelDescriptorDataLoader loader) throws DataObjectExistsException {
45          super(pf, loader);
46          init();
47      }
48  
init()49      private void init() {
50          FileObject fo = getPrimaryFile();
51          if (FileUtil.toFile(fo) != null)
52              canParse = true;
53  
54          CookieSet cookies = getCookieSet();
55          cookies.add(new ParcelDescriptorEditorSupport(this));
56          if (canParse == true)
57              cookies.add(new ParcelDescriptorParserSupport(getPrimaryFile()));
58      }
59  
getHelpCtx()60      public HelpCtx getHelpCtx() {
61          return HelpCtx.DEFAULT_HELP;
62      }
63  
createNodeDelegate()64      protected Node createNodeDelegate() {
65          if (canParse == true)
66              return new ParcelDescriptorDataNode(this);
67          else
68              return new ParcelDescriptorDataNode(this, Children.LEAF);
69      }
70  
71      // If you made an Editor Support you will want to add these methods:
addSaveCookie(SaveCookie save)72      public final void addSaveCookie(SaveCookie save) {
73          getCookieSet().add(save);
74      }
75  
removeSaveCookie(SaveCookie save)76      public final void removeSaveCookie(SaveCookie save) {
77          getCookieSet().remove(save);
78      }
79  }
80