KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > XMLRefactoringElement


1 /*
2  * XMLRefactoringElement.java
3  *
4  * Created on December 30, 2006, 4:41 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.xml.refactoring;
11
12 import java.awt.event.ActionEvent JavaDoc;
13 import javax.swing.Action JavaDoc;
14 import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImpl;
15 import org.netbeans.modules.refactoring.spi.ui.UI;
16 import org.netbeans.modules.xml.refactoring.spi.RefactoringEngine;
17 import org.netbeans.modules.xml.refactoring.spi.UIHelper;
18 import org.netbeans.modules.xml.xam.Component;
19 import org.netbeans.modules.xml.xam.Referenceable;
20 import org.openide.filesystems.FileObject;
21 import org.openide.nodes.Node;
22 import org.openide.text.PositionBounds;
23
24 /**
25  *
26  * @author Sonali
27  */

28 public class XMLRefactoringElement extends SimpleRefactoringElementImpl {
29     
30     Usage usage;
31     Node node;
32     
33     /**
34      * Creates a new instance of XMLRefactoringElement
35      */

36     public XMLRefactoringElement(Usage u) {
37         this.usage=u;
38         Component comp = usage.getComponent();
39         //UIHelper engine = usage.getContainer().getEngine().getUIHelper();
40
try {
41             node = usage.getContainer().getEngine().getUIHelper().getDisplayNode(comp);
42        } catch(NullPointerException JavaDoc e){
43            
44        }
45     }
46
47     public String JavaDoc getText() {
48         if(node != null)
49             return node.getName();
50         else
51             return "";
52     }
53
54     public String JavaDoc getDisplayText() {
55         if(node != null)
56             return node.getHtmlDisplayName();
57         else
58             return "";
59       
60        
61     }
62
63     public void performChange() {
64     }
65
66     public Object JavaDoc getComposite() {
67         return usage;
68         //return null;
69
}
70
71     public FileObject getParentFile() {
72         return usage.getContainer().getFileObject();
73     }
74
75     public PositionBounds getPosition() {
76         return null;
77     }
78     
79      public void showPreview() {
80         //UI.setComponentForRefactoringPreview(null);
81
}
82      
83      public void openInEditor(){
84          if(node != null ) {
85              Action JavaDoc preferredAction = node.getPreferredAction();
86              if (preferredAction != null) {
87              String JavaDoc command = (String JavaDoc)preferredAction.getValue(Action.ACTION_COMMAND_KEY);
88              ActionEvent JavaDoc ae = new ActionEvent JavaDoc(node, 0, command);
89              preferredAction.actionPerformed(ae);
90             }
91          }
92      
93      }
94          
95          
96      
97     
98 }
99
Popular Tags