Coverage Report - net.sf.webphotos.netbeans.project.WebPhotosProjectLogicalView
 
Classes in this File Line Coverage Branch Coverage Complexity
WebPhotosProjectLogicalView
0%
0/11
N/A
1,25
WebPhotosProjectLogicalView$ConfigurationNode
0%
0/13
N/A
1,25
 
 1  
 /**
 2  
  * Copyright 2008 WebPhotos
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package net.sf.webphotos.netbeans.project;
 18  
 
 19  
 import java.awt.Image;
 20  
 import javax.swing.Action;
 21  
 import org.netbeans.spi.project.ui.LogicalViewProvider;
 22  
 import org.netbeans.spi.project.ui.support.CommonProjectActions;
 23  
 import org.openide.filesystems.FileObject;
 24  
 import org.openide.loaders.DataFolder;
 25  
 import org.openide.loaders.DataObjectNotFoundException;
 26  
 import org.openide.nodes.AbstractNode;
 27  
 import org.openide.nodes.Children;
 28  
 import org.openide.nodes.FilterNode;
 29  
 import org.openide.nodes.Node;
 30  
 import org.openide.util.Exceptions;
 31  
 import org.openide.util.ImageUtilities;
 32  
 import org.openide.util.Lookup;
 33  
 import org.openide.util.lookup.Lookups;
 34  
 import org.openide.util.lookup.ProxyLookup;
 35  
 
 36  
 /**
 37  
  *
 38  
  * @author Guilherme
 39  
  */
 40  
 class WebPhotosProjectLogicalView implements LogicalViewProvider {
 41  
 
 42  
     private final WebPhotosProject webPhotosProject;
 43  
 
 44  0
     public WebPhotosProjectLogicalView(WebPhotosProject webPhotosProject) {
 45  0
         this.webPhotosProject = webPhotosProject;
 46  0
     }
 47  
 
 48  
     @Override
 49  
     public Node createLogicalView() {
 50  
         try {
 51  
             //Get the Text directory, creating if deleted
 52  0
             FileObject configuration = webPhotosProject.getFolder(0, true);
 53  
 
 54  
             //Get the DataObject that represents it
 55  0
             DataFolder configurationDataObject = DataFolder.findFolder(configuration);
 56  
 
 57  
             //Get its default node-we'll wrap our node around it to change the
 58  
             //display name, icon, etc
 59  0
             Node realConfigurationFolderNode = configurationDataObject.getNodeDelegate();
 60  
 
 61  
             //This FilterNode will be our project node
 62  0
             return new ConfigurationNode(realConfigurationFolderNode, webPhotosProject);
 63  
 
 64  0
         } catch (DataObjectNotFoundException donfe) {
 65  0
             Exceptions.printStackTrace(donfe);
 66  
             //Fallback-the directory couldn't be created -
 67  
             //read-only filesystem or something evil happened
 68  0
             return new AbstractNode(Children.LEAF);
 69  
         }
 70  
     }
 71  
     
 72  
     /** 
 73  
      * This is the node you actually see in the project tab for the project 
 74  
      */
 75  
     private static final class ConfigurationNode extends FilterNode {
 76  
 
 77  
         final WebPhotosProject project;
 78  
 
 79  
         public ConfigurationNode(Node node, WebPhotosProject project) throws DataObjectNotFoundException {
 80  0
             super(node, new FilterNode.Children(node),
 81  
                     //The projects system wants the project in the Node's lookup.
 82  
                     //NewAction and friends want the original Node's lookup.
 83  
                     //Make a merge of both
 84  
                     new ProxyLookup(new Lookup[]{Lookups.singleton(project),
 85  
                         node.getLookup()
 86  
                     }));
 87  0
             this.project = project;
 88  0
         }
 89  
 
 90  
         @Override
 91  
         public Action[] getActions(boolean arg0) {
 92  0
             Action[] nodeActions = new Action[7];
 93  0
             nodeActions[0] = CommonProjectActions.newFileAction();
 94  0
             nodeActions[1] = CommonProjectActions.copyProjectAction();
 95  0
             nodeActions[2] = CommonProjectActions.deleteProjectAction();
 96  0
             nodeActions[5] = CommonProjectActions.setAsMainProjectAction();
 97  0
             nodeActions[6] = CommonProjectActions.closeProjectAction();
 98  0
             return nodeActions;
 99  
         }
 100  
 
 101  
         @Override
 102  
         public Image getIcon(int type) {
 103  0
             return ImageUtilities.loadImage(Constants.PROJECT_ICON);
 104  
         }
 105  
 
 106  
         @Override
 107  
         public Image getOpenedIcon(int type) {
 108  0
             return getIcon(type);
 109  
         }
 110  
 
 111  
         @Override
 112  
         public String getDisplayName() {
 113  0
             return project.getProjectDirectory().getName();
 114  
         }
 115  
 
 116  
     }
 117  
 
 118  
     @Override
 119  
     public Node findPath(Node root, Object target) {
 120  
         //leave unimplemented for now
 121  0
         return null;
 122  
     }
 123  
 
 124  
 }