use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostStep method onEditDockerHostAction.
private void onEditDockerHostAction() {
try {
DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
String apiURL = (String) tableModel.getValueAt(dockerHostsTable.getSelectedRow(), 4);
DockerHost updateHost = dockerManager.getDockerHostForURL(apiURL);
if (updateHost != null && !updateHost.isUpdating) {
AzureDockerUIResources.updateDockerHost(model.getProject(), new EditableDockerHost(updateHost), model.getDockerHostsManager(), true);
} else {
PluginUtil.displayErrorDialog("Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
}
} catch (Exception e) {
setDialogButtonsState(false);
String msg = "An error occurred while attempting to edit the selected Docker host.\n" + e.getMessage();
if (AzureDockerUtils.DEBUG)
e.printStackTrace();
LOGGER.error("onEditDockerHostAction", e);
PluginUtil.displayErrorDialog("Update Docker Hosts Error", msg);
}
}
use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostStep method selectDefaultDockerHost.
public void selectDefaultDockerHost(DockerHost dockerHost, boolean selectOtherHosts) {
dockerHostsTable.setEnabled(selectOtherHosts);
dockerImageDescription.host = dockerHost;
dockerImageDescription.hasNewDockerHost = false;
dockerImageDescription.sid = dockerHost.sid;
final DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
tableModel.setValueAt(false, 0, 0);
for (int i = 0; i < tableModel.getRowCount(); i++) {
String apiURL = (String) tableModel.getValueAt(i, 4);
if (dockerHost.apiUrl.equals(apiURL)) {
tableModel.setValueAt(true, i, 0);
dockerHostsTable.setRowSelectionInterval(i, i);
dockerHostsTableSelection = new DockerHostsTableSelection();
dockerHostsTableSelection.host = dockerHost;
dockerHostsTableSelection.row = i;
model.setSubscription(dockerManager.getSubscriptionsMap().get(dockerHostsTableSelection.host.sid));
break;
}
}
}
use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostStep method refreshDockerHostsTable.
/* Refresh the docker hosts entries in the select host table
*
*/
private void refreshDockerHostsTable() {
DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
String oldSelection = dockerHostsTableSelection != null ? dockerHostsTableSelection.host.apiUrl : null;
if (dockerHostsTableSelection != null) {
tableModel.setValueAt(false, dockerHostsTableSelection.row, 0);
dockerHostsTableSelection = null;
}
if (dockerHostsTable.getSelectedRow() >= 0) {
dockerHostsTable.removeRowSelectionInterval(dockerHostsTable.getSelectedRow(), dockerHostsTable.getSelectedRow());
}
int size = tableModel.getRowCount();
while (size > 0) {
size--;
try {
tableModel.removeRow(size);
} catch (Exception e) {
e.printStackTrace();
}
}
dockerHostsTable.removeAll();
dockerHostsTable.repaint();
try {
List<DockerHost> dockerHosts = dockerManager.getDockerHostsList();
boolean selected = false;
if (dockerHosts != null) {
int idx = 0;
for (DockerHost host : dockerHosts) {
Vector<Object> row = new Vector<>();
row.add(false);
row.add(host.name);
row.add(host.state.toString());
row.add(host.hostOSType.toString());
row.add(host.apiUrl);
tableModel.addRow(row);
if (oldSelection != null && oldSelection.equals(host.apiUrl)) {
tableModel.setValueAt(true, idx, 0);
selected = true;
}
idx++;
}
if (!selected) {
dockerHostsTableSelection = null;
}
}
dockerHostsTable.repaint();
} catch (Exception e) {
setDialogButtonsState(false);
String msg = "An error occurred while attempting to get the list of recognizable Docker hosts.\n" + e.getMessage();
if (AzureDockerUtils.DEBUG)
e.printStackTrace();
LOGGER.error("refreshDockerHostsTable", e);
PluginUtil.displayErrorDialog("Refresh Docker Hosts Error", msg);
}
}
use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostStep method createUIComponents.
private void createUIComponents() {
final DefaultTableModel dockerListTableModel = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int col) {
return (col == 0);
}
public Class<?> getColumnClass(int colIndex) {
return getValueAt(0, colIndex).getClass();
}
};
dockerListTableModel.addColumn("");
dockerListTableModel.addColumn("Name");
dockerListTableModel.addColumn("State");
dockerListTableModel.addColumn("OS");
dockerListTableModel.addColumn("API URL");
dockerHostsTable = new JBTable(dockerListTableModel);
dockerHostsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn column = dockerHostsTable.getColumnModel().getColumn(0);
column.setMinWidth(23);
column.setMaxWidth(23);
column = dockerHostsTable.getColumnModel().getColumn(1);
column.setPreferredWidth(150);
column = dockerHostsTable.getColumnModel().getColumn(2);
column.setPreferredWidth(30);
column = dockerHostsTable.getColumnModel().getColumn(3);
column.setPreferredWidth(110);
column = dockerHostsTable.getColumnModel().getColumn(4);
column.setPreferredWidth(150);
dockerListTableModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent tableEvent) {
if (tableEvent.getType() == TableModelEvent.UPDATE) {
DockerHostsTableSelection currentSelection = new DockerHostsTableSelection();
// int column = dockerHostsTable.getSelectedColumn();
int column = tableEvent.getColumn();
currentSelection.row = tableEvent.getFirstRow();
if (column == 0) {
DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
if ((Boolean) tableModel.getValueAt(currentSelection.row, 0)) {
if (dockerHostsTableSelection == null) {
dockerHostsTableSelection = currentSelection;
dockerHostsTableSelection.host = dockerManager.getDockerHostForURL((String) tableModel.getValueAt(currentSelection.row, 4));
if (dockerHostsTableSelection.host != null) {
model.setSubscription(dockerManager.getSubscriptionsMap().get(dockerHostsTableSelection.host.sid));
}
} else {
int oldRow = dockerHostsTableSelection.row;
dockerHostsTableSelection = null;
if (currentSelection.row != oldRow) {
// disable previous selection
tableModel.setValueAt(false, oldRow, 0);
dockerHostsTableSelection = currentSelection;
dockerHostsTableSelection.host = dockerManager.getDockerHostForURL((String) tableModel.getValueAt(dockerHostsTable.getSelectedRow(), 4));
if (dockerHostsTableSelection.host != null) {
model.setSubscription(dockerManager.getSubscriptionsMap().get(dockerHostsTableSelection.host.sid));
}
}
}
setFinishButtonState(doValidate(false) == null);
setNextButtonState(doValidate(false) == null);
} else {
dockerHostsTableSelection = null;
setFinishButtonState(false);
setNextButtonState(false);
}
}
}
}
});
AnActionButton viewDockerHostsAction = new ToolbarDecorator.ElementActionButton("Details", AllIcons.Actions.Export) {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
onViewDockerHostAction();
}
};
AnActionButton refreshDockerHostsAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
AppInsightsClient.createByType(AppInsightsClient.EventType.DockerContainer, "", "Refresh", null);
onRefreshDockerHostAction();
}
};
ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(dockerHostsTable).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
onAddNewDockerHostAction();
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton anActionButton) {
onEditDockerHostAction();
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
onRemoveDockerHostAction();
}
}).setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return dockerHostsTable.getSelectedRow() != -1;
}
}).setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return dockerHostsTable.getSelectedRow() != -1;
}
}).disableUpDownActions().addExtraActions(viewDockerHostsAction, refreshDockerHostsAction);
dockerHostsPanel = tableToolbarDecorator.createPanel();
}
use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.
the class TableEntityForm method setTableEntity.
public void setTableEntity(TableEntity tableEntity) {
this.tableEntity = tableEntity;
final DefaultTableModel model = (DefaultTableModel) propertiesTable.getModel();
model.addRow(new Object[] { "", TableFileEditor.PARTITION_KEY, TableEntity.PropertyType.String, tableEntity == null ? "" : tableEntity.getPartitionKey() });
model.addRow(new Object[] { "", TableFileEditor.ROW_KEY, TableEntity.PropertyType.String, tableEntity == null ? "" : tableEntity.getRowKey() });
if (tableEntity != null) {
for (String propertyName : tableEntity.getProperties().keySet()) {
model.addRow(new Object[] { "", propertyName, tableEntity.getProperties().get(propertyName).getType(), TableFileEditor.getFormattedProperty(tableEntity.getProperties().get(propertyName)) });
}
}
}
Aggregations