KickJava   Java API By Example, From Geeks To Geeks.

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


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.schema.core.SchemaEditorSupport;
25 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie;
26 import org.openide.cookies.OpenCookie;
27 import org.openide.nodes.Node;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30 import org.openide.util.actions.NodeAction;
31
32 /**
33  * An action on the SchemaDataObject node (SchemaNode)
34  * to "Open" the schema multiview to the SchemaView tab
35  *
36  * @author Jeri Lockhart
37  */

38 public class SchemaViewOpenAction extends NodeAction{
39     private static final long serialVersionUID = 1L;
40     
41     /** Creates a new instance of SchemaViewOpenAction */
42     public SchemaViewOpenAction() {
43     }
44     
45     protected void performAction(Node[] node) {
46     if (node == null || node[0] == null){
47         return;
48     }
49     SchemaDataObject sdo = (SchemaDataObject)node[0].getLookup().lookup(SchemaDataObject.class);
50     if (sdo != null){
51         SchemaEditorSupport ses = sdo.getSchemaEditorSupport();
52         ViewComponentCookie svc = (ViewComponentCookie) sdo.getCookie(
53         ViewComponentCookie.class);
54         if(svc!=null) {
55         try {
56             if ( ses.getOpenedPanes()==null ||
57              ses.getOpenedPanes().length==0 ) {
58             
59             svc.view(ViewComponentCookie.View.STRUCTURE,
60                 sdo.getSchemaEditorSupport().getModel().getSchema());
61             } else {
62             ses.open();
63             }
64             return;
65         } catch (IOException JavaDoc ex) {
66             //ErrorManager.getDefault().notify(ex);
67
}
68         }
69     }
70     // default to open cookie
71
OpenCookie oc = (OpenCookie)node[0].getCookie(OpenCookie.class);
72     if (oc != null){
73         oc.open();
74     }
75     }
76     
77     protected boolean enable(Node[] node) {
78     return true;
79     }
80     
81     public String JavaDoc getName() {
82     return NbBundle.getMessage(SchemaViewOpenAction.class, "Open");
83     }
84     
85     public HelpCtx getHelpCtx() {
86     return HelpCtx.DEFAULT_HELP;
87     }
88     
89     protected boolean asynchronous() {
90     return false;
91     }
92     
93 }
94
Popular Tags