public void testPlaysEvent() throws Exception { Mock mockComponentFinder = mock(ComponentFinder.class); JInternalFrame internalFrame = createInternalFrame(); mockComponentFinder .expects(once()) .method("findInternalFrame") .will(returnValue(internalFrame)); internalFrame.setSelected(false); new CloseInternalFrameEvent("title") .play(null, (ComponentFinder) mockComponentFinder.proxy(), null, null); assertTrue(internalFrame.isClosed()); }
@RunsInEDT private static boolean isClosed(final JInternalFrame internalFrame) { return execute(() -> internalFrame.isClosed()); }
/** Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { String actionCmd = e.getActionCommand(); if (actionCmd.equals("cancel")) { closeForm(); } if (actionCmd.equals("new_branch")) { int index = Configurator.getIntProperty("newBranch", 0, "gui-forms"); DefaultForm form = Gui.getForm(index); if (form != null && !form.isClosed()) { form.pack(); try { form.setSelected(true); } catch (java.beans.PropertyVetoException ev) { } } else { BranchForm branchForm = new BranchForm(index, null); } } if (actionCmd.equals("checkout")) { boolean selected = false; for (int i = 0; i < myBranches.length; i++) { TableModel model = branchTable.getModel(); Boolean checked = (Boolean) model.getValueAt(i, 0); if (Boolean.TRUE.equals(checked)) selected = true; } int selectedRow = branchTable.getSelectedRow(); if (selected || (!selected && selectedRow >= 0)) checkoutItems(selected, selectedRow); else { showNoSectionMessage(); } } if (actionCmd.equals("edit")) { Point formLocation = null; int selectedRow = branchTable.getSelectedRow(); if (selectedRow >= 0) { Branch branchToEdit = (Branch) myBranches[selectedRow]; int editBranchIndex = Configurator.getIntProperty("editBranch", 0, "gui-forms"); JInternalFrame form = Gui.getForm(editBranchIndex); if (form != null && !form.isClosed()) { int switch_frame = getEditOpenedDialog(); if (switch_frame == JOptionPane.YES_OPTION) { formLocation = form.getLocation(); form.dispose(); BranchForm editBranch = new BranchForm(editBranchIndex, branchToEdit, selectedRow, formLocation); } else { try { form.setSelected(true); } catch (java.beans.PropertyVetoException ev) { } } } else { BranchForm editBranch = new BranchForm(editBranchIndex, branchToEdit, selectedRow, formLocation); } } // if(selectedRow>=0) else { showNoEditSelectionMessage(); } } if (actionCmd.equals("delete")) { boolean selected = false; for (int i = 0; i < myBranches.length; i++) { TableModel model = branchTable.getModel(); Boolean checked = (Boolean) model.getValueAt(i, 0); if (Boolean.TRUE.equals(checked)) selected = true; } int selectedRow = branchTable.getSelectedRow(); if (selected || (!selected && selectedRow >= 0)) deleteItems(selected, selectedRow); else { showNoDeleteSelectionMessage(); } } if (actionCmd.equals("branch_content")) { boolean selected = false; for (int i = 0; i < myBranches.length; i++) { TableModel model = branchTable.getModel(); Boolean checked = (Boolean) model.getValueAt(i, 0); if (Boolean.TRUE.equals(checked)) selected = true; } int selectedRow = branchTable.getSelectedRow(); if (selected || (!selected && selectedRow >= 0)) listItems(selected, selectedRow); else { showNoListcontentSection(); } } if (actionCmd.equals("select_all")) { selectAll(); } if (actionCmd.equals("select_all_pop")) { selectAllPop(); } }
@RunsInCurrentThread private static Pair<Boolean, Point> closeInfo(JInternalFrame internalFrame) { if (internalFrame.isClosed()) return new Pair<Boolean, Point>(true, null); return new Pair<Boolean, Point>(false, closeLocationOf(internalFrame)); }