KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > core > actions > SchemaSourceViewOpenAction


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.core.actions;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.xml.schema.core.SchemaDataObject;
24 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie;
25 import org.openide.ErrorManager;
26 import org.openide.actions.OpenAction;
27 import org.openide.cookies.OpenCookie;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Jeri Lockhart
34  */

35 public class SchemaSourceViewOpenAction extends OpenAction{
36     private static final long serialVersionUID = 1L;
37
38     /**
39      * SchemaSourceViewOpenAction is like OpenAction
40      * but also opens the source view to the line
41      * of the schema component
42      * The name of the action is Edit, not Open
43      *
44      * See SchemaViewOpenAction.java for the action named "Open"
45      *
46      *
47      */

48     public String JavaDoc getName() {
49         return NbBundle.getMessage(SchemaSourceViewOpenAction.class, "Edit");
50     }
51
52     protected void performAction(Node[] node) {
53         if (node == null || node[0] == null){
54             return;
55         }
56         SchemaDataObject sdo =
57                 (SchemaDataObject)node[0].getLookup().lookup(SchemaDataObject.class);
58         if(sdo!=null)
59         {
60             ViewComponentCookie svc = (ViewComponentCookie) sdo.getCookie(
61                     ViewComponentCookie.class);
62             if(svc!=null)
63             {
64                 try
65                 {
66                     svc.view(ViewComponentCookie.View.SOURCE,
67                             sdo.getSchemaEditorSupport().getModel().getSchema());
68                     return;
69                 }
70                 catch (IOException JavaDoc ex)
71                 {
72                     ErrorManager.getDefault().notify(ex);
73                 }
74             }
75         }
76         // default to open cookie
77
OpenCookie oc = (OpenCookie)node[0].getCookie(OpenCookie.class);
78         if (oc != null){
79             oc.open();
80         }
81     }
82 }
83
Popular Tags