
it.tidalwave.role.ui.impl.AsLookupPresentationModel Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueBill Stats
* Copyright (C) 2011-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://bluebill.tidalwave.it/mobile/
* SCM: http://java.net/hg/bluebill-server~stats-src
*
**********************************************************************************************************************/
package it.tidalwave.role.ui.impl;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.beans.PropertyChangeSupport;
import it.tidalwave.util.As;
import it.tidalwave.role.Composite;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.netbeans.util.AsLookupSupport;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;
import lombok.Delegate;
/***********************************************************************************************************************
*
* An implementation of {@link PresentationModel} based on {@link AsLookupSupport}.
*
* @stereotype Role
* @stereotype PresentationModel
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class AsLookupPresentationModel implements PresentationModel, Lookup.Provider
{
class MyAsLookupSupport extends AsLookupSupport
{
public MyAsLookupSupport()
{
super();
}
public MyAsLookupSupport (final @Nonnull Object[] roles)
{
super(roles);
}
public MyAsLookupSupport (final @Nonnull Object owner)
{
super(owner);
}
public MyAsLookupSupport (final @Nonnull Object owner, final @Nonnull Object[] roles)
{
super(owner, roles);
}
@Override @Nonnull
protected Lookup createLookup()
{
final Lookup superLookup = super.createLookup();
Composite, ?> delegateComposite = superLookup.lookup(Composite.class);
if (delegateComposite == null)
{
delegateComposite = Composite.DEFAULT;
}
composite = new PresentationModelComposite(delegateComposite);
return new ProxyLookup(Lookups.fixed(composite), superLookup);
}
}
@Delegate(types={ As.class, Lookup.Provider.class })
protected final MyAsLookupSupport asDelegate;
@Delegate(types=PropertyChangeSupport.class)
protected final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
@CheckForNull
protected PresentationModelComposite> composite;
private boolean inToString = false;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public AsLookupPresentationModel()
{
asDelegate = new MyAsLookupSupport();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public AsLookupPresentationModel (final @Nonnull Object owner)
{
asDelegate = new MyAsLookupSupport(owner, new Object[]{ owner });
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public AsLookupPresentationModel (final @Nonnull Object owner, final @Nonnull Object[] instanceRoles)
{
asDelegate = new MyAsLookupSupport(owner, instanceRoles);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public AsLookupPresentationModel (final @Nonnull Object[] instanceRoles)
{
asDelegate = new MyAsLookupSupport(instanceRoles);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnull
public String toString()
{
if (inToString || (composite == null) || !composite.isCountComputed())
{
return String.format("%s@%x[children count not computed]", getClass().getSimpleName(), System.identityHashCode(this));
}
try
{
inToString = true;
return String.format("%s@%x[%d children]", getClass().getSimpleName(),
System.identityHashCode(this),
composite.findChildren().count());
}
finally
{
inToString = false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy