alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

JMeter example source code file (AbstractTreeTableModel.java)

This example JMeter source code file (AbstractTreeTableModel.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - JMeter tags/keywords

abstracttreetablemodel, abstracttreetablemodel, arraylist, arraylist, class, defaulttablemodel, event, eventlistenerlist, functor, gui, object, object, override, override, string, swing, table, tree, treenode, util

The JMeter AbstractTreeTableModel.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.jorphan.gui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.swing.event.TableModelListener;
import javax.swing.event.EventListenerList;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.TreeNode;

import org.apache.jorphan.reflect.Functor;

public abstract class AbstractTreeTableModel extends DefaultTableModel implements TreeTableModel {

    private static final long serialVersionUID = 240L;

    protected final TreeNode rootNode;
    protected final EventListenerList listener = new EventListenerList();

    protected transient final ArrayList<Object> objects = new ArrayList();

    protected transient final List<String> headers = new ArrayList();

    protected transient final ArrayList<Class classes = new ArrayList>();

    protected transient final ArrayList<Functor> readFunctors;

    protected transient final ArrayList<Functor> writeFunctors;

    public AbstractTreeTableModel(TreeNode root) {
        this.rootNode = root;
        readFunctors = new ArrayList<Functor>();
        writeFunctors = new ArrayList<Functor>();
    }

    public AbstractTreeTableModel(TreeNode root, boolean editable) {
        this(root);
    }

    public AbstractTreeTableModel(String[] headers,
            Functor[] readFunctors,
            Functor[] writeFunctors,
            Class<?>[] editorClasses) {
        this.rootNode = null;
        this.headers.addAll(Arrays.asList(headers));
        this.classes.addAll(Arrays.asList(editorClasses));
        this.readFunctors = new ArrayList<Functor>(Arrays.asList(readFunctors));
        this.writeFunctors = new ArrayList<Functor>(Arrays.asList(writeFunctors));
    }

    /**
     * The root node for the TreeTable
     * @return the root node
     */
    public Object getRootNode() {
        return this.rootNode;
    }

    /**
     * {@inheritDoc}
     */
    public Object getValueAt(Object node, int col) {
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isCellEditable(Object node, int col) {
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public void setValueAt(Object val, Object node, int column) {
    }

    /**
     * The implementation is exactly the same as ObjectTableModel.getColumnCount.
     * <p>
     * {@inheritDoc}
     */
    @Override
    public int getColumnCount() {
        return headers.size();
    }

    /**
     * The implementation is exactly the same as ObjectTableModel.getRowCount.
     * <p>
     * {@inheritDoc}
     */
    @Override
    public int getRowCount() {
        if (objects == null) {
            return 0;
        }
        return objects.size();
    }

    /**
     * By default the abstract class returns true. It is up to subclasses
     * to override the implementation.
     * <p>
     * {@inheritDoc}
     */
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Class<?> getColumnClass(int arg0) {
        return classes.get(arg0);
    }

    /**
     * Subclasses need to implement the logic for the method and
     * return the value at the specific cell.
     * <p>
     * {@inheritDoc}
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getColumnName(int columnIndex) {
        return headers.get(columnIndex);
    }

    public int getChildCount(Object parent) {
        return 0;
    }

    public Object getChild(Object parent, int index) {
        return null;
    }

    /**
     * the implementation checks if the Object is a treenode. If it is,
     * it returns isLeaf(), otherwise it returns false.
     * @param node
     * @return whether object is a leaf node or not
     */
    public boolean isLeaf(Object node) {
        if (node instanceof TreeNode) {
            return ((TreeNode)node).isLeaf();
        } else {
            return false;
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void addTableModelListener(TableModelListener l) {
        this.listener.add(TableModelListener.class,l);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void removeTableModelListener(TableModelListener l) {
        this.listener.remove(TableModelListener.class,l);
    }

    public void nodeStructureChanged(TreeNode node) {

    }

    public void fireTreeNodesChanged(TreeNode source,
            Object[] path,
            int[] indexes,
            Object[] children) {

    }

    public void clearData() {
        int size = getRowCount();
        objects.clear();
        super.fireTableRowsDeleted(0, size);
    }
}

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter AbstractTreeTableModel.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.