All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.netbeans.examples.nodes.example5.model.FileModel3 Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
/***********************************************************************************************************************
 *
 * OpenBlueSky - NetBeans Platform Enhancements
 * Copyright (C) 2006-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://openbluesky.java.net
 * SCM: https://bitbucket.org/tidalwave/openbluesky-src
 *
 **********************************************************************************************************************/
package it.tidalwave.netbeans.examples.nodes.example5.model;

import javax.annotation.Nonnull;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;
import it.tidalwave.util.spi.SimpleFinderSupport;
import it.tidalwave.role.Displayable;
import it.tidalwave.role.SimpleComposite;
import it.tidalwave.role.spi.DefaultSimpleComposite;
import it.tidalwave.role.spi.DefaultDisplayable;

/***********************************************************************************************************************
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public final class FileModel3 implements Lookup.Provider
  {
    @Getter
    private final Lookup lookup;
    
    private final File file;
    
    //@bluebook-begin Displayable
    private final Displayable displayable;
    //@bluebook-end Displayable
    
    //@bluebook-begin Composite
    private final SimpleComposite composite = new DefaultSimpleComposite(
        new SimpleFinderSupport()
          {
            @Override @Nonnull
            protected List computeResults() 
              {
                final List result = new ArrayList();
                final File[] children = file.listFiles();

                if (children != null)
                  {
                    for (final File child : children)
                      {
                        result.add(new FileModel3(child.getAbsolutePath()));
                      }
                  }

                return result;
              }
          });
    //@bluebook-end Composite
    
    public FileModel3 (final @Nonnull String path) 
      {        
        file = new File(path);
        //@bluebook-begin Displayable
        displayable = new DefaultDisplayable(file.getName());
        //@bluebook-end Displayable
        lookup = Lookups.fixed(displayable, composite); 
      }    
    
    @Nonnull
    public String getPath()
      {
        return file.getAbsolutePath();  
      }
    
    //@bluebook-ignore-begin
    @Override @Nonnull
    public String toString()
      {
        return String.format("FileModel3@%x[%s]", System.identityHashCode(this), getPath());  
      }
    //@bluebook-ignore-end
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy