fr.ird.observe.client.util.table.InlineTableAutotSelectRowAndShowPopupAction Maven / Gradle / Ivy
package fr.ird.observe.client.util.table;
/*-
* #%L
* ObServe Toolkit :: Common Client
* %%
* Copyright (C) 2008 - 2017 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import fr.ird.observe.dto.data.DataDto;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
/**
* Created on 15/03/16.
*
* @author Tony Chemit - [email protected]
* @since 5.0
*/
public class InlineTableAutotSelectRowAndShowPopupAction> extends AutotSelectRowAndShowPopupActionSupport {
private final JMenuItem addWidget;
private final JMenuItem deleteWidget;
private final M tableModel;
public InlineTableAutotSelectRowAndShowPopupAction(JScrollPane scrollPane,
JTable table,
M tableModel,
JPopupMenu popup,
JMenuItem addWidget,
JMenuItem deleteWidget) {
super(scrollPane, table, popup);
this.addWidget = addWidget;
this.deleteWidget = deleteWidget;
this.tableModel = tableModel;
}
@Override
protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) {
boolean canAdd = tableModel.isValid();
boolean canDelete = !tableModel.isSelectionEmpty();
if (canDelete) {
// check also that the row is not empty
E selectedData = tableModel.getSelectedRow();
canDelete = tableModel.isRowNotEmpty(selectedData);
}
addWidget.setEnabled(canAdd);
deleteWidget.setEnabled(canDelete);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy