KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > navigation > actions > OpenAction


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  * OpenAction.java
21  *
22  * Created on September 24, 2004, 8:41 PM
23  */

24
25 package org.netbeans.modules.retouche.navigation.actions;
26
27 import java.awt.Container JavaDoc;
28 import java.awt.Point JavaDoc;
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.util.List JavaDoc;
32 import javax.swing.JEditorPane JavaDoc;
33 import org.openide.awt.*;
34 import org.openide.awt.StatusDisplayer;
35 import org.openide.cookies.*;
36 import org.openide.cookies.EditorCookie;
37 import org.openide.filesystems.FileObject;
38 import org.openide.loaders.DataObject;
39 import org.openide.nodes.*;
40 import org.openide.text.PositionBounds;
41 import org.openide.util.*;
42 import javax.swing.*;
43 import java.awt.event.*;
44 import org.netbeans.api.gsf.Element;
45 import org.netbeans.api.gsf.ElementHandle;
46 import org.netbeans.api.retouche.source.Source;
47 import org.netbeans.api.retouche.source.UiUtils;
48 import org.openide.loaders.DataObjectNotFoundException;
49 import org.openide.windows.TopComponent;
50
51 /**
52  * This file is originally from Retouche, the Java Support
53  * infrastructure in NetBeans. I have modified the file as little
54  * as possible to make merging Retouche fixes back as simple as
55  * possible.
56  * <p>
57  *
58  * An action that opens editor and jumps to the element given in constructor.
59  * Similar to editor's go to declaration action.
60  *
61  * @author tim, Dafe Simonek
62  */

63 public final class OpenAction extends AbstractAction {
64     
65     private ElementHandle<? extends Element> elementHandle;
66     private FileObject fileObject;
67       
68     public OpenAction( ElementHandle<? extends Element> elementHandle, FileObject fileObject ) {
69         this.elementHandle = elementHandle;
70         this.fileObject = fileObject;
71         putValue ( Action.NAME, NbBundle.getMessage ( OpenAction.class, "LBL_Goto" ) ); //NOI18N
72
}
73     
74     public void actionPerformed (ActionEvent ev) {
75         ElementHandle handle = elementHandle;
76         try {
77             DataObject activeFile = DataObject.find(fileObject);
78
79             if ((activeFile != null) && (handle != null)) {
80                 Source js =
81                     Source.forFileObject(activeFile.getPrimaryFile());
82
83                 if (js != null) {
84                     UiUtils.open(js, handle);
85                 }
86             }
87         } catch (DataObjectNotFoundException dnfe) {
88             Exceptions.printStackTrace(dnfe);
89         }
90     }
91
92     public boolean isEnabled () {
93           return true;
94     }
95
96     
97 }
98
Popular Tags