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.GlobalConfig; 028 import org.mactor.framework.spec.ProjectContext; 029 030 public class GlobalConfigDBGroupComboBox extends JComboBox { 031 public GlobalConfigDBGroupComboBox() { 032 addItem(null); 033 setAlignmentX(Component.LEFT_ALIGNMENT); 034 } 035 public void load() { 036 GlobalConfig gc = null; 037 try { 038 gc = ProjectContext.getGlobalInstance().loadGlobalConfig(); 039 } catch (MactorException me) { 040 } 041 removeAllItems(); 042 addItem(null); 043 if (gc == null) 044 return; 045 for (GlobalConfig.Group g : gc.getGroups().values()) { 046 if (EditorUtil.isGlobalConfigDBGroup(g)) 047 addItem(g.getName()); 048 } 049 } 050 public String getSelectedGroup() { 051 Object item = getSelectedItem(); 052 if (item == null) 053 return ""; 054 return (String) item; 055 } 056 public void setSelectedGroup(String group) { 057 int count = getItemCount(); 058 if (group == null || group.trim().length() == 0) { 059 setSelectedIndex(0); 060 return; 061 } 062 for (int i = 1; i < count; i++) { 063 String item = (String) getItemAt(i); 064 if (item.equals(group)) { 065 setSelectedIndex(i); 066 return; 067 } 068 } 069 addItem(group); 070 setSelectedIndex(count); 071 } 072 }