Package bitronix.tm.gui

Source Code of bitronix.tm.gui.DuplicatedGtridTableModel

/*
* Copyright (C) 2006-2013 Bitronix Software (http://www.bitronix.be)
*
* 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 bitronix.tm.gui;

import bitronix.tm.journal.JournalRecord;

import javax.swing.table.DefaultTableModel;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* <p></p>
*
* @author Ludovic Orban
*/
public class DuplicatedGtridTableModel extends DefaultTableModel {

    private Map duplicatedGtrids;

    public DuplicatedGtridTableModel(Map map) {
        super(map.size(), 2);
        this.duplicatedGtrids = map;
    }

    public String getColumnName(int column) {
        switch (column) {
            case 0: return "Sequence number";
            case 1: return "GTRID";
            default: return "?";
        }
    }

    public Object getValueAt(int row, int column) {
        Iterator it = duplicatedGtrids.entrySet().iterator();
        List tlogs = null;
        int i=0;
        while (i<=row && it.hasNext()) {
            i++;
            Map.Entry entry = (Map.Entry) it.next();
            tlogs = (List) entry.getValue();
        }

        if (tlogs == null)
            return null;

        switch (column) {
            case 0: return buildTlogsSequenceNumber(tlogs);
            case 1: return buildTlogsGtrid(tlogs);
            default: return "?";
        }
    }

    private String buildTlogsSequenceNumber(List tlogs) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tlogs.size(); i++) {
            JournalRecord tlog = (JournalRecord) tlogs.get(i);
            sb.append(tlog.getRecordProperties().get("sequenceNumber"));
            if (i < tlogs.size() -1)
                sb.append(", ");
        }
        return sb.toString();
    }

    private String buildTlogsGtrid(List tlogs) {
        JournalRecord tlog = (JournalRecord) tlogs.get(0);
        return tlog.getGtrid().toString();
    }

}
TOP

Related Classes of bitronix.tm.gui.DuplicatedGtridTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.