blob: d28cb5caf6a5a1e7d840a80559775d2052ff1ad5 (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*******************************************************************************
* 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.MessagesEditor;
import org.eclipse.babel.editor.plugin.MessagesEditorPlugin;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
/**
* @author Pascal Essiembre
*
*/
public class DeleteKeyAction extends AbstractTreeAction {
/**
*
*/
public DeleteKeyAction(MessagesEditor editor, TreeViewer treeViewer) {
super(editor, treeViewer);
setText(MessagesEditorPlugin.getString("key.delete")); //$NON-NLS-1$
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
setToolTipText("TODO put something here"); // TODO put tooltip
// setActionDefinitionId("org.eclilpse.babel.editor.editor.tree.delete");
// setActionDefinitionId("org.eclipse.ui.edit.delete");
// editor.getSite().getKeyBindingService().registerAction(this);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
KeyTreeNode node = getNodeSelection();
String key = node.getMessageKey();
String msgHead = null;
String msgBody = null;
if (getContentProvider().hasChildren(node)) {
msgHead = MessagesEditorPlugin
.getString("dialog.delete.head.multiple"); //$NON-NLS-1$
msgBody = MessagesEditorPlugin.getString(
"dialog.delete.body.multiple", key);//$NON-NLS-1$
} else {
msgHead = MessagesEditorPlugin
.getString("dialog.delete.head.single"); //$NON-NLS-1$
msgBody = MessagesEditorPlugin.getString(
"dialog.delete.body.single", key); //$NON-NLS-1$
}
MessageBox msgBox = new MessageBox(getShell(), SWT.ICON_QUESTION
| SWT.OK | SWT.CANCEL);
msgBox.setMessage(msgBody);
msgBox.setText(msgHead);
if (msgBox.open() == SWT.OK) {
MessagesBundleGroup messagesBundleGroup = getBundleGroup();
KeyTreeNode[] nodesToDelete = getBranchNodes(node);
for (int i = 0; i < nodesToDelete.length; i++) {
KeyTreeNode nodeToDelete = nodesToDelete[i];
messagesBundleGroup
.removeMessages(nodeToDelete.getMessageKey());
}
}
}
}
|