1 19 20 package org.netbeans.modules.xml.schema.abe; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Color ; 24 import java.awt.Component ; 25 import java.awt.Cursor ; 26 import java.awt.dnd.DropTargetDragEvent ; 27 import java.awt.dnd.DropTargetDropEvent ; 28 import java.awt.dnd.DropTargetEvent ; 29 import java.awt.event.MouseAdapter ; 30 import java.awt.event.MouseEvent ; 31 import java.beans.PropertyChangeEvent ; 32 import java.beans.PropertyChangeListener ; 33 import java.io.IOException ; 34 import java.lang.ref.WeakReference ; 35 import java.util.ArrayList ; 36 import java.util.LinkedList ; 37 import java.util.List ; 38 import javax.swing.Action ; 39 import javax.swing.JPanel ; 40 import javax.swing.JScrollPane ; 41 import javax.swing.SwingUtilities ; 42 import org.netbeans.modules.xml.axi.AXIComponent; 43 import org.netbeans.modules.xml.axi.AXIDocument; 44 import org.netbeans.modules.xml.axi.AXIModel; 45 import org.netbeans.modules.xml.axi.ContentModel; 46 import org.netbeans.modules.xml.axi.Element; 47 import org.netbeans.modules.xml.schema.abe.nodes.ABEAbstractNode; 48 import org.netbeans.modules.xml.schema.model.SchemaComponent; 49 import org.netbeans.modules.xml.schema.model.SchemaModel; 50 import org.netbeans.spi.palette.PaletteActions; 51 import org.netbeans.spi.palette.PaletteController; 52 import org.netbeans.spi.palette.PaletteFactory; 53 import org.openide.ErrorManager; 54 import org.openide.loaders.DataObject; 55 import org.openide.util.Lookup; 56 import org.openide.util.NbBundle; 57 import org.openide.windows.TopComponent; 58 59 63 public class InstanceDesignerPanel extends ABEBaseDropPanel { 64 public static final int EXPAND_BY_DEFAULT_LIMIT = 50; 65 private static final long serialVersionUID = 7526472295622776147L; 66 70 public InstanceDesignerPanel(AXIModel axiModel, DataObject schemaDataObject, TopComponent tc) { 71 this(axiModel, schemaDataObject, tc, new InstanceUIContext()); 72 } 73 74 private InstanceDesignerPanel(AXIModel axiModel, DataObject schemaDataObject, TopComponent tc, InstanceUIContext context) { 75 super(context); 76 this.axiModel = axiModel; 77 context.initialize(tc, schemaDataObject, this, getPaletteController()); 78 initComponents(); 79 initialize(); 80 initMouseListener(); 81 } 82 83 87 private void initialize() { 88 initComponents(); 89 JPanel wrapperPanel = new JPanel (new BorderLayout ()); 90 wrapperPanel.setOpaque(true); 91 wrapperPanel.setBackground(new Color (252, 250, 245)); 92 93 104 105 namespacePanel = new NamespacePanel(context); 106 add(getNamespacePanel(), BorderLayout.NORTH); 107 109 boolean expand = getAXIModel().getRoot().getElements().size() > EXPAND_BY_DEFAULT_LIMIT ? false : true; 110 globalElementsChildrenPanel = new GlobalElementsContainerPanel( 111 getUIContext(), getAXIModel().getRoot(), expand); 112 TitleWrapperPanel geWrapper = new TitleWrapperPanel(globalElementsChildrenPanel, 113 globalElementsStr, getAXIModel().getRoot(), expand, context){ 114 private static final long serialVersionUID = 7526472295622776147L; 115 public int getChildrenItemsCount() { 116 return getAXIModel().getRoot().getElements().size(); 117 } 118 }; 119 wrapperPanel.add(geWrapper, BorderLayout.NORTH); 120 121 expand = getAXIModel().getRoot().getContentModels().size() > 0 ? false : true; 122 globalComplextypeChildrenPanel = new GlobalComplextypeContainerPanel( 123 getUIContext(), getAXIModel().getRoot(), expand); 124 TitleWrapperPanel gcWrapper = new TitleWrapperPanel(globalComplextypeChildrenPanel, 125 globalComplexTypesStr, getAXIModel().getRoot(), expand, context){ 126 private static final long serialVersionUID = 7526472295622776147L; 127 public int getChildrenItemsCount() { 128 int count = 0; 129 for(ContentModel cm: getAXIModel().getRoot().getContentModels()){ 130 if(cm.getType() == cm.getType().COMPLEX_TYPE) 131 count++; 132 } 133 return count; 134 } 135 }; 136 wrapperPanel.add(gcWrapper, BorderLayout.CENTER); 137 138 JScrollPane scrollPane=new JScrollPane (wrapperPanel); 139 context.setInstanceDesignerScrollPane(scrollPane); 140 scrollPane.getVerticalScrollBar().setUnitIncrement(20); 141 scrollPane.setBorder(null); 142 scrollPane.setViewportBorder(null); 143 scrollPane.setAutoscrolls(true); 144 add(scrollPane,BorderLayout.CENTER); 145 146 147 context.getComponentSelectionManager().setSelectedComponent(namespacePanel); 148 149 context.setFocusTraversalManager(new FocusTraversalManager(context)); 150 } 151 152 153 private static String globalElementsStr = NbBundle.getMessage(InstanceDesignerPanel.class,"" + 154 "LBL_GLOBAL_ELEMENTS"); 155 private static String globalComplexTypesStr = NbBundle.getMessage(InstanceDesignerPanel.class,"" + 156 "LBL_GLOBAL_COMPLEXTYPES"); 157 158 159 160 164 private void initComponents() { 166 167 setLayout(new java.awt.BorderLayout ()); 168 169 setBackground(java.awt.Color.white); 170 } 172 173 177 public SchemaModel getSchemaModel() { 178 return schemaModel; 179 } 180 181 182 186 public InstanceUIContext getUIContext() { 187 return context; 188 } 189 190 191 195 public synchronized PaletteController getPaletteController() { 196 if (paletteController!=null) 197 return paletteController; 198 199 PaletteActions actions= 200 new PaletteActionsImpl(); 201 202 try { 203 paletteController= 204 PaletteFactory.createPalette("xmlschema-abe-palette",actions); 205 } catch (IOException e) { 206 ErrorManager.getDefault().notify(e); 207 } 208 return paletteController; 209 } 210 211 public AXIModel getAXIModel() { 212 return axiModel; 213 } 214 215 public NamespacePanel getNamespacePanel() { 216 return namespacePanel; 217 } 218 219 220 221 public void selectUIComponent(AXIComponent axiComponent){ 222 this.setCursor(new Cursor (Cursor.WAIT_CURSOR)); 223 try{ 224 ABEBaseDropPanel uiComp = null; 225 if(axiComponent == null){ 226 uiComp = namespacePanel; 227 }else{ 228 LinkedList <AXIComponent> path = new LinkedList <AXIComponent>(); 230 AXIComponent current = axiComponent; 231 path.addFirst(current); 232 while( (current != null) && !(current.getParent() instanceof AXIDocument) ){ 233 current = current.getParent(); 234 path.addFirst(current); 235 } 236 current = path.getFirst(); 238 239 if(current instanceof Element){ 240 uiComp = globalElementsChildrenPanel.getChildUIComponentFor(current); 242 }else if(current instanceof ContentModel){ 243 uiComp = globalComplextypeChildrenPanel.getChildUIComponentFor(current); 245 } 246 if(uiComp == null) 247 return; 248 path.removeFirst(); 249 for(AXIComponent comp: path){ 250 ABEBaseDropPanel cur = uiComp.getChildUIComponentFor(comp); 251 if(cur == null) 252 return; 253 uiComp = cur; 254 } 255 } 256 context.getComponentSelectionManager().setSelectedComponent(uiComp); 257 final ABEBaseDropPanel ftemp = uiComp; 258 SwingUtilities.invokeLater(new Runnable (){ 259 public void run() { 260 UIUtilities.scrollViewTo(ftemp, context); 261 } 262 }); 263 }finally{ 264 this.setCursor(new Cursor (Cursor.DEFAULT_CURSOR)); 265 } 266 } 267 268 269 public void selectUIComponent(org.netbeans.modules.xml.xam.Component component) { 270 if(component == null){ 271 selectUIComponent(null); 272 return; 273 } 274 if(component instanceof AXIComponent) 275 selectUIComponent((AXIComponent)component); 276 else { 277 AXIComponent axiComp = null; 278 try{ 279 axiComp = UIUtilities.findMatchingAXIComponent((SchemaComponent) component); 280 }catch (Exception e){} 281 selectUIComponent(axiComp); 282 } 283 } 284 285 public GlobalElementsContainerPanel getGlobalElementsPanel() { 286 return globalElementsChildrenPanel; 287 } 288 289 public GlobalComplextypeContainerPanel getGlobalComplextypePanel() { 290 return globalComplextypeChildrenPanel; 291 } 292 293 301 302 public void accept(UIVisitor visitor) { 303 } 305 306 public ABEAbstractNode getNBNode() { 307 return context.getNamespacePanel().getNBNode(); 309 } 310 311 312 313 protected void initMouseListener(){ 314 addMouseListener(new MouseAdapter () { 315 public void mouseReleased(MouseEvent e) { 316 mouseClickedActionHandler(e); 317 } 318 public void mouseClicked(MouseEvent e){ 319 mouseClickedActionHandler(e); 320 } 321 322 public void mousePressed(MouseEvent e) { 323 mouseClickedActionHandler(e); 324 } 325 326 }); 327 } 328 329 330 protected void mouseClickedActionHandler(MouseEvent e){ 331 if(e.getClickCount() == 1){ 332 if(e.isPopupTrigger()){ 333 context.getMultiComponentActionManager().showPopupMenu(e, this); 334 return; 335 } 336 } 337 context.getComponentSelectionManager().setSelectedComponent(this); 339 } 340 341 public void drop(DropTargetDropEvent event) { 342 getNamespacePanel().drop(event); 343 } 344 345 public void dragExit(DropTargetEvent event) { 346 getNamespacePanel().dragExit(event); 347 } 348 349 public void dragEnter(DropTargetDragEvent event) { 350 getNamespacePanel().dragEnter(event); 351 } 352 353 public void dragOver(DropTargetDragEvent event) { 354 getNamespacePanel().dragOver(event); 355 } 356 357 public void shutdown() { 358 context.shutdown(); 359 context = null; 360 } 361 362 363 367 370 private SchemaModel schemaModel; 371 private AXIModel axiModel; 372 private PaletteController paletteController; 373 GlobalElementsContainerPanel globalElementsChildrenPanel; 374 List <Component > childrenList = new ArrayList <Component >(); 375 NamespacePanel namespacePanel; 376 GlobalComplextypeContainerPanel globalComplextypeChildrenPanel; 377 } 380 381 class PaletteActionsImpl extends PaletteActions { 382 public Action [] getImportActions() { 383 return new Action [0]; 384 } 385 386 public Action [] getCustomPaletteActions() { 387 return new Action [0]; 388 } 389 390 public Action [] getCustomCategoryActions(Lookup lookup) { 391 return new Action [0]; 392 } 393 394 public Action [] getCustomItemActions(Lookup lookup) { 395 return new Action [0]; 396 } 397 398 public Action getPreferredAction(Lookup lookup) { 399 return null; 400 } 401 402 } 403 404 405 | Popular Tags |