Skip to content

Content of file PresentationModel.java.html

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>PresentationModel.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">TheseFoolishThings :: Examples :: DCI :: Displayable</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-role</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.role.ui</a> &gt; <span class="el_source">PresentationModel.java</span></div><h1>PresentationModel.java</h1><pre class="source lang-java linenums">/*
 * *********************************************************************************************************************
 *
 * TheseFoolishThings: Miscellaneous utilities
 * http://tidalwave.it/projects/thesefoolishthings
 *
 * Copyright (C) 2009 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
 *
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); 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 &quot;AS IS&quot; 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.
 *
 * *********************************************************************************************************************
 *
 * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
 * git clone https://github.com/tidalwave-it/thesefoolishthings-src
 *
 * *********************************************************************************************************************
 */
package it.tidalwave.role.ui;

import javax.annotation.Nonnull;
import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Collections;
import it.tidalwave.util.As;
import it.tidalwave.util.NamedCallback;
import it.tidalwave.role.ui.impl.DefaultPresentationModel;
import it.tidalwave.util.Parameters;
import static it.tidalwave.role.ui.Presentable._Presentable_;
import static it.tidalwave.util.Parameters.r;

/***********************************************************************************************************************
 *
 * TODO: As the NetBeans Node, it should allow children, have event listeners for children added/removed/changed.
As the NetBeans Node, it should allow children, have event listeners for children added/removed/changed.
* This class so becomes the true M in MVC. * * @stereotype Role * * @author Fabrizio Giudici * **********************************************************************************************************************/ public interface PresentationModel extends As { <span class="fc" id="L52"> public static Class&lt;PresentationModel&gt; PresentationModel = PresentationModel.class;</span> public static final String PROPERTY_CHILDREN = &quot;children&quot;; /** This is an undocumented feature. If you add a {@link NamedCallback} with this name as a role in this object, it * will be called back when {@link #dispose()} is called. */ public static final String CALLBACK_DISPOSE = &quot;dispose&quot;; /******************************************************************************************************************* * * Disposes this object. * ******************************************************************************************************************/ public void dispose(); /******************************************************************************************************************* * * Adds a {@link PropertyChangeListener}. * * @param listener the listener * ******************************************************************************************************************/ public void addPropertyChangeListener (@Nonnull PropertyChangeListener listener); /******************************************************************************************************************* * * Adds a {@link PropertyChangeListener} for the given property. * * @param propertyName the name of the property * @param listener the listener * ******************************************************************************************************************/ public void addPropertyChangeListener (@Nonnull String propertyName, @Nonnull PropertyChangeListener listener); /******************************************************************************************************************* * * Removes a {@link PropertyChangeListener}. * * @param listener the listener * ******************************************************************************************************************/ public void removePropertyChangeListener (@Nonnull PropertyChangeListener listener); /******************************************************************************************************************* * * Removes a {@link PropertyChangeListener} for the given property. * * @param propertyName the name of the property * @param listener the listener * ******************************************************************************************************************/ public void removePropertyChangeListener (@Nonnull String propertyName, @Nonnull PropertyChangeListener listener); /******************************************************************************************************************* * * Checks whether the given property has been bound to listeners. * * @param propertyName the name of the property * @return {@code true} if the property is bound * ******************************************************************************************************************/ public boolean hasListeners (@Nonnull String propertyName); /******************************************************************************************************************* * * Returns all the bound {@link PropertyChangeListener}s. * * @return the listeners * ******************************************************************************************************************/ @Nonnull public PropertyChangeListener[] getPropertyChangeListeners(); /******************************************************************************************************************* * * Returns the bound {@link PropertyChangeListener}s for the given property. * * @param propertyName the name of the property * @return the listeners * ******************************************************************************************************************/ @Nonnull public PropertyChangeListener[] getPropertyChangeListeners (@Nonnull String propertyName); /******************************************************************************************************************* * * Creates an instance given an owner and no roles. * * @param owner the owner * @return the new instance * @since 3.2-ALPHA-3 * ******************************************************************************************************************/ @Nonnull public static PresentationModel of (@Nonnull final Object owner) { <span class="nc" id="L148"> Parameters.mustNotBeArrayOrCollection(owner, &quot;owner&quot;);</span> <span class="nc" id="L149"> return of(owner, Collections.emptyList());</span> } /******************************************************************************************************************* * * Creates an instance given an owner and a single role. * * @param owner the owner * @param role the role (or a {@link it.tidalwave.util.RoleFactory}) * @return the new instance * @since 3.2-ALPHA-3 * ******************************************************************************************************************/ @Nonnull public static PresentationModel of (@Nonnull final Object owner, @Nonnull final Object role) { <span class="nc" id="L165"> Parameters.mustNotBeArrayOrCollection(owner, &quot;owner&quot;);</span> <span class="nc" id="L166"> Parameters.mustNotBeArrayOrCollection(role, &quot;role&quot;);</span> <span class="nc" id="L167"> return of(owner, r(role));</span> } /******************************************************************************************************************* * * Creates an instance given an owner and multiple roles. * * @param owner the owner * @param roles roles or {@link it.tidalwave.util.RoleFactory} instances * @return the new instance * @since 3.2-ALPHA-1 * @since 3.2-ALPHA-3 (refactored) * ******************************************************************************************************************/ @Nonnull public static PresentationModel of (@Nonnull final Object owner, @Nonnull final Collection&lt;Object&gt; roles) { <span class="fc" id="L184"> Parameters.mustNotBeArrayOrCollection(owner, &quot;owner&quot;);</span> <span class="fc" id="L185"> return new DefaultPresentationModel(owner, roles);</span> } /******************************************************************************************************************* * * Returns an empty instance (no roles with the exception of a dummy {@link Displayable}). * * @return the empty instance * @since 3.2-ALPHA-3 * ******************************************************************************************************************/ @Nonnull public static PresentationModel empty() { // TODO: cache a singleton, but don't do eager initialization (e.g. a final static), as it would deadlock with // SteelBlue. <span class="nc" id="L201"> return of(&quot;&quot;, Displayable.of(&quot;&lt;empty presentation model&gt;&quot;));</span> } /******************************************************************************************************************* * * Creates an instance from an owner which might have the {@link Presentable} role. If it is present, it is called * to create the {@code PresentationModel}; otherwise a default one is created. Additional roles are added. * * @param owner the owner * @param roles roles or {@link it.tidalwave.util.RoleFactory} instances * @return the new instance * @since 3.2-ALPHA-8 * @it.tidalwave.javadoc.experimental TODO: perhaps it could be merged to of(). * ******************************************************************************************************************/ @Nonnull public static PresentationModel ofMaybePresentable (@Nonnull final As owner, @Nonnull final Collection&lt;Object&gt; roles) { <span class="fc" id="L219"> Parameters.mustNotBeArrayOrCollection(owner, &quot;owner&quot;);</span> <span class="fc" id="L220"> return owner.maybeAs(_Presentable_)</span> <span class="fc" id="L221"> .map(p -&gt; p.createPresentationModel(roles))</span> <span class="fc" id="L222"> .orElseGet(() -&gt; of(owner, roles));</span> } /******************************************************************************************************************* * * Creates an instance from an owner which might have the {@link Presentable} role. If it is present, it is called * to create the {@code PresentationModel}; otherwise a default one is created. * * @param owner the owner * @return the new instance * @since 3.2-ALPHA-8 * @it.tidalwave.javadoc.experimental TODO: perhaps it could be merged to of(). * ******************************************************************************************************************/ @Nonnull public static PresentationModel ofMaybePresentable (@Nonnull final As owner) { <span class="nc" id="L239"> return ofMaybePresentable(owner, Collections.emptyList());</span> } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.6.202009150832</span></div></body></html>