Search in sources :

Example 1 with IMessagesCallback

use of com.servoy.j2db.IMessagesCallback in project servoy-client by Servoy.

the class I18NPanel method initI18NMessagesModel.

private void initI18NMessagesModel(String searchKey) {
    if (i18NMessagesModel != null) {
        String filterColumn = null;
        String[] filterValue = null;
        if (application instanceof IMessagesCallback) {
            filterColumn = ((IMessagesCallback) application).getI18NColumnNameFilter();
            filterValue = ((IMessagesCallback) application).getI18NColumnValueFilter();
        }
        Collection<I18NMessagesModelEntry> messages = i18NMessagesModel.getMessages(searchKey, filterColumn, filterValue, application.getFoundSetManager(), false, null);
        Object selLang = "<unknown>";
        if (languagesCombo.getSelectedItem() != null)
            selLang = ((Object[]) languagesCombo.getSelectedItem())[1];
        String[] columns = null;
        if (endUser) {
            columns = new String[] { Messages.getString("servoy.i18nPanel.key"), Messages.getString("servoy.i18nPanel.default"), Messages.getString("servoy.i18nPanel.locale") + " (" + selLang + ")" };
        } else {
            columns = new String[] { Messages.getString("servoy.i18nPanel.key"), Messages.getString("servoy.i18nPanel.default"), Messages.getString("servoy.i18nPanel.locale") + " (" + selLang + ")", "" };
        }
        messageModel = new DefaultTableModel(columns, 0) {

            private static final long serialVersionUID = 1L;

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return (columnIndex == 3 && !Messages.invalidConnection && !Messages.noConnection);
            }
        };
        for (I18NMessagesModelEntry entry : messages) {
            messageModel.addRow(new Object[] { entry.key, entry.defaultvalue, entry.localeValue, "" });
        }
    }
}
Also used : I18NMessagesModelEntry(com.servoy.j2db.i18n.I18NMessagesModel.I18NMessagesModelEntry) DefaultTableModel(javax.swing.table.DefaultTableModel) IMessagesCallback(com.servoy.j2db.IMessagesCallback) EventObject(java.util.EventObject)

Example 2 with IMessagesCallback

use of com.servoy.j2db.IMessagesCallback in project servoy-client by Servoy.

the class I18NPanel method createOrUpdateKey.

/**
 * @param newKey
 * @param string
 * @param string2
 */
private boolean createOrUpdateKey(String newKey, String referenceValue, String localeValue) {
    boolean operationPerformed = false;
    if (// $NON-NLS-1$
    Messages.invalidConnection || Messages.noConnection || referenceValue == null || "".equals(referenceValue))
        // false
        return operationPerformed;
    String i18nDataSource = DataSourceUtils.getI18NDataSource(application.getSolution(), application.getSettings());
    if (i18nDataSource == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("Can't create key when there is no (valid) servername/tablename for messages");
    }
    String serverName = DataSourceUtils.getDataSourceServerName(i18nDataSource);
    String tableName = DataSourceUtils.getDataSourceTableName(i18nDataSource);
    String filterName = null;
    String[] filterValue = null;
    if (application instanceof IMessagesCallback) {
        filterName = ((IMessagesCallback) application).getI18NColumnNameFilter();
        filterValue = ((IMessagesCallback) application).getI18NColumnValueFilter();
    }
    if (Messages.customMessageLoader != null) {
        try {
            TreeMap<String, MessageEntry> messages = Messages.customMessageLoader.readMessages(serverName, tableName);
            adjustMessagesMap(newKey, referenceValue, localeValue, messages);
            Messages.customMessageLoader.save(serverName, tableName, messages);
            operationPerformed = true;
        } catch (Exception e) {
            Debug.error("exception when inserting/updating i18n key: " + newKey);
            Debug.error(e);
        // throw new RuntimeException(e);
        }
    } else {
        IDataServer dataServer = application.getDataServer();
        IRepository repository = application.getRepository();
        try {
            TreeMap<String, MessageEntry> repositoryMessages = I18NUtil.loadSortedMessagesFromRepository(repository, dataServer, application.getClientID(), serverName, tableName, filterName, filterValue, application.getFoundSetManager());
            TreeMap<String, MessageEntry> messages = new TreeMap<String, I18NUtil.MessageEntry>(repositoryMessages);
            adjustMessagesMap(newKey, referenceValue, localeValue, messages);
            I18NUtil.writeMessagesToRepository(serverName, tableName, repository, dataServer, application.getClientID(), messages, false, false, repositoryMessages, filterName, filterValue, application.getFoundSetManager());
            operationPerformed = true;
        } catch (Exception e) {
            Debug.error("exception when inserting new i18n key: " + newKey);
            Debug.error(e);
        // throw new RuntimeException(e);
        }
    }
    return operationPerformed;
}
Also used : IDataServer(com.servoy.j2db.dataprocessing.IDataServer) MessageEntry(com.servoy.j2db.persistence.I18NUtil.MessageEntry) IMessagesCallback(com.servoy.j2db.IMessagesCallback) I18NUtil(com.servoy.j2db.persistence.I18NUtil) IRepository(com.servoy.j2db.persistence.IRepository) TreeMap(java.util.TreeMap)

Aggregations

IMessagesCallback (com.servoy.j2db.IMessagesCallback)2 IDataServer (com.servoy.j2db.dataprocessing.IDataServer)1 I18NMessagesModelEntry (com.servoy.j2db.i18n.I18NMessagesModel.I18NMessagesModelEntry)1 I18NUtil (com.servoy.j2db.persistence.I18NUtil)1 MessageEntry (com.servoy.j2db.persistence.I18NUtil.MessageEntry)1 IRepository (com.servoy.j2db.persistence.IRepository)1 EventObject (java.util.EventObject)1 TreeMap (java.util.TreeMap)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1