12e5b6d6dSopenharmony_ci/* 22e5b6d6dSopenharmony_ci ***************************************************************************** 32e5b6d6dSopenharmony_ci * Copyright (C) 2000-2007, 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_ciimport java.util.*; 122e5b6d6dSopenharmony_ci 132e5b6d6dSopenharmony_ciimport javax.swing.*; 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ciimport com.ibm.rbm.*; 162e5b6d6dSopenharmony_ci 172e5b6d6dSopenharmony_ci/** 182e5b6d6dSopenharmony_ci * A dialog which allows the user to create a new Bundle Item 192e5b6d6dSopenharmony_ci */ 202e5b6d6dSopenharmony_ciclass BundleItemCreationDialog extends JDialog { 212e5b6d6dSopenharmony_ci RBManager rbm; 222e5b6d6dSopenharmony_ci String groupName; 232e5b6d6dSopenharmony_ci BundleItem item; 242e5b6d6dSopenharmony_ci boolean firstInit = true; 252e5b6d6dSopenharmony_ci 262e5b6d6dSopenharmony_ci // Helper data 272e5b6d6dSopenharmony_ci int left_col_width = 125; 282e5b6d6dSopenharmony_ci int right_col_width = 275; 292e5b6d6dSopenharmony_ci int row_height = 25; 302e5b6d6dSopenharmony_ci Dimension leftDim = new Dimension(left_col_width, row_height); 312e5b6d6dSopenharmony_ci Dimension rightDim = new Dimension(right_col_width, row_height); 322e5b6d6dSopenharmony_ci 332e5b6d6dSopenharmony_ci // Components 342e5b6d6dSopenharmony_ci Box mainBox = new Box(BoxLayout.Y_AXIS); 352e5b6d6dSopenharmony_ci Box box1 = new Box(BoxLayout.X_AXIS); 362e5b6d6dSopenharmony_ci Box box2 = new Box(BoxLayout.X_AXIS); 372e5b6d6dSopenharmony_ci Box box3 = new Box(BoxLayout.X_AXIS); 382e5b6d6dSopenharmony_ci Box box4 = new Box(BoxLayout.X_AXIS); 392e5b6d6dSopenharmony_ci Box box5 = new Box(BoxLayout.X_AXIS); 402e5b6d6dSopenharmony_ci Box box6 = new Box(BoxLayout.X_AXIS); 412e5b6d6dSopenharmony_ci 422e5b6d6dSopenharmony_ci JLabel instructionsLabel = new JLabel(""); 432e5b6d6dSopenharmony_ci JLabel groupLabel = new JLabel(Resources.getTranslation("dialog_group")); 442e5b6d6dSopenharmony_ci JLabel nameLabel = new JLabel(Resources.getTranslation("dialog_key")); 452e5b6d6dSopenharmony_ci JLabel transLabel = new JLabel(Resources.getTranslation("dialog_translation")); 462e5b6d6dSopenharmony_ci JLabel commentLabel = new JLabel(Resources.getTranslation("dialog_comment")); 472e5b6d6dSopenharmony_ci JLabel lookupLabel = new JLabel(Resources.getTranslation("dialog_lookups")); 482e5b6d6dSopenharmony_ci 492e5b6d6dSopenharmony_ci JComboBox groupComboBox = new JComboBox(); 502e5b6d6dSopenharmony_ci JTextField nameField = new JTextField(""); 512e5b6d6dSopenharmony_ci JTextField transField = new JTextField(""); 522e5b6d6dSopenharmony_ci JTextField commentField = new JTextField(""); 532e5b6d6dSopenharmony_ci JTextField lookupFields[] = null; 542e5b6d6dSopenharmony_ci JLabel noLookupLabel = null; 552e5b6d6dSopenharmony_ci Box lookupBox = null; 562e5b6d6dSopenharmony_ci Box lookupBoxes[] = null; 572e5b6d6dSopenharmony_ci JLabel lookupLabels[] = null; 582e5b6d6dSopenharmony_ci 592e5b6d6dSopenharmony_ci JButton createButton = new JButton(Resources.getTranslation("button_create")); 602e5b6d6dSopenharmony_ci JButton createMoreButton = new JButton(Resources.getTranslation("button_create_more")); 612e5b6d6dSopenharmony_ci JButton cancelButton = new JButton(Resources.getTranslation("button_cancel")); 622e5b6d6dSopenharmony_ci 632e5b6d6dSopenharmony_ci Hashtable lookups = new Hashtable(); 642e5b6d6dSopenharmony_ci 652e5b6d6dSopenharmony_ci public BundleItemCreationDialog(RBManager rbm, JFrame frame, String title, boolean modal) { 662e5b6d6dSopenharmony_ci super(frame, title, modal); 672e5b6d6dSopenharmony_ci this.rbm = rbm; 682e5b6d6dSopenharmony_ci groupName = null; 692e5b6d6dSopenharmony_ci item = null; 702e5b6d6dSopenharmony_ci initComponents(); 712e5b6d6dSopenharmony_ci } 722e5b6d6dSopenharmony_ci 732e5b6d6dSopenharmony_ci public BundleItemCreationDialog(String groupName, RBManager rbm, JFrame frame, String title, boolean modal) { 742e5b6d6dSopenharmony_ci super(frame, title, modal); 752e5b6d6dSopenharmony_ci this.rbm = rbm; 762e5b6d6dSopenharmony_ci this.groupName = groupName; 772e5b6d6dSopenharmony_ci item = null; 782e5b6d6dSopenharmony_ci initComponents(); 792e5b6d6dSopenharmony_ci } 802e5b6d6dSopenharmony_ci 812e5b6d6dSopenharmony_ci public BundleItemCreationDialog(BundleItem item, RBManager rbm, JFrame frame, String title, boolean modal) { 822e5b6d6dSopenharmony_ci super(frame, title, modal); 832e5b6d6dSopenharmony_ci this.item = item; 842e5b6d6dSopenharmony_ci this.rbm = rbm; 852e5b6d6dSopenharmony_ci groupName = item.getParentGroup().getName(); 862e5b6d6dSopenharmony_ci initComponents(); 872e5b6d6dSopenharmony_ci } 882e5b6d6dSopenharmony_ci 892e5b6d6dSopenharmony_ci boolean createItem() { 902e5b6d6dSopenharmony_ci if (rbm == null) return false; 912e5b6d6dSopenharmony_ci Hashtable lookupHash = new Hashtable(); 922e5b6d6dSopenharmony_ci if (lookupBoxes != null) { 932e5b6d6dSopenharmony_ci for (int i=0; i < lookupBoxes.length; i++) { 942e5b6d6dSopenharmony_ci String nameText = lookupLabels[i].getText().trim(); 952e5b6d6dSopenharmony_ci String name = nameText.substring(nameText.indexOf("{")+1,nameText.indexOf("}")); 962e5b6d6dSopenharmony_ci String value = lookupFields[i].getText().trim(); 972e5b6d6dSopenharmony_ci lookupHash.put(name,value); 982e5b6d6dSopenharmony_ci } 992e5b6d6dSopenharmony_ci } 1002e5b6d6dSopenharmony_ci return rbm.createItem(nameField.getText().trim(), transField.getText().trim(), 1012e5b6d6dSopenharmony_ci ((BundleGroup)groupComboBox.getSelectedItem()).getName(), 1022e5b6d6dSopenharmony_ci commentField.getText().trim(), lookupHash); 1032e5b6d6dSopenharmony_ci } 1042e5b6d6dSopenharmony_ci 1052e5b6d6dSopenharmony_ci boolean editItem() { 1062e5b6d6dSopenharmony_ci if (item == null) return false; 1072e5b6d6dSopenharmony_ci Hashtable lookupHash = new Hashtable(); 1082e5b6d6dSopenharmony_ci if (lookupBoxes != null) { 1092e5b6d6dSopenharmony_ci for (int i=0; i < lookupBoxes.length; i++) { 1102e5b6d6dSopenharmony_ci String nameText = lookupLabels[i].getText().trim(); 1112e5b6d6dSopenharmony_ci String name = nameText.substring(nameText.indexOf("{")+1,nameText.indexOf("}")); 1122e5b6d6dSopenharmony_ci String value = lookupFields[i].getText().trim(); 1132e5b6d6dSopenharmony_ci lookupHash.put(name,value); 1142e5b6d6dSopenharmony_ci } 1152e5b6d6dSopenharmony_ci } 1162e5b6d6dSopenharmony_ci return rbm.editItem(item, nameField.getText().trim(), 1172e5b6d6dSopenharmony_ci transField.getText().trim(), ((BundleGroup)groupComboBox.getSelectedItem()).getName(), 1182e5b6d6dSopenharmony_ci commentField.getText().trim(), lookupHash); 1192e5b6d6dSopenharmony_ci } 1202e5b6d6dSopenharmony_ci 1212e5b6d6dSopenharmony_ci private void clearComponents() { 1222e5b6d6dSopenharmony_ci nameField.setText(""); 1232e5b6d6dSopenharmony_ci transField.setText(""); 1242e5b6d6dSopenharmony_ci commentField.setText(""); 1252e5b6d6dSopenharmony_ci initComponents(); 1262e5b6d6dSopenharmony_ci } 1272e5b6d6dSopenharmony_ci 1282e5b6d6dSopenharmony_ci protected void processKeyEvent(KeyEvent ev) { 1292e5b6d6dSopenharmony_ci if (ev.getKeyCode() == KeyEvent.VK_ENTER && ev.getID() == KeyEvent.KEY_RELEASED) { 1302e5b6d6dSopenharmony_ci if (transField.hasFocus()) { 1312e5b6d6dSopenharmony_ci // If we are in the translation field, then enter should create a new line character, not exit the dialog 1322e5b6d6dSopenharmony_ci int caretPos = transField.getCaretPosition(); 1332e5b6d6dSopenharmony_ci String oldText = transField.getText(); 1342e5b6d6dSopenharmony_ci transField.setText(oldText.substring(0,caretPos) + "\n" + oldText.substring(caretPos,oldText.length())); 1352e5b6d6dSopenharmony_ci transField.setCaretPosition(caretPos+1); 1362e5b6d6dSopenharmony_ci validate(); 1372e5b6d6dSopenharmony_ci setSize(getPreferredSize()); 1382e5b6d6dSopenharmony_ci return; 1392e5b6d6dSopenharmony_ci } 1402e5b6d6dSopenharmony_ci 1412e5b6d6dSopenharmony_ci BundleItemCreationDialog dialog = this; 1422e5b6d6dSopenharmony_ci boolean success = false; 1432e5b6d6dSopenharmony_ci if (dialog.item == null) success = dialog.createItem(); 1442e5b6d6dSopenharmony_ci else success = dialog.editItem(); 1452e5b6d6dSopenharmony_ci if (!success) { 1462e5b6d6dSopenharmony_ci String alert = (item == null ? Resources.getTranslation("error_create_item") : 1472e5b6d6dSopenharmony_ci Resources.getTranslation("error_modify_item")); 1482e5b6d6dSopenharmony_ci alert += " " + Resources.getTranslation("error_try_again_item"); 1492e5b6d6dSopenharmony_ci JOptionPane.showMessageDialog(dialog, alert, Resources.getTranslation("error"), 1502e5b6d6dSopenharmony_ci JOptionPane.ERROR_MESSAGE); 1512e5b6d6dSopenharmony_ci } else { 1522e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).updateDisplayPanels(); 1532e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).invalidate(); 1542e5b6d6dSopenharmony_ci //((RBManagerGUI)dialog.getParent()).validateMyTree(); 1552e5b6d6dSopenharmony_ci dialog.setVisible(false); 1562e5b6d6dSopenharmony_ci dialog.dispose(); 1572e5b6d6dSopenharmony_ci } 1582e5b6d6dSopenharmony_ci } else if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) { 1592e5b6d6dSopenharmony_ci closeWindow(); 1602e5b6d6dSopenharmony_ci } 1612e5b6d6dSopenharmony_ci } 1622e5b6d6dSopenharmony_ci 1632e5b6d6dSopenharmony_ci private void initComponents(){ 1642e5b6d6dSopenharmony_ci enableEvents(AWTEvent.KEY_EVENT_MASK); 1652e5b6d6dSopenharmony_ci // Error check 1662e5b6d6dSopenharmony_ci if (rbm == null || rbm.getBundles() == null) { 1672e5b6d6dSopenharmony_ci String alert = Resources.getTranslation("error_no_bundle_for_item"); 1682e5b6d6dSopenharmony_ci JOptionPane.showMessageDialog(this, alert, Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE); 1692e5b6d6dSopenharmony_ci closeWindow(); 1702e5b6d6dSopenharmony_ci return; 1712e5b6d6dSopenharmony_ci } 1722e5b6d6dSopenharmony_ci 1732e5b6d6dSopenharmony_ci // Initialize values 1742e5b6d6dSopenharmony_ci Bundle mainBundle = (Bundle)rbm.getBundles().firstElement(); 1752e5b6d6dSopenharmony_ci if (firstInit) { 1762e5b6d6dSopenharmony_ci groupComboBox = new JComboBox(mainBundle.getGroupsAsVector()); 1772e5b6d6dSopenharmony_ci if (groupName != null) { 1782e5b6d6dSopenharmony_ci for (int i = 0; i < groupComboBox.getItemCount(); i++) { 1792e5b6d6dSopenharmony_ci BundleGroup bg = (BundleGroup)groupComboBox.getItemAt(i); 1802e5b6d6dSopenharmony_ci if (bg.getName().equals(groupName)) { 1812e5b6d6dSopenharmony_ci groupComboBox.setSelectedIndex(i); 1822e5b6d6dSopenharmony_ci break; 1832e5b6d6dSopenharmony_ci } 1842e5b6d6dSopenharmony_ci } 1852e5b6d6dSopenharmony_ci } 1862e5b6d6dSopenharmony_ci } 1872e5b6d6dSopenharmony_ci 1882e5b6d6dSopenharmony_ci if (firstInit && item != null) { 1892e5b6d6dSopenharmony_ci // We are editing, not creating an item 1902e5b6d6dSopenharmony_ci createButton.setText(Resources.getTranslation("button_edit")); 1912e5b6d6dSopenharmony_ci createMoreButton.setText(Resources.getTranslation("button_edit_more")); 1922e5b6d6dSopenharmony_ci if (item.getKey() != null) nameField.setText(item.getKey()); 1932e5b6d6dSopenharmony_ci if (item.getComment() != null) commentField.setText(item.getComment()); 1942e5b6d6dSopenharmony_ci if (item.getTranslation() != null) transField.setText(item.getTranslation()); 1952e5b6d6dSopenharmony_ci if (item.getLookups() != null) lookups = item.getLookups(); 1962e5b6d6dSopenharmony_ci } 1972e5b6d6dSopenharmony_ci 1982e5b6d6dSopenharmony_ci String currentTrans = transField.getText(); 1992e5b6d6dSopenharmony_ci // ** LOOKUPS ** 2002e5b6d6dSopenharmony_ci // Update the lookups if necessary 2012e5b6d6dSopenharmony_ci if (lookupBoxes != null) { 2022e5b6d6dSopenharmony_ci for (int i=0; i < lookupBoxes.length; i++) { 2032e5b6d6dSopenharmony_ci String nameText = lookupLabels[i].getText().trim(); 2042e5b6d6dSopenharmony_ci String name = nameText.substring(nameText.indexOf("{")+1,nameText.indexOf("}")); 2052e5b6d6dSopenharmony_ci String value = lookupFields[i].getText().trim(); 2062e5b6d6dSopenharmony_ci lookups.put(name,value); 2072e5b6d6dSopenharmony_ci } 2082e5b6d6dSopenharmony_ci } 2092e5b6d6dSopenharmony_ci // Remove old lookups if necessary 2102e5b6d6dSopenharmony_ci Enumeration keys = lookups.keys(); 2112e5b6d6dSopenharmony_ci while (keys.hasMoreElements()) { 2122e5b6d6dSopenharmony_ci String name = (String)keys.nextElement(); 2132e5b6d6dSopenharmony_ci if (currentTrans.indexOf("{" + name + "}") < 0) { 2142e5b6d6dSopenharmony_ci lookups.remove(name); 2152e5b6d6dSopenharmony_ci } 2162e5b6d6dSopenharmony_ci } 2172e5b6d6dSopenharmony_ci // Add new lookups if necessary 2182e5b6d6dSopenharmony_ci if (currentTrans != null && currentTrans.indexOf("{") >= 0) { 2192e5b6d6dSopenharmony_ci while (currentTrans.indexOf("{") >= 0) { 2202e5b6d6dSopenharmony_ci currentTrans = currentTrans.substring(currentTrans.indexOf("{")+1,currentTrans.length()); 2212e5b6d6dSopenharmony_ci String name = currentTrans.substring(0,currentTrans.indexOf("}")); 2222e5b6d6dSopenharmony_ci if (!lookups.containsKey(name)) { 2232e5b6d6dSopenharmony_ci lookups.put(name,""); 2242e5b6d6dSopenharmony_ci } 2252e5b6d6dSopenharmony_ci } 2262e5b6d6dSopenharmony_ci } 2272e5b6d6dSopenharmony_ci // Remove components 2282e5b6d6dSopenharmony_ci box5.removeAll(); 2292e5b6d6dSopenharmony_ci 2302e5b6d6dSopenharmony_ci // Now create the visual components for the lookups 2312e5b6d6dSopenharmony_ci if (lookups.size() > 0) { 2322e5b6d6dSopenharmony_ci noLookupLabel = null; 2332e5b6d6dSopenharmony_ci lookupBox = new Box(BoxLayout.Y_AXIS); 2342e5b6d6dSopenharmony_ci lookupBoxes = new Box[lookups.size()]; 2352e5b6d6dSopenharmony_ci lookupFields = new JTextField[lookups.size()]; 2362e5b6d6dSopenharmony_ci lookupLabels = new JLabel[lookups.size()]; 2372e5b6d6dSopenharmony_ci int count = 0; 2382e5b6d6dSopenharmony_ci keys = lookups.keys(); 2392e5b6d6dSopenharmony_ci while (keys.hasMoreElements()) { 2402e5b6d6dSopenharmony_ci String name = (String)keys.nextElement(); 2412e5b6d6dSopenharmony_ci String value = (String)lookups.get(name); 2422e5b6d6dSopenharmony_ci RBManagerGUI.debugMsg("Lookup: " + name + " -> " + value); 2432e5b6d6dSopenharmony_ci RBManagerGUI.debugMsg(lookups.toString()); 2442e5b6d6dSopenharmony_ci lookupBoxes[count] = new Box(BoxLayout.X_AXIS); 2452e5b6d6dSopenharmony_ci lookupFields[count] = new JTextField((value == null ? "" : value)); 2462e5b6d6dSopenharmony_ci lookupLabels[count] = new JLabel("{" + name + "}"); 2472e5b6d6dSopenharmony_ci lookupBoxes[count].add(Box.createHorizontalGlue()); 2482e5b6d6dSopenharmony_ci lookupBoxes[count].add(lookupLabels[count]); 2492e5b6d6dSopenharmony_ci lookupBoxes[count].add(Box.createHorizontalStrut(5)); 2502e5b6d6dSopenharmony_ci lookupBoxes[count].add(lookupFields[count]); 2512e5b6d6dSopenharmony_ci lookupBox.add(lookupBoxes[count]); 2522e5b6d6dSopenharmony_ci count++; 2532e5b6d6dSopenharmony_ci } 2542e5b6d6dSopenharmony_ci } else { 2552e5b6d6dSopenharmony_ci lookupBox = null; 2562e5b6d6dSopenharmony_ci lookupBoxes = null; 2572e5b6d6dSopenharmony_ci lookupFields = null; 2582e5b6d6dSopenharmony_ci lookupLabels = null; 2592e5b6d6dSopenharmony_ci noLookupLabel = new JLabel(Resources.getTranslation("none")); 2602e5b6d6dSopenharmony_ci } 2612e5b6d6dSopenharmony_ci 2622e5b6d6dSopenharmony_ci // Set up the components 2632e5b6d6dSopenharmony_ci if (firstInit) { 2642e5b6d6dSopenharmony_ci groupLabel.setPreferredSize(leftDim); 2652e5b6d6dSopenharmony_ci groupComboBox.setPreferredSize(rightDim); 2662e5b6d6dSopenharmony_ci nameLabel.setPreferredSize(leftDim); 2672e5b6d6dSopenharmony_ci nameField.setColumns(30); 2682e5b6d6dSopenharmony_ci commentLabel.setPreferredSize(leftDim); 2692e5b6d6dSopenharmony_ci commentField.setColumns(30); 2702e5b6d6dSopenharmony_ci transLabel.setPreferredSize(leftDim); 2712e5b6d6dSopenharmony_ci transField.setColumns(30); 2722e5b6d6dSopenharmony_ci lookupLabel.setPreferredSize(leftDim); 2732e5b6d6dSopenharmony_ci 2742e5b6d6dSopenharmony_ci box1.add(groupLabel); box1.add(groupComboBox); 2752e5b6d6dSopenharmony_ci box2.add(nameLabel); box2.add(nameField); 2762e5b6d6dSopenharmony_ci box4.add(commentLabel); box4.add(commentField); 2772e5b6d6dSopenharmony_ci box3.add(transLabel); box3.add(transField); 2782e5b6d6dSopenharmony_ci 2792e5b6d6dSopenharmony_ci createButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_create_trigger"))); 2802e5b6d6dSopenharmony_ci createMoreButton.setMnemonic(RBManagerMenuBar.getKeyEventKey(Resources.getTranslation("button_create_more_trigger"))); 2812e5b6d6dSopenharmony_ci getRootPane().setDefaultButton(createButton); 2822e5b6d6dSopenharmony_ci } 2832e5b6d6dSopenharmony_ci box5.add(Box.createHorizontalGlue()); box5.add(lookupLabel); box5.add(Box.createHorizontalStrut(5)); 2842e5b6d6dSopenharmony_ci if (noLookupLabel != null) { 2852e5b6d6dSopenharmony_ci noLookupLabel.setPreferredSize(rightDim); 2862e5b6d6dSopenharmony_ci box5.add(noLookupLabel); 2872e5b6d6dSopenharmony_ci } 2882e5b6d6dSopenharmony_ci else 2892e5b6d6dSopenharmony_ci box5.add(lookupBox); 2902e5b6d6dSopenharmony_ci if (firstInit) { 2912e5b6d6dSopenharmony_ci box6.add(createButton); 2922e5b6d6dSopenharmony_ci box6.add(Box.createHorizontalStrut(5)); 2932e5b6d6dSopenharmony_ci if (item == null) 2942e5b6d6dSopenharmony_ci box6.add(createMoreButton); 2952e5b6d6dSopenharmony_ci box6.add(Box.createHorizontalStrut(5)); 2962e5b6d6dSopenharmony_ci box6.add(cancelButton); 2972e5b6d6dSopenharmony_ci } 2982e5b6d6dSopenharmony_ci 2992e5b6d6dSopenharmony_ci instructionsLabel.setBorder(BorderFactory.createEtchedBorder()); 3002e5b6d6dSopenharmony_ci 3012e5b6d6dSopenharmony_ci // Add the appropriate listeners 3022e5b6d6dSopenharmony_ci if (firstInit) { 3032e5b6d6dSopenharmony_ci cancelButton.addActionListener(new ActionListener() { 3042e5b6d6dSopenharmony_ci public void actionPerformed(ActionEvent ev) { 3052e5b6d6dSopenharmony_ci JDialog dialog = (JDialog)((JButton)ev.getSource()).getParent().getParent().getParent().getParent().getParent().getParent(); 3062e5b6d6dSopenharmony_ci dialog.setVisible(false); 3072e5b6d6dSopenharmony_ci dialog.dispose(); 3082e5b6d6dSopenharmony_ci } 3092e5b6d6dSopenharmony_ci }); 3102e5b6d6dSopenharmony_ci 3112e5b6d6dSopenharmony_ci createButton.addActionListener(new ActionListener() { 3122e5b6d6dSopenharmony_ci public void actionPerformed(ActionEvent ev) { 3132e5b6d6dSopenharmony_ci BundleItemCreationDialog dialog = 3142e5b6d6dSopenharmony_ci (BundleItemCreationDialog)((JButton)ev.getSource()).getParent().getParent().getParent().getParent().getParent().getParent(); 3152e5b6d6dSopenharmony_ci boolean success = false; 3162e5b6d6dSopenharmony_ci if (dialog.item == null) success = dialog.createItem(); 3172e5b6d6dSopenharmony_ci else success = dialog.editItem(); 3182e5b6d6dSopenharmony_ci if (!success) { 3192e5b6d6dSopenharmony_ci String alert = (item == null ? Resources.getTranslation("error_create_item") : 3202e5b6d6dSopenharmony_ci Resources.getTranslation("error_modify_item")); 3212e5b6d6dSopenharmony_ci alert += " " + Resources.getTranslation("error_try_again_item"); 3222e5b6d6dSopenharmony_ci JOptionPane.showMessageDialog(dialog, alert, Resources.getTranslation("error"), 3232e5b6d6dSopenharmony_ci JOptionPane.ERROR_MESSAGE); 3242e5b6d6dSopenharmony_ci } else { 3252e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).updateDisplayPanels(); 3262e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).invalidate(); 3272e5b6d6dSopenharmony_ci //((RBManagerGUI)dialog.getParent()).validateMyTree(); 3282e5b6d6dSopenharmony_ci dialog.setVisible(false); 3292e5b6d6dSopenharmony_ci dialog.dispose(); 3302e5b6d6dSopenharmony_ci } 3312e5b6d6dSopenharmony_ci } 3322e5b6d6dSopenharmony_ci }); 3332e5b6d6dSopenharmony_ci 3342e5b6d6dSopenharmony_ci createMoreButton.addActionListener(new ActionListener() { 3352e5b6d6dSopenharmony_ci public void actionPerformed(ActionEvent ev) { 3362e5b6d6dSopenharmony_ci BundleItemCreationDialog dialog = 3372e5b6d6dSopenharmony_ci (BundleItemCreationDialog)((JButton)ev.getSource()).getParent().getParent().getParent().getParent().getParent().getParent(); 3382e5b6d6dSopenharmony_ci boolean success = false; 3392e5b6d6dSopenharmony_ci if (dialog.item == null) success = createItem(); 3402e5b6d6dSopenharmony_ci else success = dialog.editItem(); 3412e5b6d6dSopenharmony_ci if (!success) { 3422e5b6d6dSopenharmony_ci String alert = (item == null ? Resources.getTranslation("error_create_item") : 3432e5b6d6dSopenharmony_ci Resources.getTranslation("error_modify_item")); 3442e5b6d6dSopenharmony_ci alert += " " + Resources.getTranslation("error_try_again_item"); 3452e5b6d6dSopenharmony_ci JOptionPane.showMessageDialog(dialog, alert, Resources.getTranslation("error"), 3462e5b6d6dSopenharmony_ci JOptionPane.ERROR_MESSAGE); 3472e5b6d6dSopenharmony_ci } else { 3482e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).updateDisplayPanels(); 3492e5b6d6dSopenharmony_ci ((RBManagerGUI)dialog.getParent()).invalidate(); 3502e5b6d6dSopenharmony_ci //((RBManagerGUI)dialog.getParent()).validateMyTree(); 3512e5b6d6dSopenharmony_ci dialog.clearComponents(); 3522e5b6d6dSopenharmony_ci } 3532e5b6d6dSopenharmony_ci } 3542e5b6d6dSopenharmony_ci }); 3552e5b6d6dSopenharmony_ci 3562e5b6d6dSopenharmony_ci transField.addFocusListener(new FocusListener() { 3572e5b6d6dSopenharmony_ci public void focusGained(FocusEvent ev) {} 3582e5b6d6dSopenharmony_ci public void focusLost(FocusEvent ev) { 3592e5b6d6dSopenharmony_ci BundleItemCreationDialog dialog = 3602e5b6d6dSopenharmony_ci (BundleItemCreationDialog)((JTextField)ev.getSource()).getParent().getParent().getParent().getParent().getParent().getParent(); 3612e5b6d6dSopenharmony_ci firstInit = false; 3622e5b6d6dSopenharmony_ci dialog.initComponents(); 3632e5b6d6dSopenharmony_ci } 3642e5b6d6dSopenharmony_ci }); 3652e5b6d6dSopenharmony_ci } 3662e5b6d6dSopenharmony_ci 3672e5b6d6dSopenharmony_ci // Complete the initialization of the frame 3682e5b6d6dSopenharmony_ci if (firstInit) 3692e5b6d6dSopenharmony_ci setLocation(new java.awt.Point(50, 50)); 3702e5b6d6dSopenharmony_ci mainBox.removeAll(); 3712e5b6d6dSopenharmony_ci //mainBox.add(instructionsLabel); 3722e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3732e5b6d6dSopenharmony_ci mainBox.add(box1); 3742e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3752e5b6d6dSopenharmony_ci mainBox.add(box2); 3762e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3772e5b6d6dSopenharmony_ci mainBox.add(box3); 3782e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3792e5b6d6dSopenharmony_ci mainBox.add(box4); 3802e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3812e5b6d6dSopenharmony_ci if (noLookupLabel == null) { 3822e5b6d6dSopenharmony_ci mainBox.add(box5); 3832e5b6d6dSopenharmony_ci mainBox.add(Box.createVerticalStrut(5)); 3842e5b6d6dSopenharmony_ci } 3852e5b6d6dSopenharmony_ci mainBox.add(box6); 3862e5b6d6dSopenharmony_ci getContentPane().add(mainBox, BorderLayout.CENTER); 3872e5b6d6dSopenharmony_ci validateTree(); 3882e5b6d6dSopenharmony_ci pack(); 3892e5b6d6dSopenharmony_ci setVisible(true); 3902e5b6d6dSopenharmony_ci //setResizable(false); 3912e5b6d6dSopenharmony_ci firstInit = false; 3922e5b6d6dSopenharmony_ci } 3932e5b6d6dSopenharmony_ci 3942e5b6d6dSopenharmony_ci void closeWindow() { 3952e5b6d6dSopenharmony_ci setVisible(false); 3962e5b6d6dSopenharmony_ci dispose(); 3972e5b6d6dSopenharmony_ci } 3982e5b6d6dSopenharmony_ci} 3992e5b6d6dSopenharmony_ci 400