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

com.talk2object.plum.view.web.component.builder.AbstractConditionBuilder Maven / Gradle / Ivy

The newest version!
package com.talk2object.plum.view.web.component.builder;

import org.apache.commons.lang3.StringUtils;

import com.talk2object.plum.view.component.Component;
import com.talk2object.plum.view.component.containers.Panel;
import com.talk2object.plum.view.web.component.container.window.dialog.WebDialogTitlePanel;

public abstract class AbstractConditionBuilder implements
		ConditionalWebComponentBuilder {

	protected boolean checkClasses(Component component,
			Class... classes) {
		boolean result = true;

		Component parent = component;

		for (int i = 0; i < classes.length; i++) {
			if (parent == null) {
				result = false;
				break;
			}

			Class cls = classes[i];

			if (!cls.isAssignableFrom(parent.getClass())) {
				result = false;
				break;
			}

			parent = (Component) parent.getParent();
		}
		return result;
	}

	/**
	 * component name from this to ancesters
	 * 
	 * @param component
	 * @param names
	 * @return
	 */
	protected boolean checkNames(Component component, String... names) {
		boolean result = true;

		Component parent = component;
		for (int i = 0; i < names.length; i++) {
			if (parent == null) {
				result = false;
				break;
			}

			String name = names[i];

			if (!StringUtils.equals(name, parent.getName())) {
				result = false;
				break;
			}

			parent = (Component) parent.getParent();
			i++;
		}
		return result;
	}

	@Override
	public Object visit(WebViewBuilder builder, Component component) {
		return builder.commonVisit(WebDialogTitlePanel.class, Panel.class,
				component);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy