KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > actions > InstantiateAction


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 package org.openide.actions;
21
22
23 import java.io.IOException JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.openide.loaders.DataObject;
26 import org.openide.nodes.Node;
27 import org.openide.util.*;
28 import org.openide.util.actions.NodeAction;
29
30 /** Instantiate a template.
31 * Enabled only when there is one selected node and
32 * it represents a data object satisfying {@link DataObject#isTemplate}.
33 *
34 * @author Jaroslav Tulach
35 *
36 * @deprecated Deprecated since 3.42. The use of this action should be avoided.
37 */

38 @Deprecated JavaDoc
39 public class InstantiateAction extends NodeAction {
40     /** generated Serialized Version UID */
41     static final long serialVersionUID = 1482795804240508824L;
42
43     protected boolean enable (Node[] activatedNodes) {
44         if (activatedNodes.length != 1) return false;
45         DataObject obj = (DataObject)activatedNodes[0].getCookie (DataObject.class);
46         return obj != null && obj.isTemplate ();
47     }
48
49     protected void performAction (Node[] activatedNodes) {
50         DataObject obj = (DataObject)activatedNodes[0].getCookie (DataObject.class);
51         if (obj != null && obj.isTemplate ()) {
52             try {
53                 instantiateTemplate (obj);
54             } catch (UserCancelException ex) {
55                 // canceled by user
56
// do not notify the exception
57
} catch (IOException JavaDoc ex) {
58                 Exceptions.printStackTrace(ex);
59             }
60         }
61     }
62
63     /* @return the name of the action
64     */

65     public String JavaDoc getName() {
66         return NbBundle.getMessage(org.openide.loaders.DataObject.class, "Instantiate");
67     }
68
69     public HelpCtx getHelpCtx () {
70         return new HelpCtx (InstantiateAction.class);
71     }
72
73     /** Instantiate a template object.
74     * Asks user for the target file's folder and creates the file.
75     * Then runs the node delegate's {@link org.openide.nodes.NodeOperation#customize customizer} (if there is one).
76     * Also the node's {@link Node#getDefaultAction default action}, if any, is run.
77     * @param obj the template to use
78     * @return set of created objects or null if user canceled the action
79     * @exception IOException on I/O error
80     * @see DataObject#createFromTemplate
81     */

82     public static Set JavaDoc<DataObject> instantiateTemplate(DataObject obj)
83     throws IOException JavaDoc {
84         // Create component for for file name input
85
return NewTemplateAction.getWizard (null).instantiate (obj);
86     }
87 }
88
Popular Tags