Example usage for javax.swing.table TableCellEditor stopCellEditing

List of usage examples for javax.swing.table TableCellEditor stopCellEditing

Introduction

In this page you can find the example usage for javax.swing.table TableCellEditor stopCellEditing.

Prototype

public boolean stopCellEditing();

Source Link

Document

Tells the editor to stop editing and accept any partially edited value as the value of the editor.

Usage

From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java

@Override
public void save() {
    // In case there are in-progress changes.
    TableCellEditor editor = customRemoverTable.getCellEditor();
    if (editor != null) {
        editor.stopCellEditing();
    }/*from   ww w .  java2s.co m*/

    ConfigTuple ct = configFiles.get(controllerConfigs.getSelectedItem());
    ct.loader.getProcessorConfigs().Custom.clear();

    // Roll up the pattern processors.
    DefaultTableModel model = (DefaultTableModel) this.customRemoverTable.getModel();
    for (int i = 0; i < customRemoverTable.getRowCount(); i++) {
        JsonObject args = new JsonObject();
        String pattern = model.getValueAt(i, 1).toString();
        if (!StringUtils.isEmpty(pattern)) {
            args.addProperty("pattern", pattern);
            ProcessorConfig pc = new ProcessorConfig("PatternRemover", (Boolean) model.getValueAt(i, 0), true,
                    args);
            ct.loader.getProcessorConfigs().Custom.add(pc);
        }
    }

    try {
        FirmwareUtils.save(ct.file, ct.loader);
    } catch (IOException ex) {
        GUIHelpers.displayErrorDialog("Problem saving controller config: " + ex.getMessage());
        logger.log(Level.SEVERE, null, ex);
    }
}

From source file:hr.fer.zemris.vhdllab.platform.ui.wizard.support.PortWizardPage.java

private Component createButtons() {
    addAction = new ActionCommand(PAGE_ID + ".addRow") {
        @Override//  ww w  . j  a  v  a2  s.c  om
        protected void doExecuteCommand() {
            Port port = new Port();
            port.setDirection(PortDirection.IN);
            model.addRow(port);
        }
    };
    removeAction = new ActionCommand(PAGE_ID + ".removeRow") {
        @Override
        protected void onButtonAttached(AbstractButton button) {
            this.setEnabled(false); // remove action is initially disabled
            super.onButtonAttached(button);
        }

        @Override
        protected void doExecuteCommand() {
            int selectedRow = table.getSelectedRow();
            if (selectedRow != -1) {
                TableCellEditor cellEditor = table.getCellEditor();
                if (cellEditor != null) {
                    cellEditor.stopCellEditing();
                }
                model.remove(selectedRow);
                int rowToSelect = Math.min(selectedRow, model.getRowCount() - 1);
                if (rowToSelect != -1) {
                    table.getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect);
                }
            }
        }
    };
    getCommandConfigurer().configure(addAction);
    getCommandConfigurer().configure(removeAction);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(addAction.createButton());
    buttonPanel.add(removeAction.createButton());
    JPanel control = new JPanel(new BorderLayout());
    control.add(buttonPanel, BorderLayout.WEST);
    return control;
}

From source file:com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettingsConfigurable.java

protected void createCustomTagsComponent(FormBuilder builder) {
    myTagNameColumnInfo myTagNameColumnInfo = new myTagNameColumnInfo();
    customTagsModel = new ListTableModel<HTMLMasonCustomTag>(myTagNameColumnInfo, new myTagRoleColumInfo());

    myTagNameColumnInfo.setCustomTagsModel(customTagsModel);

    customTagsTable = new JBTable(customTagsModel);

    final TableColumn secondColumn = customTagsTable.getColumnModel().getColumn(1);

    ComboBoxTableRenderer<HTMLMasonCustomTagRole> roleComboBoxTableRenderer = new ComboBoxTableRenderer<HTMLMasonCustomTagRole>(
            HTMLMasonCustomTagRole.values()) {
        @Override//from  w w  w.j a  v a 2s  .c  o  m
        protected String getTextFor(@NotNull HTMLMasonCustomTagRole value) {
            return value.getTitle();
        }

        @Override
        public boolean isCellEditable(EventObject event) {
            if (event instanceof MouseEvent) {
                return ((MouseEvent) event).getClickCount() >= 1;
            }

            return true;
        }

    };
    secondColumn.setCellRenderer(roleComboBoxTableRenderer);
    secondColumn.setCellEditor(roleComboBoxTableRenderer);

    builder.addLabeledComponent(new JLabel("Custom tags that mimics built-in HTML::Mason tags:"),
            ToolbarDecorator.createDecorator(customTagsTable).setAddAction(new AnActionButtonRunnable() {
                @Override
                public void run(AnActionButton anActionButton) {
                    final TableCellEditor cellEditor = customTagsTable.getCellEditor();
                    if (cellEditor != null) {
                        cellEditor.stopCellEditing();
                    }
                    final TableModel model = customTagsTable.getModel();

                    int indexToEdit = -1;

                    for (HTMLMasonCustomTag entry : customTagsModel.getItems()) {
                        if (StringUtil.isEmpty(entry.getText())) {
                            indexToEdit = customTagsModel.indexOf(entry);
                            break;
                        }
                    }

                    if (indexToEdit == -1) {
                        customTagsModel.addRow(new HTMLMasonCustomTag(
                                "customTag" + customTagsModel.getItems().size(), HTMLMasonCustomTagRole.PERL));
                        indexToEdit = model.getRowCount() - 1;
                    }

                    TableUtil.editCellAt(customTagsTable, indexToEdit, 0);
                }
            }).disableDownAction().disableUpAction()
                    .setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel());
}

From source file:com.mirth.connect.client.ui.alert.AlertActionPane.java

private void updateActionTable(List<AlertAction> alertActions) {
    // Make sure there aren't any cell editors still active
    TableCellEditor cellEditor = actionTable.getCellEditor();

    if (cellEditor != null) {
        cellEditor.stopCellEditing();
    }//from w w  w. j a  va  2s  . c  o  m

    for (Protocol protocol : protocols.values()) {
        if (protocol.hasOptions()) {
            MirthComboBoxTableCellEditor editor = new MirthComboBoxTableCellEditor(actionTable,
                    protocol.getRecipientNames().toArray(), 1, true, new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            JComboBox comboBox = (JComboBox) e.getSource();
                            if (comboBox.isPopupVisible() && actionTable.getCellEditor() != null) {
                                actionTable.getCellEditor().stopCellEditing();
                            }
                            PlatformUI.MIRTH_FRAME.setSaveEnabled(true);

                        }

                    });

            editor.setEditable(true);
            editor.getComboBox().setCanEnableSave(false);
            editor.getComboBox().setAutoResizeDropdown(true);

            MirthComboBoxTableCellRenderer renderer = new MirthComboBoxTableCellRenderer(
                    protocol.getRecipientNames().toArray());
            renderer.setEditable(true);

            // Update the recipient column renderer and editor with the current names
            ((RecipientCellRenderer) actionTable.getColumnExt(RECIPIENT_COLUMN_INDEX).getCellRenderer())
                    .setCellRenderer(protocol.getProtocolName(), renderer);
            ((RecipientCellEditor) actionTable.getColumnExt(RECIPIENT_COLUMN_NAME).getCellEditor())
                    .setCellEditor(protocol.getProtocolName(), editor);
        }
    }

    ActionTableModel model = (ActionTableModel) actionTable.getModel();
    model.refreshData(alertActions);
    if (model.getRowCount() == 0) {
        actionTable.clearSelection();
        removeActionButton.setEnabled(false);
    } else {
        actionTable.getSelectionModel().setSelectionInterval(0, 0);
        removeActionButton.setEnabled(true);
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Stop the cell editors to ensure data is flushed
 *///from   w  w w  . ja v  a 2s  . c  om
private void stopCellEditors() {
    final Iterator<JTable> iter = _tables.values().iterator();
    while (iter.hasNext()) {
        final JTable table = iter.next();
        final int editingColumn = table.getEditingColumn();
        final int editingRow = table.getEditingRow();
        if (editingColumn > -1) {
            final TableCellEditor cellEditor = table.getCellEditor(editingRow, editingColumn);
            if (null != cellEditor) {
                cellEditor.stopCellEditing();
            }
        }
    }
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void stopEditing() {
    // if the user had typed in a value in the content search table, close the cell editor so that any value that was entered will be included in the search
    TableCellEditor cellEditor = contentSearchTable.getCellEditor();
    if (cellEditor != null) {
        cellEditor.stopCellEditing();
    }//from w ww. ja  v  a  2 s. com

    cellEditor = metaDataSearchTable.getCellEditor();
    if (cellEditor != null) {
        cellEditor.stopCellEditing();
    }
}

From source file:dbseer.gui.user.DBSeerDataSet.java

public void updateTableOld() {
    TableCellEditor editor = table.getCellEditor();
    if (editor != null)
        editor.stopCellEditing(); // stop editing
    for (int i = 0; i < tableModel.getRowCount(); ++i) {
        for (int j = 0; j < tableHeaders.length; ++j) {
            if (tableModel.getValueAt(i, 0).equals(tableHeaders[j])) {
                switch (j) {
                case TYPE_NAME:
                    tableModel.setValueAt(this.name, i, 1);
                    break;
                case TYPE_PATH:
                    tableModel.setValueAt(this.path, i, 1);
                    break;
                case TYPE_END_INDEX:
                    tableModel.setValueAt(String.valueOf(this.endIndex), i, 1);
                    break;
                case TYPE_USE_ENTIRE_DATASET:
                    tableModel.setValueAt(this.useEntireDataSet.booleanValue(), i, 1);
                    break;
                case TYPE_START_INDEX:
                    tableModel.setValueAt(String.valueOf(this.startIndex), i, 1);
                    break;
                case TYPE_NUM_TRANSACTION_TYPE:
                    tableModel.setValueAt(String.valueOf(this.numTransactionTypes), i, 1);
                    break;
                default:
                    break;
                }//from  w w w  . j  av  a 2  s  .c o m
                break;
            }
        }

        if (i > TYPE_NUM_TRANSACTION_TYPE) {
            if (i - TYPE_NUM_TRANSACTION_TYPE <= transactionTypes.size()) {
                DBSeerTransactionType txType = transactionTypes.get(i - TYPE_NUM_TRANSACTION_TYPE - 1);
                tableModel.setValueAt(txType.getName(), i, 1);
            }
        }
        if (i > TYPE_NUM_TRANSACTION_TYPE + numTransactionTypes) {
            if (i - TYPE_NUM_TRANSACTION_TYPE - numTransactionTypes <= numTransactionTypes) {
                DBSeerTransactionType txType = transactionTypes
                        .get(i - TYPE_NUM_TRANSACTION_TYPE - numTransactionTypes - 1);
                if (txType.isEnabled()) {
                    tableModel.setValueAt(true, i, 1);
                } else {
                    tableModel.setValueAt(false, i, 1);
                }
            }
        }
    }
    tableModel.fireTableDataChanged();
}

From source file:dbseer.gui.user.DBSeerDataSet.java

public void setFromTable() {
    TableCellEditor editor = table.getCellEditor();
    if (editor != null)
        editor.stopCellEditing(); // stop editing
    transactionTypes.clear();/*from   w  w  w.  jav a2s  . c  o  m*/

    for (int i = 0; i < tableModel.getRowCount(); ++i) {
        for (int j = 0; j < tableHeaders.length; ++j) {
            if (tableModel.getValueAt(i, 0).equals(tableHeaders[j])) {
                switch (j) {
                case TYPE_NAME:
                    this.name = (String) tableModel.getValueAt(i, 1);
                    break;
                case TYPE_PATH:
                    this.path = (String) tableModel.getValueAt(i, 1);
                    break;
                case TYPE_END_INDEX:
                    if (UserInputValidator.validateNumber(String.valueOf(tableModel.getValueAt(i, 1))))
                        this.endIndex = (Integer) tableModel.getValueAt(i, 1);
                    break;
                case TYPE_USE_ENTIRE_DATASET:
                    this.useEntireDataSet = (Boolean) tableModel.getValueAt(i, 1);
                    break;
                case TYPE_START_INDEX:
                    if (UserInputValidator.validateNumber(String.valueOf(tableModel.getValueAt(i, 1))))
                        ;
                    this.startIndex = (Integer) tableModel.getValueAt(i, 1);
                    break;
                case TYPE_NUM_TRANSACTION_TYPE:
                    if (UserInputValidator.validateNumber((String.valueOf(tableModel.getValueAt(i, 1)))))
                        ;
                    this.numTransactionTypes = (Integer) tableModel.getValueAt(i, 1);
                    break;
                default:
                    break;
                }
                break;
            }
        }
        if (i > TYPE_NUM_TRANSACTION_TYPE && i <= TYPE_NUM_TRANSACTION_TYPE + this.numTransactionTypes) {
            DBSeerTransactionType txType = new DBSeerTransactionType((String) tableModel.getValueAt(i, 1),
                    true);
            transactionTypes.add(txType);
        }
        if (i > TYPE_NUM_TRANSACTION_TYPE + numTransactionTypes) {
            int idx = i - TYPE_NUM_TRANSACTION_TYPE - numTransactionTypes;
            if (idx <= numTransactionTypes && idx >= 1) {
                if (((Boolean) tableModel.getValueAt(i, 1)).booleanValue()) {
                    transactionTypes.get(idx - 1).setEnabled(true);
                } else {
                    transactionTypes.get(idx - 1).setEnabled(false);
                }
            }
        }
    }
    dataSetLoaded = false;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public JPanel createDetailsView() {
    final VFSJFileChooser chooser = getFileChooser();

    JPanel p = new JPanel(new BorderLayout());

    final JTable detailsTable = new JTable(getDetailsTableModel()) {
        // Handle Escape key events here
        @Override/*  w  w w .j  a  v  a 2s.  c  om*/
        protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
            if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) {
                // We are not editing, forward to filechooser.
                chooser.dispatchEvent(e);

                return true;
            }

            return super.processKeyBinding(ks, e, condition, pressed);
        }

        @Override
        public void tableChanged(TableModelEvent e) {
            super.tableChanged(e);

            if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                // update header with possibly changed column set
                updateDetailsColumnModel(this);
            }
        }
    };

    //        detailsTable.setRowSorter(getRowSorter());
    detailsTable.setAutoCreateColumnsFromModel(false);
    detailsTable.setComponentOrientation(chooser.getComponentOrientation());
    //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    detailsTable.setShowGrid(false);
    detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

    //        detailsTable.addKeyListener(detailsKeyListener);
    Font font = list.getFont();
    detailsTable.setFont(font);
    detailsTable.setIntercellSpacing(new Dimension(0, 0));

    TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer(
            detailsTable.getTableHeader().getDefaultRenderer());
    detailsTable.getTableHeader().setDefaultRenderer(headerRenderer);

    TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser);
    detailsTable.setDefaultRenderer(Object.class, cellRenderer);

    // So that drag can be started on a mouse press
    detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    detailsTable.addMouseListener(getMouseHandler());
    // No need to addListSelectionListener because selections are forwarded
    // to our JList.

    // 4835633 : tell BasicTableUI that this is a file list
    detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE);

    if (listViewWindowsStyle) {
        detailsTable.addFocusListener(repaintListener);
    }

    JTableHeader header = detailsTable.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(detailsTableModel.new ColumnListener());
    header.setReorderingAllowed(true);

    // TAB/SHIFT-TAB should transfer focus and ENTER should select an item.
    // We don't want them to navigate within the table
    ActionMap am = SwingUtilities.getUIActionMap(detailsTable);
    am.remove("selectNextRowCell");
    am.remove("selectPreviousRowCell");
    am.remove("selectNextColumnCell");
    am.remove("selectPreviousColumnCell");
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);

    JScrollPane scrollpane = new JScrollPane(detailsTable);
    scrollpane.setComponentOrientation(chooser.getComponentOrientation());
    LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground");

    // Adjust width of first column so the table fills the viewport when
    // first displayed (temporary listener).
    scrollpane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JScrollPane sp = (JScrollPane) e.getComponent();
            fixNameColumnWidth(sp.getViewport().getSize().width);
            sp.removeComponentListener(this);
        }
    });

    // 4835633.
    // If the mouse is pressed in the area below the Details view table, the
    // event is not dispatched to the Table MouseListener but to the
    // scrollpane.  Listen for that here so we can clear the selection.
    scrollpane.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            JScrollPane jsp = ((JScrollPane) e.getComponent());
            JTable table = (JTable) jsp.getViewport().getView();

            if (!e.isShiftDown()
                    || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) {
                clearSelection();

                TableCellEditor tce = table.getCellEditor();

                if (tce != null) {
                    tce.stopCellEditing();
                }
            }
        }
    });

    detailsTable.setForeground(list.getForeground());
    detailsTable.setBackground(list.getBackground());

    if (listViewBorder != null) {
        scrollpane.setBorder(listViewBorder);
    }

    p.add(scrollpane, BorderLayout.CENTER);

    detailsTableModel.fireTableStructureChanged();

    return p;
}

From source file:fi.hoski.remote.ui.Admin.java

private void editReservations(final EventType eventType) {
    final Event event = chooseEvent(eventType, "CHOOSE");
    if (event != null) {
        final String eventTitle = TextUtil.getText(event.getEventType().name()) + " "
                + event.get(Event.EventDate);
        safeTitle = frame.getTitle();/*from   w ww  . j  a  v  a2  s  .  com*/
        frame.setTitle(eventTitle);
        reservationList = dss.getReservations(event);
        selectedReservations = new ArrayList<Reservation>();
        unSelectedReservations = new ArrayList<Reservation>();
        if (Event.isInspection(eventType)) {
            for (Reservation reservation : reservationList) {
                Boolean inspected = (Boolean) reservation.get(Reservation.INSPECTED);
                if (inspected != null && inspected) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        } else {
            for (Reservation reservation : reservationList) {
                Long order = (Long) reservation.get(Reservation.ORDER);
                if (order != null && order != 0) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        }
        DataObjectModel baseModel = Reservation.getModel(eventType);
        DataObjectModel unorderedModel = null;
        DataObjectModel orderedModel = null;
        switch (eventType) {
        case LAUNCH:
        case LIFT:
        case HULL_INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            break;
        case INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.INSPECTION_GASS, Reservation.INSPECTOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.NOTES);
            break;
        }

        final DataObjectListTableModel<Reservation> unorderedTableModel = new DataObjectListTableModel<Reservation>(
                unorderedModel, unSelectedReservations);
        final JTable unorderedtable = new FitTable(unorderedTableModel);
        TableSelectionHandler tsh1 = new TableSelectionHandler(unorderedtable);
        unorderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        unorderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        unorderedtable.addKeyListener(unorderedTableModel.getRemover(dss));
        unorderedtable.setDragEnabled(true);
        unorderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler unorderedTransferHandler = new DataObjectTransferHandler<Reservation>(
                unorderedTableModel);
        unorderedtable.setTransferHandler(unorderedTransferHandler);

        final DataObjectListTableModel<Reservation> orderedTableModel = new DataObjectListTableModel<Reservation>(
                orderedModel, selectedReservations);
        orderedTableModel.setEditable(Reservation.INSPECTION_CLASS, Reservation.INSPECTION_GASS,
                Reservation.BASICINSPECTION, Reservation.INSPECTOR);
        final JTable orderedtable = new FitTable(orderedTableModel);
        TableSelectionHandler tsh2 = new TableSelectionHandler(orderedtable);
        orderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        orderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        orderedtable.addKeyListener(orderedTableModel.getRemover(dss));
        orderedtable.setDragEnabled(true);
        orderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler orderedTransferHandler = new DataObjectTransferHandler<Reservation>(orderedTableModel);
        orderedtable.setTransferHandler(orderedTransferHandler);
        if (Event.isInspection(eventType)) {
            unorderedtable.setAutoCreateRowSorter(true);
            orderedtable.setAutoCreateRowSorter(true);
        }
        leftPane = new JScrollPane();
        leftPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-leftPane")));
        leftPane.setViewportView(unorderedtable);
        leftPane.setTransferHandler(unorderedTransferHandler);

        rightPane = new JScrollPane();
        rightPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-rightPane")));
        rightPane.setViewportView(orderedtable);
        rightPane.setTransferHandler(orderedTransferHandler);

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane);
        splitPane.setDividerLocation(0.5);
        menuReservation.setEnabled(false);
        safeContainer = frame.getContentPane();
        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.add(splitPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        contentPane.add(buttonPanel, BorderLayout.SOUTH);

        JButton saveButton = new JButton();
        TextUtil.populate(saveButton, "SAVE");
        saveButton.setEnabled(!Event.isInspection(eventType));
        ActionListener saveAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                saveReservations();
            }
        };
        saveButton.addActionListener(saveAction);
        buttonPanel.add(saveButton);

        switch (eventType) {
        case INSPECTION: {
            if (privileged) {
                JButton inspectButton = new JButton();
                TextUtil.populate(inspectButton, "SET INSPECTED");
                ActionListener inspectAction = new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        TableCellEditor cellEditor = orderedtable.getCellEditor();
                        if (cellEditor != null) {
                            cellEditor.stopCellEditing();
                        }
                        try {
                            setAsInspected();
                        } catch (SQLException | ClassNotFoundException ex) {
                            ex.printStackTrace();
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                        }
                    }
                };
                inspectButton.addActionListener(inspectAction);
                buttonPanel.add(inspectButton);
            }

            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printTypeButton = new JButton();
            TextUtil.populate(printTypeButton, "PRINT");
            ActionListener printTypeAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printNameBoatTypeOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printTypeButton.addActionListener(printTypeAction);
            buttonPanel.add(printTypeButton);

            JButton printDockButton = new JButton();
            TextUtil.populate(printDockButton, "PRINT DOCK ORDER");
            ActionListener printDockAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printDockOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printDockButton.addActionListener(printDockAction);
            buttonPanel.add(printDockButton);

        }
            break;
        case HULL_INSPECTION: {
            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printAlphaOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);

        }
            break;
        case LAUNCH:
        case LIFT: {
            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printBrief = new JButton();
            TextUtil.populate(printBrief, "BRIEF PRINT");
            ActionListener printBriefAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printOrderBrief(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printBrief.addActionListener(printBriefAction);
            buttonPanel.add(printBrief);

            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        if (eventType == EventType.LAUNCH) {
                            printLaunchOrder(eventTitle);
                        } else {
                            printLiftOrder(eventTitle);
                        }
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);
        }
            break;
        }

        JButton cancelButton = new JButton();
        TextUtil.populate(cancelButton, "CANCEL");
        ActionListener cancelAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        };
        cancelButton.addActionListener(cancelAction);
        buttonPanel.add(cancelButton);

        frame.setContentPane(contentPane);
        frame.pack();
        frame.setVisible(true);
        KeyListener keyListener = new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 10) {
                    int selectedRow = unorderedtable.getSelectedRow();
                    if (selectedRow != -1) {
                        RowSorter<? extends TableModel> rowSorter = unorderedtable.getRowSorter();
                        if (rowSorter != null) {
                            selectedRow = rowSorter.convertRowIndexToModel(selectedRow);
                        }
                        Reservation reservation = unorderedTableModel.getObject(selectedRow);
                        orderedTableModel.add(reservation);
                        unorderedTableModel.remove(reservation);
                        e.consume();
                        unorderedtable.changeSelection(selectedRow, 0, false, false);
                    }
                }
            }
        };
        unorderedtable.addKeyListener(keyListener);
        unorderedtable.requestFocusInWindow();
    }
}