1 19 package org.netbeans.modules.java.editor.codegen.ui; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.util.List ; 24 import javax.lang.model.element.Element; 25 import javax.swing.text.JTextComponent ; 26 import org.netbeans.api.java.source.ElementHandle; 27 import org.netbeans.modules.java.editor.codegen.DelegateMethodGenerator; 28 import org.openide.explorer.ExplorerManager; 29 import org.openide.util.NbBundle; 30 31 35 public class DelegatePanel extends javax.swing.JPanel implements PropertyChangeListener { 36 37 private JTextComponent component; 38 private ElementSelectorPanel delegateSelector; 39 private ElementSelectorPanel methodSelector; 40 41 42 public DelegatePanel(JTextComponent component, ElementNode.Description description) { 43 this.component = component; 44 initComponents(); 45 delegateSelector = new ElementSelectorPanel(description, false); 46 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 47 gridBagConstraints.gridx = 0; 48 gridBagConstraints.gridy = 1; 49 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 50 gridBagConstraints.weightx = 0.5; 51 gridBagConstraints.weighty = 1.0; 52 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 53 add(delegateSelector, gridBagConstraints); 54 delegateSelector.getExplorerManager().addPropertyChangeListener(this); 55 56 methodSelector = new ElementSelectorPanel(null, false); 57 gridBagConstraints = new java.awt.GridBagConstraints (); 58 gridBagConstraints.gridx = 1; 59 gridBagConstraints.gridy = 1; 60 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 61 gridBagConstraints.weightx = 0.5; 62 gridBagConstraints.weighty = 1.0; 63 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 64 add(methodSelector, gridBagConstraints); 65 66 delegateLabel.setText(NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_field_select")); delegateLabel.setLabelFor(delegateSelector); 68 methodLabel.setText(NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_method_select")); methodLabel.setLabelFor(methodSelector); 70 71 72 delegateSelector.doInitialExpansion(1); 73 } 74 75 public ElementHandle<? extends Element> getDelegateField() { 76 List <ElementHandle<? extends Element>> handles = delegateSelector.getTreeSelectedElements(); 77 return handles.size() == 1 ? handles.get(0) : null; 78 } 79 80 public List <ElementHandle<? extends Element>> getDelegateMethods() { 81 return ((ElementSelectorPanel)methodSelector).getSelectedElements(); 82 } 83 84 89 private void initComponents() { 91 java.awt.GridBagConstraints gridBagConstraints; 92 93 delegateLabel = new javax.swing.JLabel (); 94 methodLabel = new javax.swing.JLabel (); 95 96 setFocusable(false); 97 setLayout(new java.awt.GridBagLayout ()); 98 gridBagConstraints = new java.awt.GridBagConstraints (); 99 gridBagConstraints.gridx = 0; 100 gridBagConstraints.gridy = 0; 101 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 102 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 103 gridBagConstraints.insets = new java.awt.Insets (12, 12, 6, 12); 104 add(delegateLabel, gridBagConstraints); 105 gridBagConstraints = new java.awt.GridBagConstraints (); 106 gridBagConstraints.gridx = 1; 107 gridBagConstraints.gridy = 0; 108 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 109 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 110 gridBagConstraints.weightx = 0.5; 111 gridBagConstraints.insets = new java.awt.Insets (12, 0, 6, 12); 112 add(methodLabel, gridBagConstraints); 113 } 115 public void propertyChange(PropertyChangeEvent evt) { 116 if ( ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) ) { 117 ElementHandle<? extends Element> handle = getDelegateField(); 118 methodSelector.setRootElement(handle == null ? null : DelegateMethodGenerator.getAvailableMethods(component, handle), false); 119 methodSelector.doInitialExpansion(-1); 120 } 121 } 122 123 public javax.swing.JLabel delegateLabel; 125 public javax.swing.JLabel methodLabel; 126 } 128 | Popular Tags |