Search in sources :

Example 1 with MessagesStore

use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.

the class Translator2 method saveFiles.

protected boolean saveFiles() {
    java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
    if (changedMessagesStores.size() > 0) {
        StringBuilder msg = new StringBuilder();
        for (MessagesStore messagesStore : changedMessagesStores) {
            String filename = messagesStore.getSaveFilename(messagesStore.getSourceFolder());
            messagesStore.setFilename(filename);
            msg.append(messagesStore.getFilename());
            if (!new File(filename).exists()) {
                msg.append(" (NEW!)");
            }
            msg.append(Const.CR);
        }
        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "i18nDialog.ChangedFiles"), BaseMessages.getString(PKG, "i18nDialog.ChangedMessagesFiles"), msg.toString());
        if (dialog.open() != null) {
            try {
                for (MessagesStore messagesStore : changedMessagesStores) {
                    messagesStore.write();
                    log.logBasic(BaseMessages.getString(PKG, "i18n.Log.SavedMessagesFile", messagesStore.getFilename()));
                }
            } catch (KettleException e) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
                return false;
            }
            return true;
        } else {
            return false;
        }
    } else {
        // TODO: disable the button if nothing changed.
        return true;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) File(java.io.File) MessagesStore(org.pentaho.di.ui.i18n.MessagesStore)

Example 2 with MessagesStore

use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.

the class Translator2 method saveFilesToZip.

protected void saveFilesToZip() {
    if (saveFiles()) {
        java.util.List<MessagesStore> messagesStores = store.getMessagesStores(selectedLocale, null);
        if (messagesStores.size() > 0) {
            StringBuilder msg = new StringBuilder();
            for (MessagesStore messagesStore : messagesStores) {
                // Find the main locale variation for this messages store...
                // 
                MessagesStore mainLocaleMessagesStore = store.findMainLocaleMessagesStore(messagesStore.getSourceFolder(), messagesStore.getMessagesPackage());
                String sourceDirectory = mainLocaleMessagesStore.getSourceDirectory(rootDirectories);
                String filename = messagesStore.getSaveFilename(sourceDirectory);
                messagesStore.setFilename(filename);
                msg.append(filename).append(Const.CR);
            }
            // Ask for the target filename if we're still here...
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.zip", "*" });
            dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.ZIPFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
            if (dialog.open() != null) {
                String zipFilename = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                try {
                    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename));
                    byte[] buf = new byte[1024];
                    for (MessagesStore messagesStore : messagesStores) {
                        FileInputStream in = new FileInputStream(messagesStore.getFilename());
                        out.putNextEntry(new ZipEntry(messagesStore.getFilename()));
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        out.closeEntry();
                        in.close();
                    }
                    out.close();
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
                }
            }
        }
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) MessagesStore(org.pentaho.di.ui.i18n.MessagesStore) FileInputStream(java.io.FileInputStream) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) SourceCrawlerPackageException(org.pentaho.di.ui.i18n.SourceCrawlerPackageException) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 3 with MessagesStore

use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.

the class Translator2 method quitFile.

public boolean quitFile() {
    java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
    if (changedMessagesStores.size() > 0) {
        MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "i18nDialog.ChangedFilesWhenExit", changedMessagesStores.size() + ""));
        mb.setText(BaseMessages.getString(PKG, "i18nDialog.Warning"));
        int answer = mb.open();
        if (answer == SWT.NO) {
            return false;
        }
    }
    WindowProperty winprop = new WindowProperty(shell);
    props.setScreen(winprop);
    props.saveProps();
    shell.dispose();
    display.dispose();
    return true;
}
Also used : WindowProperty(org.pentaho.di.ui.core.gui.WindowProperty) MessagesStore(org.pentaho.di.ui.i18n.MessagesStore) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 4 with MessagesStore

use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.

the class Translator2 method searchAgain.

protected void searchAgain(String searchLocale) {
    if (searchString != null) {
        // We want to search for key in the list here...
        // That means we'll enter a String to search for in the values
        // 
        String upperSearchString = searchString.toUpperCase();
        boolean lastKeyFound = lastFoundKey == null;
        // Search through all the main locale messages stores for the selected
        // package
        // 
        java.util.List<MessagesStore> mainLocaleMessagesStores = store.getMessagesStores(searchLocale, selectedMessagesPackage);
        for (MessagesStore messagesStore : mainLocaleMessagesStores) {
            for (String key : messagesStore.getMessagesMap().keySet()) {
                String value = messagesStore.getMessagesMap().get(key);
                String upperValue = value.toUpperCase();
                if (upperValue.indexOf(upperSearchString) >= 0) {
                    // 
                    if (lastKeyFound) {
                        int index = wTodo.indexOf(key);
                        if (index >= 0) {
                            lastFoundKey = key;
                            wTodo.setSelection(index);
                            showKeySelection(wTodo.getSelection()[0]);
                            return;
                        }
                    }
                    if (key.equals(lastFoundKey)) {
                        lastKeyFound = true;
                    }
                }
            }
        }
    }
}
Also used : MessagesStore(org.pentaho.di.ui.i18n.MessagesStore)

Aggregations

MessagesStore (org.pentaho.di.ui.i18n.MessagesStore)4 KettleException (org.pentaho.di.core.exception.KettleException)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)1 WindowProperty (org.pentaho.di.ui.core.gui.WindowProperty)1 SourceCrawlerPackageException (org.pentaho.di.ui.i18n.SourceCrawlerPackageException)1