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

org.ujoframework.extensions.AbstractUjoExt Maven / Gradle / Ivy

There is a newer version: 1.22
Show newest version
/*
 *  Copyright 2007-2010 Pavel Ponec
 *
 *  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.
 */

package org.ujoframework.extensions;

import org.ujoframework.UjoAction;
import java.util.List;
import org.ujoframework.Ujo;
import org.ujoframework.UjoProperty;
import org.ujoframework.core.UjoActionImpl;
import org.ujoframework.core.UjoManager;
import org.ujoframework.swing.UjoPropertyRow;

/**
 * This is a simple abstract implementation of Ujo. 
* For implementation define only a "public static final UjoProperty" constants in a child class. * The code syntax is Java 1.5 complied.
*
Features: very simple implementaton and a sufficient performance for common tasks. The architecture is useful for a rare assignment of values in object too. * @author Pavel Ponec */ public abstract class AbstractUjoExt extends AbstractUjo implements UjoExt { /** Getter based on one UjoProperty */ @SuppressWarnings("unchecked") public VALUE get ( final UjoProperty property ) { return property.of((UJO)this); } /** Getter based on two properties */ @SuppressWarnings("unchecked") public VALUE get ( final UjoProperty property1 , final UjoProperty property2) { final PathProperty path = PathProperty.newInstance(property1, property2); return get(path); } /** Getter based on three properties */ @SuppressWarnings("unchecked") public VALUE get ( final UjoProperty property1 , final UjoProperty property2 , final UjoProperty property3 ) { final PathProperty path = PathProperty.newInstance(property1, property2, property3); return get(path); } /** Setter based on UjoProperty. Type of value is checked in the runtime. */ @SuppressWarnings({"unchecked"}) public UJO_IMPL set ( final UjoProperty property , final VALUE value ) { readUjoManager().assertAssign(property, value); property.setValue((UJO)this, value); return (UJO_IMPL) this; } /** Setter based on two properties. Type of value is checked in the runtime. */ public void set ( final UjoProperty property1 , final UjoProperty property2 , final VALUE value ) { final PathProperty path = PathProperty.newInstance(property1, property2); set(path, value); } /** Setter based on three properties. Type of value is checked in the runtime. */ public void set ( final UjoProperty property1 , final UjoProperty property2 , final UjoProperty property3 , final VALUE value ) { final PathProperty path = PathProperty.newInstance(property1, property2, property3); set(path, value); } // ------ LIST ---------- /** Returns a count of Items. If the property is null, method returns 0. *
Inside is called a method ListUjoPropertyCommon.getItemCount() internally. */ @SuppressWarnings("unchecked") public int getItemCount ( final ListUjoProperty property ) { return ((ListUjoProperty)property).getItemCount(this); } /** Add Value, if the List is null then the list will be created. *
Inside is called a method ListUjoPropertyCommon.addItem(...) internally. */ @SuppressWarnings("unchecked") public UJO_IMPL add ( final ListUjoProperty property , final ITEM value ) { property.addItem((UJO) this, value); return (UJO_IMPL) this; } /** Add Value, if the List is null then the list will be created. *
Inside is called a method ListUjoPropertyCommon.setItem(...) internally. */ @SuppressWarnings("unchecked") public UJO_IMPL set ( final ListUjoProperty property , final int index , final ITEM value ) { property.setItem((UJO)this, index, value); return (UJO_IMPL) this; } /** Get Value *
Inside is called a method ListUjoPropertyCommon.getItem(...) internally. */ @SuppressWarnings("unchecked") public ITEM get ( final ListUjoProperty property , final int index ) { return (ITEM) ((ListUjoProperty)property).getItem(this, index); } /** * Remove an item from the List by an index. * @param property * @param index * @return removed item */ @SuppressWarnings("unchecked") public ITEM remove ( final ListUjoProperty property , final int index ) { return (ITEM) ((ListUjoProperty)property).getList(this).remove(index); } /** * Removes the first occurrence in this list of the specified element. * @param property ListUjoPropertyCommon * @param item Item to remove * @return true if the list is not null and contains the specified element */ @SuppressWarnings("unchecked") public boolean remove ( final ListUjoProperty property , final ITEM item ) { return ((ListUjoProperty)property).removeItem(this, item); } /** Returns a not null List. If original list value is empty, the new List is created. *
Inside is called a method ListUjoPropertyCommon.getList() internally. */ @SuppressWarnings("unchecked") public ,ITEM> LIST list ( final ListUjoProperty property ) { return (LIST) ((ListUjoProperty)property).getList(this); } /** Indicates whether a parameter value "equal to" property default value. */ @SuppressWarnings("unchecked") public boolean isDefault ( final UjoProperty property) { final boolean result = ((UjoProperty) property).isDefault(this); return result; } // ----------- TEXT -------------- /** * Returns a String value by a NULL context. * otherwise method returns an instance of String. * * @param property A Property * @return If property type is "container" then result is null. */ public String getText(final UjoProperty property) { return readUjoManager().getText(this, property, null); } /** * Set value from a String format by a NULL context. Types Ujo, List, Object[] are not supported by default. *
The method is an alias for a method writeValueString(...) * @param property Property * @param value String value */ public void setText(final UjoProperty property, final String value) { readUjoManager().setText(this, property, value, null, null); } // ------- UTILITIES BUT NO INTERFACE SUPPORT ------- /** Compare the property value with a parametrer value. The property value can be null. */ @SuppressWarnings("unchecked") public boolean equals(UjoProperty property, VALUE value) { return property.equals((UJO)this, value); } /** * Find a property by a "property name". * @param propertyName The name of property * @return The first UjoProperty with the same name. * @throws java.lang.IllegalArgumentException If property not found. */ public UjoProperty findProperty(final String propertyName) throws IllegalArgumentException { final boolean throwException = true; return readProperties().find(propertyName, throwException); } /** Create a list of UjoProperty. */ public List createPropertyList() { return UjoManager.getInstance().createPropertyList(this, new UjoActionImpl(this)); } /** * Clone the UjoCloneable object. The Object and its items must have got a constructor with no parameters. *
Note: There are supported attributes *
    *
  • null value
  • *
  • Ujo
  • *
  • UjoCloneable
  • *
  • List
  • *
  • array of privitive values
  • *
      */ @Override @SuppressWarnings("unchecked") public UJO_IMPL clone(final int depth, final Object context) { return (UJO_IMPL) super.clone(depth, context); } /** Copy all attributes to the target */ public void copyTo(Ujo target, Object context) { UjoManager.getInstance().copy(this, target, new UjoActionImpl(UjoAction.ACTION_COPY, context), (UjoProperty[]) null); } /** Copy selected attributes to the target */ public void copyTo(Ujo target, UjoProperty... properties) { UjoManager.getInstance().copy(this, target, new UjoActionImpl(UjoAction.ACTION_COPY), properties); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy