001 /****************************************************************************** 002 * Copyright (C) MActor Developers. All rights reserved. * 003 * ---------------------------------------------------------------------------* 004 * This file is part of MActor. * 005 * * 006 * MActor is free software; you can redistribute it and/or modify * 007 * it under the terms of the GNU General Public License as published by * 008 * the Free Software Foundation; either version 2 of the License, or * 009 * (at your option) any later version. * 010 * * 011 * MActor is distributed in the hope that it will be useful, * 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 014 * GNU General Public License for more details. * 015 * * 016 * You should have received a copy of the GNU General Public License * 017 * along with MActor; if not, write to the Free Software * 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 019 ******************************************************************************/ 020 package org.mactor.ui.gui.project.editors; 021 022 import java.awt.Component; 023 024 import javax.swing.JComboBox; 025 026 import org.mactor.framework.MactorException; 027 import org.mactor.framework.spec.MessageBrokersConfig; 028 import org.mactor.framework.spec.ProjectContext; 029 import org.mactor.framework.spec.MessageBrokersConfig.MessageBrokerConfig; 030 031 public class MessageBrokerChannelsComboBox extends JComboBox { 032 public MessageBrokerChannelsComboBox() { 033 addItem(null); 034 setAlignmentX(Component.LEFT_ALIGNMENT); 035 load(); 036 } 037 public void load() { 038 MessageBrokersConfig mbc = null; 039 try { 040 mbc = ProjectContext.getGlobalInstance().loadMessageBrokersConfig(); 041 } catch (MactorException me) { 042 } 043 removeAllItems(); 044 addItem(null); 045 if (mbc == null) 046 return; 047 for (MessageBrokerConfig mb : mbc.getMessageBrokers()) { 048 for (MessageBrokerConfig.ChannelConfig c : mb.getChannels().values()) { 049 addItem(c.getName()); 050 } 051 } 052 } 053 public String getSelectedChannel() { 054 Object item = getSelectedItem(); 055 if (item == null) 056 return ""; 057 return (String) item; 058 } 059 public void setSelectedChannel(String channel) { 060 int count = getItemCount(); 061 if (channel == null || channel.trim().length() == 0) { 062 setSelectedIndex(0); 063 return; 064 } 065 for (int i = 1; i < count; i++) { 066 String item = (String) getItemAt(i); 067 if (item.equals(channel)) { 068 setSelectedIndex(i); 069 return; 070 } 071 } 072 setSelectedIndex(0); 073 } 074 }