private InstanceListPane initInstanceListPane(List instances, String title) { InstanceListPane instanceList = new InstanceListPane(); instanceList.getInstanceList().addListSelectionListener(selectionListener); instanceList.setIsViewable(false); if (mouseAdaptor == null) { // To view instances mouseAdaptor = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) doPopup(e); } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) doPopup(e); } // Use mouseClicked method. See InstanceListPane.init(). public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { JList list = (JList) e.getSource(); if (list.getSelectedValues().length != 1) return; InstanceListPane instanceList = figureOutInstanceListPane(list); if (instanceList == changedList || instanceList == localHasMoreIEList) { showComparison(); } else { GKInstance instance = (GKInstance) list.getSelectedValue(); JDialog parentDialog = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, centerPane); FrameManager.getManager().showInstance(instance, parentDialog); } } } }; } instanceList.getInstanceList().addMouseListener(mouseAdaptor); InstanceUtilities.sortInstances(instances); instanceList.setDisplayedInstances(instances); // instanceList.setTitle(title); instanceList.setListCellRenderer(cellRenderer); instanceList.hideTitle(); SectionTitlePane titlePane = new SectionTitlePane(title); titlePane.setSectionPane(instanceList); centerPane.add(titlePane); centerPane.add(instanceList); listToTitle.put(instanceList, titlePane); return instanceList; }
/** * A helper method to update GUIs related the passed InstanceListPane: delete, or update the * assoicated title. * * @param instanceList */ private void updateInstanceList(InstanceListPane instanceList) { if (instanceList == null) return; // Just in case if (instanceList.getDisplayedInstances().size() == 0) { removeInstanceList(instanceList); // Have to null the original reference if (instanceList == changedList) changedList = null; else if (instanceList == newList) newList = null; else if (instanceList == deleteInDBList) deleteInDBList = null; else if (instanceList == localHasMoreIEList) localHasMoreIEList = null; else if (instanceList == deleteList) deleteList = null; } else { // Update label SectionTitlePane titlePane = (SectionTitlePane) listToTitle.get(instanceList); String title = titlePane.getTitle(); int index = title.lastIndexOf(":"); title = title.substring(0, index) + ": " + instanceList.getDisplayedInstances().size(); titlePane.setTitle(title); } }