Example usage for javax.swing.table DefaultTableModel findColumn

List of usage examples for javax.swing.table DefaultTableModel findColumn

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel findColumn.

Prototype

public int findColumn(String columnName) 

Source Link

Document

Returns a column given its name.

Usage

From source file:com.mirth.connect.client.ui.ChannelSetup.java

/**
 * Save all of the current channel information in the editor to the actual channel
 *//*from  w ww  . j  a  v a  2 s  .  co m*/
public boolean saveChanges() {
    if (!parent.checkChannelName(summaryNameField.getText(), currentChannel.getId())) {
        return false;
    }

    if (metadataPruningOnRadio.isSelected() && metadataPruningDaysTextField.getText().equals("")) {
        parent.alertWarning(parent,
                "If metadata pruning is enabled, the age of metadata to prune cannot be blank.");
        return false;
    }

    if (contentPruningDaysRadio.isSelected() && contentPruningDaysTextField.getText().equals("")) {
        parent.alertWarning(parent,
                "If content pruning is enabled, the age of content to prune cannot be blank.");
        return false;
    }

    if (metadataPruningOnRadio.isSelected() && contentPruningDaysRadio.isSelected()) {
        Integer metadataPruningDays = Integer.parseInt(metadataPruningDaysTextField.getText());
        Integer contentPruningDays = Integer.parseInt(contentPruningDaysTextField.getText());

        if (contentPruningDays > metadataPruningDays) {
            parent.alertWarning(parent,
                    "The age of content to prune cannot be greater than the age of metadata to prune.");
            return false;
        }
    }

    // Store the current metadata column data in a map with the column name as the key and the type as the value.
    Map<String, MetaDataColumnType> currentColumns = new HashMap<String, MetaDataColumnType>();
    for (MetaDataColumn column : currentChannel.getProperties().getMetaDataColumns()) {
        currentColumns.put(column.getName(), column.getType());
    }

    Set<String> columnNames = new HashSet<String>();
    for (int i = 0; i < metaDataTable.getRowCount(); i++) {
        DefaultTableModel model = (DefaultTableModel) metaDataTable.getModel();

        // Do not allow metadata column names to be empty
        String columnName = (String) model.getValueAt(i, model.findColumn(METADATA_NAME_COLUMN_NAME));
        if (StringUtils.isEmpty(columnName)) {
            parent.alertWarning(parent,
                    "Empty column name detected in custom metadata table. Column names cannot be empty.");
            return false;
        } else {
            // Do not allow duplicate column names
            if (columnNames.contains(columnName)) {
                parent.alertWarning(parent,
                        "Duplicate column name detected in custom metadata table. Column names must be unique.");
                return false;
            }

            if (columnName.equalsIgnoreCase("MESSAGE_ID") || columnName.equalsIgnoreCase("METADATA_ID")) {
                parent.alertWarning(parent, columnName
                        + " is a reserved keyword and cannot be used as a column name in the custom metadata table.");
                return false;
            }

            // Add the column name to a set so it can be checked for duplicates
            columnNames.add(columnName);
        }

        MetaDataColumnType columnType = (MetaDataColumnType) model.getValueAt(i,
                model.findColumn(METADATA_TYPE_COLUMN_NAME));

        // Remove columns from the map only if they have NOT been modified in a way such that their data will be deleted on deploy
        if (currentColumns.containsKey(columnName) && currentColumns.get(columnName).equals(columnType)) {
            currentColumns.remove(columnName);
        }
    }

    // Notify the user if an existing column was modified in a way such that it will be deleted on deploy
    if (!currentColumns.isEmpty()) {
        if (!parent.alertOption(parent,
                "Renaming, deleting, or changing the type of existing custom metadata columns\nwill delete all existing data "
                        + "for that column. Are you sure you want to do this?")) {
            return false;
        }
    }

    boolean enabled = summaryEnabledCheckbox.isSelected();

    saveSourcePanel();

    if (parent.currentContentPage == transformerPane) {
        transformerPane.accept(false);
        transformerPane.modified = false; // TODO: Check this. Fix to prevent double save on confirmLeave
    }

    if (parent.currentContentPage == filterPane) {
        filterPane.accept(false);
        filterPane.modified = false; // TODO: Check this. Fix to prevent double save on confirmLeave
    }

    saveDestinationPanel();

    MessageStorageMode messageStorageMode = MessageStorageMode.fromInt(messageStorageSlider.getValue());
    String errorString = getQueueErrorString(messageStorageMode);

    if (errorString != null) {
        parent.alertWarning(parent, StringUtils.capitalize(errorString)
                + " queueing must be disabled first before using the selected message storage mode.");
        return false;
    }

    currentChannel.setName(summaryNameField.getText());
    currentChannel.setDescription(summaryDescriptionText.getText());

    updateScripts();
    setLastModified();

    currentChannel.getProperties().setClearGlobalChannelMap(clearGlobalChannelMapCheckBox.isSelected());
    currentChannel.getProperties().setEncryptData(encryptMessagesCheckBox.isSelected());
    currentChannel.getProperties().setInitialState((DeployedState) initialState.getSelectedItem());
    currentChannel.getProperties().setStoreAttachments(attachmentStoreCheckBox.isSelected());

    String validationMessage = checkAllForms(currentChannel);
    if (validationMessage != null) {
        enabled = false;

        // If there is an error on one of the forms, then run the
        // validation on the current form to display any errors.
        if (channelView.getSelectedComponent() == destination) {
            // If the destination is enabled...
            if (currentChannel.getDestinationConnectors().get(destinationTable.getSelectedModelIndex())
                    .isEnabled()) {
                destinationConnectorPanel.checkProperties(destinationConnectorPanel.getProperties(), true);
            }
        } else if (channelView.getSelectedComponent() == source) {
            sourceConnectorPanel.checkProperties(sourceConnectorPanel.getProperties(), true);
        }

        summaryEnabledCheckbox.setSelected(false);

        parent.alertCustomError(this.parent, validationMessage, CustomErrorDialog.ERROR_SAVING_CHANNEL);
    }

    // Set the channel to enabled or disabled after it has been validated
    currentChannel.setEnabled(enabled);

    saveChannelTags();
    saveMetaDataColumns();
    saveMessageStorage(messageStorageMode);
    saveMessagePruning();

    // Update resource names
    parent.updateResourceNames(currentChannel);

    for (ChannelTabPlugin channelTabPlugin : LoadedExtensions.getInstance().getChannelTabPlugins().values()) {
        channelTabPlugin.getChannelTabPanel().save(currentChannel);
    }

    boolean updated = false;

    try {
        // Will throw exception if the connection died or there was an exception
        // saving the channel, skipping the rest of this code.
        updated = parent.updateChannel(currentChannel,
                parent.channelPanel.getCachedChannelStatuses().containsKey(currentChannel.getId()));

        try {
            currentChannel = (Channel) SerializationUtils.clone(
                    parent.channelPanel.getCachedChannelStatuses().get(currentChannel.getId()).getChannel());

            if (parent.currentContentPage == transformerPane) {
                if (channelView.getSelectedIndex() == SOURCE_TAB_INDEX) {
                    transformerPane.reload(currentChannel.getSourceConnector());
                } else if (channelView.getSelectedIndex() == DESTINATIONS_TAB_INDEX) {
                    int destination = destinationTable.getSelectedModelIndex();
                    transformerPane.reload(currentChannel.getDestinationConnectors().get(destination));
                }
            }
            if (parent.currentContentPage == filterPane) {
                if (channelView.getSelectedIndex() == SOURCE_TAB_INDEX) {
                    filterPane.reload(currentChannel.getSourceConnector(),
                            currentChannel.getSourceConnector().getFilter());
                } else if (channelView.getSelectedIndex() == DESTINATIONS_TAB_INDEX) {
                    Connector destination = currentChannel.getDestinationConnectors()
                            .get(destinationTable.getSelectedModelIndex());
                    filterPane.reload(destination, destination.getFilter());
                }
            }
            updateRevision();
            updateLastModified();
        } catch (SerializationException e) {
            parent.alertThrowable(this.parent, e);
        }
    } catch (ClientException e) {
        parent.alertThrowable(this.parent, e);
    }

    sourceConnectorPanel.updateQueueWarning(currentChannel.getProperties().getMessageStorageMode());
    destinationConnectorPanel.updateQueueWarning(currentChannel.getProperties().getMessageStorageMode());

    if (updated && saveGroupId != null) {
        parent.channelPanel.addChannelToGroup(currentChannel.getId(), saveGroupId);
        saveGroupId = null;
    }

    return updated;
}