Example usage for javax.swing JButton getHeight

List of usage examples for javax.swing JButton getHeight

Introduction

In this page you can find the example usage for javax.swing JButton getHeight.

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:de.tntinteractive.portalsammler.gui.MainDialog.java

private JButton createConfigButton() {
    final JButton button = new JButton("Konfiguration...");
    button.addActionListener(new ActionListener() {
        @Override//  w ww.j  av  a 2s  .  c  o m
        public void actionPerformed(final ActionEvent e) {
            final JPopupMenu menu = MainDialog.this.createConfigMenu();
            final JButton source = (JButton) e.getSource();
            menu.show(source, 0, source.getHeight());
        }
    });
    return button;
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JToolBar createDefinitionToolbar() {
    final JButton openButton = new JButton(Theme.ICON_OPEN);
    openButton.setToolTipText(Messages.getString("Toolbar.open")); //$NON-NLS-1$
    openButton.addActionListener(new ActionListener() {
        @Override//from w  ww. j a v  a  2s  .  co  m
        public void actionPerformed(final ActionEvent event) {
            openFile();
        }
    });
    definitionToolbar.add(openButton);

    final JPopupMenu importMenu = new JPopupMenu(Messages.getString("Toolbar.import")); //$NON-NLS-1$
    final JMenuItem importBonitaItem = new JMenuItem("Bonita");
    importBonitaItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent event) {
            importBonita();
        }
    });
    importMenu.add(importBonitaItem);
    final JButton importButton = new JButton(Theme.ICON_IMPORT);
    importButton.setToolTipText(Messages.getString("Toolbar.import")); //$NON-NLS-1$
    importButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent event) {
            importMenu.show(importButton, 0, importButton.getHeight());
        }
    });
    definitionToolbar.add(importButton);

    return definitionToolbar;
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

public MirthTable(String prefix, Set<String> defaultVisibleColumns) {
    super();//  w w w .jav  a2  s  .  c  om

    this.prefix = prefix;
    this.defaultVisibleColumns = defaultVisibleColumns;

    userPreferences = Preferences.userNodeForPackage(Mirth.class);
    columnOrderMap = new HashMap<String, Integer>();
    if (StringUtils.isNotEmpty(prefix)) {
        try {
            userPreferences = Preferences.userNodeForPackage(Mirth.class);
            String columns = userPreferences.get(prefix + "ColumnOrderMap", "");

            if (StringUtils.isNotEmpty(columns)) {
                columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns,
                        Map.class);
            }
        } catch (Exception e) {
        }

        sortKeys = new ArrayList<SortKey>();
        try {
            String sortOrder = userPreferences.get(prefix + "SortOrder", "");

            if (StringUtils.isNotEmpty(sortOrder)) {
                sortKeys = ObjectXMLSerializer.getInstance().deserialize(sortOrder, List.class);
            }
        } catch (Exception e) {
        }
    }

    setDragEnabled(true);
    addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            boolean isAccelerated = (((e.getModifiers()
                    & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0)
                    || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0));
            if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) {
                PlatformUI.MIRTH_FRAME.doContextSensitiveSave();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    /*
     * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping
     * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can
     * override it.
     */
    putClientProperty("terminateEditOnFocusLost", Boolean.FALSE);

    getTableHeader().addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            saveColumnOrder();
        }
    });

    final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon());

    columnControlButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu columnMenu = getColumnMenu();
            Dimension buttonSize = columnControlButton.getSize();
            int xPos = columnControlButton.getComponentOrientation().isLeftToRight()
                    ? buttonSize.width - columnMenu.getPreferredSize().width
                    : 0;
            columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight());
        }
    });

    setColumnControl(columnControlButton);
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public MirthTreeTable(String prefix, Set<String> defaultVisibleColumns) {
    customHiddenColumnMap = new HashMap<String, Set<String>>();

    this.prefix = prefix;
    this.defaultVisibleColumns = defaultVisibleColumns;

    columnOrderMap = new HashMap<String, Integer>();
    sortOrderColumn = -1;/*from w w  w  .j  a va 2s. c  om*/
    sortOrder = null;

    if (StringUtils.isNotEmpty(prefix)) {
        try {
            userPreferences = Preferences.userNodeForPackage(Mirth.class);
            String columns = userPreferences.get(prefix + "ColumnOrderMap", "");

            if (StringUtils.isNotEmpty(columns)) {
                columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns,
                        Map.class);
            }
        } catch (Exception e) {
        }

        try {
            String order = userPreferences.get(prefix + "SortOrder", "");

            if (StringUtils.isNotEmpty(order)) {
                sortOrder = ObjectXMLSerializer.getInstance().deserialize(order, SortOrder.class);
                sortOrderColumn = userPreferences.getInt(prefix + "SortOrderColumn", -1);
            }
        } catch (Exception e) {
        }
    }

    addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            boolean isAccelerated = (((e.getModifiers()
                    & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0)
                    || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0));
            if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) {
                PlatformUI.MIRTH_FRAME.doContextSensitiveSave();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    /*
     * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping
     * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can
     * override it.
     */
    putClientProperty("terminateEditOnFocusLost", Boolean.FALSE);

    JTableHeader header = getTableHeader();
    header.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            saveColumnOrder();
        }
    });
    header.setDefaultRenderer(new SortableHeaderCellRenderer(header.getDefaultRenderer()));

    final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon());

    columnControlButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu columnMenu = getColumnMenu();
            Dimension buttonSize = columnControlButton.getSize();
            int xPos = columnControlButton.getComponentOrientation().isLeftToRight()
                    ? buttonSize.width - columnMenu.getPreferredSize().width
                    : 0;
            columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight());
        }

    });

    setColumnControl(columnControlButton);
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

/**
 * The first element for each group defines which field to use for the quicksearch. The next two define the name and
 * regexp for the group./*from w w w  . ja v a 2 s  .  com*/
 */
public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
    super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups"));

    this.frame = frame;
    hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"),
            !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"),
            Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    ButtonGroup nonHits = new ButtonGroup();
    nonHits.add(hideNonHits);
    nonHits.add(grayOut);
    floatCb.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()));
    andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS,
            andCb.isSelected()));
    invCb.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()));
    showOverlappingGroups.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING,
                    showOverlappingGroups.isSelected());
            if (!showOverlappingGroups.isSelected()) {
                groupsTree.setOverlappingGroups(Collections.emptyList());
            }
        }
    });

    grayOut.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));

    JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) {

        floatCb.setSelected(true);
        highlCb.setSelected(false);
    } else {
        highlCb.setSelected(true);
        floatCb.setSelected(false);
    }
    JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) {
        andCb.setSelected(true);
        orCb.setSelected(false);
    } else {
        orCb.setSelected(true);
        andCb.setSelected(false);
    }

    showNumberOfElements.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS,
                    showNumberOfElements.isSelected());
            if (groupsTree != null) {
                groupsTree.invalidate();
                groupsTree.repaint();
            }
        }
    });

    autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP,
            autoAssignGroup.isSelected()));

    invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS));
    showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING));
    editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE);
    editModeCb.setSelected(editModeIndicator);
    showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
    autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));

    JButton openSettings = new JButton(IconTheme.JabRefIcon.PREFERENCES.getSmallIcon());
    settings.add(andCb);
    settings.add(orCb);
    settings.addSeparator();
    settings.add(invCb);
    settings.addSeparator();
    settings.add(editModeCb);
    settings.addSeparator();
    settings.add(grayOut);
    settings.add(hideNonHits);
    settings.addSeparator();
    settings.add(showOverlappingGroups);
    settings.addSeparator();
    settings.add(showNumberOfElements);
    settings.add(autoAssignGroup);
    openSettings.addActionListener(e -> {
        if (!settings.isVisible()) {
            JButton src = (JButton) e.getSource();
            showNumberOfElements
                    .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
            autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));
            settings.show(src, 0, openSettings.getHeight());
        }
    });

    editModeCb.addActionListener(e -> setEditMode(editModeCb.getState()));

    JButton newButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getSmallIcon());
    int butSize = newButton.getIcon().getIconHeight() + 5;
    Dimension butDim = new Dimension(butSize, butSize);

    newButton.setPreferredSize(butDim);
    newButton.setMinimumSize(butDim);
    JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFile.GROUP).getHelpButton();
    helpButton.setPreferredSize(butDim);
    helpButton.setMinimumSize(butDim);
    JButton autoGroup = new JButton(IconTheme.JabRefIcon.AUTO_GROUP.getSmallIcon());
    autoGroup.setPreferredSize(butDim);
    autoGroup.setMinimumSize(butDim);
    openSettings.setPreferredSize(butDim);
    openSettings.setMinimumSize(butDim);
    Insets butIns = new Insets(0, 0, 0, 0);
    helpButton.setMargin(butIns);
    openSettings.setMargin(butIns);
    newButton.addActionListener(e -> {
        GroupDialog gd = new GroupDialog(frame, panel, null);
        gd.setVisible(true);
        if (gd.okPressed()) {
            AbstractGroup newGroup = gd.getResultingGroup();
            groupsRoot.addNewGroup(newGroup, panel.getUndoManager());
            panel.markBaseChanged();
            frame.output(Localization.lang("Created group \"%0\".", newGroup.getName()));
        }
    });
    andCb.addActionListener(e -> valueChanged(null));
    orCb.addActionListener(e -> valueChanged(null));
    invCb.addActionListener(e -> valueChanged(null));
    showOverlappingGroups.addActionListener(e -> valueChanged(null));
    autoGroup.addActionListener(e -> {
        AutoGroupDialog gd = new AutoGroupDialog(frame, panel, groupsRoot,
                Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,",
                Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
        gd.setVisible(true);
        // gd does the operation itself
    });
    floatCb.addActionListener(e -> valueChanged(null));
    highlCb.addActionListener(e -> valueChanged(null));
    hideNonHits.addActionListener(e -> valueChanged(null));
    grayOut.addActionListener(e -> valueChanged(null));
    newButton.setToolTipText(Localization.lang("New group"));
    andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups."));
    orCb.setToolTipText(
            Localization.lang("Display all entries belonging to one or more of the selected groups."));
    autoGroup.setToolTipText(Localization.lang("Automatically create groups for database."));
    openSettings.setToolTipText(Localization.lang("Settings"));
    invCb.setToolTipText(
            "<html>" + Localization.lang("Show entries <b>not</b> in group selection") + "</html>");
    showOverlappingGroups.setToolTipText(Localization
            .lang("Highlight groups that contain entries contained in any currently selected group"));
    floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top"));
    highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection"));
    editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries"));
    ButtonGroup bgr = new ButtonGroup();
    bgr.add(andCb);
    bgr.add(orCb);
    ButtonGroup visMode = new ButtonGroup();
    visMode.add(floatCb);
    visMode.add(highlCb);

    JPanel rootPanel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    rootPanel.setLayout(gbl);

    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.gridwidth = 1;
    con.gridy = 0;

    con.gridx = 0;
    gbl.setConstraints(newButton, con);
    rootPanel.add(newButton);

    con.gridx = 1;
    gbl.setConstraints(autoGroup, con);
    rootPanel.add(autoGroup);

    con.gridx = 2;
    gbl.setConstraints(openSettings, con);
    rootPanel.add(openSettings);

    con.gridx = 3;
    con.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(helpButton, con);
    rootPanel.add(helpButton);

    groupsTree = new GroupsTree(this);
    groupsTree.addTreeSelectionListener(this);

    JScrollPane groupsTreePane = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.weighty = 1;
    con.gridx = 0;
    con.gridwidth = 4;
    con.gridy = 1;
    gbl.setConstraints(groupsTreePane, con);
    rootPanel.add(groupsTreePane);

    add(rootPanel, BorderLayout.CENTER);
    setEditMode(editModeIndicator);
    definePopup();
    NodeAction moveNodeUpAction = new MoveNodeUpAction();
    moveNodeUpAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK));
    NodeAction moveNodeDownAction = new MoveNodeDownAction();
    moveNodeDownAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK));
    NodeAction moveNodeLeftAction = new MoveNodeLeftAction();
    moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK));
    NodeAction moveNodeRightAction = new MoveNodeRightAction();
    moveNodeRightAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK));

    setGroups(GroupTreeNode.fromGroup(new AllEntriesGroup()));
}

From source file:ca.phon.ipamap.IpaMap.java

private void init() {
    setLayout(new BorderLayout());

    // favorites//from w w w .j  ava  2s.  co  m
    IpaGrids favData = getFavData();
    final Grid fg = favData.getGrid().get(0);
    favPanel = getGridPanel(fg);
    favPanel.setCollapsed(getSavedSectionToggle(fg.getName()));
    favToggleButton = getToggleButton(fg, favPanel);
    favToggleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSavedSectionToggle(fg.getName(), !getSavedSectionToggle(fg.getName()));
        }
    });

    JPanel favSection = new JPanel(new VerticalLayout(0));
    favSection.add(favToggleButton);
    favSection.add(favPanel);
    favContainer = favSection;

    // search
    Grid emptyGrid = (new ObjectFactory()).createGrid();
    emptyGrid.setName("Search Results (0)");
    emptyGrid.setRows(0);
    emptyGrid.setCols(0);

    searchPanel = getGridPanel(emptyGrid);
    searchToggleButton = getToggleButton(emptyGrid, searchPanel);

    final JButton searchButton = new JButton("Search");
    searchButton.putClientProperty("JComponent.sizeVariant", "small");

    searchButton.addActionListener(this::showSearchFrame);

    JPanel searchSection = new JPanel(new VerticalLayout(0));
    searchSection.add(searchButton);
    searchSection.add(searchToggleButton);
    searchContainer = searchSection;

    // static content
    final JPanel centerPanel = new JPanel(new VerticalLayout(0));
    IpaGrids grids = getGridData();
    for (final Grid grid : grids.getGrid()) {
        final JXCollapsiblePane cp = getGridPanel(grid);

        cp.setCollapsed(getSavedSectionToggle(grid.getName()));
        JXButton toggleBtn = getToggleButton(grid, cp);
        toggleBtn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setSavedSectionToggle(grid.getName(), !getSavedSectionToggle(grid.getName()));
            }
        });

        toggleButtons.add(toggleBtn);

        centerPanel.add(toggleBtn);
        centerPanel.add(cp);

        gridPanels.add(cp);
    }

    scrollPane = new JScrollPane(centerPanel);
    scrollPane.setAutoscrolls(true);
    scrollPane.setWheelScrollingEnabled(true);
    //      scrollPane.setViewportView(centerPanel);
    add(scrollPane, BorderLayout.CENTER);

    //      JPanel btmPanel = new JPanel(new BorderLayout());
    //      scalePanel.add(smallLbl, BorderLayout.WEST);
    //      scalePanel.add(scaleSlider, BorderLayout.CENTER);
    //      scalePanel.add(largeLbl, BorderLayout.EAST);

    final JButton scrollBtn = new JButton("-");
    scrollBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            //            popupMenu.show(scrollBtn, 0, scrollBtn.getHeight());
            JPopupMenu ctxMenu = new JPopupMenu();
            setupContextMenu(ctxMenu, scrollBtn);
            ctxMenu.show(scrollBtn, 0, scrollBtn.getHeight());
        }
    });

    //      Font infoFont = new Font("Courier New", Font.PLAIN, 12);
    infoLabel = new JLabel();
    infoLabel.setFont(infoLabel.getFont().deriveFont(Font.ITALIC));
    infoLabel.setText("[]");
    infoLabel.setOpaque(false);

    statusBar = new JXStatusBar();
    statusBar.setLayout(new BorderLayout());
    statusBar.add(infoLabel, BorderLayout.CENTER);

    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, scrollBtn);

    add(statusBar, BorderLayout.SOUTH);

    JPanel topPanel = new JPanel(new VerticalLayout(0));
    topPanel.add(searchSection);
    topPanel.add(favSection);
    add(topPanel, BorderLayout.NORTH);

}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Initialises the application's GUI elements.
 *///from  ww w.ja va2  s .  c o m
private void initGui() {
    initMenus();

    JPanel appContent = new JPanel(new GridBagLayout());
    this.getContentPane().add(appContent);

    // Buckets panel.
    JPanel bucketsPanel = new JPanel(new GridBagLayout());

    JButton bucketActionButton = new JButton();
    bucketActionButton.setToolTipText("Bucket actions menu");
    guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png");
    bucketActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this), new GridBagConstraints(0, 0, 1, 1, 1,
            0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    bucketsPanel.add(bucketActionButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    bucketTableModel = new BucketTableModel(false);
    bucketTableModelSorter = new TableSorter(bucketTableModel);
    bucketsTable = new JTable(bucketTableModelSorter);
    bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());
    bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bucketsTable.getSelectionModel().addListSelectionListener(this);
    bucketsTable.setShowHorizontalLines(true);
    bucketsTable.setShowVerticalLines(false);
    bucketsTable.addMouseListener(new ContextMenuListener());
    bucketsPanel.add(new JScrollPane(bucketsTable), new GridBagConstraints(0, 1, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
    bucketsPanel.add(new JLabel(" "), new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Filter panel.
    filterObjectsPanel = new JPanel(new GridBagLayout());
    filterObjectsPrefix = new JTextField();
    filterObjectsPrefix.setToolTipText("Only show objects with this prefix");
    filterObjectsPrefix.addActionListener(this);
    filterObjectsPrefix.setActionCommand("RefreshObjects");
    filterObjectsDelimiter = new JComboBox(new String[] { "", "/", "?", "\\" });
    filterObjectsDelimiter.setEditable(true);
    filterObjectsDelimiter.setToolTipText("Object name delimiter");
    filterObjectsDelimiter.addActionListener(this);
    filterObjectsDelimiter.setActionCommand("RefreshObjects");
    filterObjectsPanel.add(new JHtmlLabel("Prefix:", this), new GridBagConstraints(0, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this), new GridBagConstraints(2, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
    filterObjectsPanel.add(filterObjectsDelimiter, new GridBagConstraints(3, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.setVisible(false);

    // Objects panel.
    JPanel objectsPanel = new JPanel(new GridBagLayout());
    int row = 0;
    filterObjectsCheckBox = new JCheckBox("Filter objects");
    filterObjectsCheckBox.addActionListener(this);
    filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed");
    objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this), new GridBagConstraints(0, row, 1, 1,
            1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    JButton objectActionButton = new JButton();
    objectActionButton.setToolTipText("Object actions menu");
    guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
    objectActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsTable = new JTable();
    objectTableModel = new ObjectTableModel();
    objectTableModelSorter = new TableSorter(objectTableModel);
    objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
    objectsTable.setModel(objectTableModelSorter);
    objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 301092191828910402L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue());
            return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
        }
    });
    objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 7285511556343895652L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Date date = (Date) value;
            return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus,
                    row, column);
        }
    });
    objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    objectsTable.getSelectionModel().addListSelectionListener(this);
    objectsTable.setShowHorizontalLines(true);
    objectsTable.setShowVerticalLines(true);
    objectsTable.addMouseListener(new ContextMenuListener());
    objectsTableSP = new JScrollPane(objectsTable);
    objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));
    objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this);
    objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
    objectsSummaryLabel.setFocusable(false);
    objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    // Combine sections.
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bucketsPanel, objectsPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setContinuousLayout(true);

    appContent.add(splitPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Set preferred sizes
    int preferredWidth = 800;
    int preferredHeight = 600;
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    splitPane.setResizeWeight(0.30);

    // Initialize drop target.
    initDropTarget(new JComponent[] { objectsTableSP, objectsTable });
    objectsTable.getDropTarget().setActive(false);
    objectsTableSP.getDropTarget().setActive(false);
}

From source file:op.care.dfn.PnlDFN.java

private CollapsiblePane createCP4(final DFN dfn) {
    final CollapsiblePane dfnPane = new CollapsiblePane();

    ActionListener applyActionListener = new ActionListener() {
        @Override/*from ww w  .j  av  a  2s  .com*/
        public void actionPerformed(ActionEvent actionEvent) {
            if (dfn.getState() == DFNTools.STATE_DONE) {
                return;
            }
            if (!dfn.isOnDemand() && dfn.getNursingProcess().isClosed()) {
                return;
            }

            if (DFNTools.isChangeable(dfn)) {
                EntityManager em = OPDE.createEM();
                try {
                    em.getTransaction().begin();

                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                    DFN myDFN = em.merge(dfn);
                    em.lock(myDFN, LockModeType.OPTIMISTIC);
                    if (!myDFN.isOnDemand()) {
                        em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                    }

                    myDFN.setState(DFNTools.STATE_DONE);
                    myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                    myDFN.setIst(new Date());
                    myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                    myDFN.setMdate(new Date());

                    em.getTransaction().commit();

                    CollapsiblePane cp1 = createCP4(myDFN);

                    synchronized (mapDFN2Pane) {
                        mapDFN2Pane.put(myDFN, cp1);
                    }
                    synchronized (mapShift2DFN) {
                        int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                        mapShift2DFN.get(myDFN.getShift()).remove(position);
                        mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                    }

                    CollapsiblePane cp2 = createCP4(myDFN.getShift());
                    synchronized (mapShift2Pane) {
                        mapShift2Pane.put(myDFN.getShift(), cp2);
                    }

                    buildPanel(false);

                } catch (OptimisticLockException ole) {
                    OPDE.warn(ole);
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                        OPDE.getMainframe().emptyFrame();
                        OPDE.getMainframe().afterLogin();
                    }
                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                } catch (Exception e) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    OPDE.fatal(e);
                } finally {
                    em.close();
                }

            } else {
                OPDE.getDisplayManager()
                        .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
            }
        }
    };

    String title = "<html><font size=+1>" +
    //                (dfn.isFloating() ? (dfn.isActive() ? "(!) " : "(OK) ") : "") +
            SYSTools.left(dfn.getIntervention().getBezeichnung(), MAX_TEXT_LENGTH)
            + DFNTools.getScheduleText(dfn, " [", "]") + ", " + dfn.getMinutes() + " "
            + SYSTools.xx("misc.msg.Minute(s)")
            + (dfn.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(dfn.getUser().getUID()) + "</i>" : "")
            + "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title,
            OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener
                    : null);
    dfnPane.setCollapseOnTitleClick(false);
    //        cptitle.getTitleButton().setIcon(DFNTools.getIcon(dfn));
    JLabel icon1 = new JLabel(DFNTools.getIcon(dfn));
    icon1.setOpaque(false);
    JLabel icon2 = new JLabel(DFNTools.getFloatingIcon(dfn));
    icon2.setOpaque(false);
    cptitle.getAdditionalIconPanel().add(icon1);
    cptitle.getAdditionalIconPanel().add(icon2);

    if (dfn.isFloating()) {
        cptitle.getButton().setToolTipText(SYSTools.xx("nursingrecords.dfn.enforced.tooltip") + ": "
                + DateFormat.getDateInstance().format(dfn.getStDatum()));
    }

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)
            && (dfn.isOnDemand() || !dfn.getNursingProcess().isClosed())) {
        /***
         *      _     _            _                _
         *     | |__ | |_ _ __    / \   _ __  _ __ | |_   _
         *     | '_ \| __| '_ \  / _ \ | '_ \| '_ \| | | | |
         *     | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| |
         *     |_.__/ \__|_| |_/_/   \_\ .__/| .__/|_|\__, |
         *                             |_|   |_|      |___/
         */
        JButton btnApply = new JButton(SYSConst.icon22apply);
        btnApply.setPressedIcon(SYSConst.icon22applyPressed);
        btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnApply.setContentAreaFilled(false);
        btnApply.setBorder(null);
        btnApply.addActionListener(applyActionListener);
        btnApply.setEnabled(!dfn.isOnDemand() && dfn.isOpen());
        cptitle.getRight().add(btnApply);
        //            JPanel spacer = new JPanel();
        //            spacer.setOpaque(false);
        //            cptitle.getRight().add(spacer);
        /***
         *      _     _          ____                     _
         *     | |__ | |_ _ __  / ___|__ _ _ __   ___ ___| |
         *     | '_ \| __| '_ \| |   / _` | '_ \ / __/ _ \ |
         *     | |_) | |_| | | | |__| (_| | | | | (_|  __/ |
         *     |_.__/ \__|_| |_|\____\__,_|_| |_|\___\___|_|
         *
         */
        final JButton btnCancel = new JButton(SYSConst.icon22cancel);
        btnCancel.setPressedIcon(SYSConst.icon22cancelPressed);
        btnCancel.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnCancel.setContentAreaFilled(false);
        btnCancel.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (dfn.getState() == DFNTools.STATE_REFUSED) {
                    return;
                }

                if (DFNTools.isChangeable(dfn)) {
                    EntityManager em = OPDE.createEM();
                    try {
                        em.getTransaction().begin();

                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                        DFN myDFN = em.merge(dfn);
                        em.lock(myDFN, LockModeType.OPTIMISTIC);
                        if (!myDFN.isOnDemand()) {
                            em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                        }

                        myDFN.setState(DFNTools.STATE_REFUSED);
                        myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                        myDFN.setIst(new Date());
                        myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                        myDFN.setMdate(new Date());

                        em.getTransaction().commit();

                        CollapsiblePane cp1 = createCP4(myDFN);
                        synchronized (mapDFN2Pane) {
                            mapDFN2Pane.put(myDFN, cp1);
                        }
                        synchronized (mapShift2DFN) {
                            int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                            mapShift2DFN.get(myDFN.getShift()).remove(position);
                            mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                        }
                        CollapsiblePane cp2 = createCP4(myDFN.getShift());
                        synchronized (mapShift2Pane) {
                            mapShift2Pane.put(myDFN.getShift(), cp2);
                        }
                        buildPanel(false);
                    } catch (OptimisticLockException ole) {
                        OPDE.warn(ole);
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                            OPDE.getMainframe().emptyFrame();
                            OPDE.getMainframe().afterLogin();
                        }
                        OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                    } catch (Exception e) {
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        OPDE.fatal(e);
                    } finally {
                        em.close();
                    }

                } else {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                }
            }
        });
        btnCancel.setEnabled(!dfn.isOnDemand() && dfn.isOpen());
        cptitle.getRight().add(btnCancel);

        /***
         *      _     _         _____                 _
         *     | |__ | |_ _ __ | ____|_ __ ___  _ __ | |_ _   _
         *     | '_ \| __| '_ \|  _| | '_ ` _ \| '_ \| __| | | |
         *     | |_) | |_| | | | |___| | | | | | |_) | |_| |_| |
         *     |_.__/ \__|_| |_|_____|_| |_| |_| .__/ \__|\__, |
         *                                     |_|        |___/
         */
        final JButton btnEmpty = new JButton(SYSConst.icon22empty);
        btnEmpty.setPressedIcon(SYSConst.icon22emptyPressed);
        btnEmpty.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnEmpty.setContentAreaFilled(false);
        btnEmpty.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnEmpty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (dfn.getState() == DFNTools.STATE_OPEN) {
                    return;
                }

                if (DFNTools.isChangeable(dfn)) {
                    EntityManager em = OPDE.createEM();
                    try {
                        em.getTransaction().begin();

                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                        DFN myDFN = em.merge(dfn);
                        em.lock(myDFN, LockModeType.OPTIMISTIC);
                        if (!myDFN.isOnDemand()) {
                            em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                        }

                        // on demand DFNs are deleted if they not wanted anymore
                        if (myDFN.isOnDemand()) {
                            em.remove(myDFN);
                            synchronized (mapDFN2Pane) {
                                mapDFN2Pane.remove(myDFN);
                            }
                            synchronized (mapShift2DFN) {
                                mapShift2DFN.get(myDFN.getShift()).remove(myDFN);
                            }
                        } else {
                            // the normal DFNs (those assigned to a NursingProcess) are reset to the OPEN state.
                            myDFN.setState(DFNTools.STATE_OPEN);
                            myDFN.setUser(null);
                            myDFN.setIst(null);
                            myDFN.setiZeit(null);
                            myDFN.setMdate(new Date());
                            CollapsiblePane cp1 = createCP4(myDFN);
                            synchronized (mapDFN2Pane) {
                                mapDFN2Pane.put(myDFN, cp1);
                            }
                            synchronized (mapShift2DFN) {
                                int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                                mapShift2DFN.get(myDFN.getShift()).remove(position);
                                mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                            }
                        }
                        em.getTransaction().commit();

                        CollapsiblePane cp2 = createCP4(myDFN.getShift());
                        synchronized (mapShift2Pane) {
                            mapShift2Pane.put(myDFN.getShift(), cp2);
                        }
                        buildPanel(false);
                    } catch (OptimisticLockException ole) {
                        OPDE.warn(ole);
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                            OPDE.getMainframe().emptyFrame();
                            OPDE.getMainframe().afterLogin();
                        }
                        OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                    } catch (Exception e) {
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        OPDE.fatal(e);
                    } finally {
                        em.close();
                    }

                } else {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                }
            }
        });
        btnEmpty.setEnabled(!dfn.isOpen());
        cptitle.getRight().add(btnEmpty);

        /***
         *      _     _         __  __ _             _
         *     | |__ | |_ _ __ |  \/  (_)_ __  _   _| |_ ___  ___
         *     | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __|
         *     | |_) | |_| | | | |  | | | | | | |_| | ||  __/\__ \
         *     |_.__/ \__|_| |_|_|  |_|_|_| |_|\__,_|\__\___||___/
         *
         */
        final JButton btnMinutes = new JButton(SYSConst.icon22clock);
        btnMinutes.setPressedIcon(SYSConst.icon22clockPressed);
        btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnMinutes.setContentAreaFilled(false);
        btnMinutes.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnMinutes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (!DFNTools.isChangeable(dfn)) {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                    return;
                }
                final JPopupMenu menu = SYSCalendar.getMinutesMenu(
                        new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() {
                            @Override
                            public void execute(Object o) {
                                EntityManager em = OPDE.createEM();
                                try {
                                    em.getTransaction().begin();

                                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                    DFN myDFN = em.merge(dfn);
                                    em.lock(myDFN, LockModeType.OPTIMISTIC);
                                    if (!myDFN.isOnDemand()) {
                                        em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                                    }

                                    myDFN.setMinutes(new BigDecimal((Integer) o));
                                    myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                                    myDFN.setMdate(new Date());
                                    em.getTransaction().commit();

                                    CollapsiblePane cp1 = createCP4(myDFN);
                                    synchronized (mapDFN2Pane) {
                                        mapDFN2Pane.put(myDFN, cp1);
                                    }
                                    synchronized (mapShift2DFN) {
                                        int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                                        mapShift2DFN.get(myDFN.getShift()).remove(position);
                                        mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                                    }
                                    CollapsiblePane cp2 = createCP4(myDFN.getShift());
                                    synchronized (mapShift2Pane) {
                                        mapShift2Pane.put(myDFN.getShift(), cp2);
                                    }

                                    buildPanel(false);
                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    }
                                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        });

                menu.show(btnMinutes, 0, btnMinutes.getHeight());
            }
        });
        btnMinutes.setEnabled(dfn.getState() != DFNTools.STATE_OPEN);
        cptitle.getRight().add(btnMinutes);
    }

    /***
     *      _     _         ___        __
     *     | |__ | |_ _ __ |_ _|_ __  / _| ___
     *     | '_ \| __| '_ \ | || '_ \| |_ / _ \
     *     | |_) | |_| | | || || | | |  _| (_) |
     *     |_.__/ \__|_| |_|___|_| |_|_|  \___/
     *
     */
    final JButton btnInfo = new JButton(SYSConst.icon22info);
    final JidePopup popupInfo = new JidePopup();
    btnInfo.setPressedIcon(SYSConst.icon22infoPressed);
    btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnInfo.setContentAreaFilled(false);
    btnInfo.setBorder(null);
    final JTextPane txt = new JTextPane();
    txt.setContentType("text/html");
    txt.setEditable(false);

    popupInfo.setMovable(false);
    popupInfo.getContentPane().setLayout(new BoxLayout(popupInfo.getContentPane(), BoxLayout.LINE_AXIS));
    popupInfo.getContentPane().add(new JScrollPane(txt));
    popupInfo.removeExcludedComponent(txt);
    popupInfo.setDefaultFocusComponent(txt);

    btnInfo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            popupInfo.setOwner(btnInfo);
            txt.setText(SYSTools.toHTML(SYSConst.html_div(dfn.getInterventionSchedule().getBemerkung())));
            GUITools.showPopup(popupInfo, SwingConstants.WEST);
        }
    });

    btnInfo.setEnabled(
            !dfn.isOnDemand() && !SYSTools.catchNull(dfn.getInterventionSchedule().getBemerkung()).isEmpty());
    cptitle.getRight().add(btnInfo);

    dfnPane.setTitleLabelComponent(cptitle.getMain());

    dfnPane.setBackground(dfn.getBG());
    dfnPane.setForeground(dfn.getFG());
    try {
        dfnPane.setCollapsed(true);
    } catch (PropertyVetoException e) {
        OPDE.error(e);
    }
    dfnPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JTextPane contentPane = new JTextPane();
            contentPane.setContentType("text/html");
            contentPane.setEditable(false);
            contentPane.setText(SYSTools
                    .toHTML(NursingProcessTools.getAsHTML(dfn.getNursingProcess(), false, true, false, false)));
            dfnPane.setContentPane(contentPane);
        }
    });
    dfnPane.setCollapsible(dfn.getNursingProcess() != null);
    dfnPane.setHorizontalAlignment(SwingConstants.LEADING);
    dfnPane.setOpaque(false);
    return dfnPane;
}

From source file:op.care.reports.PnlReport.java

private JPanel getMenu(final NReport nreport) {

    JPanel pnlMenu = new JPanel(new VerticalLayout());

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
        /***/*  ww w.j av a 2s  .  c  o  m*/
         *      _____    _ _ _
         *     | ____|__| (_) |_
         *     |  _| / _` | | __|
         *     | |__| (_| | | |_
         *     |_____\__,_|_|\__|
         *
         */
        final JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.reports.btnEdit.tooltip",
                SYSConst.icon22edit3, null);
        btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnEdit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgReport(nreport.clone(), new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o != null) {

                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                final NReport newReport = em.merge((NReport) o);
                                NReport oldReport = em.merge(nreport);
                                em.lock(oldReport, LockModeType.OPTIMISTIC);
                                newReport.setReplacementFor(oldReport);

                                for (SYSNR2FILE oldAssignment : oldReport.getAttachedFilesConnections()) {
                                    em.remove(oldAssignment);
                                }
                                oldReport.getAttachedFilesConnections().clear();
                                for (SYSNR2PROCESS oldAssignment : oldReport.getAttachedQProcessConnections()) {
                                    em.remove(oldAssignment);
                                }
                                oldReport.getAttachedQProcessConnections().clear();

                                oldReport.setEditedBy(em.merge(OPDE.getLogin().getUser()));
                                oldReport.setEditDate(new Date());
                                oldReport.setReplacedBy(newReport);

                                em.getTransaction().commit();

                                final String keyNewDay = DateFormat.getDateInstance()
                                        .format(newReport.getPit());
                                final String keyOldDay = DateFormat.getDateInstance()
                                        .format(oldReport.getPit());

                                synchronized (contentmap) {
                                    contentmap.remove(keyNewDay);
                                    contentmap.remove(keyOldDay);
                                }
                                synchronized (linemap) {
                                    linemap.remove(oldReport);
                                }

                                synchronized (valuecache) {
                                    valuecache.get(keyOldDay).remove(nreport);
                                    valuecache.get(keyOldDay).add(oldReport);
                                    Collections.sort(valuecache.get(keyOldDay));

                                    if (valuecache.containsKey(keyNewDay)) {
                                        valuecache.get(keyNewDay).add(newReport);
                                        Collections.sort(valuecache.get(keyNewDay));
                                    }
                                }

                                synchronized (listUsedCommontags) {
                                    boolean reloadSearch = false;
                                    for (Commontags ctag : newReport.getCommontags()) {
                                        if (!listUsedCommontags.contains(ctag)) {
                                            listUsedCommontags.add(ctag);
                                            reloadSearch = true;
                                        }
                                    }
                                    if (reloadSearch) {
                                        prepareSearchArea();
                                    }
                                }

                                if (minmax.isAfter(new DateTime(newReport.getPit()))) {
                                    minmax.setStart(new DateTime(newReport.getPit()));
                                }

                                if (minmax.isBefore(new DateTime(newReport.getPit()))) {
                                    minmax.setEnd(new DateTime(newReport.getPit()));
                                }

                                createCP4Day(new LocalDate(oldReport.getPit()));
                                createCP4Day(new LocalDate(newReport.getPit()));

                                buildPanel();
                                GUITools.scroll2show(jspReports, cpMap.get(keyNewDay), cpsReports,
                                        new Closure() {
                                            @Override
                                            public void execute(Object o) {
                                                GUITools.flashBackground(linemap.get(newReport), Color.YELLOW,
                                                        2);
                                            }
                                        });
                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                } else {
                                    reloadDisplay(true);
                                }
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }
                        }
                    }
                });
            }
        });
        btnEdit.setEnabled(NReportTools.isChangeable(nreport));
        pnlMenu.add(btnEdit);
        /***
         *      ____       _      _
         *     |  _ \  ___| | ___| |_ ___
         *     | | | |/ _ \ |/ _ \ __/ _ \
         *     | |_| |  __/ |  __/ ||  __/
         *     |____/ \___|_|\___|\__\___|
         *
         */
        final JButton btnDelete = GUITools.createHyperlinkButton("nursingrecords.reports.btnDelete.tooltip",
                SYSConst.icon22delete, null);
        btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgYesNo(
                        SYSTools.xx("misc.questions.delete1") + "<br/><i>"
                                + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format(
                                        nreport.getPit())
                                + "</i><br/>" + SYSTools.xx("misc.questions.delete2"),
                        SYSConst.icon48delete, new Closure() {
                            @Override
                            public void execute(Object answer) {
                                if (answer.equals(JOptionPane.YES_OPTION)) {
                                    EntityManager em = OPDE.createEM();
                                    try {
                                        em.getTransaction().begin();
                                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                        final NReport delReport = em.merge(nreport);
                                        em.lock(delReport, LockModeType.OPTIMISTIC);
                                        delReport.setDeletedBy(em.merge(OPDE.getLogin().getUser()));
                                        for (SYSNR2FILE oldAssignment : delReport
                                                .getAttachedFilesConnections()) {
                                            em.remove(oldAssignment);
                                        }
                                        delReport.getAttachedFilesConnections().clear();
                                        for (SYSNR2PROCESS oldAssignment : delReport
                                                .getAttachedQProcessConnections()) {
                                            em.remove(oldAssignment);
                                        }
                                        delReport.getAttachedQProcessConnections().clear();
                                        em.getTransaction().commit();

                                        final String keyDay = DateFormat.getDateInstance()
                                                .format(delReport.getPit());

                                        synchronized (contentmap) {
                                            contentmap.remove(keyDay);
                                        }
                                        synchronized (linemap) {
                                            linemap.remove(delReport);
                                        }

                                        synchronized (valuecache) {
                                            valuecache.get(keyDay).remove(nreport);
                                            valuecache.get(keyDay).add(delReport);
                                            Collections.sort(valuecache.get(keyDay));
                                        }

                                        createCP4Day(new LocalDate(delReport.getPit()));

                                        buildPanel();
                                        if (tbShowReplaced.isSelected()) {
                                            GUITools.flashBackground(linemap.get(delReport), Color.YELLOW, 2);
                                        }
                                    } catch (OptimisticLockException ole) {
                                        OPDE.warn(ole);
                                        if (em.getTransaction().isActive()) {
                                            em.getTransaction().rollback();
                                        }
                                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                            OPDE.getMainframe().emptyFrame();
                                            OPDE.getMainframe().afterLogin();
                                        } else {
                                            reloadDisplay(true);
                                        }
                                    } catch (Exception e) {
                                        if (em.getTransaction().isActive()) {
                                            em.getTransaction().rollback();
                                        }
                                        OPDE.fatal(e);
                                    } finally {
                                        em.close();
                                    }

                                }
                            }
                        });
            }
        });
        btnDelete.setEnabled(NReportTools.isChangeable(nreport));
        pnlMenu.add(btnDelete);

        /***
         *      _     _       _____  _    ____
         *     | |__ | |_ _ _|_   _|/ \  / ___|___
         *     | '_ \| __| '_ \| | / _ \| |  _/ __|
         *     | |_) | |_| | | | |/ ___ \ |_| \__ \
         *     |_.__/ \__|_| |_|_/_/   \_\____|___/
         *
         */
        final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple,
                null);
        btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnTAGs.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                final JidePopup popup = new JidePopup();

                final JPanel pnl = new JPanel(new BorderLayout(5, 5));
                final PnlCommonTags pnlCommonTags = new PnlCommonTags(nreport.getCommontags(), true, 3);
                pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER);
                JButton btnApply = new JButton(SYSConst.icon22apply);
                pnl.add(btnApply, BorderLayout.SOUTH);
                btnApply.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        EntityManager em = OPDE.createEM();
                        try {
                            em.getTransaction().begin();
                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            final NReport myReport = em.merge(nreport);
                            em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                            myReport.getCommontags().clear();
                            for (Commontags commontag : pnlCommonTags.getListSelectedTags()) {
                                myReport.getCommontags().add(em.merge(commontag));
                            }

                            em.getTransaction().commit();

                            final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit());

                            synchronized (contentmap) {
                                contentmap.remove(keyNewDay);
                            }
                            synchronized (linemap) {
                                linemap.remove(nreport);
                            }

                            synchronized (valuecache) {
                                valuecache.get(keyNewDay).remove(nreport);
                                valuecache.get(keyNewDay).add(myReport);
                                Collections.sort(valuecache.get(keyNewDay));
                            }

                            synchronized (listUsedCommontags) {
                                boolean reloadSearch = false;
                                for (Commontags ctag : myReport.getCommontags()) {
                                    if (!listUsedCommontags.contains(ctag)) {
                                        listUsedCommontags.add(ctag);
                                        reloadSearch = true;
                                    }
                                }
                                if (reloadSearch) {
                                    prepareSearchArea();
                                }
                            }

                            createCP4Day(new LocalDate(myReport.getPit()));

                            buildPanel();
                            GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                        } catch (OptimisticLockException ole) {
                            OPDE.warn(ole);
                            OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            } else {
                                reloadDisplay(true);
                            }
                        } catch (Exception e) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            OPDE.fatal(e);
                        } finally {
                            em.close();
                        }
                    }
                });

                popup.setMovable(false);
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.setOwner(btnTAGs);
                popup.removeExcludedComponent(btnTAGs);
                pnl.setPreferredSize(new Dimension(350, 150));
                popup.getContentPane().add(pnl);
                popup.setDefaultFocusComponent(pnl);

                GUITools.showPopup(popup, SwingConstants.WEST);

            }
        });
        btnTAGs.setEnabled(NReportTools.isChangeable(nreport) && NReportTools.isMine(nreport));
        pnlMenu.add(btnTAGs);

        /***
         *      _     _         __  __ _             _
         *     | |__ | |_ _ __ |  \/  (_)_ __  _   _| |_ ___  ___
         *     | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __|
         *     | |_) | |_| | | | |  | | | | | | |_| | ||  __/\__ \
         *     |_.__/ \__|_| |_|_|  |_|_|_| |_|\__,_|\__\___||___/
         *
         */
        final JButton btnMinutes = GUITools.createHyperlinkButton("nursingrecords.reports.btnminutes.tooltip",
                SYSConst.icon22clock, null);
        btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnMinutes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {

                final JPopupMenu menu = SYSCalendar.getMinutesMenu(
                        new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() {
                            @Override
                            public void execute(Object o) {
                                EntityManager em = OPDE.createEM();
                                try {
                                    em.getTransaction().begin();

                                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                    NReport myReport = em.merge(nreport);
                                    em.lock(myReport, LockModeType.OPTIMISTIC);

                                    myReport.setMinutes((Integer) o);
                                    myReport.setEditDate(new Date());

                                    em.getTransaction().commit();

                                    final String keyNewDay = DateFormat.getDateInstance()
                                            .format(myReport.getPit());

                                    synchronized (contentmap) {
                                        contentmap.remove(keyNewDay);
                                    }
                                    synchronized (linemap) {
                                        linemap.remove(nreport);
                                    }

                                    synchronized (valuecache) {
                                        valuecache.get(keyNewDay).remove(nreport);
                                        valuecache.get(keyNewDay).add(myReport);
                                        Collections.sort(valuecache.get(keyNewDay));
                                    }

                                    createCP4Day(new LocalDate(myReport.getPit()));

                                    buildPanel();
                                    GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    } else {
                                        reloadDisplay(true);
                                    }
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        });

                menu.show(btnMinutes, 0, btnMinutes.getHeight());
            }
        });
        btnMinutes.setEnabled(!nreport.isObsolete() && NReportTools.isMine(nreport));
        pnlMenu.add(btnMinutes);

        pnlMenu.add(new JSeparator());

        /***
         *      _     _         _____ _ _
         *     | |__ | |_ _ __ |  ___(_) | ___  ___
         *     | '_ \| __| '_ \| |_  | | |/ _ \/ __|
         *     | |_) | |_| | | |  _| | | |  __/\__ \
         *     |_.__/ \__|_| |_|_|   |_|_|\___||___/
         *
         */
        final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach,
                null);
        btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnFiles.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Closure fileHandleClosure = nreport.isObsolete() ? null : new Closure() {
                    @Override
                    public void execute(Object o) {
                        EntityManager em = OPDE.createEM();
                        final NReport myReport = em.find(NReport.class, nreport.getID());
                        em.close();

                        final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit());

                        synchronized (contentmap) {
                            contentmap.remove(keyNewDay);
                        }
                        synchronized (linemap) {
                            linemap.remove(nreport);
                        }

                        synchronized (valuecache) {
                            valuecache.get(keyNewDay).remove(nreport);
                            valuecache.get(keyNewDay).add(myReport);
                            Collections.sort(valuecache.get(keyNewDay));
                        }

                        createCP4Day(new LocalDate(myReport.getPit()));

                        buildPanel();
                        GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                    }
                };
                new DlgFiles(nreport, fileHandleClosure);
            }
        });
        btnFiles.setEnabled(OPDE.isFTPworking());
        pnlMenu.add(btnFiles);

        /***
         *      _     _         ____
         *     | |__ | |_ _ __ |  _ \ _ __ ___   ___ ___  ___ ___
         *     | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __|
         *     | |_) | |_| | | |  __/| | | (_) | (_|  __/\__ \__ \
         *     |_.__/ \__|_| |_|_|   |_|  \___/ \___\___||___/___/
         *
         */
        final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip",
                SYSConst.icon22link, null);
        btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnProcess.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgProcessAssign(nreport, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o == null) {
                            return;
                        }
                        Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o;

                        ArrayList<QProcess> assigned = result.getFirst();
                        ArrayList<QProcess> unassigned = result.getSecond();

                        EntityManager em = OPDE.createEM();

                        try {
                            em.getTransaction().begin();

                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            NReport myReport = em.merge(nreport);
                            em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                            ArrayList<SYSNR2PROCESS> attached = new ArrayList<SYSNR2PROCESS>(
                                    myReport.getAttachedQProcessConnections());
                            for (SYSNR2PROCESS linkObject : attached) {
                                if (unassigned.contains(linkObject.getQProcess())) {
                                    linkObject.getQProcess().getAttachedNReportConnections().remove(linkObject);
                                    linkObject.getNReport().getAttachedQProcessConnections().remove(linkObject);
                                    em.merge(new PReport(
                                            SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": "
                                                    + nreport.getTitle() + " ID: " + nreport.getID(),
                                            PReportTools.PREPORT_TYPE_REMOVE_ELEMENT,
                                            linkObject.getQProcess()));
                                    em.remove(linkObject);
                                }
                            }
                            attached.clear();

                            for (QProcess qProcess : assigned) {
                                java.util.List<QProcessElement> listElements = qProcess.getElements();
                                if (!listElements.contains(myReport)) {
                                    QProcess myQProcess = em.merge(qProcess);
                                    SYSNR2PROCESS myLinkObject = em
                                            .merge(new SYSNR2PROCESS(myQProcess, myReport));
                                    em.merge(new PReport(
                                            SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": "
                                                    + nreport.getTitle() + " ID: " + nreport.getID(),
                                            PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess));
                                    qProcess.getAttachedNReportConnections().add(myLinkObject);
                                    myReport.getAttachedQProcessConnections().add(myLinkObject);
                                }
                            }

                            em.getTransaction().commit();

                            final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit());

                            synchronized (contentmap) {
                                contentmap.remove(keyNewDay);
                            }
                            synchronized (linemap) {
                                linemap.remove(nreport);
                            }

                            synchronized (valuecache) {
                                valuecache.get(keyNewDay).remove(nreport);
                                valuecache.get(keyNewDay).add(myReport);
                                Collections.sort(valuecache.get(keyNewDay));
                            }

                            createCP4Day(new LocalDate(myReport.getPit()));

                            buildPanel();
                            GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                        } catch (OptimisticLockException ole) {
                            OPDE.warn(ole);
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            } else {
                                reloadDisplay(true);
                            }
                        } catch (RollbackException ole) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            }
                            OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                        } catch (Exception e) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            OPDE.fatal(e);
                        } finally {
                            em.close();
                        }

                    }
                });
            }
        });
        pnlMenu.add(btnProcess);

    }
    return pnlMenu;
}

From source file:org.eobjects.datacleaner.panels.DatabaseDriversPanel.java

private void updateComponents() {
    this.removeAll();
    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(WidgetFactory.createToolBarSeparator());

    final JButton addDriverButton = new JButton("Add database driver",
            imageManager.getImageIcon(IconUtils.ACTION_ADD));
    addDriverButton.addActionListener(new ActionListener() {
        @Override/*from  w  w  w  .  j ava2 s.c  om*/
        public void actionPerformed(ActionEvent e) {

            final JMenu menu = new JMenu("Automatic download and install");
            menu.setIcon(imageManager.getImageIcon("images/actions/download.png"));

            final List<DatabaseDriverDescriptor> drivers = _databaseDriverCatalog.getDatabaseDrivers();
            for (DatabaseDriverDescriptor dd : drivers) {
                final String[] urls = dd.getDownloadUrls();
                if (urls != null && _databaseDriverCatalog.getState(dd) == DatabaseDriverState.NOT_INSTALLED) {
                    final JMenuItem downloadAndInstallMenuItem = WidgetFactory
                            .createMenuItem(dd.getDisplayName(), dd.getIconImagePath());
                    downloadAndInstallMenuItem.addActionListener(createDownloadActionListener(dd));
                    menu.add(downloadAndInstallMenuItem);
                }
            }

            if (menu.getMenuComponentCount() == 0) {
                menu.setEnabled(false);
            }

            final JMenuItem localJarFilesMenuItem = WidgetFactory.createMenuItem("Local JAR file(s)...",
                    "images/filetypes/archive.png");
            localJarFilesMenuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    AddDatabaseDriverDialog dialog = new AddDatabaseDriverDialog(_databaseDriverCatalog,
                            DatabaseDriversPanel.this, _windowContext, _userPreferences);
                    dialog.setVisible(true);
                }
            });

            final JPopupMenu popup = new JPopupMenu();
            popup.add(menu);
            popup.add(localJarFilesMenuItem);
            popup.show(addDriverButton, 0, addDriverButton.getHeight());
        }
    });
    toolBar.add(addDriverButton);

    final DCTable table = getDatabaseDriverTable();
    this.add(toolBar, BorderLayout.NORTH);
    this.add(table.toPanel(), BorderLayout.CENTER);
}