12e5b6d6dSopenharmony_ci/*
22e5b6d6dSopenharmony_ci *****************************************************************************
32e5b6d6dSopenharmony_ci * Copyright (C) 2000-2004, International Business Machines Corporation and  *
42e5b6d6dSopenharmony_ci * others. All Rights Reserved.                                              *
52e5b6d6dSopenharmony_ci *****************************************************************************
62e5b6d6dSopenharmony_ci */
72e5b6d6dSopenharmony_cipackage com.ibm.rbm.gui;
82e5b6d6dSopenharmony_ci
92e5b6d6dSopenharmony_ciimport java.awt.*;
102e5b6d6dSopenharmony_ciimport java.awt.event.*;
112e5b6d6dSopenharmony_ci
122e5b6d6dSopenharmony_ciimport javax.swing.*;
132e5b6d6dSopenharmony_ciimport javax.swing.table.*;
142e5b6d6dSopenharmony_ciimport javax.swing.event.*;
152e5b6d6dSopenharmony_ci
162e5b6d6dSopenharmony_ciimport com.ibm.rbm.*;
172e5b6d6dSopenharmony_ci
182e5b6d6dSopenharmony_ci/**
192e5b6d6dSopenharmony_ci * The class used to display groups
202e5b6d6dSopenharmony_ci */
212e5b6d6dSopenharmony_ciclass RBGroupPanel extends JPanel {
222e5b6d6dSopenharmony_ci	RBManager rbm;
232e5b6d6dSopenharmony_ci	Bundle bundle;
242e5b6d6dSopenharmony_ci	RBManagerGUI listener;
252e5b6d6dSopenharmony_ci
262e5b6d6dSopenharmony_ci	// Components
272e5b6d6dSopenharmony_ci	JLabel      jLabelGroupTitle;
282e5b6d6dSopenharmony_ci	JLabel      jLabelGroupNameTitle;
292e5b6d6dSopenharmony_ci	JLabel      jLabelGroupCommentTitle;
302e5b6d6dSopenharmony_ci	JLabel      jLabelGroupComment;
312e5b6d6dSopenharmony_ci	JComboBox   jComboBoxGroup;
322e5b6d6dSopenharmony_ci	JTable      jTableGroupTable;
332e5b6d6dSopenharmony_ci	JScrollPane jScrollPaneGroupTable;
342e5b6d6dSopenharmony_ci
352e5b6d6dSopenharmony_ci	// Components - Manager
362e5b6d6dSopenharmony_ci	JList       jListGroup;
372e5b6d6dSopenharmony_ci	JButton     createItemButton;
382e5b6d6dSopenharmony_ci	JButton     createGroupButton;
392e5b6d6dSopenharmony_ci	JButton     editItemButton;
402e5b6d6dSopenharmony_ci	JButton     editGroupButton;
412e5b6d6dSopenharmony_ci	JButton     deleteItemButton;
422e5b6d6dSopenharmony_ci	JButton     deleteGroupButton;
432e5b6d6dSopenharmony_ci	JPanel      itemPanel;
442e5b6d6dSopenharmony_ci	JPanel      groupPanel;
452e5b6d6dSopenharmony_ci
462e5b6d6dSopenharmony_ci	public RBGroupPanel(RBManagerGUI gui) {
472e5b6d6dSopenharmony_ci		super();
482e5b6d6dSopenharmony_ci		listener = gui;
492e5b6d6dSopenharmony_ci	}
502e5b6d6dSopenharmony_ci
512e5b6d6dSopenharmony_ci	public void setBundle(Bundle b) {
522e5b6d6dSopenharmony_ci		rbm = null;
532e5b6d6dSopenharmony_ci		if (bundle == null) {
542e5b6d6dSopenharmony_ci			bundle = b;
552e5b6d6dSopenharmony_ci			initComponents();
562e5b6d6dSopenharmony_ci		} else if (bundle != b) {
572e5b6d6dSopenharmony_ci			bundle = b;
582e5b6d6dSopenharmony_ci			updateComponents();
592e5b6d6dSopenharmony_ci		}
602e5b6d6dSopenharmony_ci	}
612e5b6d6dSopenharmony_ci
622e5b6d6dSopenharmony_ci	public void setManager(RBManager m) {
632e5b6d6dSopenharmony_ci		bundle = null;
642e5b6d6dSopenharmony_ci		if (rbm == null) {
652e5b6d6dSopenharmony_ci			rbm = m;
662e5b6d6dSopenharmony_ci			initComponents();
672e5b6d6dSopenharmony_ci		} else if (rbm != m) {
682e5b6d6dSopenharmony_ci			rbm = m;
692e5b6d6dSopenharmony_ci			updateComponents();
702e5b6d6dSopenharmony_ci		}
712e5b6d6dSopenharmony_ci	}
722e5b6d6dSopenharmony_ci
732e5b6d6dSopenharmony_ci	public void removeElements() {
742e5b6d6dSopenharmony_ci		if (rbm != null || bundle != null) {
752e5b6d6dSopenharmony_ci			rbm = null;
762e5b6d6dSopenharmony_ci			bundle = null;
772e5b6d6dSopenharmony_ci			initComponents();
782e5b6d6dSopenharmony_ci		}
792e5b6d6dSopenharmony_ci	}
802e5b6d6dSopenharmony_ci
812e5b6d6dSopenharmony_ci	// Marks the selected resource as translated and removes from this view
822e5b6d6dSopenharmony_ci	private void markSelectedResourceAsTranslated() {
832e5b6d6dSopenharmony_ci		if (bundle == null) return;
842e5b6d6dSopenharmony_ci		if (jTableGroupTable.getSelectedRow() < 0) return;
852e5b6d6dSopenharmony_ci		if (jTableGroupTable.getModel() instanceof GroupItemsTableModel) {
862e5b6d6dSopenharmony_ci			int row = jTableGroupTable.getSelectedRow();
872e5b6d6dSopenharmony_ci			GroupItemsTableModel model = (GroupItemsTableModel)jTableGroupTable.getModel();
882e5b6d6dSopenharmony_ci			BundleItem item = model.getBundleItem(row);
892e5b6d6dSopenharmony_ci			item.setTranslated(true);
902e5b6d6dSopenharmony_ci			model.update();
912e5b6d6dSopenharmony_ci		}
922e5b6d6dSopenharmony_ci	}
932e5b6d6dSopenharmony_ci
942e5b6d6dSopenharmony_ci	// Removes the selected resource from the resource file
952e5b6d6dSopenharmony_ci	private void deleteSelectedResource() {
962e5b6d6dSopenharmony_ci		if (bundle == null) return;
972e5b6d6dSopenharmony_ci		if (jTableGroupTable.getSelectedRow() < 0) return;
982e5b6d6dSopenharmony_ci		if (jTableGroupTable.getModel() instanceof GroupItemsTableModel) {
992e5b6d6dSopenharmony_ci			int row = jTableGroupTable.getSelectedRow();
1002e5b6d6dSopenharmony_ci			GroupItemsTableModel model = (GroupItemsTableModel)jTableGroupTable.getModel();
1012e5b6d6dSopenharmony_ci			BundleItem item = model.getBundleItem(row);
1022e5b6d6dSopenharmony_ci			if (item.getParentGroup() != null && item.getParentGroup().getParentBundle() != null) {
1032e5b6d6dSopenharmony_ci				Bundle parentBundle = item.getParentGroup().getParentBundle();
1042e5b6d6dSopenharmony_ci				parentBundle.removeItem(item.getKey());
1052e5b6d6dSopenharmony_ci			}
1062e5b6d6dSopenharmony_ci			model.update();
1072e5b6d6dSopenharmony_ci		}
1082e5b6d6dSopenharmony_ci	}
1092e5b6d6dSopenharmony_ci
1102e5b6d6dSopenharmony_ci	private void initComponents() {
1112e5b6d6dSopenharmony_ci		// Initialize components
1122e5b6d6dSopenharmony_ci		if (bundle != null) {
1132e5b6d6dSopenharmony_ci			jLabelGroupTitle          = new JLabel(bundle.name);
1142e5b6d6dSopenharmony_ci			jComboBoxGroup            = new JComboBox(new GroupComboBoxModel(bundle));
1152e5b6d6dSopenharmony_ci
1162e5b6d6dSopenharmony_ci			jTableGroupTable          = new JTable(new GroupItemsTableModel((BundleGroup)jComboBoxGroup.getSelectedItem()));
1172e5b6d6dSopenharmony_ci			jScrollPaneGroupTable     = new JScrollPane(jTableGroupTable);
1182e5b6d6dSopenharmony_ci			jLabelGroupNameTitle      = new JLabel(Resources.getTranslation("basegroup_group_name"));
1192e5b6d6dSopenharmony_ci			jLabelGroupCommentTitle   = new JLabel(Resources.getTranslation("basegroup_group_comment"));
1202e5b6d6dSopenharmony_ci			jLabelGroupComment        = new JLabel(((BundleGroup)jComboBoxGroup.getSelectedItem()).getComment());
1212e5b6d6dSopenharmony_ci
1222e5b6d6dSopenharmony_ci			// Lower panel components
1232e5b6d6dSopenharmony_ci			JPanel  lowerPanel = new JPanel();
1242e5b6d6dSopenharmony_ci			JButton deleteButton = new JButton(Resources.getTranslation("button_delete_resource"));
1252e5b6d6dSopenharmony_ci			JButton translateButton = new JButton(Resources.getTranslation("button_mark_translated"));
1262e5b6d6dSopenharmony_ci
1272e5b6d6dSopenharmony_ci			deleteButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_delete_resource_trigger")));
1282e5b6d6dSopenharmony_ci			translateButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_mark_translated_trigger")));
1292e5b6d6dSopenharmony_ci			lowerPanel.setBorder(BorderFactory.createTitledBorder(Resources.getTranslation("languageuntrans_selected_resources_options")));
1302e5b6d6dSopenharmony_ci			lowerPanel.setLayout(new GridLayout(1,2));
1312e5b6d6dSopenharmony_ci
1322e5b6d6dSopenharmony_ci			jLabelGroupNameTitle.setHorizontalAlignment(SwingConstants.LEFT);
1332e5b6d6dSopenharmony_ci
1342e5b6d6dSopenharmony_ci			jTableGroupTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1352e5b6d6dSopenharmony_ci			jTableGroupTable.addMouseListener(listener);
1362e5b6d6dSopenharmony_ci
1372e5b6d6dSopenharmony_ci			jComboBoxGroup.addActionListener(new GroupComboActionListener(this));
1382e5b6d6dSopenharmony_ci
1392e5b6d6dSopenharmony_ci			jLabelGroupTitle.setFont(new Font("SansSerif",Font.PLAIN,18));
1402e5b6d6dSopenharmony_ci
1412e5b6d6dSopenharmony_ci			// Add action listeners
1422e5b6d6dSopenharmony_ci			deleteButton.addActionListener(new ActionListener(){
1432e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
1442e5b6d6dSopenharmony_ci					deleteSelectedResource();
1452e5b6d6dSopenharmony_ci				}
1462e5b6d6dSopenharmony_ci			});
1472e5b6d6dSopenharmony_ci
1482e5b6d6dSopenharmony_ci			translateButton.addActionListener(new ActionListener(){
1492e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
1502e5b6d6dSopenharmony_ci					markSelectedResourceAsTranslated();
1512e5b6d6dSopenharmony_ci				}
1522e5b6d6dSopenharmony_ci			});
1532e5b6d6dSopenharmony_ci
1542e5b6d6dSopenharmony_ci			// Update the display
1552e5b6d6dSopenharmony_ci			setLayout(new GridBagLayout());
1562e5b6d6dSopenharmony_ci			GridBagConstraints gbc = new GridBagConstraints();
1572e5b6d6dSopenharmony_ci			removeAll();
1582e5b6d6dSopenharmony_ci			lowerPanel.add(deleteButton);
1592e5b6d6dSopenharmony_ci			lowerPanel.add(translateButton);
1602e5b6d6dSopenharmony_ci
1612e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
1622e5b6d6dSopenharmony_ci			gbc.weighty = 0.0;
1632e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
1642e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.HORIZONTAL;
1652e5b6d6dSopenharmony_ci			add(jLabelGroupTitle, gbc);
1662e5b6d6dSopenharmony_ci			gbc.weightx = 0.0;
1672e5b6d6dSopenharmony_ci			gbc.gridwidth = 1;
1682e5b6d6dSopenharmony_ci			add(jLabelGroupNameTitle, gbc);
1692e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
1702e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
1712e5b6d6dSopenharmony_ci			add(jComboBoxGroup, gbc);
1722e5b6d6dSopenharmony_ci			gbc.weightx = 0.0;
1732e5b6d6dSopenharmony_ci			gbc.gridwidth = 1;
1742e5b6d6dSopenharmony_ci			add(jLabelGroupCommentTitle, gbc);
1752e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
1762e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
1772e5b6d6dSopenharmony_ci			add(jLabelGroupComment, gbc);
1782e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.BOTH;
1792e5b6d6dSopenharmony_ci			gbc.weighty = 1.0;
1802e5b6d6dSopenharmony_ci			add(jScrollPaneGroupTable, gbc);
1812e5b6d6dSopenharmony_ci			gbc.weighty = 0.0;
1822e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.HORIZONTAL;
1832e5b6d6dSopenharmony_ci			add(lowerPanel, gbc);
1842e5b6d6dSopenharmony_ci		} else if (rbm != null) {
1852e5b6d6dSopenharmony_ci			Bundle mainBundle = (Bundle)rbm.getBundles().firstElement();
1862e5b6d6dSopenharmony_ci			jLabelGroupTitle          = new JLabel(rbm.getBaseClass() + " - " + Resources.getTranslation("groups"));
1872e5b6d6dSopenharmony_ci			jComboBoxGroup            = new JComboBox(new GroupComboBoxModel(mainBundle));//mainBundle.getGroupsAsVector());
1882e5b6d6dSopenharmony_ci
1892e5b6d6dSopenharmony_ci			jListGroup                = new JList(new GroupItemsListModel((BundleGroup)jComboBoxGroup.getSelectedItem()));
1902e5b6d6dSopenharmony_ci			jScrollPaneGroupTable     = new JScrollPane(jListGroup);
1912e5b6d6dSopenharmony_ci			jLabelGroupNameTitle      = new JLabel(Resources.getTranslation("basegroup_group_name"));
1922e5b6d6dSopenharmony_ci			jLabelGroupCommentTitle   = new JLabel(Resources.getTranslation("basegroup_group_comment"));
1932e5b6d6dSopenharmony_ci			try {
1942e5b6d6dSopenharmony_ci				jLabelGroupComment    = new JLabel(((BundleGroup)jComboBoxGroup.getSelectedItem()).getComment());
1952e5b6d6dSopenharmony_ci			} catch (NullPointerException npe) {
1962e5b6d6dSopenharmony_ci				jLabelGroupComment    = new JLabel("");
1972e5b6d6dSopenharmony_ci			}
1982e5b6d6dSopenharmony_ci
1992e5b6d6dSopenharmony_ci			createItemButton          = new JButton(Resources.getTranslation("button_create_resource"));
2002e5b6d6dSopenharmony_ci			createGroupButton         = new JButton(Resources.getTranslation("button_create_group"));
2012e5b6d6dSopenharmony_ci			deleteItemButton          = new JButton(Resources.getTranslation("button_delete_resource"));
2022e5b6d6dSopenharmony_ci			deleteGroupButton         = new JButton(Resources.getTranslation("button_delete_group"));
2032e5b6d6dSopenharmony_ci			editItemButton            = new JButton(Resources.getTranslation("button_edit_resource"));
2042e5b6d6dSopenharmony_ci			editGroupButton           = new JButton(Resources.getTranslation("button_edit_group"));
2052e5b6d6dSopenharmony_ci
2062e5b6d6dSopenharmony_ci			itemPanel                 = new JPanel();
2072e5b6d6dSopenharmony_ci			groupPanel                = new JPanel();
2082e5b6d6dSopenharmony_ci
2092e5b6d6dSopenharmony_ci			itemPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
2102e5b6d6dSopenharmony_ci																  Resources.getTranslation("basegroup_item_options")));
2112e5b6d6dSopenharmony_ci			groupPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
2122e5b6d6dSopenharmony_ci																  Resources.getTranslation("basegroup_group_options")));
2132e5b6d6dSopenharmony_ci			itemPanel.setLayout(new GridLayout(1,3));
2142e5b6d6dSopenharmony_ci			groupPanel.setLayout(new GridLayout(1,3));
2152e5b6d6dSopenharmony_ci			itemPanel.setMaximumSize(new Dimension(20000,50));
2162e5b6d6dSopenharmony_ci			groupPanel.setMaximumSize(new Dimension(20000,50));
2172e5b6d6dSopenharmony_ci
2182e5b6d6dSopenharmony_ci			createItemButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_create_resource_trigger")));
2192e5b6d6dSopenharmony_ci			editItemButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_edit_resource_trigger")));
2202e5b6d6dSopenharmony_ci			deleteItemButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_delete_resource_trigger")));
2212e5b6d6dSopenharmony_ci			createGroupButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_create_group_trigger")));
2222e5b6d6dSopenharmony_ci
2232e5b6d6dSopenharmony_ci			jListGroup.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
2242e5b6d6dSopenharmony_ci
2252e5b6d6dSopenharmony_ci			jComboBoxGroup.addActionListener(new GroupComboActionListener(this));
2262e5b6d6dSopenharmony_ci
2272e5b6d6dSopenharmony_ci			jLabelGroupTitle.setFont(new Font("SansSerif",Font.PLAIN,18));
2282e5b6d6dSopenharmony_ci
2292e5b6d6dSopenharmony_ci			// Add the listeners
2302e5b6d6dSopenharmony_ci			jListGroup.addMouseListener(new MouseAdapter() {
2312e5b6d6dSopenharmony_ci				public void mouseClicked(MouseEvent ev) {
2322e5b6d6dSopenharmony_ci					if(ev.getClickCount() == 2 && ev.getSource() instanceof JList) {
2332e5b6d6dSopenharmony_ci						// A double click means they want to edit a bundle item
2342e5b6d6dSopenharmony_ci						if (((JList)ev.getSource()).getSelectedValue() != null)
2352e5b6d6dSopenharmony_ci							new BundleItemCreationDialog((BundleItem)((JList)ev.getSource()).getSelectedValue(),
2362e5b6d6dSopenharmony_ci								listener.rbm, listener, Resources.getTranslation("dialog_title_edit_item"), true);
2372e5b6d6dSopenharmony_ci					}
2382e5b6d6dSopenharmony_ci				}
2392e5b6d6dSopenharmony_ci			});
2402e5b6d6dSopenharmony_ci
2412e5b6d6dSopenharmony_ci			createItemButton.addActionListener(new ActionListener(){
2422e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
2432e5b6d6dSopenharmony_ci					new BundleItemCreationDialog(((BundleGroup)jComboBoxGroup.getSelectedItem()).getName(),
2442e5b6d6dSopenharmony_ci												 listener.rbm, listener,
2452e5b6d6dSopenharmony_ci												 Resources.getTranslation("dialog_title_new_item"), true);
2462e5b6d6dSopenharmony_ci					updateComponents();
2472e5b6d6dSopenharmony_ci				}
2482e5b6d6dSopenharmony_ci			});
2492e5b6d6dSopenharmony_ci			createGroupButton.addActionListener(listener);
2502e5b6d6dSopenharmony_ci			editItemButton.addActionListener(new ActionListener() {
2512e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
2522e5b6d6dSopenharmony_ci					if (jListGroup.getSelectedValue() != null)
2532e5b6d6dSopenharmony_ci						new BundleItemCreationDialog((BundleItem)jListGroup.getSelectedValue(),
2542e5b6d6dSopenharmony_ci							listener.rbm, listener, Resources.getTranslation("dialog_title_edit_item"), true);
2552e5b6d6dSopenharmony_ci					updateComponents();
2562e5b6d6dSopenharmony_ci				}
2572e5b6d6dSopenharmony_ci			});
2582e5b6d6dSopenharmony_ci			editGroupButton.addActionListener(new ActionListener() {
2592e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
2602e5b6d6dSopenharmony_ci					new BundleGroupEditDialog((BundleGroup)jComboBoxGroup.getSelectedItem(),
2612e5b6d6dSopenharmony_ci											  listener, Resources.getTranslation("dialog_title_edit_group"), true);
2622e5b6d6dSopenharmony_ci					updateComponents();
2632e5b6d6dSopenharmony_ci				}
2642e5b6d6dSopenharmony_ci			});
2652e5b6d6dSopenharmony_ci			deleteGroupButton.addActionListener(new ActionListener() {
2662e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
2672e5b6d6dSopenharmony_ci					int response = JOptionPane.showConfirmDialog(listener,
2682e5b6d6dSopenharmony_ci						Resources.getTranslation("dialog_warning_delete_group"),
2692e5b6d6dSopenharmony_ci						Resources.getTranslation("dialog_title_delete_group"), JOptionPane.OK_CANCEL_OPTION,
2702e5b6d6dSopenharmony_ci						JOptionPane.WARNING_MESSAGE);
2712e5b6d6dSopenharmony_ci					if (response == JOptionPane.OK_OPTION) {
2722e5b6d6dSopenharmony_ci						// Delete the group
2732e5b6d6dSopenharmony_ci						int index = jComboBoxGroup.getSelectedIndex();
2742e5b6d6dSopenharmony_ci						BundleGroup group = (BundleGroup)jComboBoxGroup.getSelectedItem();
2752e5b6d6dSopenharmony_ci						if (group.getName().equals("Ungrouped Items"))
2762e5b6d6dSopenharmony_ci							return;
2772e5b6d6dSopenharmony_ci						if (index < jComboBoxGroup.getItemCount()-1)
2782e5b6d6dSopenharmony_ci							jComboBoxGroup.setSelectedIndex(index+1);
2792e5b6d6dSopenharmony_ci						else
2802e5b6d6dSopenharmony_ci							jComboBoxGroup.setSelectedIndex(index-1);
2812e5b6d6dSopenharmony_ci						rbm.deleteGroup(group.getName());
2822e5b6d6dSopenharmony_ci					}
2832e5b6d6dSopenharmony_ci					updateComponents();
2842e5b6d6dSopenharmony_ci				}
2852e5b6d6dSopenharmony_ci			});
2862e5b6d6dSopenharmony_ci
2872e5b6d6dSopenharmony_ci			deleteItemButton.addActionListener(new ActionListener() {
2882e5b6d6dSopenharmony_ci				public void actionPerformed(ActionEvent ev) {
2892e5b6d6dSopenharmony_ci					int response = JOptionPane.showConfirmDialog(listener,
2902e5b6d6dSopenharmony_ci						Resources.getTranslation("dialog_warning_delete_item"),
2912e5b6d6dSopenharmony_ci						Resources.getTranslation("dialog_title_delete_item"), JOptionPane.OK_CANCEL_OPTION,
2922e5b6d6dSopenharmony_ci						JOptionPane.WARNING_MESSAGE);
2932e5b6d6dSopenharmony_ci					if (response == JOptionPane.OK_OPTION) {
2942e5b6d6dSopenharmony_ci						Object o = jListGroup.getSelectedValue();
2952e5b6d6dSopenharmony_ci						if (o != null) {
2962e5b6d6dSopenharmony_ci							BundleItem item = (BundleItem) o;
2972e5b6d6dSopenharmony_ci							handleDeleteItem(item.getKey());
2982e5b6d6dSopenharmony_ci							//panel.rbm.deleteItem(item.getKey());
2992e5b6d6dSopenharmony_ci						}
3002e5b6d6dSopenharmony_ci					}
3012e5b6d6dSopenharmony_ci					updateComponents();
3022e5b6d6dSopenharmony_ci				}
3032e5b6d6dSopenharmony_ci			});
3042e5b6d6dSopenharmony_ci
3052e5b6d6dSopenharmony_ci			// Update the display
3062e5b6d6dSopenharmony_ci			setLayout(new GridBagLayout());
3072e5b6d6dSopenharmony_ci			GridBagConstraints gbc = new GridBagConstraints();
3082e5b6d6dSopenharmony_ci			removeAll();
3092e5b6d6dSopenharmony_ci			itemPanel.add(createItemButton, BorderLayout.WEST);
3102e5b6d6dSopenharmony_ci			itemPanel.add(editItemButton, BorderLayout.CENTER);
3112e5b6d6dSopenharmony_ci			itemPanel.add(deleteItemButton, BorderLayout.EAST);
3122e5b6d6dSopenharmony_ci			groupPanel.add(createGroupButton, BorderLayout.WEST);
3132e5b6d6dSopenharmony_ci			groupPanel.add(editGroupButton, BorderLayout.CENTER);
3142e5b6d6dSopenharmony_ci			groupPanel.add(deleteGroupButton, BorderLayout.EAST);
3152e5b6d6dSopenharmony_ci
3162e5b6d6dSopenharmony_ci
3172e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
3182e5b6d6dSopenharmony_ci			gbc.weighty = 0.0;
3192e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
3202e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.HORIZONTAL;
3212e5b6d6dSopenharmony_ci			add(jLabelGroupTitle, gbc);
3222e5b6d6dSopenharmony_ci			gbc.weightx = 0.0;
3232e5b6d6dSopenharmony_ci			gbc.gridwidth = 1;
3242e5b6d6dSopenharmony_ci			add(jLabelGroupNameTitle, gbc);
3252e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
3262e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
3272e5b6d6dSopenharmony_ci			add(jComboBoxGroup, gbc);
3282e5b6d6dSopenharmony_ci			gbc.weightx = 0.0;
3292e5b6d6dSopenharmony_ci			gbc.gridwidth = 1;
3302e5b6d6dSopenharmony_ci			add(jLabelGroupCommentTitle, gbc);
3312e5b6d6dSopenharmony_ci			gbc.weightx = 1.0;
3322e5b6d6dSopenharmony_ci			gbc.gridwidth = GridBagConstraints.REMAINDER;
3332e5b6d6dSopenharmony_ci			add(jLabelGroupComment, gbc);
3342e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.BOTH;
3352e5b6d6dSopenharmony_ci			gbc.weighty = 1.0;
3362e5b6d6dSopenharmony_ci			add(jScrollPaneGroupTable, gbc);
3372e5b6d6dSopenharmony_ci			gbc.weighty = 0.0;
3382e5b6d6dSopenharmony_ci			gbc.fill = GridBagConstraints.HORIZONTAL;
3392e5b6d6dSopenharmony_ci			add(groupPanel, gbc);
3402e5b6d6dSopenharmony_ci			add(itemPanel, gbc);
3412e5b6d6dSopenharmony_ci		} else {
3422e5b6d6dSopenharmony_ci			removeAll();
3432e5b6d6dSopenharmony_ci		}
3442e5b6d6dSopenharmony_ci	}
3452e5b6d6dSopenharmony_ci
3462e5b6d6dSopenharmony_ci	public void updateComponents() {
3472e5b6d6dSopenharmony_ci		// Initialize components
3482e5b6d6dSopenharmony_ci		if (bundle != null) {
3492e5b6d6dSopenharmony_ci			jLabelGroupTitle.setText(bundle.name);
3502e5b6d6dSopenharmony_ci
3512e5b6d6dSopenharmony_ci			((GroupItemsTableModel)jTableGroupTable.getModel()).setGroup((BundleGroup)jComboBoxGroup.getSelectedItem());
3522e5b6d6dSopenharmony_ci			jLabelGroupComment.setText(((BundleGroup)jComboBoxGroup.getSelectedItem()).getComment());
3532e5b6d6dSopenharmony_ci
3542e5b6d6dSopenharmony_ci			jTableGroupTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
3552e5b6d6dSopenharmony_ci
3562e5b6d6dSopenharmony_ci			// Update the group comment
3572e5b6d6dSopenharmony_ci			jLabelGroupComment.setText(((BundleGroup)jComboBoxGroup.getSelectedItem()).getComment());
3582e5b6d6dSopenharmony_ci			((GroupComboBoxModel)jComboBoxGroup.getModel()).update();
3592e5b6d6dSopenharmony_ci		} else if (rbm != null) {
3602e5b6d6dSopenharmony_ci
3612e5b6d6dSopenharmony_ci			// Update the list of groups
3622e5b6d6dSopenharmony_ci//			try {
3632e5b6d6dSopenharmony_ci				((GroupComboBoxModel)jComboBoxGroup.getModel()).update();
3642e5b6d6dSopenharmony_ci//			}
3652e5b6d6dSopenharmony_ci//			catch (Exception e) {}
3662e5b6d6dSopenharmony_ci			// Update the group comment
3672e5b6d6dSopenharmony_ci			if ((BundleGroup)jComboBoxGroup.getSelectedItem() != null)
3682e5b6d6dSopenharmony_ci				jLabelGroupComment.setText(((BundleGroup)jComboBoxGroup.getSelectedItem()).getComment());
3692e5b6d6dSopenharmony_ci			else
3702e5b6d6dSopenharmony_ci				jLabelGroupComment.setText("");
3712e5b6d6dSopenharmony_ci			// Update the list of resources
3722e5b6d6dSopenharmony_ci			ListModel lmodel = jListGroup.getModel();
3732e5b6d6dSopenharmony_ci			if (lmodel instanceof GroupItemsListModel) {
3742e5b6d6dSopenharmony_ci				//((GroupItemsListModel)lmodel).update();
3752e5b6d6dSopenharmony_ci				((GroupItemsListModel)lmodel).setGroup((BundleGroup)jComboBoxGroup.getSelectedItem());
3762e5b6d6dSopenharmony_ci			}
3772e5b6d6dSopenharmony_ci			else {
3782e5b6d6dSopenharmony_ci				GroupItemsListModel newModel = new GroupItemsListModel((BundleGroup)jComboBoxGroup.getSelectedItem());
3792e5b6d6dSopenharmony_ci				RBManagerGUI.debugMsg("List Model not as anticipated: " + lmodel.getClass().getName());
3802e5b6d6dSopenharmony_ci				jListGroup.setModel(newModel);
3812e5b6d6dSopenharmony_ci				newModel.update();
3822e5b6d6dSopenharmony_ci			}
3832e5b6d6dSopenharmony_ci		} else {
3842e5b6d6dSopenharmony_ci			RBManagerGUI.debugMsg("Update, but no active components");
3852e5b6d6dSopenharmony_ci			removeAll();
3862e5b6d6dSopenharmony_ci		}
3872e5b6d6dSopenharmony_ci		//validate();
3882e5b6d6dSopenharmony_ci	}
3892e5b6d6dSopenharmony_ci
3902e5b6d6dSopenharmony_ci	private void handleDeleteItem(String key) {
3912e5b6d6dSopenharmony_ci		if (rbm != null) rbm.deleteItem(key);
3922e5b6d6dSopenharmony_ci	}
3932e5b6d6dSopenharmony_ci}
3942e5b6d6dSopenharmony_ci
3952e5b6d6dSopenharmony_ci/**
3962e5b6d6dSopenharmony_ci * The action listener which monitors changes in the group to display
3972e5b6d6dSopenharmony_ci */
3982e5b6d6dSopenharmony_ciclass GroupComboActionListener implements ActionListener {
3992e5b6d6dSopenharmony_ci	RBGroupPanel panel;
4002e5b6d6dSopenharmony_ci
4012e5b6d6dSopenharmony_ci	protected GroupComboActionListener(RBGroupPanel panel) {
4022e5b6d6dSopenharmony_ci		this.panel = panel;
4032e5b6d6dSopenharmony_ci	}
4042e5b6d6dSopenharmony_ci
4052e5b6d6dSopenharmony_ci	public void actionPerformed(ActionEvent ev) {
4062e5b6d6dSopenharmony_ci		panel.updateComponents();
4072e5b6d6dSopenharmony_ci	}
4082e5b6d6dSopenharmony_ci}
4092e5b6d6dSopenharmony_ci
4102e5b6d6dSopenharmony_ci/**
4112e5b6d6dSopenharmony_ci * The list model for groups
4122e5b6d6dSopenharmony_ci */
4132e5b6d6dSopenharmony_ciclass GroupItemsListModel extends AbstractListModel {
4142e5b6d6dSopenharmony_ci	BundleGroup group;
4152e5b6d6dSopenharmony_ci
4162e5b6d6dSopenharmony_ci	public void setGroup(BundleGroup group) {
4172e5b6d6dSopenharmony_ci		this.group = group;
4182e5b6d6dSopenharmony_ci		update();
4192e5b6d6dSopenharmony_ci	}
4202e5b6d6dSopenharmony_ci
4212e5b6d6dSopenharmony_ci	public GroupItemsListModel(BundleGroup group) {
4222e5b6d6dSopenharmony_ci		this.group = group;
4232e5b6d6dSopenharmony_ci	}
4242e5b6d6dSopenharmony_ci
4252e5b6d6dSopenharmony_ci	public int getSize() {
4262e5b6d6dSopenharmony_ci		if (group == null)
4272e5b6d6dSopenharmony_ci			return 0;
4282e5b6d6dSopenharmony_ci		int result = group.getItemCount();
4292e5b6d6dSopenharmony_ci		return result;
4302e5b6d6dSopenharmony_ci	}
4312e5b6d6dSopenharmony_ci
4322e5b6d6dSopenharmony_ci	public Object getElementAt(int index) {
4332e5b6d6dSopenharmony_ci		return group.getBundleItem(index);
4342e5b6d6dSopenharmony_ci	}
4352e5b6d6dSopenharmony_ci
4362e5b6d6dSopenharmony_ci	public void update() {
4372e5b6d6dSopenharmony_ci		fireContentsChanged(this, 0, getSize()-1);
4382e5b6d6dSopenharmony_ci	}
4392e5b6d6dSopenharmony_ci}
4402e5b6d6dSopenharmony_ci
4412e5b6d6dSopenharmony_ci/**
4422e5b6d6dSopenharmony_ci * The table model for searched Items
4432e5b6d6dSopenharmony_ci */
4442e5b6d6dSopenharmony_ciclass GroupComboBoxModel extends DefaultComboBoxModel {
4452e5b6d6dSopenharmony_ci	Bundle bundle;
4462e5b6d6dSopenharmony_ci
4472e5b6d6dSopenharmony_ci	public GroupComboBoxModel (Bundle bundle) {
4482e5b6d6dSopenharmony_ci		this.bundle = bundle;
4492e5b6d6dSopenharmony_ci		setSelectedItem(bundle.getBundleGroup(0));
4502e5b6d6dSopenharmony_ci	}
4512e5b6d6dSopenharmony_ci
4522e5b6d6dSopenharmony_ci	public int getSize() {
4532e5b6d6dSopenharmony_ci		return bundle.getGroupCount();
4542e5b6d6dSopenharmony_ci	}
4552e5b6d6dSopenharmony_ci
4562e5b6d6dSopenharmony_ci	public Object getElementAt(int index) {
4572e5b6d6dSopenharmony_ci		return bundle.getBundleGroup(index);
4582e5b6d6dSopenharmony_ci	}
4592e5b6d6dSopenharmony_ci
4602e5b6d6dSopenharmony_ci	public Object getSelectedItem() {
4612e5b6d6dSopenharmony_ci		return super.getSelectedItem();
4622e5b6d6dSopenharmony_ci		//return getElementAt(0);
4632e5b6d6dSopenharmony_ci	}
4642e5b6d6dSopenharmony_ci
4652e5b6d6dSopenharmony_ci	public void update() {
4662e5b6d6dSopenharmony_ci		fireContentsChanged(this, 0, getSize()-1);
4672e5b6d6dSopenharmony_ci	}
4682e5b6d6dSopenharmony_ci}
4692e5b6d6dSopenharmony_ci
4702e5b6d6dSopenharmony_ci/**
4712e5b6d6dSopenharmony_ci * The table model for bundle groups
4722e5b6d6dSopenharmony_ci */
4732e5b6d6dSopenharmony_ciclass GroupItemsTableModel extends AbstractTableModel {
4742e5b6d6dSopenharmony_ci	BundleGroup group;
4752e5b6d6dSopenharmony_ci
4762e5b6d6dSopenharmony_ci	public GroupItemsTableModel(BundleGroup group) {
4772e5b6d6dSopenharmony_ci		this.group = group;
4782e5b6d6dSopenharmony_ci	}
4792e5b6d6dSopenharmony_ci
4802e5b6d6dSopenharmony_ci	public int getColumnCount() { return 3; }
4812e5b6d6dSopenharmony_ci
4822e5b6d6dSopenharmony_ci	public int getRowCount() {
4832e5b6d6dSopenharmony_ci		return group.getItemCount();
4842e5b6d6dSopenharmony_ci	}
4852e5b6d6dSopenharmony_ci
4862e5b6d6dSopenharmony_ci	public void setGroup(BundleGroup bg) {
4872e5b6d6dSopenharmony_ci		group = bg;
4882e5b6d6dSopenharmony_ci		fireTableChanged(new TableModelEvent(this));
4892e5b6d6dSopenharmony_ci	}
4902e5b6d6dSopenharmony_ci
4912e5b6d6dSopenharmony_ci	public Object getValueAt(int row, int col) {
4922e5b6d6dSopenharmony_ci		BundleItem item = group.getBundleItem(row);
4932e5b6d6dSopenharmony_ci
4942e5b6d6dSopenharmony_ci		String retStr = null;
4952e5b6d6dSopenharmony_ci
4962e5b6d6dSopenharmony_ci		switch(col) {
4972e5b6d6dSopenharmony_ci		case 0:
4982e5b6d6dSopenharmony_ci			retStr = item.getKey();
4992e5b6d6dSopenharmony_ci			break;
5002e5b6d6dSopenharmony_ci		case 1:
5012e5b6d6dSopenharmony_ci			retStr = item.getTranslation();
5022e5b6d6dSopenharmony_ci			break;
5032e5b6d6dSopenharmony_ci		case 2:
5042e5b6d6dSopenharmony_ci			retStr = (item.getComment() == null ? "" : item.getComment());
5052e5b6d6dSopenharmony_ci			break;
5062e5b6d6dSopenharmony_ci		default:
5072e5b6d6dSopenharmony_ci			retStr = Resources.getTranslation("table_cell_error");
5082e5b6d6dSopenharmony_ci		}
5092e5b6d6dSopenharmony_ci
5102e5b6d6dSopenharmony_ci		return retStr;
5112e5b6d6dSopenharmony_ci	}
5122e5b6d6dSopenharmony_ci
5132e5b6d6dSopenharmony_ci	public String getColumnName(int col) {
5142e5b6d6dSopenharmony_ci		if (col == 0) return Resources.getTranslation("languagegroup_column_key");
5152e5b6d6dSopenharmony_ci		else if (col == 1) return Resources.getTranslation("languagegroup_column_translation");
5162e5b6d6dSopenharmony_ci		else if (col == 2) return Resources.getTranslation("languagegroup_column_comment");
5172e5b6d6dSopenharmony_ci		else return Resources.getTranslation("table_column_error");
5182e5b6d6dSopenharmony_ci	}
5192e5b6d6dSopenharmony_ci
5202e5b6d6dSopenharmony_ci	public BundleItem getBundleItem(int row) {
5212e5b6d6dSopenharmony_ci		if (row >= group.getItemCount())
5222e5b6d6dSopenharmony_ci		    return null;
5232e5b6d6dSopenharmony_ci		return group.getBundleItem(row);
5242e5b6d6dSopenharmony_ci	}
5252e5b6d6dSopenharmony_ci
5262e5b6d6dSopenharmony_ci	public void update() {
5272e5b6d6dSopenharmony_ci		fireTableDataChanged();
5282e5b6d6dSopenharmony_ci	}
5292e5b6d6dSopenharmony_ci}
5302e5b6d6dSopenharmony_ci
531