|
Glassfish example source code file (HelpTreeIndexAdaptor.java)
The Glassfish HelpTreeIndexAdaptor.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.admingui.common.help; import com.sun.jsftemplating.component.factory.tree.TreeAdaptor; import com.sun.jsftemplating.component.factory.tree.TreeAdaptorBase; import com.sun.jsftemplating.layout.descriptors.LayoutComponent; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import org.glassfish.admingui.plugin.Index; import org.glassfish.admingui.plugin.IndexItem; /** * <p> The id for the given tree node
* model object.</p>
*/
public String getId(Object nodeObject) {
String id = "invalideNodeObjectType";
if (nodeObject == null) {
id = "nullNodeObject";
} else if (nodeObject instanceof IndexItem) {
String target = ((IndexItem) nodeObject).getTarget();
id = genId(null != target ? target : "i" + Integer.toString(nodeObject.hashCode()));
} else if (nodeObject instanceof Index) {
id = getLayoutComponent().getId(
FacesContext.getCurrentInstance(), getParentUIComponent());
}
return id;
}
/**
* <p> This method generates an ID that is safe for JSF for the given
* String. It does not guarantee that the id is unique, it is the
* responsibility of the caller to pass in a String that will result
* in a UID. All non-ascii characters will be stripped.</p>
*
* @param uid A non-null String.
*/
private String genId(String uid) {
char[] chArr = uid.toCharArray();
int len = chArr.length;
int newIdx = 0;
for (int idx = 0; idx < len; idx++) {
char test = chArr[idx];
if (Character.isLetterOrDigit(test) || test == '_' || test == '-') {
chArr[newIdx++] = test;
}
}
return new String(chArr, 0, newIdx);
}
/**
* <p> This method returns any facets that should be applied to the
* <code>TreeNode (comp). Useful facets for the sun
* <code>TreeNode component are: "content" and "image".
*
* <p> Facets that already exist on comp , or facets that
* are directly added to <code>comp do not need to be returned
* from this method.</p>
*
* <p> This implementation directly adds a "content" and "image" facet and
* returns <code>null from this method.
*
* @param comp The tree node <code>UIComponent.
* @param nodeObject The (model) object representing the tree node.
*/
public Map<String, UIComponent> getFacets(UIComponent comp, Object nodeObject) {
// Do nothing
return null;
}
/**
* <p> Advanced framework feature which provides better handling for
* things such as expanding TreeNodes, beforeEncode, and other
* events.</p>
*
* <p> This method should return a Map of List
* of <code>Handler objects. Each List in the
* <code>Map should be registered under a key that cooresponds
* to to the "event" in which the <code>Handlers should be
* invoked.</p>
*/
public Map getHandlersByType(UIComponent comp, Object nodeObject) {
// Do nothing
return null;
}
/**
* <p> This method returns the UIComponent factory class
* implementation that should be used to create a
* <code>TreeNode for the given tree node model object.
*
* <p> This implementation returns the default return value, unless the
* <code>nodeObject represents the root node. In that case it
* will return a the TreeFactory factory class:</p>
*
* <p> com.sun.jsftemplating.component.factory.sun.TreeFactory
*/
public String getFactoryClass(Object nodeObject) {
String factory = super.getFactoryClass(nodeObject);
if (nodeObject instanceof Index) {
// For the root... make it the tree itself.
factory =
"com.sun.jsftemplating.component.factory.sun.TreeFactory";
}
return factory;
}
/**
* <p> Comparator class for {@link IndexItem}s. Uses "text" for
* comparison, ignoring case.</p>
*/
private static class IndexItemComparator implements Comparator<IndexItem> {
@Override
public int compare(IndexItem x, IndexItem y) {
int result = 0;
if (null != x && null != y) {
if (!x.equals(y)) {
String xText = x.getText(), yText = y.getText();
if (null != xText && null != yText) {
result = xText.compareToIgnoreCase(yText);
}
}
} else {
if (null == x && null == y) {
result = 0;
} else {
// consider null to be less.
if (null == x) {
result = -1;
} else {
result = 1;
}
}
}
return result;
}
}
}
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish HelpTreeIndexAdaptor.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.