Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2d0273eb4a3d14de2a38629477a8cc8897ea6bcb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2007 Pascal Essiembre.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Pascal Essiembre - initial API and implementation
 ******************************************************************************/
package org.eclipse.babel.editor.tree.actions;

import org.eclipse.babel.core.message.internal.MessagesBundleGroup;
import org.eclipse.babel.core.message.tree.internal.KeyTreeNode;
import org.eclipse.babel.editor.internal.AbstractMessagesEditor;
import org.eclipse.babel.editor.plugin.MessagesEditorPlugin;
import org.eclipse.babel.editor.util.UIUtils;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;

/**
 * @author Pascal Essiembre
 * 
 */
public class AddKeyAction extends AbstractTreeAction {

    /**
     * 
     */
    public AddKeyAction(AbstractMessagesEditor editor, TreeViewer treeViewer) {
        super(editor, treeViewer);
        setText(MessagesEditorPlugin.getString("key.add") + " ..."); //$NON-NLS-1$
        setImageDescriptor(UIUtils.getImageDescriptor(UIUtils.IMAGE_ADD));
        setToolTipText("TODO put something here"); // TODO put tooltip
    }

    /**
     * @see org.eclipse.jface.action.Action#run()
     */
    @Override
    public void run() {
        KeyTreeNode node = getNodeSelection();
        String key = node.getMessageKey();
        String msgHead = MessagesEditorPlugin.getString("dialog.add.head");
        String msgBody = MessagesEditorPlugin.getString("dialog.add.body");
        InputDialog dialog = new InputDialog(getShell(), msgHead, msgBody, key,
                new IInputValidator() {
                    public String isValid(String newText) {
                        if (getBundleGroup().isMessageKey(newText)) {
                            return MessagesEditorPlugin
                                    .getString("dialog.error.exists");
                        }
                        return null;
                    }
                });
        dialog.open();
        if (dialog.getReturnCode() == Window.OK) {
            String inputKey = dialog.getValue();
            MessagesBundleGroup messagesBundleGroup = getBundleGroup();
            messagesBundleGroup.addMessages(inputKey);
        }
    }

}

Back to the top