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

it.tidalwave.metadata.persistence.node.impl.ValueNode Maven / Gradle / Ivy

/*******************************************************************************
 *
 * blueMarine - open source photo workflow
 * =======================================
 *
 * Copyright (C) 2003-2009 by Fabrizio Giudici
 * Project home page: http://bluemarine.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. 
 *
 *******************************************************************************
 *
 * $Id: ValueNode.java,v d60681e7fc1d 2009/09/17 23:59:23 fabrizio $
 *
 ******************************************************************************/
package it.tidalwave.metadata.persistence.node.impl;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import javax.swing.SwingUtilities;
import org.openide.util.WeakListeners;
import org.openide.nodes.PropertySupport;
import it.tidalwave.metadata.persistence.MetadataProperty;
import it.tidalwave.metadata.persistence.PropertyAndValue;
import javax.annotation.Nonnull;

/*******************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: ValueNode.java,v d60681e7fc1d 2009/09/17 23:59:23 fabrizio $
 *
 ******************************************************************************/
public class ValueNode extends ManagedNode
  {
    @Nonnull
    private final PropertyAndValue propertyAndValue;
    
    /***************************************************************************
     *
     *
     **************************************************************************/
    private final PropertyChangeListener propertyChangeListener = new PropertyChangeListener() 
      {
        public void propertyChange (@Nonnull final PropertyChangeEvent event)
          {
            SwingUtilities.invokeLater(new Runnable()  
              {
                public void run() 
                  {
                    refreshAttributes();
                  }
              });  
          }
      };
    
    /***************************************************************************
     *
     *
     **************************************************************************/
    protected ValueNode (@Nonnull final MetadataProperty property,
                         @Nonnull final Object object)
      {
        this(property.findOrCreatePropertyAndValue(object));
        
        final Property nbProperty = new PropertySupport.ReadOnly("dataObjectCount", String.class, "#", "")
          {
            private String previousValue = "..."; // show ellipses only the first time
            
            @Override
            @Nonnull
            public String getValue() 
              {
                try
                  {
                    return previousValue = Integer.toString(propertyAndValue.getDataObjectCount());
                  }
                catch (PropertyAndValue.TemporarilyUnavailableException e)
                  {
                    return previousValue;
                  }
              }
          };
          
        nbProperty.setValue("suppressCustomEditor", true);
        addProperty(nbProperty);
      }

    /***************************************************************************
     *
     *
     **************************************************************************/
    private ValueNode (@Nonnull final PropertyAndValue propertyAndValue)
      {
        super(propertyAndValue);
        this.propertyAndValue = propertyAndValue;
        refreshAttributes();
        propertyAndValue.addPropertyChangeListener(WeakListeners.propertyChange(propertyChangeListener, propertyAndValue));
      }

//    /***************************************************************************
//     *
//     *
//     **************************************************************************/
//    @Override
//    public void destroy() 
//      throws IOException
//      {
//        super.destroy();
////        categoryChildFactory.getNodeFinder().remove(metadataTag); TODO
//      }
    
    /***************************************************************************
     *
     *
     **************************************************************************/
    @Override
    @Nonnull
    public String toString()
      {
        return String.format("ValueNode[%s]", propertyAndValue);
      }

    /***************************************************************************
     *
     *
     **************************************************************************/
    public final void refreshChildren()
      {
      }
    
    /***************************************************************************
     *
     *
     **************************************************************************/
    protected void refreshAttributes() 
      {
        final String string = nodeManager.getDisplayName(this);
        setName(string);
        setDisplayName(string);
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy