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

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

The newest version!
/***********************************************************************************************************************
 *
 * blueMarine Metadata - open source media workflow
 * Copyright (C) 2007-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://bluemarine.tidalwave.it
 * SCM: https://kenai.com/hg/bluemarine~metadata-src
 *
 **********************************************************************************************************************/
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$
 *
 ******************************************************************************/
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