KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > LangRenameAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.properties;
22
23
24 import java.text.MessageFormat JavaDoc;
25
26 import org.openide.actions.RenameAction;
27 import org.openide.nodes.Node;
28 import org.openide.NotifyDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.util.NbBundle;
31
32
33 /**
34  * Renames a <code>PropertiesLocaleNode</code> node,
35  * i.e. one locale (=locale suffix of one properties file)
36  * belonging to certain bundle of properties files.
37  *
38  * @author Petr Jiricka
39  * @see Node#setName
40  */

41 public class LangRenameAction extends RenameAction {
42
43     /** Generated serial version UID. */
44     static final long serialVersionUID =-6548687347804513177L;
45     
46
47     /** Performs action. Overrides superclass method. */
48     protected void performAction (Node[] activatedNodes) {
49         Node n = activatedNodes[0]; // we supposed that one node is activated
50
Node.Cookie cake = n.getCookie(PropertiesLocaleNode.class);
51         PropertiesLocaleNode pln = (PropertiesLocaleNode)cake;
52
53         String JavaDoc lang = Util.getLocaleSuffix(pln.getFileEntry());
54         if (lang.length() > 0)
55             if (lang.charAt(0) == PropertiesDataLoader.PRB_SEPARATOR_CHAR)
56                 lang = lang.substring(1);
57
58         NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
59         NbBundle.getMessage(LangRenameAction.class,
60                     "LBL_RenameLabel"), //NOI18N
61
NbBundle.getMessage(LangRenameAction.class,
62                     "LBL_RenameTitle")); //NOI18N
63

64         dlg.setInputText(lang);
65         if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
66             try {
67                 pln.setName(Util.assembleName (pln.getFileEntry().getDataObject().getPrimaryFile().getName(), dlg.getInputText()));
68             }
69             catch (IllegalArgumentException JavaDoc e) {
70                 // catch & report badly formatted names
71
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
72                     MessageFormat.format(
73                         NbBundle.getBundle("org.openide.actions.Bundle").getString("MSG_BadFormat"),
74                         new Object JavaDoc[] {pln.getName()}),
75                     NotifyDescriptor.ERROR_MESSAGE);
76                         
77                 DialogDisplayer.getDefault().notify(msg);
78             }
79         }
80     }
81 }
82
Popular Tags