blob: bc4ff39433817d41260bfb45ed7dde2d7a160e2c (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*******************************************************************************
* 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
* Matthias Lettmayer - implemented action and created dialog
******************************************************************************/
package org.eclipse.babel.editor.actions;
import java.util.Locale;
import org.eclipse.babel.core.message.internal.MessagesBundleGroup;
import org.eclipse.babel.editor.internal.MessagesEditor;
import org.eclipse.babel.editor.util.UIUtils;
import org.eclipse.babel.editor.widgets.LocaleSelector;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* @author Pascal Essiembre
*
*/
public class NewLocaleAction extends Action {
private MessagesEditor editor;
/**
*
*/
public NewLocaleAction() {
super("New &Locale...");
setToolTipText("Add a new locale to the resource bundle.");
setImageDescriptor(UIUtils
.getImageDescriptor(UIUtils.IMAGE_NEW_PROPERTIES_FILE));
}
// TODO RBEditor hold such an action registry. Then move this method to
// constructor
public void setEditor(MessagesEditor editor) {
this.editor = editor;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
// created choose locale dialog
Dialog localeDialog = new Dialog(editor.getSite().getShell()) {
LocaleSelector selector;
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Add new local");
}
@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
selector = new LocaleSelector(comp);
return comp;
}
@Override
protected void okPressed() {
// add local to bundleGroup
MessagesBundleGroup bundleGroup = editor.getBundleGroup();
Locale newLocal = selector.getSelectedLocale();
// exists local already?
boolean existsLocal = false;
Locale[] locales = bundleGroup.getLocales();
for (Locale locale : locales) {
if (locale == null) {
if (newLocal == null) {
existsLocal = true;
break;
}
} else if (locale.equals(newLocal)) {
existsLocal = true;
break;
}
}
if (!existsLocal)
bundleGroup.addMessagesBundle(newLocal);
super.okPressed();
}
};
// open dialog
localeDialog.open();
}
}
|